create.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /**
  2. * crm 新建/编辑通用逻辑
  3. * @author yxk
  4. */
  5. import { QueryField, CheckOnlyField } from 'API/base'
  6. import { PreviewFiledName } from 'API/examine'
  7. import { QueryBusinessSetting } from 'API/crm/flow'
  8. import formMixins from '@/mixins/formMixins.js'
  9. import { deepCopy } from '@/utils/lib.js'
  10. import { isArray, isObject } from '@/utils/types.js'
  11. // import invoiceField from '../invoiceField.js'
  12. import { crmEnum } from '../enum.js'
  13. export default {
  14. mixins: [formMixins],
  15. data() {
  16. return {
  17. id: null,
  18. batchId: null,
  19. guid: null,
  20. routerQuery: {},
  21. fieldArr: [],
  22. showAudit: false,
  23. auditUser: null,
  24. authInfo: {},
  25. auditConditionFields: [],
  26. loading: false,
  27. timer: null
  28. }
  29. },
  30. computed: {
  31. typeObj() {
  32. return crmEnum[this.moduleType] || {}
  33. },
  34. navTitle() {
  35. const action = this.routerQuery.id ? '编辑' : '新建'
  36. return action + this.typeObj.label || ''
  37. }
  38. },
  39. onLoad(options) {
  40. this.routerQuery = options || {}
  41. this.id = options.id
  42. this.batchId = options.batchId
  43. this.guid = this.$guid()
  44. },
  45. onUnload() {
  46. getApp().globalData.formBridge = {}
  47. },
  48. methods: {
  49. /**
  50. * 根据权限判断字段是否可编辑
  51. * @param {Object} field
  52. */
  53. getDisabledStatusByAuth(field) {
  54. const crmType = this.moduleType
  55. if (crmType === 'business' && ['business_type', 'business_status'].includes(field.formType)) return false
  56. if (crmType === 'contract' && ['business', 'contacts', 'customer'].includes(field.formType)) return false
  57. if (crmType === 'receivables' && ['contract', 'customer'].includes(field.formType)) return false
  58. if (crmType === 'visit' && ['business', 'contacts', 'customer'].includes(field.formType)) return false
  59. if (crmType === 'invoice' && ['contractId', 'contractMoney'].includes(field.fieldName)) return true
  60. // 1 不能查看不能编辑 2 可查看 3 可查看可编辑
  61. return field.authLevel !== 3 // false 可编辑
  62. },
  63. setForm() {
  64. const bridge = getApp().globalData.formBridge
  65. // console.log('setForm bridge: ', bridge)
  66. if (!bridge.default) return
  67. this.$nextTick(() => {
  68. this.$refs.form.setForm(bridge.default || {})
  69. Object.keys(bridge.default).forEach(key => {
  70. this.$refs.form.setDisabled(key, true)
  71. this.$refs.form.setConfig(key, { disabledMsg: '' })
  72. })
  73. })
  74. // #ifdef APP-PLUS
  75. // App 偶发会出现字段渲染不上的问题,在此强制刷新页面
  76. this.$nextTick(() => {
  77. if (!this.$isEmpty(bridge.default)) {
  78. this.$refs.form.updateView()
  79. }
  80. })
  81. // #endif
  82. },
  83. /**
  84. * 获取审批流程条件
  85. */
  86. getAuditList() {
  87. const label = {
  88. contract: 1,
  89. receivables: 2,
  90. invoice: 3
  91. }[this.routerQuery.type] || ''
  92. PreviewFiledName({
  93. label
  94. })
  95. .then(res => {
  96. this.showAudit = res !== null
  97. if (!this.showAudit) return
  98. const mapIns = new Map()
  99. this.auditConditionFields = res.filter(o => !mapIns.has(o.fieldId) && mapIns.set(o.fieldId, 1))
  100. console.log('PreviewFiledName: ', this.auditConditionFields)
  101. this.$nextTick(() => {
  102. const dataMap = {}
  103. const bridge = getApp().globalData.formBridge || {}
  104. this.auditConditionFields.forEach(o => {
  105. const findRes = this.fieldArr.find(f => f.fieldName === o.fieldName)
  106. if (findRes) {
  107. let value = null
  108. if (bridge.default && bridge.default.hasOwnProperty(o.fieldName)) {
  109. value = bridge.default[o.fieldName]
  110. } else {
  111. value = findRes.value
  112. }
  113. switch (findRes.formType) {
  114. case 'select':
  115. if (this.$isEmpty(value)) value = ''
  116. if (isArray(value)) {
  117. value = value[0].value
  118. }
  119. break
  120. case 'checkbox':
  121. if (this.$isEmpty(value)) value = ''
  122. if (isArray(value)) {
  123. value = value.map(o => o.value).join(',')
  124. }
  125. break
  126. default:
  127. value = this.$isEmpty(value) ? '' : value
  128. }
  129. o._val = value
  130. dataMap[o.fieldName] = value
  131. }
  132. })
  133. this.$refs.wkAuditAdd.getAuditInfo({
  134. label,
  135. dataMap
  136. })
  137. })
  138. })
  139. .catch(() => {})
  140. },
  141. /**
  142. * 根据审批条件变更审批流
  143. */
  144. changeAuditFlow(field, value) {
  145. if (!this.showAudit) return
  146. if (![
  147. 'contract',
  148. 'receivables',
  149. 'invoice'
  150. ].includes(this.moduleType)) return
  151. const findRes = this.auditConditionFields.find(o => o.fieldName === field.fieldName)
  152. if (!findRes) return
  153. if (this.timer) {
  154. clearTimeout(this.timer)
  155. this.timer = null
  156. }
  157. this.timer = setTimeout(() => {
  158. // number floatnumber select checkbox
  159. switch (field.formType) {
  160. case 'select':
  161. if (this.$isEmpty(value)) value = ''
  162. if (isArray(value)) {
  163. value = value[0].value
  164. }
  165. break
  166. case 'checkbox':
  167. if (this.$isEmpty(value)) value = ''
  168. if (isArray(value)) {
  169. value = value.map(o => o.value).join(',')
  170. }
  171. break
  172. default:
  173. value = this.$isEmpty(value) ? '' : value
  174. }
  175. findRes._val = value
  176. const dataMap = {}
  177. this.auditConditionFields.forEach(o => {
  178. if (o.hasOwnProperty('_val')) {
  179. dataMap[o.fieldName] = this.$isEmpty(o._val) ? '' : o._val
  180. } else {
  181. dataMap[o.fieldName] = ''
  182. }
  183. })
  184. this.$nextTick(() => {
  185. const label = {
  186. contract: 1,
  187. receivables: 2,
  188. invoice: 3
  189. }[this.routerQuery.type] || ''
  190. this.$refs.wkAuditAdd.getAuditInfo({
  191. label,
  192. dataMap
  193. })
  194. clearTimeout(this.timer)
  195. this.timer = null
  196. })
  197. }, 500)
  198. },
  199. /**
  200. * 获取保存的审批数据
  201. * @param {Object} form
  202. */
  203. baseGetAuditSaveData(form) {
  204. // 审批信息
  205. if (this.showAudit) {
  206. const data = this.$refs.wkAuditAdd.getSaveData()
  207. if (data === null) {
  208. this.loading = false
  209. return
  210. }
  211. const dataMap = {}
  212. this.auditConditionFields.forEach(o => {
  213. if (o.hasOwnProperty('_val')) {
  214. dataMap[o.fieldName] = this.$isEmpty(o._val) ? '' : o._val
  215. }
  216. })
  217. const label = {
  218. contract: 1,
  219. receivables: 2,
  220. invoice: 3
  221. }[this.routerQuery.type] || ''
  222. form.examineFlowData = {
  223. ...data,
  224. label,
  225. dataMap
  226. }
  227. }
  228. },
  229. /**
  230. * 保存前处理数据
  231. * @param {Object} form
  232. */
  233. baseFormatSaveData(form) {
  234. if (this.id && this.batchId) {
  235. form.entity[this.typeObj.primaryKey] = this.id
  236. form.entity.batchId = this.batchId
  237. }
  238. if (!form.hasOwnProperty('field')) {
  239. form.field = []
  240. }
  241. const bridge = getApp().globalData.formBridge || {}
  242. if (bridge.assignForm) {
  243. form = Object.assign(form, bridge.assignForm)
  244. }
  245. const arr = form.field
  246. .filter(o => o.formType !== 'desc_text')
  247. .map(o => {
  248. return {
  249. fieldName: o.fieldName,
  250. name: o.name,
  251. type: o.type,
  252. fieldId: o.fieldId,
  253. value: o.value,
  254. fieldType: o.fieldType
  255. }
  256. })
  257. form.field = arr
  258. }
  259. }
  260. }