diff --git a/src/views/repair/tickets/Components/TicketItemShow.vue b/src/views/repair/tickets/Components/TicketItemShow.vue index 296170e..5cc4ef9 100644 --- a/src/views/repair/tickets/Components/TicketItemShow.vue +++ b/src/views/repair/tickets/Components/TicketItemShow.vue @@ -31,7 +31,14 @@ - + + + + + @@ -53,36 +60,36 @@ - + - + - + - + - + - + @@ -125,7 +132,7 @@ export default { type: String, default: null }, - isEdit:{ + isEdit: { type: Boolean, } }, @@ -134,14 +141,14 @@ export default { loading: !(this.list && this.list.length) && !this.isEdit, dialogVisible: false, item: {}, - formRules:{ + formRules: { itemPrice: [{required: true, message: '单价不能为空', trigger: 'blur'}], itemCount: [{required: true, message: '数量不能为空', trigger: 'blur'}], itemDiscount: [{required: true, message: "折扣不能为空", trigger: 'blur'}] }, formLoading: false, // 需要计算的列 - includeColumn: ['itemMoney', 'itemCount'] + includeColumn: ['itemMoney', 'itemCount', 'itemProfit', 'itemProfitRate'] } }, computed: { @@ -159,7 +166,7 @@ export default { } }, methods: { - async editItem(row){ + async editItem(row) { this.resetForm('formRef') try { const res = await getItemById(row.id) @@ -167,40 +174,63 @@ export default { this.dialogVisible = true this.item['repair'] = null this.item['adviser'] = null - }catch{} + } catch { + } }, - async submitForm(){ + async submitForm() { try { await this.$refs.formRef.validate() await updateById(this.item) this.dialogVisible = false this.$modal.msgSuccess("修改成功") this.$emit('success', this.item.ticketId) - }catch{} + } catch { + } }, - getSummaries(param){ - const { columns, data } = param; - const sums = []; - columns.forEach((column, index) => { - if (index === 0) { - sums[index] = '合计'; - return; - } - const values = data.map(item => Number(item[column.property])); - if (this.includeColumn.includes(column.property)) { - sums[index] = values.reduce((prev, curr) => { - const value = Number(curr); - if (!isNaN(value)) { - return prev + curr; - } else { - return prev; - } - }, 0); - sums[index]; - } - }); - return sums; + getSummaries(param) { + const {columns, data} = param; + const sums = []; + columns.forEach((column, index) => { + if (index === 0) { + sums[index] = '合计'; + return; } + + if (this.includeColumn.includes(column.property)) { + const values = data.map(item => Number(item[column.property])); + sums[index] = values.reduce((prev, curr) => { + const value = Number(curr); + if (!isNaN(value)) { + return prev + curr; + } else { + return prev; + } + }, 0); + + // 特殊处理毛利率字段 + if (column.property === 'itemProfitRate') { + // 计算总毛利率 = (总毛利 / 总金额) * 100% + const totalProfit = data.reduce((sum, item) => { + const profit = Number(item.itemProfit); + return !isNaN(profit) ? sum + profit : sum; + }, 0); + + const totalMoney = data.reduce((sum, item) => { + const money = Number(item.itemMoney); + return !isNaN(money) ? sum + money : sum; + }, 0); + + if (totalMoney !== 0) { + sums[index] = ((totalProfit / totalMoney) * 100).toFixed(2) + '%'; + } else { + sums[index] = '0%'; + } + } + } + }); + return sums; +} + } } diff --git a/src/views/repair/tickets/Components/TicketsShow.vue b/src/views/repair/tickets/Components/TicketsShow.vue index 4277517..d61a2a1 100644 --- a/src/views/repair/tickets/Components/TicketsShow.vue +++ b/src/views/repair/tickets/Components/TicketsShow.vue @@ -245,6 +245,22 @@ +
+ + + + {{ otherInfo.profitRate * 100 }}% + + + + {{ otherInfo.profitRateNo * 100}}% + + +