提交 e2b7fb01 authored 作者: 刘旭's avatar 刘旭

优化

上级 4ea27ba0
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onLoad, onBackPress } from '@dcloudio/uni-app'; import { onLoad, onBackPress, onShow } from '@dcloudio/uni-app';
import { ref } from 'vue'; import { ref } from 'vue';
import { checkoutCart, orderSubmit } from '@/api/index'; import { checkoutCart, orderSubmit } from '@/api/index';
import config from '@/utils/config'; import config from '@/utils/config';
...@@ -198,6 +198,7 @@ const initCheckoutCart = (cartId: number, types: number) => { ...@@ -198,6 +198,7 @@ const initCheckoutCart = (cartId: number, types: number) => {
}); });
}; };
// 更新
const init = () => { const init = () => {
switch (type.value) { switch (type.value) {
case 'cart': case 'cart':
...@@ -217,6 +218,11 @@ const init = () => { ...@@ -217,6 +218,11 @@ const init = () => {
break; break;
} }
}; };
// 防止地址选择后不会更新渲染
onShow(() => {
init();
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
...@@ -173,8 +173,9 @@ ...@@ -173,8 +173,9 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, getCurrentInstance, ComponentInternalInstance, computed } from 'vue'; import { ref, getCurrentInstance, ComponentInternalInstance, computed } from 'vue';
import { fillQuotation, quotationInit, quotationOrder } from '@/api/cart'; import { fillQuotation, quotationInit, quotationOrder } from '@/api/cart';
import { onLoad, onReady, onShow } from '@dcloudio/uni-app'; import { onLoad, onReady } from '@dcloudio/uni-app';
import { orderDetail, getTax } from '@/api/index'; import { orderDetail, getTax } from '@/api/index';
import { getProductLineIndex } from '@/api/productLine';
import { quotationExist } from '@/api/cart' import { quotationExist } from '@/api/cart'
import config from '@/utils/config'; import config from '@/utils/config';
import orderForm from './components/orderForm.vue'; import orderForm from './components/orderForm.vue';
...@@ -263,10 +264,12 @@ let guaranteeList = ref([ ...@@ -263,10 +264,12 @@ let guaranteeList = ref([
let uFormRef = ref(); let uFormRef = ref();
let quotationData = ref(); let quotationData = ref();
let orderId = ref() let orderId = ref()
let addressData = ref() // 获取收货地址信息
let tax = ref() // 税率 let tax = ref() // 税率
let lineId = ref() // 产品线id 可以分辨是产品线还是普通商品
onLoad((options: any) => { onLoad((options: any) => {
console.log(options);
if(options.lineId) lineId.value = options.lineId
orderId.value = options.orderId orderId.value = options.orderId
// 判断是否重复报价 // 判断是否重复报价
quotationExist({ orderId: orderId.value }).then((res: any) => { quotationExist({ orderId: orderId.value }).then((res: any) => {
...@@ -286,18 +289,19 @@ onLoad((options: any) => { ...@@ -286,18 +289,19 @@ onLoad((options: any) => {
}) })
}); });
onShow(() => { // 更新收货地址
uni.$on('updateAddress', (data: any) => {
// 判断是否在报价页面返回 // 判断是否在报价页面返回
if(addressData.value) { if(data.addr) {
// 同步修改收货地址的信息 // 同步修改收货地址的信息
formData.value.toCust = addressData.value.name formData.value.toCust = data.addr.name
formData.value.quotationAttend = addressData.value.contactName formData.value.quotationAttend = data.addr.contactName
formData.value.quotationEmail = addressData.value.customerEmail formData.value.quotationEmail = data.addr.customerEmail
formData.value.quotationTel = addressData.value.tel formData.value.quotationTel = data.addr.tel
formData.value.addr = addressData.value.province + formData.value.addr = data.addr.province +
addressData.value.city + addressData.value.county + addressData.value.addressDetail data.addr.city + data.addr.county + data.addr.addressDetail
} }
console.log(data.addr);
}) })
// 引入校验 // 引入校验
...@@ -325,35 +329,51 @@ let taxTotlePirce = computed(() => { ...@@ -325,35 +329,51 @@ let taxTotlePirce = computed(() => {
}); });
let submit = () => { let submit = () => {
uFormRef.value?.validate((valid: any, err: any) => { // 保证单价必填
if(valid) { new Promise((resolve, reject) => {
// 保证单价必填 detailData.value.some((item: any) => {
detailData.value.some((item: any) => { if (typeof item.unitPrice === 'undefined') {
if (typeof item.unitPrice === 'undefined') { return uni.showToast({
return uni.showToast({ title: `请填写 ${item.goodsName} 单价`,
title: `请填写 ${item.goodsName} 单价`, icon: 'none',
icon: 'none', });
}); }
})
resolve(true)
}).then(() => {
uFormRef.value?.validate((valid: any, err: any) => {
if(valid) {
if(lineId.value) {
// 同步价格
quotationData.value.items.forEach((item: any) => {
detailData.value.map((res: any) => {
if(item.goodsName == res.goodsName) {
item.price = res.unitPrice
}
})
})
} else {
// 同步价格
quotationData.value.items.forEach((item: any) => {
detailData.value.map((res: any) => {
if(item.goodsName == res.goodsName) {
item.price = res.unitPrice
}
})
})
} }
}) let data = {
// 同步价格 items: quotationData.value.items,
quotationData.value.items.forEach((item: any) => { quotation: formData.value,
detailData.value.map((res: any) => { };
if(item.goodsName == res.goodsName) {
item.price = res.unitPrice fillQuotation(data).then((res: any) => {
} if (res.data.code === 200) showModel.value = true
}) });
}) } else {
let data = { console.log(err);
items: quotationData.value.items, }
quotation: formData.value, })
};
fillQuotation(data).then((res: any) => {
if (res.data.code === 200) showModel.value = true
});
} else {
console.log(err);
}
}) })
}; };
...@@ -428,6 +448,28 @@ let initQuotation = (orderId: number) => { ...@@ -428,6 +448,28 @@ let initQuotation = (orderId: number) => {
}; };
let initQuotaionData = (id: number) => { let initQuotaionData = (id: number) => {
// 查询产品线
if(lineId.value) {
getProductLineIndex({ lineId: lineId.value }).then((res: any) => {
if (res.data.code === 200) {
detailData.value = res.data.data.cartList
// 从quotationData获取 在detailData中添加 合同报价字段
if(quotationData.value) {
detailData.value.map((detail: any) => {
detail.unitPrice = undefined
quotationData.value.items.map((item: any) => {
if(item.goodsName == detail.goodsName) {
detail.contractQuotation = item.contractQuotation
}
})
})
console.log(detailData.value);
} else initQuotation(orderId.value)
// console.log(res, '订单详情信息');
}
})
} else
// 查询普通商品
orderDetail({ orderId: id }).then((res: any) => { orderDetail({ orderId: id }).then((res: any) => {
if (res.data.code === 200) { if (res.data.code === 200) {
detailData.value = res.data.data.orderGoods detailData.value = res.data.data.orderGoods
......
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed } from 'vue'; import { ref, computed } from 'vue';
import { onLoad, onBackPress } from '@dcloudio/uni-app'; import { onLoad, onBackPress } from '@dcloudio/uni-app';
import { getTax, orderDetail } from '@/api/index'; import { orderDetail } from '@/api/index';
import { quotationInit } from '@/api/cart'; import { quotationInit } from '@/api/cart';
import { getProductLineIndex } from '@/api/productLine'; import { getProductLineIndex } from '@/api/productLine';
import { useStore } from '@/store/useStore'; import { useStore } from '@/store/useStore';
...@@ -85,7 +85,6 @@ onLoad((options: any) => { ...@@ -85,7 +85,6 @@ onLoad((options: any) => {
orderId.value = options.orderId; orderId.value = options.orderId;
console.log(type.value, 'type.value'); console.log(type.value, 'type.value');
initOrderData(options.orderId); initOrderData(options.orderId);
initTax(); // 查询税率
}); });
// 返回首页 // 返回首页
...@@ -102,25 +101,28 @@ let toIndex = () => { ...@@ -102,25 +101,28 @@ let toIndex = () => {
// 生成报价 // 生成报价
let generateQuote = () => { let generateQuote = () => {
let data = [] as any; // let data = [] as any;
let flag = true; // let flag = true;
detailData.value.map((item: any) => { // detailData.value.map((item: any) => {
if (typeof item.unitPrice === 'undefined') { // if (typeof item.unitPrice === 'undefined') {
flag = false; // flag = false;
return uni.showToast({ // return uni.showToast({
title: `请填写 ${item.goodsName} 单价`, // title: `请填写 ${item.goodsName} 单价`,
icon: 'none', // icon: 'none',
}); // });
} else // } else
data.push({ // data.push({
goodsName: item.goodsName, // goodsName: item.goodsName,
unitPrice: item.unitPrice, // unitPrice: item.unitPrice,
}); // });
// });
// if (flag)
// uni.navigateTo({
// url: `../order/quotation?orderId=${orderId.value}`,
// });
uni.navigateTo({
url: `../order/quotation?orderId=${orderId.value}&lineId=${lineId.value}`,
}); });
if (flag)
uni.navigateTo({
url: `../order/quotation?orderId=${orderId.value}`,
});
}; };
// 总价格 // 总价格
...@@ -170,35 +172,23 @@ let download = () => { ...@@ -170,35 +172,23 @@ let download = () => {
}); });
}; };
// 获取下载pdf信息
// let initPdf = (orderId: number) => {
// getOrderPdf({ orderId }).then((res: any) => {
// if (res.data.code === 200) {
// console.log(res, 'pdf');
// }
// });
// };
// 获取税率
let initTax = () => {
getTax().then((res: any) => {
if (res.data.code === 200) tax.value = Number(res.data.data.mall_tax_rate);
});
};
let initQuotationInit = (orderId: number) => { let initQuotationInit = (orderId: number) => {
quotationInit({ orderId }).then((res: any) => { quotationInit({ orderId }).then((res: any) => {
console.log(res, '产品线'); console.log(res, '产品线');
}); });
}; };
let lineId = ref();
// 获取goodsId // 获取goodsId
let initOrderData = (orderId: number) => { let initOrderData = (orderId: number) => {
orderDetail({ orderId }).then((res: any) => { orderDetail({ orderId }).then((res: any) => {
if (res.data.code === 200) { if (res.data.code === 200) {
enclosure.value = res.data.data.orderInfo.enclosure; enclosure.value = res.data.data.orderInfo.enclosure;
res.data.data.orderGoods.map((item: any) => { res.data.data.orderGoods.map((item: any, i: number) => {
initProductLineIndex(item.goodsId); if (res.data.data.orderGoods.length - 1 === i) {
lineId.value = item.goodsId;
initProductLineIndex(item.goodsId);
}
}); });
} }
}); });
...@@ -214,6 +204,7 @@ let initProductLineIndex = (lineId: number) => { ...@@ -214,6 +204,7 @@ let initProductLineIndex = (lineId: number) => {
}); });
}; };
// 通过type判断返回页面
onBackPress((options: any) => { onBackPress((options: any) => {
if (type.value === 'productline') { if (type.value === 'productline') {
if (options.from === 'navigateBack') { if (options.from === 'navigateBack') {
......
...@@ -83,12 +83,11 @@ const setAddress = (item: any) => { ...@@ -83,12 +83,11 @@ const setAddress = (item: any) => {
success() { success() {
let pages = getCurrentPages(); // 当前页面 let pages = getCurrentPages(); // 当前页面
let beforePage: any = pages[pages.length - 2]; // 上一页 let beforePage: any = pages[pages.length - 2]; // 上一页
console.log(beforePage); // console.log(beforePage);
uni.navigateBack({ uni.navigateBack({
success: function() { success: function() {
if (beforePage.route === 'pages/order/quotation') if (beforePage.route === 'pages/order/quotation')
beforePage.$vm.addressData = item; uni.$emit('updateAddress', { addr: item });
else beforePage.$vm.init(); // 执行上一页的onLoad方法
}, },
}); });
}, },
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论