Commit 4a06e5a0c2e085a7ab055b53e0d17a4ebd0021d4

Authored by 史婷婷
1 parent 94604b5d

feat: 审批页增加表单必填校验方法-通用&&补货单-审批(特殊角色&正常角色)

... ... @@ -251,6 +251,11 @@ export default {
251 251 ...vals,
252 252 }
253 253 },
  254 + // 校验表单 默认通过
  255 + basicRefCheck() {
  256 + const ref = this.$refs.basicRef
  257 + return ref && typeof ref.checkForm === 'function' ? ref.checkForm() : true
  258 + },
254 259 // 驳回
255 260 onReject() {
256 261 this.approveType = 'REFUSE'
... ... @@ -260,6 +265,11 @@ export default {
260 265 // 通过
261 266 // 在这里增加业务判断 比如 资信管理,判断有没有填写客户信息、公司评审(这些是不同角色进行操作的)
262 267 onPass() {
  268 + // 校验表单
  269 + if (!this.basicRefCheck()) {
  270 + return
  271 + }
  272 + console.log('onPass');
263 273 console.log('审核__roles&&bizFlag', this.roleCodes, this.auditCtx.bizFlag);
264 274 // 客户资信的审核
265 275 if (this.auditCtx.bizFlag === 'CUSTOMER_CREDIT_EDIT') {
... ...
... ... @@ -14,12 +14,13 @@
14 14 <view class="row"><text class="label">购货单位</text><text class="value">{{ form.customerName }}</text>
15 15 </view>
16 16 <view class="row"><text class="label">原计划发货日期</text><text class="value">{{ form.originPlanShipDate
17   - }}</text></view>
  17 + }}</text></view>
18 18 </view>
19 19
20 20 <!-- 产品 -->
21 21 <view class="section2">
22   - <Product mode="approve" :list="initPurchaseOrderLineList" @change="purchaseOrderLineListChange"/>
  22 + <Product mode="approve" :list="initPurchaseOrderLineList"
  23 + :canEditSupplementary="canEditSupplementary" @change="purchaseOrderLineListChange" />
23 24 </view>
24 25 <view class="section3">
25 26 <view class="view-total">
... ... @@ -35,7 +36,7 @@
35 36 <view class="row">
36 37 <view class="row2">
37 38 <text class="label">需求补货</text><text class="value">{{ form.totalSupplementaryQuantity
38   - }}</text>
  39 + }}</text>
39 40 </view>
40 41 </view>
41 42 </view>
... ... @@ -58,6 +59,8 @@ export default {
58 59 return {
59 60 form: {},
60 61 initPurchaseOrderLineList: [],
  62 + roleCodes: [],
  63 + canEditSupplementary: false
61 64 }
62 65 },
63 66 computed: {
... ... @@ -67,13 +70,25 @@ export default {
67 70 immediate: true,
68 71 handler(val) {
69 72 const v = (val !== undefined && val !== null) ? String(val) : ''
70   - if (v) this.loadDetail(v)
  73 + if (v) {
  74 + this.loadDetail(v);
  75 + this.getRoleInfo();
  76 + }
71 77 }
72 78 }
73 79 },
74 80 onLoad(query) {
  81 +
75 82 },
76 83 methods: {
  84 + getRoleInfo() {
  85 + this.roleCodes = this.$store.getters.roleCodes || [];
  86 + console.log('roleCodes', this.roleCodes)
  87 + // 一分厂经营办计划员/二分厂经营办计划员/三分厂经营办计划员/四分厂经营办计划员
  88 + const allowed = ['yfcjybjhy', 'efcjybjhy', 'sfcjybjhy', 'ztfcjybjhy'];
  89 + this.canEditSupplementary = allowed.some((code) => this.roleCodes.includes(code));
  90 + console.log('canEditSupplementary', this.canEditSupplementary)
  91 + },
77 92 async loadDetail(id) {
78 93 try {
79 94 const res = await getDetailApi(id)
... ... @@ -119,6 +134,38 @@ export default {
119 134 this.form.purchaseOrderLineList = list
120 135 this.calculateSummary(list)
121 136 },
  137 + getFormValues() {
  138 + const m = this.form || {}
  139 + return JSON.parse(JSON.stringify(m))
  140 + },
  141 + // 审批-通过:校验表单
  142 + checkForm() {
  143 + if (this.canEditSupplementary) {
  144 + const list = Array.isArray(this.form.purchaseOrderLineList) ? this.form.purchaseOrderLineList : [];
  145 + console.log('checkForm__list', list)
  146 + if (list.length === 0) {
  147 + uni.showToast({ title: '请先添加产品', icon: 'none' })
  148 + return false
  149 + }
  150 + const fields = [
  151 + { key: 'supplementaryQuantity', label: '需求补货数量' },
  152 + ]
  153 + for (let i = 0; i < list.length; i++) {
  154 + const it = list[i] || {}
  155 + for (const f of fields) {
  156 + const v = it && it[f.key]
  157 + if (v === undefined || v === null || String(v).trim() === '') {
  158 + uni.showToast({ title: `产品第${i + 1}条:${f.label}不能为空!`, icon: 'none' })
  159 + return false
  160 + }
  161 + }
  162 + }
  163 + return true
  164 + } else {
  165 + return true
  166 + }
  167 +
  168 + }
122 169 }
123 170 }
124 171 </script>
... ... @@ -201,11 +248,13 @@ export default {
201 248 font-weight: 600;
202 249 }
203 250 }
  251 +
204 252 .section3 {
205 253 padding: 0 32rpx;
206 254 background-color: #fff;
207 255 margin-top: 20rpx;
208 256 }
  257 +
209 258 .view-total {
210 259 padding: 20rpx 0;
211 260
... ...
... ... @@ -347,14 +347,12 @@
347 347 </template>
348 348 </uni-list-item>
349 349 <uni-list-item title="需求补货数量(kg)">
350   - <!-- <template v-slot:footer>
351   - <text class="value">{{ item.supplementaryQuantity }}</text>
352   - </template> -->
353 350 <template v-slot:footer>
354   - <uni-easyinput type="digit" v-model="item.supplementaryQuantity"
  351 + <uni-easyinput v-if="canEditSupplementary" type="digit" v-model="item.supplementaryQuantity"
355 352 placeholder="请输入需求补货数量kg" :inputBorder="false"
356 353 @input="onNonNegativeNumberInput($event, item, idx, 'supplementaryQuantity')"
357 354 @blur="onNonNegativeNumberBlur(item, idx, 'supplementaryQuantity')" />
  355 + <text v-else class="value">{{ item.supplementaryQuantity }}</text>
358 356 </template>
359 357 </uni-list-item>
360 358 <uni-list-item class="amount-item" title="单价(元/kg)">
... ... @@ -475,12 +473,14 @@ export default {
475 473 totalQuantity: { type: Number, default: 0 },
476 474 totalShippedQuantity: { type: Number, default: 0 },
477 475 totalSupplementaryQuantity: { type: Number, default: 0 },
478   - orderDate: { type: String, default: '' }
  476 + orderDate: { type: String, default: '' },
  477 + canEditSupplementary: { type: Boolean, default: false }
479 478 },
480 479 data() {
481 480 return {
482 481 items: [],
483 482 collapsedView: false,
  483 + roleCodes: [],
484 484 }
485 485 },
486 486 computed: {
... ... @@ -498,7 +498,11 @@ export default {
498 498 const mm = String(dt.getMonth() + 1).padStart(2, '0')
499 499 const dd = String(dt.getDate()).padStart(2, '0')
500 500 return `${yy}/${mm}/${dd}`
501   - }
  501 + },
  502 + // roleCodes() {
  503 + // const g = this.$store && this.$store.getters
  504 + // return (g && g.roleCodes) || [];
  505 + // },
502 506 },
503 507 watch: {
504 508 items: {
... ... @@ -518,7 +522,7 @@ export default {
518 522 },
519 523 created() {
520 524 const init = Array.isArray(this.list) && this.list.length > 0 ? this.list.map(v => ({ ...this.defaultItem(), ...v, collapsed: false })) : [{ ...this.defaultItem(), collapsed: false }]
521   - this.items = init
  525 + this.items = init;
522 526 },
523 527 methods: {
524 528 defaultItem() {
... ...