✨ feat(订单模块):提交订单对接

This commit is contained in:
Haiyi
2022-09-27 17:14:52 +08:00
parent 6c0ecd5ea1
commit 9377ea964f
12 changed files with 230 additions and 133 deletions
+105 -59
View File
@@ -9,35 +9,45 @@ import Popup from '@/components/popup'
import { debounce } from '@/common/util'
import {
mpsaleOrderpreView,
mpsaleOrderput,
mpsaleOrderaddress
mpsaleOrderpost,
} from '@/api/order'
import { alert } from '@/common/common'
import { formatPriceDiv, formatDateTime, formatWeightDiv } from '@/common/format'
import IconFont from '@/components/iconfont/iconfont'
export default () => {
const router: any = useRouter()
const [infoObj, setInfoObj] = useState<any>({})
useDidShow(() => {
getDetail()
})
//页面下拉刷新
usePullDownRefresh(() => {
getDetail()
})
//获取选择的客户
let pages = Taro.getCurrentPages();
let currPage = pages[pages.length - 1]; // 获取当前页面
setInfoObj({
...infoObj,
province_name: currPage.data.addressObj.province_name,
address_id: currPage.data.addressObj.id,
city_name: currPage.data.addressObj.city_name,
district_name: currPage.data.addressObj.district_name,
target_user_name: currPage.data.addressObj.name,
purchaser_phone: currPage.data.addressObj.phone,
})
})
useEffect(() => {
getDetail()
}, [])
useEffect(() => {
setInfoObj(infoObj)
console.log(infoObj, 66666)
}, [infoObj])
//收货方法,1:自提,2物流
const [receivingStatus, setReceivingStatus] = useState(null)
const [receivingStatus, setReceivingStatus] = useState<any>(null)
//切换自提或者物流
const { fetchData: selectFetch } = mpsaleOrderaddress()
const onReceivingStatus = debounce(async (e, value) => {
if (infoObj.status === 8 || infoObj.status === 9 || infoObj.status === 4 || infoObj.status === 5) {
alert.error('不允许更改')
return false
}
e.stopPropagation()
if (receivingStatus === value) {
if (receivingStatus == value) {
alert.error('不能选择相同的方式')
return false
}
@@ -45,57 +55,37 @@ export default () => {
title: '请稍等...',
mask: true
})
const res = await selectFetch({ id: Number(infoObj.id), shipment_mode: value })
if (res.msg === 'success') {
Taro.hideLoading()
Taro.showToast({
title: '成功',
icon: 'success'
})
setReceivingStatus(value)
} else {
Taro.hideLoading()
Taro.showToast({
title: res.msg,
icon: 'error'
})
}
setReceivingStatus(value)
Taro.hideLoading()
}, 300)
const { fetchData: infoFetch } = mpsaleOrderpreView()
const [infoObj, setInfoObj] = useState<any>({})
//获取订单详情
const getDetail = async () => {
let arr: any[] = []
arr = JSON.parse(decodeURIComponent(router.params.shopping_cart_product_color_list))
let list: any[] = []
router.params?.shopping_cart_product_color_list?.forEach(item => {
arr?.forEach(item => {
list.push({
shopping_cart_product_color_id: item.shopping_cart_product_color_id,
shopping_cart_product_color_id: item,
sale_price: 0
})
})
const query = {
purchaser_id: router.params.purchaser_id,
sale_mode: router.params.sale_mode,
purchaser_id: Number(router.params.purchaser_id),
sale_mode: Number(router.params.sale_mode),
shopping_cart_product_color_list: list
}
const res = await infoFetch(query)
setInfoObj(res.data)
setReceivingStatus(res.data.shipment_mode)
setReceivingStatus(1)
}
//备注操作
const [showDesc, setShowDesc] = useState(false)
const { fetchData: remarkFetch } = mpsaleOrderput()
const getRemark = useCallback(async (e) => {
const res = await remarkFetch({ remark: e, id: Number(router.params.id) })
if (res.msg === 'success') {
Taro.showToast({
title: '成功',
icon: 'success'
})
setShowDesc(false)
getDetail()
}
setShowDesc(false)
setInfoObj((val) => ({ ...val, remark: e }))
}, [])
@@ -103,10 +93,65 @@ export default () => {
const handSelect = (obj) => {
Taro.navigateTo({
url: '/pages/addressManager/index?orderId=' + obj.id + '&purchaser_id=' + obj.purchaser_id
url: '/pages/addressManager/index?orderId=' + '-100' + '&purchaser_id=' + router.params.purchaser_id
})
}
//提交订单
const { fetchData: postFetch } = mpsaleOrderpost()
const handSure = () => {
if (receivingStatus == 2 && !infoObj.address_id) {
return alert.error('请选择地址')
}
let list: any[] = []
infoObj.product_list.forEach(item => {
item.product_colors.forEach(it => {
list.push({
sale_price: it.sale_price,
shopping_cart_product_color_id: Number(it.id)
})
})
})
let query = {
address_id: Number(infoObj.address_id) ? Number(infoObj.address_id) : 0,
list: list,
physical_warehouse: infoObj.physical_warehouse,
purchaser_id: Number(router.params.purchaser_id),
remark: infoObj.remark,
sale_mode: infoObj.sale_mode,
shipment_mode: receivingStatus
}
Taro.showModal({
content: "确认提交吗?",
confirmText: "确认",
cancelText: "取消",
success: async function (res) {
if (res.confirm) {
Taro.showLoading({
title: '请稍等...',
mask: true
})
const res = await postFetch(query)
if (res?.msg === 'success') {
Taro.showToast({
title: '成功'
})
Taro.hideLoading()
Taro.redirectTo({
url: '/pages/orderDetails/index?id=' + res.data.id
})
} else {
Taro.hideLoading()
Taro.showToast({
title: res?.msg,
icon: 'error'
})
}
}
}
})
}
return (
<View className={styles.mainBox}>
<AddressDetailBox
@@ -121,19 +166,20 @@ export default () => {
modeName={infoObj.sale_mode_name}
>
<View className={styles.pussBox}>
<View className={styles.pussName}>{infoObj.purchaser_name}</View>
<View className={styles.pussPhone}>{infoObj.purchaser_phone}</View>
<View className={styles.pussName}>{router.params.purchaser_name}</View>
{/* <View className={styles.pussPhone}>{infoObj.purchaser_phone}</View> */}
</View>
</DefaultBox>
<View className={styles.total}> {infoObj.total_fabrics} 种面料,{infoObj.total_colors} 个颜色,共 {infoObj.sale_mode === 0 ? infoObj.total_number : infoObj.total_number / 100} {infoObj.sale_mode === 0 ? '条' : 'm'}</View>
{/* <View className={styles.total}> {infoObj.product_list?.length} 种面料,{infoObj.total_colors} 个颜色,共 {infoObj.sale_mode === 0 ? infoObj.total_number : infoObj.total_number / 100} {infoObj.sale_mode === 0 ? '条' : 'm'}</View> */}
<View className={styles.productBox}>
<GoodsItem list={infoObj?.product_list} obj={infoObj}></GoodsItem>
<View className={styles.flexMoney}>
<View className={styles.flexTotalBox}>
<View className={styles.totalFont}>合计金额</View>
<View className={classnames('iconfont', 'icon-tishi', styles.tishi)}></View>
<IconFont name={'icon-tishi'} size={28} ></IconFont>
{/* <View className={classnames('iconfont', 'icon-tishi', styles.tishi)}></View> */}
</View>
<View className={styles.shoudPay}>{formatPriceDiv(infoObj.total_should_collect_money)}</View>
<View className={styles.shoudPay}>{formatPriceDiv(infoObj.estimate_amount)}</View>
</View>
</View>
<DefaultBox title={'备注信息'} showMode={true} modeName={`${'填写/修改备注'} >`} clickNode={() => setShowDesc(true)}>
@@ -147,11 +193,11 @@ export default () => {
<View className={styles.leftBottom}>
<View className={styles.topFlex}>
<View className={styles.topFont}>预估金额:</View>
<View className={styles.topTotal}>¥3564.00</View>
<View className={styles.topTotal}>¥{formatPriceDiv(infoObj.estimate_amount)}</View>
</View>
<View className={styles.bottomFlex}>3 种面料,3 种颜色,共 3 M</View>
<View className={styles.bottomFlex}>{infoObj.product_list?.length} 种面料,{infoObj.total_colors} 种颜色,共 {infoObj.sale_mode === 0 ? infoObj.total_number : infoObj.total_number / 100} {infoObj.sale_mode === 0 ? '条' : 'm'}</View>
</View>
<View className={styles.rightBottom}>提交订单</View>
<View className={styles.rightBottom} onClick={() => handSure()}>提交订单</View>
</View>
</View>
)
@@ -219,12 +265,12 @@ const GoodsItem = memo((porps: PropGoods) => {
<View className={styles.itemPic} style={{ backgroundColor: `rgb(${it?.rgb?.r} ${it?.rgb?.g} ${it?.rgb?.b})` }}></View>
<View className={styles.itemRight}>
<View className={styles.item_right_top}>
<View className={styles.itemName}>{it.code}# {it.name}</View>
<View className={styles.itemName}>{it.code} {it.name}</View>
<View className={styles.itemNums}>x{obj?.sale_mode === 0 ? it.roll : it.length / 100}{obj?.sale_mode === 0 ? '条' : 'm'}</View>
</View>
<View className={styles.item_right_Bottom}>
<View className={styles.itemMoney}>¥{it.sale_price / 100}/{obj?.sale_mode === 0 ? '条' : 'm'}</View>
<View className={styles.itemMoneyOne}>¥{formatPriceDiv(it.total_sale_price)}</View>
<View className={styles.itemMoneyOne}>¥{formatPriceDiv(it.estimate_amount)}</View>
</View>
</View>
</View>