Commit 61fa90fb2c98d734d38dc726feac63ed40b19326

Authored by gesilong
2 parents a07513c5 a9831143

Merge branch 'cjerp-2.0' into test_cjerp

... ... @@ -48,3 +48,16 @@ export function getPurchaseDeptApi() {
48 48 method: 'get'
49 49 })
50 50 }
  51 +export function getRegionApi() {
  52 + return request({
  53 + url: '/system/dept/getRegion',
  54 + method: 'get'
  55 + })
  56 +}
  57 +export function getAllRegionApi(purchaseDepartment) {
  58 + return request({
  59 + url: '/system/dept/getAllRegion',
  60 + method: 'get',
  61 + params: { purchaseDepartment }
  62 + })
  63 +}
\ No newline at end of file
... ...
... ... @@ -299,9 +299,17 @@
299 299 </template>
300 300 </uni-list-item>
301 301
302   - <uni-list-item title="采购处">
303   - <template v-slot:footer>
304   - <uni-easyinput v-model="form.purchaseDepartmentName" disabled placeholder="" :inputBorder="false" />
  302 + <uni-list-item class="select-item" :class="form.purchaseDepartment ? 'is-filled' : 'is-empty'" clickable
  303 + @click="openSheet('purchaseDepartment')" :rightText="displayLabel('purchaseDepartmentName')" showArrow>
  304 + <template v-slot:body>
  305 + <view class="item-title"><text>采购处</text></view>
  306 + </template>
  307 + </uni-list-item>
  308 +
  309 + <uni-list-item class="select-item" :class="form.region ? 'is-filled' : 'is-empty'" clickable
  310 + @click="openSheet('region')" :rightText="displayLabel('region')" showArrow>
  311 + <template v-slot:body>
  312 + <view class="item-title"><text>区域</text></view>
305 313 </template>
306 314 </uni-list-item>
307 315
... ... @@ -343,7 +351,7 @@ import FileUpload from '@/components/file-upload/index.vue'
343 351 import SingleSelectSheet from '@/components/single-select/index.vue'
344 352 import MultiSelectSheet from '@/components/multi-select/index.vue'
345 353 import { getDicByCodes, getDicName } from '@/utils/dic.js'
346   -import { domesticCustomerCreditSaveApi, getPurchaseDeptApi } from '@/api/procure-manage/domesticCustomerCredit.js'
  354 +import { domesticCustomerCreditSaveApi, getPurchaseDeptApi, getAllRegionApi, getRegionApi } from '@/api/procure-manage/domesticCustomerCredit.js'
347 355
348 356 export default {
349 357 name: 'DomesticTradeAdd',
... ... @@ -369,6 +377,8 @@ export default {
369 377 operationMethodOptions: [],
370 378 developNewOptions: [],
371 379 purchaseSourceOptions: [],
  380 + regionOptions: [],
  381 + purchaseDeptOptions: [],
372 382 form: {
373 383 unitName: '',
374 384 customerShortName: '',
... ... @@ -419,16 +429,14 @@ export default {
419 429 investigatorName: '',
420 430 purchaseDepartment: '',
421 431 purchaseDepartmentName: '',
  432 + region: '',
  433 + regionName: '',
422 434 reviewValidUntil: ''
423 435 }
424 436 }
425 437 },
426 438 created() {
427   - this.loadDicData()
428   - this.loadPurchaseDeptOptions()
429   - const u = (this.$store && this.$store.state && this.$store.state.user) ? this.$store.state.user : {}
430   - this.form.investigatorId = u && u.id ? String(u.id) : ''
431   - this.form.investigatorName = u && u.name ? String(u.name) : ''
  439 + this.initPage()
432 440 },
433 441 computed: {
434 442 showCompanyNatureOther() {
... ... @@ -437,6 +445,14 @@ export default {
437 445 }
438 446 },
439 447 methods: {
  448 + async initPage() {
  449 + const u = (this.$store && this.$store.state && this.$store.state.user) ? this.$store.state.user : {}
  450 + this.form.investigatorId = u && u.id ? String(u.id) : ''
  451 + this.form.investigatorName = u && u.name ? String(u.name) : ''
  452 + await this.loadDicData()
  453 + await this.loadPurchaseDeptList()
  454 + await this.loadRegionOptions()
  455 + },
440 456 async loadDicData() {
441 457 try {
442 458 const results = await getDicByCodes(['COMPANY_NATURE', 'DEVELOP_NEW', 'OPERATION_METHOD', 'PURCHASE_SOURCE'])
... ... @@ -447,6 +463,7 @@ export default {
447 463 PURCHASE_SOURCE: (results.PURCHASE_SOURCE && results.PURCHASE_SOURCE.data) || []
448 464 }
449 465 this.dicOptions = next
  466 + console.log(next,'next')
450 467 this.companyNatureOptions = this.dicToSheetOptions(next.COMPANY_NATURE)
451 468 this.developNewOptions = this.dicToSheetOptions(next.DEVELOP_NEW)
452 469 this.operationMethodOptions = this.dicToSheetOptions(next.OPERATION_METHOD)
... ... @@ -461,20 +478,102 @@ export default {
461 478 uni.showToast({ title: '字典加载失败', icon: 'none' })
462 479 }
463 480 },
464   - async loadPurchaseDeptOptions() {
  481 + dicToSheetOptions(items) {
  482 + const list = Array.isArray(items) ? items : []
  483 + return list.map(it => ({ label: it && it.name != null ? String(it.name) : '', value: it && it.code != null ? String(it.code) : '' })).filter(it => it.value)
  484 + },
  485 + async loadPurchaseDeptList() {
465 486 try {
466 487 const res = await getPurchaseDeptApi()
467   - const data = (res && res.data) ? res.data : {}
468   - this.form.purchaseDepartment = data && data.id != null ? String(data.id) : ''
469   - this.form.purchaseDepartmentName = data && data.name != null ? String(data.name) : ''
  488 + const raw = res && res.data != null ? res.data : []
  489 + this.purchaseDeptOptions = this.normalizeRegionOptions(raw)
470 490 } catch (e) {
471   - this.form.purchaseDepartment = ''
472   - this.form.purchaseDepartmentName = ''
  491 + this.purchaseDeptOptions = []
473 492 }
474 493 },
475   - dicToSheetOptions(items) {
476   - const list = Array.isArray(items) ? items : []
477   - return list.map(it => ({ label: it && it.name != null ? String(it.name) : '', value: it && it.code != null ? String(it.code) : '' })).filter(it => it.value)
  494 + normalizeRegionOptions(raw) {
  495 + const list = Array.isArray(raw)
  496 + ? raw
  497 + : (Array.isArray(raw && raw.data) ? raw.data : (Array.isArray(raw && raw.rows) ? raw.rows : []))
  498 + return list.map(it => {
  499 + const id = it && (it.id != null ? it.id : (it.value != null ? it.value : (it.regionId != null ? it.regionId : '')))
  500 + const name = it && (it.name != null ? it.name : (it.label != null ? it.label : (it.regionName != null ? it.regionName : '')))
  501 + return { label: name != null ? String(name) : '', value: id != null ? String(id) : '' }
  502 + }).filter(it => it.value)
  503 + },
  504 + getOptionLabel(options, value) {
  505 + const v = value != null ? String(value) : ''
  506 + if (!v) return ''
  507 + const match = (options || []).find(o => String(o.value) === v)
  508 + return match ? String(match.label || '') : ''
  509 + },
  510 + syncRegionWithOptions() {
  511 + const label = this.getOptionLabel(this.regionOptions, this.form.region)
  512 + if (!label) {
  513 + this.form.region = ''
  514 + this.form.regionName = ''
  515 + return
  516 + }
  517 + this.form.regionName = label
  518 + },
  519 + async loadRegionOptions() {
  520 + let defaultRegionId = ''
  521 + let defaultRegionName = ''
  522 + try {
  523 + const regionRes = await getRegionApi()
  524 + const regionData = (regionRes && regionRes.data != null) ? regionRes.data : null
  525 + const parsed = regionData ? this.parseRegionIdAndName(regionData) : { id: '', name: '' }
  526 + if (parsed.id) {
  527 + defaultRegionId = parsed.id
  528 + defaultRegionName = parsed.name
  529 + }
  530 + } catch (e) {
  531 + // fall through to getAllRegionApi
  532 + }
  533 + const purchaseDepartment = this.form.purchaseDepartment ? String(this.form.purchaseDepartment) : ''
  534 + if (!purchaseDepartment) {
  535 + if (defaultRegionId) {
  536 + this.regionOptions = [{ label: defaultRegionName || String(defaultRegionId), value: defaultRegionId }]
  537 + this.form.region = defaultRegionId
  538 + this.form.regionName = defaultRegionName || String(defaultRegionId)
  539 + } else {
  540 + this.regionOptions = []
  541 + this.form.region = ''
  542 + this.form.regionName = ''
  543 + }
  544 + return
  545 + }
  546 + try {
  547 + const res = await getAllRegionApi(purchaseDepartment)
  548 + const raw = res && res.data != null ? res.data : []
  549 + this.regionOptions = this.normalizeRegionOptions(raw)
  550 + if (defaultRegionId) {
  551 + const label = this.getOptionLabel(this.regionOptions, defaultRegionId)
  552 + if (label) {
  553 + this.form.region = defaultRegionId
  554 + this.form.regionName = label
  555 + } else {
  556 + // 默认区域不在完整列表中,仍保留为选中项
  557 + this.regionOptions.push({ label: defaultRegionName || String(defaultRegionId), value: defaultRegionId })
  558 + this.form.region = defaultRegionId
  559 + this.form.regionName = defaultRegionName || String(defaultRegionId)
  560 + }
  561 + } else {
  562 + this.syncRegionWithOptions()
  563 + }
  564 + } catch (e) {
  565 + this.regionOptions = []
  566 + this.form.region = ''
  567 + this.form.regionName = ''
  568 + }
  569 + },
  570 + parseRegionIdAndName(raw) {
  571 + if (!raw) return { id: '', name: '' }
  572 + if (Array.isArray(raw)) return this.parseRegionIdAndName(raw[0])
  573 + if (typeof raw === 'string' || typeof raw === 'number') return { id: String(raw), name: '' }
  574 + const id = raw.id != null ? raw.id : (raw.value != null ? raw.value : (raw.regionId != null ? raw.regionId : ''))
  575 + const name = raw.name != null ? raw.name : (raw.label != null ? raw.label : (raw.regionName != null ? raw.regionName : ''))
  576 + return { id: id != null ? String(id) : '', name: name != null ? String(name) : '' }
478 577 },
479 578 labelsOfOptions(options, csv) {
480 579 const v = csv == null ? '' : String(csv)
... ... @@ -491,7 +590,9 @@ export default {
491 590 displayLabel(field) {
492 591 const m = this.form || {}
493 592 const map = {
  593 + purchaseDepartmentName: '请选择采购处',
494 594 companyNatureName: '请选择公司性质',
  595 + region: '请选择区域',
495 596 purchaseSource: '请选择',
496 597 operationMode: '请选择',
497 598 isNewDevelopment: '请选择',
... ... @@ -520,6 +621,14 @@ export default {
520 621 const v = m.isNewDevelopment
521 622 return v ? getDicName('DEVELOP_NEW', String(v), this.dicOptions.DEVELOP_NEW) : map[field]
522 623 }
  624 + if (field === 'region') {
  625 + const v = m.region
  626 + if (!v) return map[field]
  627 + return this.getOptionLabel(this.regionOptions, v) || map[field]
  628 + }
  629 + if (field === 'purchaseDepartmentName') {
  630 + return this.getOptionLabel(this.purchaseDeptOptions, m.purchaseDepartment) || map[field]
  631 + }
523 632 const v = m[field]
524 633 if (v === true) return '是'
525 634 if (v === false) return '否'
... ... @@ -527,6 +636,8 @@ export default {
527 636 },
528 637 openSheet(field) {
529 638 const map = {
  639 + region: { title: '区域', options: this.regionOptions },
  640 + purchaseDepartment: { title: '采购处', options: this.purchaseDeptOptions },
530 641 purchaseSource: { title: '收购来源', options: this.purchaseSourceOptions },
531 642 operationMode: { title: '操作方式', options: this.operationMethodOptions },
532 643 isNewDevelopment: { title: '是否新开发', options: this.developNewOptions },
... ... @@ -567,6 +678,14 @@ export default {
567 678 const field = this.sheet.field
568 679 if (!field) return
569 680 this.form[field] = value
  681 + if (field === 'region') this.form.regionName = label != null ? String(label) : this.getOptionLabel(this.regionOptions, value)
  682 + if (field === 'purchaseDepartment') {
  683 + this.form.purchaseDepartmentName = label != null ? String(label) : this.getOptionLabel(this.purchaseDeptOptions, value)
  684 + console.log(value,'value')
  685 + console.log(this.purchaseDeptOptions,'purchaseDeptOptions')
  686 + console.log(this.form.purchaseDepartmentName ,'purchasthis.form.purchaseDepartmentName eDeptOptions')
  687 + this.loadRegionOptions()
  688 + }
570 689 this.sheet.visible = false
571 690 },
572 691 onMultiSheetConfirm({ value, label }) {
... ... @@ -649,6 +768,9 @@ export default {
649 768 { key: 'reviewValidUntil', label: '评审有效期' },
650 769 { key: 'investigatorId', label: '资信调查人ID' }
651 770 ]
  771 + if (Array.isArray(this.regionOptions) && this.regionOptions.length) {
  772 + requiredTextFields.push({ key: 'region', label: '区域' })
  773 + }
652 774 for (let i = 0; i < requiredTextFields.length; i++) {
653 775 const f = requiredTextFields[i]
654 776 const v = this.form && this.form[f.key]
... ... @@ -707,6 +829,7 @@ export default {
707 829 delete payload.companyNatureName
708 830 delete payload.investigatorName
709 831 delete payload.purchaseDepartmentName
  832 + delete payload.regionName
710 833 payload.registeredCapital = Number(payload.registeredCapital)
711 834 const files = (Array.isArray(this.attachmentFiles) ? this.attachmentFiles : []).filter(it => it && it.id)
712 835 payload.attachmentFileIds = files.map(it => String(it.id || '')).filter(Boolean).join(',')
... ... @@ -722,7 +845,7 @@ export default {
722 845 await domesticCustomerCreditSaveApi(payload)
723 846 uni.showToast({ title: '提交成功', icon: 'success' })
724 847 try { uni.setStorageSync('DOMESTIC_TRADE_LIST_NEED_REFRESH', '1') } catch (e) {}
725   - setTimeout(() => { uni.navigateBack() }, 300)
  848 + setTimeout(() => { uni.redirectTo({ url: '/pages/domestic_trade/index' }) }, 300)
726 849 } catch (e) {
727 850 uni.showToast({ title: (e && e.msg) || '提交失败', icon: 'none' })
728 851 } finally {
... ...
... ... @@ -75,6 +75,7 @@
75 75 <view class="section">
76 76 <view class="row"><text class="label">资信调查人</text><text class="value">{{ safeText(form.investigatorName) }}</text></view>
77 77 <view class="row"><text class="label">采购处</text><text class="value">{{ safeText(purchaseDepartmentName) }}</text></view>
  78 + <view class="row"><text class="label">区域</text><text class="value">{{ safeText(regionName) }}</text></view>
78 79 <view class="row"><text class="label">评审有效期</text><text class="value">{{ safeText(form.reviewValidUntil) }}</text></view>
79 80 <view class="row">
80 81 <text class="label">附件</text>
... ... @@ -96,8 +97,7 @@
96 97 import { downloadFile } from '@/utils/downloadFile.js'
97 98 import DetailButtons from '@/components/detail-buttons/index.vue'
98 99 import { getDicByCodes, getDicName } from '@/utils/dic.js'
99   -import { domesticCustomerCreditCancelApi, domesticCustomerCreditGetApi } from '@/api/procure-manage/domesticCustomerCredit.js'
100   -import { getPurchaseDeptApi } from '@/api/procure-manage/domesticCustomerCredit.js'
  100 +import { domesticCustomerCreditCancelApi, domesticCustomerCreditGetApi, getPurchaseDeptApi, getAllRegionApi } from '@/api/procure-manage/domesticCustomerCredit.js'
101 101
102 102 export default {
103 103 name: 'DomesticTradeDetail',
... ... @@ -116,6 +116,7 @@ export default {
116 116 PURCHASE_SOURCE: []
117 117 },
118 118 purchaseDept: null,
  119 + regionOptions: [],
119 120 buttons: [{
120 121 text: '审核详情',
121 122 visible: true,
... ... @@ -131,7 +132,14 @@ export default {
131 132 visible: true,
132 133 variant: 'outline',
133 134 event: 'edit',
134   - },{
  135 + },
  136 + // {
  137 + // text: '申请变更',
  138 + // visible: true,
  139 + // variant: 'outline',
  140 + // event: 'changeApply',
  141 + // },
  142 + {
135 143 text: '取消',
136 144 visible: true,
137 145 variant: 'outline',
... ... @@ -142,11 +150,14 @@ export default {
142 150 computed: {
143 151 displayButtons() {
144 152 const s = this.form && this.form.status || false
  153 + const d = this.form && this.form.showExamineDetail || false
  154 + const e = this.form && this.form.showExamine || false
145 155 return [
146   - { ...this.buttons[0], visible: s && this.$auth.hasPermi('procure-manage:domestic-trade:review') },
147   - { ...this.buttons[1], visible: s === 'AUDIT' && this.$auth.hasPermi('procure-manage:domestic-trade:approve') },
148   - { ...this.buttons[2], visible: this.$auth.hasPermi('procure-manage:domestic-trade:modify') },
149   - { ...this.buttons[3], visible: this.$auth.hasPermi('procure-manage:domestic-trade:cancel') },
  156 + { ...this.buttons[0], visible: d && this.$auth.hasPermi('procure-manage:domestic-trade:review') },
  157 + { ...this.buttons[1], visible: s === 'AUDIT' && e && this.$auth.hasPermi('procure-manage:domestic-trade:approve') },
  158 + { ...this.buttons[2], visible: s === 'REFUSE' && this.$auth.hasPermi('procure-manage:domestic-trade:modify') },
  159 + // { ...this.buttons[3], visible: s === 'PASS' && this.$auth.hasPermi('procure-manage:domestic-trade:change') },
  160 + { ...this.buttons[3], visible: s === 'REFUSE' && this.$auth.hasPermi('procure-manage:domestic-trade:cancel') },
150 161 ]
151 162 },
152 163 companyNatureOptions() {
... ... @@ -187,6 +198,14 @@ export default {
187 198 if (this.purchaseDept && this.purchaseDept.name != null) return String(this.purchaseDept.name)
188 199 const v = this.form && this.form.purchaseDepartmentName != null ? String(this.form.purchaseDepartmentName) : ''
189 200 return v || '-'
  201 + },
  202 + regionName() {
  203 + const name = this.safeText(this.form && this.form.regionName)
  204 + if (name) return name
  205 + const id = this.form && this.form.region != null ? String(this.form.region) : ''
  206 + const labelFromOptions = this.getOptionLabel(this.regionOptions, id)
  207 + if (labelFromOptions) return labelFromOptions
  208 + return id || '-'
190 209 }
191 210 },
192 211 created() {
... ... @@ -218,8 +237,45 @@ export default {
218 237 const res = await getPurchaseDeptApi()
219 238 const data = (res && res.data) ? res.data : {}
220 239 this.purchaseDept = (data && typeof data === 'object') ? data : null
  240 + await this.loadRegionOptions()
221 241 } catch (e) {
222 242 this.purchaseDept = null
  243 + this.regionOptions = []
  244 + }
  245 + },
  246 + normalizeRegionOptions(raw) {
  247 + const list = Array.isArray(raw)
  248 + ? raw
  249 + : (Array.isArray(raw && raw.data) ? raw.data : (Array.isArray(raw && raw.rows) ? raw.rows : []))
  250 + return list.map(it => {
  251 + const id = it && (it.id != null ? it.id : (it.value != null ? it.value : (it.regionId != null ? it.regionId : '')))
  252 + const name = it && (it.name != null ? it.name : (it.label != null ? it.label : (it.regionName != null ? it.regionName : '')))
  253 + return { label: name != null ? String(name) : '', value: id != null ? String(id) : '' }
  254 + }).filter(it => it.value)
  255 + },
  256 + getOptionLabel(options, value) {
  257 + const v = value != null ? String(value) : ''
  258 + if (!v) return ''
  259 + const match = (options || []).find(o => String(o.value) === v)
  260 + return match ? String(match.label || '') : ''
  261 + },
  262 + getPurchaseDepartmentId() {
  263 + if (this.purchaseDept && this.purchaseDept.id != null) return String(this.purchaseDept.id)
  264 + const v = this.form && this.form.purchaseDepartment != null ? String(this.form.purchaseDepartment) : ''
  265 + return v || ''
  266 + },
  267 + async loadRegionOptions() {
  268 + const purchaseDepartment = this.getPurchaseDepartmentId()
  269 + if (!purchaseDepartment) {
  270 + this.regionOptions = []
  271 + return
  272 + }
  273 + try {
  274 + const res = await getAllRegionApi(purchaseDepartment)
  275 + const raw = res && res.data != null ? res.data : []
  276 + this.regionOptions = this.normalizeRegionOptions(raw)
  277 + } catch (e) {
  278 + this.regionOptions = []
223 279 }
224 280 },
225 281 dicToSheetOptions(items) {
... ... @@ -231,6 +287,7 @@ export default {
231 287 if (typeof btn.onClick === 'function') return btn.onClick(this.form, btn.params)
232 288 const e = btn.event || ''
233 289 if (e === 'edit') return this.onEdit(btn && btn.params)
  290 + if (e === 'changeApply') return this.onChangeApply(btn && btn.params)
234 291 if (e === 'audit') return this.onAudit(btn && btn.params)
235 292 if (e === 'auditDetail') return this.onAuditDetail(btn && btn.params)
236 293 if (e === 'cancel') return this.onCancel(btn && btn.params)
... ... @@ -238,6 +295,9 @@ export default {
238 295 onEdit(params) {
239 296 uni.navigateTo({ url: '/pages/domestic_trade/modify?id=' + this.id })
240 297 },
  298 + onChangeApply(params) {
  299 + uni.navigateTo({ url: '/pages/domestic_trade/change?id=' + this.id })
  300 + },
241 301 onAudit(params) {
242 302 const id = this.id || (this.form && this.form.id) || ''
243 303 if (!id) return
... ... @@ -308,8 +368,10 @@ export default {
308 368 data.investigatorName = u && u.name ? String(u.name) : ''
309 369 }
310 370 this.form = data
  371 + await this.loadRegionOptions()
311 372 } catch (e) {
312 373 this.form = {}
  374 + this.regionOptions = []
313 375 uni.showToast({ title: '详情加载失败', icon: 'none' })
314 376 } finally {
315 377 this.loading = false
... ...
... ... @@ -73,6 +73,7 @@
73 73 <view class="section">
74 74 <view class="row"><text class="label">资信调查人</text><text class="value">{{ safeText(form.investigatorName) }}</text></view>
75 75 <view class="row"><text class="label">采购处</text><text class="value">{{ safeText(purchaseDepartmentName) }}</text></view>
  76 + <view class="row"><text class="label">区域</text><text class="value">{{ safeText(regionName) }}</text></view>
76 77 <view class="row"><text class="label">评审有效期</text><text class="value">{{ safeText(form.reviewValidUntil) }}</text></view>
77 78 <view class="row">
78 79 <text class="label">附件</text>
... ... @@ -91,7 +92,7 @@
91 92 <script>
92 93 import { downloadFile } from '@/utils/downloadFile.js'
93 94 import { getDicByCodes, getDicName } from '@/utils/dic.js'
94   -import { domesticCustomerCreditGetExamineByIdApi, getPurchaseDeptApi } from '@/api/procure-manage/domesticCustomerCredit.js'
  95 +import { domesticCustomerCreditGetExamineByIdApi, getPurchaseDeptApi, getAllRegionApi } from '@/api/procure-manage/domesticCustomerCredit.js'
95 96
96 97 export default {
97 98 name: 'DomesticCustomerCreditViewer',
... ... @@ -105,7 +106,8 @@ export default {
105 106 OPERATION_METHOD: [],
106 107 PURCHASE_SOURCE: []
107 108 },
108   - purchaseDept: null
  109 + purchaseDept: null,
  110 + regionOptions: []
109 111 }
110 112 },
111 113 computed: {
... ... @@ -143,6 +145,14 @@ export default {
143 145 if (this.purchaseDept && this.purchaseDept.name != null) return String(this.purchaseDept.name)
144 146 const v = this.form && this.form.purchaseDepartmentName != null ? String(this.form.purchaseDepartmentName) : ''
145 147 return v || '-'
  148 + },
  149 + regionName() {
  150 + const name = this.safeText(this.form && this.form.regionName)
  151 + if (name) return name
  152 + const id = this.form && this.form.region != null ? String(this.form.region) : ''
  153 + const labelFromOptions = this.getOptionLabel(this.regionOptions, id)
  154 + if (labelFromOptions) return labelFromOptions
  155 + return id || '-'
146 156 }
147 157 },
148 158 created() {
... ... @@ -177,8 +187,45 @@ export default {
177 187 const res = await getPurchaseDeptApi()
178 188 const data = (res && res.data) ? res.data : {}
179 189 this.purchaseDept = (data && typeof data === 'object') ? data : null
  190 + await this.loadRegionOptions()
180 191 } catch (e) {
181 192 this.purchaseDept = null
  193 + this.regionOptions = []
  194 + }
  195 + },
  196 + normalizeRegionOptions(raw) {
  197 + const list = Array.isArray(raw)
  198 + ? raw
  199 + : (Array.isArray(raw && raw.data) ? raw.data : (Array.isArray(raw && raw.rows) ? raw.rows : []))
  200 + return list.map(it => {
  201 + const id = it && (it.id != null ? it.id : (it.value != null ? it.value : (it.regionId != null ? it.regionId : '')))
  202 + const name = it && (it.name != null ? it.name : (it.label != null ? it.label : (it.regionName != null ? it.regionName : '')))
  203 + return { label: name != null ? String(name) : '', value: id != null ? String(id) : '' }
  204 + }).filter(it => it.value)
  205 + },
  206 + getOptionLabel(options, value) {
  207 + const v = value != null ? String(value) : ''
  208 + if (!v) return ''
  209 + const match = (options || []).find(o => String(o.value) === v)
  210 + return match ? String(match.label || '') : ''
  211 + },
  212 + getPurchaseDepartmentId() {
  213 + if (this.purchaseDept && this.purchaseDept.id != null) return String(this.purchaseDept.id)
  214 + const v = this.form && this.form.purchaseDepartment != null ? String(this.form.purchaseDepartment) : ''
  215 + return v || ''
  216 + },
  217 + async loadRegionOptions() {
  218 + const purchaseDepartment = this.getPurchaseDepartmentId()
  219 + if (!purchaseDepartment) {
  220 + this.regionOptions = []
  221 + return
  222 + }
  223 + try {
  224 + const res = await getAllRegionApi(purchaseDepartment)
  225 + const raw = res && res.data != null ? res.data : []
  226 + this.regionOptions = this.normalizeRegionOptions(raw)
  227 + } catch (e) {
  228 + this.regionOptions = []
182 229 }
183 230 },
184 231 dicToSheetOptions(items) {
... ... @@ -210,8 +257,10 @@ export default {
210 257 try {
211 258 const res = await domesticCustomerCreditGetExamineByIdApi(id)
212 259 this.form = (res && res.data) ? res.data : {}
  260 + await this.loadRegionOptions()
213 261 } catch (e) {
214 262 this.form = {}
  263 + this.regionOptions = []
215 264 }
216 265 },
217 266 onDownload(item) {
... ...
... ... @@ -299,9 +299,17 @@
299 299 </template>
300 300 </uni-list-item>
301 301
302   - <uni-list-item title="采购处">
303   - <template v-slot:footer>
304   - <uni-easyinput v-model="form.purchaseDepartmentName" disabled placeholder="" :inputBorder="false" />
  302 + <uni-list-item class="select-item" :class="form.purchaseDepartment ? 'is-filled' : 'is-empty'" clickable
  303 + @click="openSheet('purchaseDepartment')" :rightText="displayLabel('purchaseDepartmentName')" showArrow>
  304 + <template v-slot:body>
  305 + <view class="item-title"><text>采购处</text></view>
  306 + </template>
  307 + </uni-list-item>
  308 +
  309 + <uni-list-item class="select-item" :class="form.region ? 'is-filled' : 'is-empty'" clickable
  310 + @click="openSheet('region')" :rightText="displayLabel('region')" showArrow>
  311 + <template v-slot:body>
  312 + <view class="item-title"><text>区域</text></view>
305 313 </template>
306 314 </uni-list-item>
307 315
... ... @@ -343,7 +351,7 @@ import FileUpload from '@/components/file-upload/index.vue'
343 351 import SingleSelectSheet from '@/components/single-select/index.vue'
344 352 import MultiSelectSheet from '@/components/multi-select/index.vue'
345 353 import { getDicByCodes, getDicName } from '@/utils/dic.js'
346   -import { domesticCustomerCreditGetApi, domesticCustomerCreditSaveApi, getPurchaseDeptApi } from '@/api/procure-manage/domesticCustomerCredit.js'
  354 +import { domesticCustomerCreditGetApi, domesticCustomerCreditSaveApi, getPurchaseDeptApi, getAllRegionApi, getRegionApi } from '@/api/procure-manage/domesticCustomerCredit.js'
347 355
348 356 export default {
349 357 name: 'DomesticTradeModify',
... ... @@ -371,7 +379,8 @@ export default {
371 379 operationMethodOptions: [],
372 380 developNewOptions: [],
373 381 purchaseSourceOptions: [],
374   - purchaseDept: null,
  382 + regionOptions: [],
  383 + purchaseDeptOptions: [],
375 384 form: {
376 385 id: '',
377 386 unitName: '',
... ... @@ -423,6 +432,8 @@ export default {
423 432 investigatorName: '',
424 433 purchaseDepartment: '',
425 434 purchaseDepartmentName: '',
  435 + region: '',
  436 + regionName: '',
426 437 reviewValidUntil: ''
427 438 }
428 439 }
... ... @@ -437,7 +448,8 @@ export default {
437 448 const id = (query && (query.id || query.code)) ? String(query.id || query.code) : ''
438 449 this.id = id
439 450 await this.loadDicData()
440   - await this.loadPurchaseDeptOptions()
  451 + await this.loadPurchaseDeptList()
  452 + await this.loadRegionOptions()
441 453 await this.loadDetail()
442 454 },
443 455 methods: {
... ... @@ -468,23 +480,111 @@ export default {
468 480 const list = Array.isArray(items) ? items : []
469 481 return list.map(it => ({ label: it && it.name != null ? String(it.name) : '', value: it && it.code != null ? String(it.code) : '' })).filter(it => it.value)
470 482 },
471   - async loadPurchaseDeptOptions() {
  483 + async loadPurchaseDeptList() {
472 484 try {
473 485 const res = await getPurchaseDeptApi()
474   - const data = (res && res.data) ? res.data : {}
475   - this.purchaseDept = (data && typeof data === 'object') ? data : null
476   - this.form.purchaseDepartment = data && data.id != null ? String(data.id) : ''
477   - this.form.purchaseDepartmentName = data && data.name != null ? String(data.name) : ''
  486 + const raw = res && res.data != null ? res.data : []
  487 + this.purchaseDeptOptions = this.normalizeRegionOptions(raw)
  488 + } catch (e) {
  489 + this.purchaseDeptOptions = []
  490 + }
  491 + },
  492 + normalizeRegionOptions(raw) {
  493 + const list = Array.isArray(raw)
  494 + ? raw
  495 + : (Array.isArray(raw && raw.data) ? raw.data : (Array.isArray(raw && raw.rows) ? raw.rows : []))
  496 + return list.map(it => {
  497 + const id = it && (it.id != null ? it.id : (it.value != null ? it.value : (it.regionId != null ? it.regionId : '')))
  498 + const name = it && (it.name != null ? it.name : (it.label != null ? it.label : (it.regionName != null ? it.regionName : '')))
  499 + return { label: name != null ? String(name) : '', value: id != null ? String(id) : '' }
  500 + }).filter(it => it.value)
  501 + },
  502 + getOptionLabel(options, value) {
  503 + const v = value != null ? String(value) : ''
  504 + if (!v) return ''
  505 + const match = (options || []).find(o => String(o.value) === v)
  506 + return match ? String(match.label || '') : ''
  507 + },
  508 + syncRegionWithOptions() {
  509 + const label = this.getOptionLabel(this.regionOptions, this.form.region)
  510 + if (!label) {
  511 + this.form.region = ''
  512 + this.form.regionName = ''
  513 + return
  514 + }
  515 + this.form.regionName = label
  516 + },
  517 + async loadRegionOptions() {
  518 + let defaultRegionId = ''
  519 + let defaultRegionName = ''
  520 + try {
  521 + const regionRes = await getRegionApi()
  522 + const regionData = (regionRes && regionRes.data != null) ? regionRes.data : null
  523 + const parsed = regionData ? this.parseRegionIdAndName(regionData) : { id: '', name: '' }
  524 + if (parsed.id) {
  525 + defaultRegionId = parsed.id
  526 + defaultRegionName = parsed.name
  527 + }
  528 + } catch (e) {
  529 + // fall through to getAllRegionApi
  530 + }
  531 + const purchaseDepartment = this.form.purchaseDepartment ? String(this.form.purchaseDepartment) : ''
  532 + if (!purchaseDepartment) {
  533 + if (defaultRegionId) {
  534 + this.regionOptions = [{ label: defaultRegionName || String(defaultRegionId), value: defaultRegionId }]
  535 + if (!this.form.region) {
  536 + this.form.region = defaultRegionId
  537 + this.form.regionName = defaultRegionName || String(defaultRegionId)
  538 + }
  539 + } else {
  540 + this.regionOptions = []
  541 + this.form.region = ''
  542 + this.form.regionName = ''
  543 + }
  544 + return
  545 + }
  546 + try {
  547 + const res = await getAllRegionApi(purchaseDepartment)
  548 + const raw = res && res.data != null ? res.data : []
  549 + this.regionOptions = this.normalizeRegionOptions(raw)
  550 + if (defaultRegionId) {
  551 + const label = this.getOptionLabel(this.regionOptions, defaultRegionId)
  552 + if (label) {
  553 + if (!this.form.region) {
  554 + this.form.region = defaultRegionId
  555 + this.form.regionName = label
  556 + }
  557 + } else {
  558 + // 默认区域不在完整列表中,仍保留为选中项
  559 + this.regionOptions.push({ label: defaultRegionName || String(defaultRegionId), value: defaultRegionId })
  560 + if (!this.form.region) {
  561 + this.form.region = defaultRegionId
  562 + this.form.regionName = defaultRegionName || String(defaultRegionId)
  563 + }
  564 + }
  565 + } else {
  566 + this.syncRegionWithOptions()
  567 + }
478 568 } catch (e) {
479   - this.purchaseDept = null
480   - this.form.purchaseDepartment = ''
481   - this.form.purchaseDepartmentName = ''
  569 + this.regionOptions = []
  570 + this.form.region = ''
  571 + this.form.regionName = ''
482 572 }
483 573 },
  574 + parseRegionIdAndName(raw) {
  575 + if (!raw) return { id: '', name: '' }
  576 + if (Array.isArray(raw)) return this.parseRegionIdAndName(raw[0])
  577 + if (typeof raw === 'string' || typeof raw === 'number') return { id: String(raw), name: '' }
  578 + const id = raw.id != null ? raw.id : (raw.value != null ? raw.value : (raw.regionId != null ? raw.regionId : ''))
  579 + const name = raw.name != null ? raw.name : (raw.label != null ? raw.label : (raw.regionName != null ? raw.regionName : ''))
  580 + return { id: id != null ? String(id) : '', name: name != null ? String(name) : '' }
  581 + },
484 582 displayLabel(field) {
485 583 const m = this.form
486 584 const map = {
  585 + purchaseDepartmentName: '请选择采购处',
487 586 companyNatureName: '请选择公司性质',
  587 + region: '请选择区域',
488 588 purchaseSource: '请选择',
489 589 operationMode: '请选择',
490 590 isNewDevelopment: '请选择',
... ... @@ -513,6 +613,14 @@ export default {
513 613 const v = m.isNewDevelopment
514 614 return v ? getDicName('DEVELOP_NEW', String(v), this.dicOptions.DEVELOP_NEW) : map[field]
515 615 }
  616 + if (field === 'region') {
  617 + const v = m.region
  618 + if (!v) return map[field]
  619 + return this.getOptionLabel(this.regionOptions, v) || map[field]
  620 + }
  621 + if (field === 'purchaseDepartmentName') {
  622 + return this.getOptionLabel(this.purchaseDeptOptions, m.purchaseDepartment) || map[field]
  623 + }
516 624 const v = m[field]
517 625 if (v === true) return '是'
518 626 if (v === false) return '否'
... ... @@ -520,6 +628,8 @@ export default {
520 628 },
521 629 openSheet(field) {
522 630 const map = {
  631 + region: { title: '区域', options: this.regionOptions },
  632 + purchaseDepartment: { title: '采购处', options: this.purchaseDeptOptions },
523 633 purchaseSource: { title: '收购来源', options: this.purchaseSourceOptions },
524 634 operationMode: { title: '操作方式', options: this.operationMethodOptions },
525 635 isNewDevelopment: { title: '是否新开发', options: this.developNewOptions },
... ... @@ -556,10 +666,15 @@ export default {
556 666 value: this.form.companyNature || ''
557 667 }
558 668 },
559   - onSheetConfirm({ value }) {
  669 + onSheetConfirm({ value, label }) {
560 670 const field = this.sheet.field
561 671 if (!field) return
562 672 this.form[field] = value
  673 + if (field === 'region') this.form.regionName = label != null ? String(label) : this.getOptionLabel(this.regionOptions, value)
  674 + if (field === 'purchaseDepartment') {
  675 + this.form.purchaseDepartmentName = label != null ? String(label) : this.getOptionLabel(this.purchaseDeptOptions, value)
  676 + this.loadRegionOptions()
  677 + }
563 678 this.sheet.visible = false
564 679 },
565 680 onMultiSheetConfirm({ value }) {
... ... @@ -642,6 +757,9 @@ export default {
642 757 { key: 'reviewValidUntil', label: '评审有效期' },
643 758 { key: 'investigatorId', label: '资信调查人ID' }
644 759 ]
  760 + if (Array.isArray(this.regionOptions) && this.regionOptions.length) {
  761 + requiredTextFields.push({ key: 'region', label: '区域' })
  762 + }
645 763 for (let i = 0; i < requiredTextFields.length; i++) {
646 764 const f = requiredTextFields[i]
647 765 const v = this.form && this.form[f.key]
... ... @@ -700,6 +818,7 @@ export default {
700 818 delete payload.companyNatureName
701 819 delete payload.investigatorName
702 820 delete payload.purchaseDepartmentName
  821 + delete payload.regionName
703 822 payload.registeredCapital = Number(payload.registeredCapital)
704 823 const files = (Array.isArray(this.attachmentFiles) ? this.attachmentFiles : []).filter(it => it && it.id)
705 824 payload.attachmentFileIds = files.map(it => String(it.id || '')).filter(Boolean).join(',')
... ... @@ -714,7 +833,7 @@ export default {
714 833 try {
715 834 await domesticCustomerCreditSaveApi(payload)
716 835 uni.showToast({ title: '保存成功', icon: 'success' })
717   - setTimeout(() => { uni.navigateBack() }, 300)
  836 + setTimeout(() => { uni.redirectTo({ url: '/pages/domestic_trade/index' }) }, 300)
718 837 } catch (e) {
719 838 uni.showToast({ title: (e && e.msg) || '保存失败', icon: 'none' })
720 839 } finally {
... ... @@ -727,15 +846,12 @@ export default {
727 846 const res = await domesticCustomerCreditGetApi(this.id)
728 847 const data = res && res.data ? res.data : {}
729 848 const next = { ...this.form, ...(data || {}) }
730   - if (this.purchaseDept && this.purchaseDept.id != null) {
731   - next.purchaseDepartment = String(this.purchaseDept.id)
732   - next.purchaseDepartmentName = this.purchaseDept.name != null ? String(this.purchaseDept.name) : ''
733   - }
734 849 next.id = next.id || this.id || ''
735 850 const u = (this.$store && this.$store.state && this.$store.state.user) ? this.$store.state.user : {}
736 851 if (!next.investigatorId) next.investigatorId = u && u.id ? String(u.id) : ''
737 852 if (!next.investigatorName) next.investigatorName = u && u.name ? String(u.name) : ''
738 853 this.form = next
  854 + this.syncRegionWithOptions()
739 855 this.form.companyNatureName = this.labelsOf(this.companyNatureOptions, this.form.companyNature)
740 856 this.attachmentFiles = this.normalizeAttachmentFiles(data || next)
741 857 } catch (e) {
... ...
... ... @@ -469,7 +469,7 @@ export default {
469 469 await foreignTradeCreditSaveApi(payload)
470 470 uni.showToast({ title: '提交成功', icon: 'success' })
471 471 try { uni.setStorageSync('FOREIGN_TRADE_LIST_NEED_REFRESH', '1') } catch (e) {}
472   - setTimeout(() => { uni.navigateBack() }, 300)
  472 + setTimeout(() => { uni.redirectTo({ url: '/pages/foreign_trade/index' }) }, 300)
473 473 } catch (e) {
474 474 uni.showToast({ title: (e && e.msg) || '提交失败', icon: 'none' })
475 475 } finally {
... ...
... ... @@ -491,7 +491,7 @@ export default {
491 491 await foreignTradeCreditSaveApi(payload)
492 492 uni.showToast({ title: '保存成功', icon: 'success' })
493 493 try { uni.setStorageSync('FOREIGN_TRADE_LIST_NEED_REFRESH', '1') } catch (e) {}
494   - setTimeout(() => { uni.navigateBack() }, 300)
  494 + setTimeout(() => { uni.redirectTo({ url: '/pages/foreign_trade/index' }) }, 300)
495 495 } catch (e) {
496 496 uni.showToast({ title: (e && e.msg) || '保存失败', icon: 'none' })
497 497 } finally {
... ...
... ... @@ -145,13 +145,13 @@ export default {
145 145 {
146 146 title: '采购管理',
147 147 items: [{
148   - text: '内贸客户资信',
  148 + text: '内贸客户资信管理',
149 149 icon: '/static/images/index/order_list.png',
150 150 link: '/pages/domestic_trade/index',
151 151 name: 'DomesticTrade'
152 152 },
153 153 {
154   - text: '外客户资信',
  154 + text: '外贸客户资信管理',
155 155 icon: '/static/images/index/order_list.png',
156 156 link: '/pages/foreign_trade/index',
157 157 name: 'ForeignTrade'
... ...