Commit eaebf1b5f54b1cbe93c451b9a604de04818bf315

Authored by gesilong
1 parent bbe19b01

commit: 联调完成编辑;查看

@@ -94,6 +94,16 @@ export function createContractApi(data) { @@ -94,6 +94,16 @@ export function createContractApi(data) {
94 }) 94 })
95 } 95 }
96 96
  97 +// 更新合同
  98 +export function updateContractApi(data) {
  99 + return request({
  100 + url: `${baseUrl}/contractDistributorStandard`,
  101 + method: 'put',
  102 + data,
  103 + contentType: ContentTypeEnum.JSON
  104 + })
  105 +}
  106 +
97 // 查看合同 107 // 查看合同
98 export function getContractApi(id) { 108 export function getContractApi(id) {
99 return request({ 109 return request({
@@ -231,6 +231,7 @@ export default { @@ -231,6 +231,7 @@ export default {
231 includesTransportFee: false, 231 includesTransportFee: false,
232 includesTransportFeeName: '', 232 includesTransportFeeName: '',
233 unit: '元、公斤、元/公斤', 233 unit: '元、公斤、元/公斤',
  234 + totalAmountCapital: '',
234 destinationId: [], 235 destinationId: [],
235 destinationLabel: '' 236 destinationLabel: ''
236 }, 237 },
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 </view> 14 </view>
15 15
16 <view class="section1"> 16 <view class="section1">
17 - <ProductRel mode="view" :value="productList" /> 17 + <ProductRel mode="view" :list="productList" />
18 </view> 18 </view>
19 19
20 <view class="section"> 20 <view class="section">
@@ -34,7 +34,7 @@ @@ -34,7 +34,7 @@
34 </template> 34 </template>
35 </uni-list-item> 35 </uni-list-item>
36 36
37 - <!-- <ProductRel mode="add" :orderDateBase="form.orderDate" v-model="productLineList" @change="onProductsChange" :options="productList" /> --> 37 + <ProductRel mode="add" :orderDateBase="form.orderDate" :list="productLineList" @change="onProductsChange" :options="productList" />
38 38
39 <uni-list-item title="合计人民币金额(大写)"> 39 <uni-list-item title="合计人民币金额(大写)">
40 <template v-slot:footer> 40 <template v-slot:footer>
@@ -196,7 +196,7 @@ import SingleSelectSheet from '@/components/single-select/index.vue' @@ -196,7 +196,7 @@ import SingleSelectSheet from '@/components/single-select/index.vue'
196 import RelateSelectSheet from '@/components/relate-select/index.vue' 196 import RelateSelectSheet from '@/components/relate-select/index.vue'
197 import ProductRel from './productRel.vue' 197 import ProductRel from './productRel.vue'
198 import CitySelector from '@/components/city-selector/index.vue' 198 import CitySelector from '@/components/city-selector/index.vue'
199 -import { getContractApi } from '@/api/contract' 199 +import { getContractApi, updateContractApi } from '@/api/contract'
200 import { getDicByCodes } from '@/utils/dic' 200 import { getDicByCodes } from '@/utils/dic'
201 import { formatCurrencyToChinese } from '@/utils/common' 201 import { formatCurrencyToChinese } from '@/utils/common'
202 202
@@ -251,6 +251,7 @@ export default { @@ -251,6 +251,7 @@ export default {
251 sumAmountExcl: 0, 251 sumAmountExcl: 0,
252 sumTotal: 0, 252 sumTotal: 0,
253 productLineList: [], 253 productLineList: [],
  254 + newProductLineList: [],
254 productList: [] 255 productList: []
255 } 256 }
256 }, 257 },
@@ -333,6 +334,7 @@ export default { @@ -333,6 +334,7 @@ export default {
333 }, 334 },
334 onProductsChange(products) { 335 onProductsChange(products) {
335 const list = Array.isArray(products) ? products : [] 336 const list = Array.isArray(products) ? products : []
  337 + this.newProductLineList = list
336 const sumQ = list.reduce((acc, it) => acc + (parseFloat(it.quantity) || 0), 0) 338 const sumQ = list.reduce((acc, it) => acc + (parseFloat(it.quantity) || 0), 0)
337 const sumE = list.reduce((acc, it) => acc + (parseFloat(it.amountExcludingTax) || 0), 0) 339 const sumE = list.reduce((acc, it) => acc + (parseFloat(it.amountExcludingTax) || 0), 0)
338 const sumT = list.reduce((acc, it) => acc + (parseFloat(it.totalAmount) || 0), 0) 340 const sumT = list.reduce((acc, it) => acc + (parseFloat(it.totalAmount) || 0), 0)
@@ -411,17 +413,66 @@ export default { @@ -411,17 +413,66 @@ export default {
411 this.form.executionStandardRemarks = '' 413 this.form.executionStandardRemarks = ''
412 } 414 }
413 }, 415 },
  416 + validateRequired() {
  417 + const checks = [
  418 + { key: 'code', label: '编号' },
  419 + { key: 'supplier', label: '供方' },
  420 + { key: 'buyer', label: '需方' },
  421 + { key: 'orderDate', label: '订货日期' }
  422 + ]
  423 + for (const it of checks) {
  424 + const val = this.form[it.key]
  425 + const empty = (val === undefined || val === null || (typeof val === 'string' && val.trim() === '') || (typeof val === 'number' && isNaN(val)))
  426 + if (empty) { uni.showToast({ title: `请先选择${it.label}`, icon: 'none' }); return false }
  427 + }
  428 + if (!Array.isArray(this.productLineList) || this.productLineList.length === 0) {
  429 + uni.showToast({ title: '请至少添加一条产品明细', icon: 'none' }); return false
  430 + }
  431 + for (const [idx, it] of this.productLineList.entries()) {
  432 + if (!it.productName || !it.quantity || !it.unitPrice) {
  433 + uni.showToast({ title: `第${idx + 1}条明细未完整填写`, icon: 'none' }); return false
  434 + }
  435 + }
  436 + return true
  437 + },
414 async onSubmit() { 438 async onSubmit() {
415 -  
416 - const { destinationLabel, destinationId, ...formForSubmit } = this.form;  
417 - // 区id  
418 - const destination = destinationId && destinationId.length > 0 ? destinationId[destinationId.length - 1] : '';  
419 - const payload = { 439 + console.log('onSubmit__payload', payload)
  440 + if (!this.validateRequired()) return
  441 + const confirmRes = await new Promise(resolve => {
  442 + uni.showModal({ title: '提示', content: '确定保存当前经销未锁规合同吗?', confirmText: '确定', cancelText: '取消', success: resolve })
  443 + })
  444 + if (!(confirmRes && confirmRes.confirm)) return
  445 + const clean = (obj) => {
  446 + const out = {}
  447 + Object.keys(obj || {}).forEach(k => {
  448 + const v = obj[k]
  449 + const isEmptyString = typeof v === 'string' && v.trim() === ''
  450 + const isUndef = v === undefined || v === null
  451 + const isNaNNumber = typeof v === 'number' && isNaN(v)
  452 + if (!(isEmptyString || isUndef || isNaNNumber)) out[k] = v
  453 + })
  454 + return out
  455 + }
  456 + const lines = (this.newProductLineList || []).map(it => clean(it))
  457 + const { destinationLabel, destinationId, ...formForSubmit } = this.form;
  458 + const destination = destinationId && destinationId.length > 0 ? destinationId[destinationId.length - 1] : '';
  459 + const payload = clean({
420 ...formForSubmit, 460 ...formForSubmit,
  461 + id: this.form.id,
421 destination, 462 destination,
  463 + type: 'DISTRIB_STD',
  464 + sumQuantity: this.sumQuantity,
  465 + sumAmountExcl: this.sumAmountExcl,
  466 + sumTotal: this.sumTotal,
  467 + contractDistributorLineList: lines
  468 + })
  469 + try {
  470 + await updateContractApi(payload)
  471 + uni.showToast({ title: '保存成功', icon: 'none' })
  472 + setTimeout(() => { uni.redirectTo({ url: '/pages/contract_retail/index' }) }, 400)
  473 + } catch (e) {
  474 + uni.showToast({ title: '提交失败', icon: 'none' })
422 } 475 }
423 - console.log('onSubmit__payload', payload)  
424 - uni.showToast({ title: '暂未接入保存接口', icon: 'none' })  
425 } 476 }
426 } 477 }
427 } 478 }
@@ -174,7 +174,7 @@ export default { @@ -174,7 +174,7 @@ export default {
174 name: 'ProductRel', 174 name: 'ProductRel',
175 props: { 175 props: {
176 mode: { type: String, default: 'add' }, 176 mode: { type: String, default: 'add' },
177 - value: { type: Array, default: () => [] }, 177 + list: { type: Array, default: () => [] },
178 max: { type: Number, default: 8 }, 178 max: { type: Number, default: 8 },
179 orderDateBase: { type: String, default: '' }, 179 orderDateBase: { type: String, default: '' },
180 options: { type: Array, default: () => [] } 180 options: { type: Array, default: () => [] }
@@ -201,22 +201,24 @@ export default { @@ -201,22 +201,24 @@ export default {
201 handler() { this.emitChange() }, 201 handler() { this.emitChange() },
202 deep: true 202 deep: true
203 }, 203 },
204 - value: { 204 + list: {
205 handler(v) { 205 handler(v) {
206 - const arr = Array.isArray(v) ? v : []  
207 - this.items = arr.map(x => ({ ...this.defaultItem(), ...x, collapsed: true })) 206 + // const arr = Array.isArray(v) ? v : []
  207 + // this.items = arr.map(x => ({ ...this.defaultItem(), ...x, collapsed: true }))
  208 + this.items = v.map(x => ({ ...this.defaultItem(), ...x, collapsed: true }))
  209 + console.log('v', v)
208 }, 210 },
209 deep: true 211 deep: true
210 } 212 }
211 }, 213 },
212 created() { 214 created() {
213 - const init = Array.isArray(this.value) && this.value.length > 0 ? this.value.map(v => ({ ...this.defaultItem(), ...v, collapsed: true })) : [{ ...this.defaultItem(), collapsed: false }] 215 + const init = Array.isArray(this.list) && this.list.length > 0 ? this.list.map(v => ({ ...this.defaultItem(), ...v, collapsed: true })) : [{ ...this.defaultItem(), collapsed: false }]
214 this.items = init 216 this.items = init
215 this.recalculateAll() 217 this.recalculateAll()
216 }, 218 },
217 methods: { 219 methods: {
218 defaultItem() { 220 defaultItem() {
219 - return { productId: '', productName: '', industry: '', brand: '', quality: '', thickness: '', thicknessTolPos: '', thicknessTolNeg: '', width: '', widthTolPos: '', widthTolNeg: '', length: '', lengthTolPos: '', lengthTolNeg: '', status: '', quantity: 0, unitPrice: 0, amountExcludingTax: 0, totalAmount: 0, orderDate: '' } 221 + return { productId: '', productName: '', industry: '', brand: '', quality: '', thickness: '', thicknessTolPos: '', thicknessTolNeg: '', width: '', widthTolPos: '', widthTolNeg: '', length: '', lengthTolPos: '', lengthTolNeg: '', status: '', quantity: '', unitPrice: '', amountExcludingTax: 0, totalAmount: 0, orderDate: '' }
220 }, 222 },
221 onImmediateChange(idx) { 223 onImmediateChange(idx) {
222 this.$nextTick(() => this.recalculate(idx)) 224 this.$nextTick(() => this.recalculate(idx))
@@ -235,7 +237,14 @@ export default { @@ -235,7 +237,14 @@ export default {
235 onNumberBlur(idx, field, digits) { 237 onNumberBlur(idx, field, digits) {
236 const it = this.items[idx] 238 const it = this.items[idx]
237 if (!it) return 239 if (!it) return
238 - const num = this.toNumber(it[field]) 240 + const raw = it[field]
  241 + // 如果为空则保持为空,不自动置为0,仅重新计算依赖字段
  242 + if (raw === '' || raw === null || raw === undefined) {
  243 + this.$set(this.items, idx, it)
  244 + this.recalculate(idx)
  245 + return
  246 + }
  247 + const num = this.toNumber(raw)
239 const rounded = this.round(num, digits) 248 const rounded = this.round(num, digits)
240 it[field] = rounded 249 it[field] = rounded
241 this.$set(this.items, idx, it) 250 this.$set(this.items, idx, it)