You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
6.0 KiB

4 months ago
​
4 months ago
​
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
​
​
4 months ago
4 months ago
4 months ago
​
​
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
4 months ago
4 months ago
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
4 months ago
​
​
​
​
​
4 months ago
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
4 months ago
​
​
​
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
4 months ago
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <template>
  2. <div class="po-customer-field-auth">
  3. <el-button v-if="!readonly" type="primary" :loading="saving" style="margin-bottom: 10px" @click="save">保存字段权限</el-button>
  4. <div class="rq">
  5. <el-table class="field-auth-table" :data="rows" border style="width: 100%" height="400">
  6. <el-table-column prop="fieldCode" label="字段编码" min-width="160" />
  7. <el-table-column prop="fieldLabel" label="字段名称" min-width="140" />
  8. <el-table-column label="显示名称" min-width="180">
  9. <template slot-scope="{ row }">
  10. <el-input
  11. v-model="row.displayLabel"
  12. :disabled="readonly || !isExtField(row)"
  13. clearable
  14. placeholder="扩展字段可维护"
  15. />
  16. </template>
  17. </el-table-column>
  18. <el-table-column label="字典类型" min-width="160">
  19. <template slot-scope="{ row }">
  20. <el-input
  21. v-model="row.dictType"
  22. :disabled="readonly || !isDictTypeEditable(row)"
  23. clearable
  24. :placeholder="isExtDateField(row) ? '日期扩展字段不可填' : '留空=默认组件'"
  25. />
  26. </template>
  27. </el-table-column>
  28. <el-table-column label="可见" width="70">
  29. <template slot-scope="{ row }">
  30. <el-checkbox
  31. v-model="row.visibleFlag"
  32. true-label="Y"
  33. false-label="N"
  34. :disabled="readonly || isMandatoryField(row)"
  35. @change="onVisibleChange(row)" />
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="必填" width="70">
  39. <template slot-scope="{ row }">
  40. <!-- 必填对标准/扩展字段均可维护;必录字段锁定为必填不可取消;只读或字段不可见时禁用(ship_via 已移出必录名单,可自由勾选) -->
  41. <el-checkbox
  42. v-model="row.requiredFlag"
  43. true-label="Y"
  44. false-label="N"
  45. :disabled="readonly || isForceRequiredField(row) || row.visibleFlag !== 'Y'" />
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. </div>
  50. </div>
  51. </template>
  52. <script>
  53. import { listPoCustomerFieldAuth, savePoCustomerFieldAuth } from '@/api/order/poCustomer'
  54. // 系统级必录字段:默认必填且不允许取消(与后端 PoFieldAuthSupport.FORCE_REQUIRED_FIELD_CODES 保持一致)
  55. const FORCE_REQUIRED_FIELD_CODES = [
  56. 'po_no', 'buyer', 'supplier_name', 'destination', 'order_date',
  57. 'enquiry', 'part_no', 'qty', 'want_receive_date', 'price'
  58. ]
  59. export default {
  60. name: 'ComPoCustomerFieldAuth',
  61. props: {
  62. site: { type: String, required: true },
  63. customerCode: { type: String, default: '' },
  64. readonly: { type: Boolean, default: false }
  65. },
  66. data () {
  67. return { rows: [], saving: false }
  68. },
  69. watch: {
  70. customerCode: {
  71. immediate: true,
  72. handler () { this.load() }
  73. }
  74. },
  75. methods: {
  76. load () {
  77. if (!this.customerCode) {
  78. this.rows = []
  79. return
  80. }
  81. listPoCustomerFieldAuth({ site: this.site, customerCode: this.customerCode }).then(({ data }) => {
  82. this.rows = (data && data.code === 0 && data.rows) ? data.rows.map(r => ({
  83. ...r,
  84. fieldLabel: r.fieldLabel || r.fieldCode,
  85. mandatoryFlag: (r.mandatoryFlag || 'N').toUpperCase(),
  86. displayLabel: r.displayLabel || r.fieldLabel || r.fieldCode,
  87. dictType: this.isDictTypeEditable(r) ? (r.dictType || '') : '',
  88. visibleFlag: ((r.mandatoryFlag || 'N').toUpperCase() === 'Y') ? 'Y' : (r.visibleFlag || 'Y'),
  89. requiredFlag: this.isForceRequiredField(r) ? 'Y' : (r.requiredFlag || 'N')
  90. })) : []
  91. })
  92. },
  93. isExtField (row) {
  94. const code = row && row.fieldCode ? String(row.fieldCode).toLowerCase() : ''
  95. return code.indexOf('ext_') === 0
  96. },
  97. isExtDateField (row) {
  98. const code = row && row.fieldCode ? String(row.fieldCode).toLowerCase() : ''
  99. return /^ext_dt\d{2}$/.test(code)
  100. },
  101. isDictTypeEditable (row) {
  102. return this.isExtField(row) && !this.isExtDateField(row)
  103. },
  104. isMandatoryField (row) {
  105. return !!(row && String(row.mandatoryFlag || '').toUpperCase() === 'Y')
  106. },
  107. isForceRequiredField (row) {
  108. const code = row && row.fieldCode ? String(row.fieldCode).trim().toLowerCase() : ''
  109. return !!code && FORCE_REQUIRED_FIELD_CODES.indexOf(code) !== -1
  110. },
  111. onVisibleChange (row) {
  112. if (this.isMandatoryField(row)) {
  113. this.$set(row, 'visibleFlag', 'Y')
  114. return
  115. }
  116. // 字段设为不可见时,必填无意义,自动取消勾选,避免出现「隐藏却必填」(必录字段除外,始终锁定为 Y)
  117. if (row.visibleFlag !== 'Y' && !this.isForceRequiredField(row)) {
  118. this.$set(row, 'requiredFlag', 'N')
  119. }
  120. },
  121. normalizeNullable (value) {
  122. if (value === null || value === undefined) return null
  123. const text = String(value).trim()
  124. return text ? text : null
  125. },
  126. normalizeDictTypeForSave (row) {
  127. if (!this.isDictTypeEditable(row)) {
  128. return null
  129. }
  130. return this.normalizeNullable(row && row.dictType)
  131. },
  132. save () {
  133. if (!this.customerCode) return
  134. this.saving = true
  135. savePoCustomerFieldAuth({
  136. site: this.site,
  137. customerCode: this.customerCode,
  138. rows: this.rows.map(r => ({
  139. fieldCode: r.fieldCode,
  140. visibleFlag: r.visibleFlag,
  141. requiredFlag: r.requiredFlag,
  142. displayLabel: this.normalizeNullable(r.displayLabel),
  143. dictType: this.normalizeDictTypeForSave(r),
  144. active: r.active || 'Y'
  145. }))
  146. }).then(({ data }) => {
  147. this.saving = false
  148. if (data && data.code === 0) {
  149. this.$message.success('保存成功')
  150. this.load()
  151. } else {
  152. this.$message.error((data && data.msg) || '保存失败')
  153. }
  154. }).catch(() => {
  155. this.saving = false
  156. this.$message.error('保存失败')
  157. })
  158. }
  159. }
  160. }
  161. </script>
  162. <style scoped>
  163. .po-customer-field-auth .field-auth-table {
  164. margin-bottom: 10px;
  165. }
  166. </style>