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

优化

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