订单列表对接

This commit is contained in:
2022-05-26 17:32:59 +08:00
parent 1367c0f654
commit e73bd1bc25
10 changed files with 271 additions and 120 deletions
@@ -1,3 +1,6 @@
import { EditSaleOrderAddressApi, EditSaleOrderShipmentModeApi } from "@/api/order";
import { alert } from "@/common/common";
import { debounce } from "@/common/util";
import AddressList from "@/components/AddressList";
import Popup from "@/components/popup";
import { Text, View } from "@tarojs/components"
@@ -12,29 +15,25 @@ export type AddressInfoParam = {
address_detail: string,
id?: number,
name: string,
phone: string
phone: string,
}
type Param = {
onSelect?: (val:any) => void, //选择
defaultValue?: AddressInfoParam|null //默认值
disabled?: false|true //true禁用后只用于展示
shipment_mode?: 1|2 //1自提 2物流
defaultValue?: AddressInfoParam|null, //默认值
disabled?: false|true, //true禁用后只用于展示
shipment_mode?: 1|2, //1自提 2物流
onChangeShipmentMode?: (val: number) => void, //返回收货方式
orderId?: number //订单id
}
export default memo(forwardRef(({onSelect, defaultValue = null, disabled = false, shipment_mode = 1}: Param, ref) => {
export default memo(forwardRef(({onSelect, onChangeShipmentMode, defaultValue = null, orderId = 0, shipment_mode = 1}: Param, ref) => {
const [showAddressList, setShowAddressList] = useState(false)
useEffect(() => {
setUserInfo(() => defaultValue)
}, [defaultValue])
//选择地址
const [userInfo, setUserInfo] = useState<any>()
const getAddress = useCallback((val) => {
setShowAddressList(() => false)
setUserInfo(() => val)
onSelect?.(val)
}, [])
//地址格式
const formatAddress = useMemo(() => {
@@ -46,13 +45,7 @@ export default memo(forwardRef(({onSelect, defaultValue = null, disabled = false
if(receivingStatus == 2)
setShowAddressList(() => true)
}
//收货方法,1:自提,2物流
const [receivingStatus, setReceivingStatus] = useState(1)
const onReceivingStatus = (val, e) => {
e.stopPropagation()
setReceivingStatus(val)
console.log("e::::", e)
}
useEffect(() => {
setReceivingStatus(() => shipment_mode)
}, [shipment_mode])
@@ -61,6 +54,41 @@ export default memo(forwardRef(({onSelect, defaultValue = null, disabled = false
useImperativeHandle(ref, () => ({
changeShow
}))
//收货方法,1:自提,2物流
const [receivingStatus, setReceivingStatus] = useState(1)
const {fetchData: shipmentModeFetchData} = EditSaleOrderShipmentModeApi()
const onReceivingStatus = (value, e) => {
e.stopPropagation()
changeReceivingStatus(value)
}
const changeReceivingStatus = debounce(async (value) => {
alert.loading('正在修改')
const res = await shipmentModeFetchData({id: orderId, shipment_mode:value})
if(res.success) {
alert.success('修改成功')
onChangeShipmentMode?.(value)
setReceivingStatus(value)
} else {
alert.none(res.msg)
}
}, 10)
//修改地址
const {fetchData: addressFetchData} = EditSaleOrderAddressApi()
const getAddress = async (value) => {
alert.loading('正在修改')
setShowAddressList(() => false)
setUserInfo(() => value)
const res = await addressFetchData({id: orderId, address_id: value.id})
if(res.success) {
alert.success('修改成功')
onSelect?.(value)
} else {
alert.none(res.msg)
}
}
return (
<View>
<View className={styles.order_address} onClick={() => changeShow()}>
@@ -86,7 +114,7 @@ export default memo(forwardRef(({onSelect, defaultValue = null, disabled = false
<Popup show={showAddressList} showTitle={false} onClose={() => setShowAddressList(false)}>
<View className={styles.order_address_list}>
<View className={styles.order_address_title}>请选择收货地址</View>
<AddressList onSelect={(item) => getAddress(item)}/>
<AddressList onSelect={getAddress}/>
</View>
</Popup>
</View>
+26 -21
View File
@@ -8,6 +8,7 @@ import { alert } from "@/common/common";
import { formatImgUrl } from "@/common/fotmat";
import useCheckAuthorize from "@/use/useCheckAuthorize";
import { GetPayCode } from "@/api/onlinePay";
import LoadingCard from "@/components/loadingCard";
type Param = {
@@ -58,7 +59,7 @@ export default memo(({show = true, onClose}:Param) => {
filePath: '',
base64: ''
})
const {fetchData} = GetPayCode()
const {fetchData, state} = GetPayCode()
const getCore = async () => {
let res = await fetchData({
title: "面料销售电子确认单",
@@ -80,7 +81,7 @@ export default memo(({show = true, onClose}:Param) => {
phone:"15818085802",
order_total_length:"12",
order_total_price:"63000",
qrcode:"www.zzfzyc.com/checkorder/XS-211005888",
qrcode:"https://www.zzfzyc.com/checkorder/XS-211005888",
order_total_weight:"300.00",
list: [{product_code:'5215',product_name:'26S双纱亲水滑爽棉',product_color_code:'053',product_color_name:'洋红',num:'4',weight:'123.23',sale_price:'43',total_price:'4510.7'}]
})
@@ -91,10 +92,18 @@ export default memo(({show = true, onClose}:Param) => {
let filePath = Taro.env.USER_DATA_PATH + '/img' + time +'.'+ format
fileData.current.filePath = filePath
fileData.current.base64 = bodyData
const save = Taro.getFileSystemManager()
save.writeFile({
filePath: fileData.current.filePath,
data: fileData.current.base64,
encoding: 'base64',
})
}
useEffect(() => {
getCore()
}, [])
if(show)
getCore()
}, [show])
//检查是否开启保存图片权限
const {check} = useCheckAuthorize({scope:'scope.writePhotosAlbum', msg:'您没授权,无法保存图片'})
@@ -105,30 +114,23 @@ export default memo(({show = true, onClose}:Param) => {
//保存图片
const saveImage = () => {
const save = Taro.getFileSystemManager()
alert.loading('正在保存图片')
save.writeFile({
Taro.saveImageToPhotosAlbum({
filePath: fileData.current.filePath,
data: fileData.current.base64,
encoding: 'base64',
success: function (res) {
Taro.saveImageToPhotosAlbum({
filePath: fileData.current.filePath,
success: function (res) {
alert.success('图片保存成功')
},
fail: function (err) {
console.log('err::', err)
}
})
alert.success('图片保存成功')
},
fail: function (err) {
console.log('err::', err)
}
})
}
//预览图片
const showImage = () => {
console.log('fileData.current.filePath::', fileData.current.filePath)
Taro.previewImage({
current: fileData.current.filePath, // 当前显示图片的http链接
current: fileData.current.filePath, // 当前显示
urls: [fileData.current.filePath] // 需要预览的图片http链接列表
})
}
@@ -144,9 +146,12 @@ export default memo(({show = true, onClose}:Param) => {
<Text className={classnames(styles.miconfont, 'iconfont, icon-zhuyi')}></Text>
扫码支付成功后,自动更新状态
</View>
<ScrollView scrollY className={styles.scanPay_list}>
<Image mode="widthFix" src={payCodeImage} onClick={showImage}></Image>
</ScrollView>
<View className={styles.scanPay_list}>
{(state.loading)&&<LoadingCard/>||
<ScrollView scrollY className={styles.scanPay_list}>
<Image mode="widthFix" src={payCodeImage} onClick={showImage}></Image>
</ScrollView>}
</View>
<View className={styles.btns} onClick={saveImageCheck}>保存电子确认单</View>
</View>
</Popup>