Commit 29e5e1e428aa2387b54f9d14ea3131fc813f29da

Authored by 史婷婷
2 parents 2b226301 eaebf1b5

Merge branch 'cjerp-1.0' of http://gitlab.qgutech.com/zhuyuanliang/erp-mobile into cjerp-1.0

... ... @@ -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 108 export function getContractApi(id) {
99 109 return request({
... ...
... ... @@ -231,6 +231,7 @@ export default {
231 231 includesTransportFee: false,
232 232 includesTransportFeeName: '',
233 233 unit: '元、公斤、元/公斤',
  234 + totalAmountCapital: '',
234 235 destinationId: [],
235 236 destinationLabel: ''
236 237 },
... ...
... ... @@ -14,7 +14,7 @@
14 14 </view>
15 15
16 16 <view class="section1">
17   - <ProductRel mode="view" :value="productList" />
  17 + <ProductRel mode="view" :list="productList" />
18 18 </view>
19 19
20 20 <view class="section">
... ...
... ... @@ -34,7 +34,7 @@
34 34 </template>
35 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 39 <uni-list-item title="合计人民币金额(大写)">
40 40 <template v-slot:footer>
... ... @@ -196,7 +196,7 @@ import SingleSelectSheet from '@/components/single-select/index.vue'
196 196 import RelateSelectSheet from '@/components/relate-select/index.vue'
197 197 import ProductRel from './productRel.vue'
198 198 import CitySelector from '@/components/city-selector/index.vue'
199   -import { getContractApi } from '@/api/contract'
  199 +import { getContractApi, updateContractApi } from '@/api/contract'
200 200 import { getDicByCodes } from '@/utils/dic'
201 201 import { formatCurrencyToChinese } from '@/utils/common'
202 202
... ... @@ -251,6 +251,7 @@ export default {
251 251 sumAmountExcl: 0,
252 252 sumTotal: 0,
253 253 productLineList: [],
  254 + newProductLineList: [],
254 255 productList: []
255 256 }
256 257 },
... ... @@ -333,6 +334,7 @@ export default {
333 334 },
334 335 onProductsChange(products) {
335 336 const list = Array.isArray(products) ? products : []
  337 + this.newProductLineList = list
336 338 const sumQ = list.reduce((acc, it) => acc + (parseFloat(it.quantity) || 0), 0)
337 339 const sumE = list.reduce((acc, it) => acc + (parseFloat(it.amountExcludingTax) || 0), 0)
338 340 const sumT = list.reduce((acc, it) => acc + (parseFloat(it.totalAmount) || 0), 0)
... ... @@ -411,17 +413,66 @@ export default {
411 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 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 460 ...formForSubmit,
  461 + id: this.form.id,
421 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 174 name: 'ProductRel',
175 175 props: {
176 176 mode: { type: String, default: 'add' },
177   - value: { type: Array, default: () => [] },
  177 + list: { type: Array, default: () => [] },
178 178 max: { type: Number, default: 8 },
179 179 orderDateBase: { type: String, default: '' },
180 180 options: { type: Array, default: () => [] }
... ... @@ -201,22 +201,24 @@ export default {
201 201 handler() { this.emitChange() },
202 202 deep: true
203 203 },
204   - value: {
  204 + list: {
205 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 211 deep: true
210 212 }
211 213 },
212 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 216 this.items = init
215 217 this.recalculateAll()
216 218 },
217 219 methods: {
218 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 223 onImmediateChange(idx) {
222 224 this.$nextTick(() => this.recalculate(idx))
... ... @@ -235,7 +237,14 @@ export default {
235 237 onNumberBlur(idx, field, digits) {
236 238 const it = this.items[idx]
237 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 248 const rounded = this.round(num, digits)
240 249 it[field] = rounded
241 250 this.$set(this.items, idx, it)
... ...