create.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <wk-nav-bar :title="navTitle">
  6. <!-- #ifndef MP-WEIXIN -->
  7. <button class="button white-btn" @click="handleSave">
  8. 保存
  9. </button>
  10. <!-- #endif -->
  11. </wk-nav-bar>
  12. <view class="container">
  13. <view class="scroll-content">
  14. <wk-form
  15. ref="form"
  16. :fields="fieldArr"
  17. :batch-id="batchId"
  18. @change="handleValueChange" />
  19. <view class="empty-box" />
  20. </view>
  21. </view>
  22. <!-- #ifdef MP-WEIXIN -->
  23. <view class="footer-btn-group">
  24. <button class="button" @click="handleSave">
  25. 保存
  26. </button>
  27. </view>
  28. <!-- #endif -->
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. QueryFieldList,
  35. AddContacts,
  36. UpdateContacts,
  37. GetList as crmContactsIndex
  38. } from 'API/crm/concat'
  39. import CreateMixins from '../mixins/create.js'
  40. import { deepCopy } from '@/utils/lib.js'
  41. export default {
  42. name: 'CreateContacts',
  43. mixins: [CreateMixins],
  44. data() {
  45. return {
  46. moduleType: 'contacts',
  47. }
  48. },
  49. onLoad() {
  50. this.getFieldList()
  51. },
  52. methods: {
  53. getFieldList() {
  54. const params = { type: 1 }
  55. if (this.id) params.id = this.id
  56. QueryFieldList(params)
  57. .then(res => {
  58. let searchList = []
  59. if (this.routerQuery.id) {
  60. let customerId = res.filter((item, index) => {
  61. return item.fieldName === 'customerId'
  62. })[0].value[0].customerId
  63. searchList.push({
  64. formType: 'text',
  65. name: 'customer_id',
  66. type: 1,
  67. values: [customerId]
  68. })
  69. }
  70. res.forEach(field => {
  71. // 自动编号为非必填
  72. if (field.autoGeneNumber === 1) {
  73. field.isNull = 0
  74. }
  75. if (!this.$isEmpty(field.authLevel)) {
  76. // 判断字段权限,如果没有权限则直接禁止修改
  77. field.disabled = this.getDisabledStatusByAuth(field)
  78. if (field.disabled) {
  79. if (field.sys_config) {
  80. field.sys_config.disabledMsg = ''
  81. }
  82. }
  83. }
  84. field.value = this.mixinsFormatFieldValue(field)
  85. if (field.fieldName === 'parentContactsId') {
  86. if (this.routerQuery.id) {
  87. field.sys_config = {
  88. otherParams: {
  89. searchList: searchList,
  90. type: 3
  91. }
  92. }
  93. } else {
  94. field.disabled = true
  95. field.sys_config = {
  96. disabledMsg: '请先选择客户'
  97. }
  98. }
  99. // 客户下直属上级
  100. }
  101. })
  102. this.fieldArr = res
  103. this.setForm()
  104. })
  105. .catch(() => {
  106. })
  107. },
  108. /**
  109. * 表单值发生改变
  110. * @param {Object} data
  111. */
  112. handleValueChange(data) {
  113. this.changeAuditFlow(data.field, data.value)
  114. let findIndex = -1
  115. const bridge = getApp().globalData.formBridge
  116. const bridgeDefault = bridge.default || {}
  117. if (data.field.formType === 'customer') {
  118. // 如果修改的是客户
  119. const arr = ['parentContactsId']
  120. arr.forEach(key => {
  121. findIndex = this.fieldArr.findIndex(o => o.fieldName === key)
  122. if (findIndex !== -1 && !bridgeDefault.hasOwnProperty(key)) {
  123. const fieldItem = deepCopy(this.fieldArr[findIndex])
  124. fieldItem.value = []
  125. if (data.value.length > 0) {
  126. const searchList = [{
  127. formType: 'text',
  128. name: 'customer_id',
  129. type: 1,
  130. values: [data.value[0].customerId]
  131. }]
  132. fieldItem.sys_config.otherParams = {
  133. searchList: searchList,
  134. type: 3
  135. }
  136. fieldItem.disabled = false
  137. } else {
  138. fieldItem.sys_config = {
  139. disabledMsg: '请先选择客户',
  140. otherParams: {}
  141. }
  142. fieldItem.disabled = true
  143. }
  144. this.$refs.form.updateFields(findIndex, fieldItem)
  145. }
  146. })
  147. }
  148. },
  149. /**
  150. * 保存
  151. */
  152. handleSave() {
  153. this.loading = true
  154. this.$refs.form.getForm().then(async form => {
  155. if (this.id == form.entity.parentContactsId) {
  156. this.$toast('直属上级不能为当前联系人')
  157. this.loading = false
  158. return
  159. }
  160. this.baseFormatSaveData(form)
  161. // this.loading = false
  162. // return
  163. const request = this.id ? UpdateContacts : AddContacts
  164. request(form).then(() => {
  165. this.$toast(this.id ? '修改成功' : '添加成功')
  166. this.$refreshAndToPrev(this)
  167. }).catch(() => {
  168. this.loading = false
  169. })
  170. }).catch(() => {
  171. this.loading = false
  172. })
  173. }
  174. }
  175. }
  176. </script>
  177. <style scoped lang="scss">
  178. @import '../style/create.scss';
  179. </style>