2022-05-20 20:32:39 +08:00

93 lines
3.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Text, View } from "@tarojs/components"
import styles from './index.module.scss'
import classnames from "classnames";
import { useCallback, useMemo, useRef, useState } from "react";
import ShipmentMode from "./components/shipmentMode";
import AddressList from "@/components/AddressList";
import { alert, goLink } from "@/common/common";
import { getParam } from "@/common/system";
import {EditSaleOrderAddressApi, EditSaleOrderShipmentModeApi} from "@/api/order";
import Taro from "@tarojs/taro";
export default () => {
//获取临时传递的数据
const params = getParam()
const [paramsData, setParamsData] = useState<any>(params)
//提交的数据
const [submitData, setSubmitData] = useState({
address_id:0,
id:params.id,
shipment_mode: params.shipment_mode
})
//格式化地址
const address = useMemo(() => {
return paramsData.province_name+' '+paramsData.city_name+' '+paramsData.district_name+' '+paramsData.address_detail
}, [paramsData])
//获取收货方法
const getShipmentMode = useCallback((num) => {
setSubmitData((val) => ({...val, shipment_mode:num}))
}, [])
//获取地址
const getSelectAddress = useCallback((e) => {
setSubmitData((val) => ({...val, address_id:e.id}))
}, [])
//修改请求
const {fetchData: addressFetchData} = EditSaleOrderAddressApi()
const {fetchData: shipmentFetchData} = EditSaleOrderShipmentModeApi()
const editData = async () => {
if(submitData.address_id) {
let res = await addressFetchData(submitData)
if(!res.success) {
alert.error(res.msg)
return false
}
}
let res = await shipmentFetchData(submitData)
if(!res.success) {
alert.error(res.msg)
return false
}
Taro.navigateBack()
}
return (
<View className={styles.order_edit_main}>
<View className={classnames(styles.title_msg)}>
<Text className={classnames(styles.miconfont, 'iconfont icon-zhuyi')}></Text>
<View className={styles.title_msg_con}>
<Text></Text>
<Text></Text>
</View>
</View>
<View className={styles.shipmentMode_con}>
<ShipmentMode onSelect={getShipmentMode} defaultValue={paramsData.shipment_mode}/>
</View>
<View className={styles.old_address}>
<Text className={styles.old_address_text}>:</Text>
<Text className={styles.old_address_text}>{address}</Text>
<View className={styles.userInfo}>
<Text className={styles.userInfo_text}>{paramsData.name}</Text>
<Text className={styles.userInfo_text}>{paramsData.phone}</Text>
</View>
</View>
<View className={styles.select_address_con}>
<View className={styles.title}></View>
<View className={styles.address_list}>
<AddressList focusBorderEnabled={true} addButtonEnabled={false} onSelect={getSelectAddress}/>
</View>
<View className={styles.submitBtn}>
<View onClick={() => goLink('/pages/addressAdd/index', {type:'add'})} className={classnames(styles.addAddress, styles.addressBtn)}></View>
<View className={classnames(styles.submitUpdate, styles.addressBtn)} onClick={() => editData()}></View>
</View>
</View>
<View className="common_safe_area_y"></View>
</View>
)
}