add.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <wk-nav-bar title="添加团队成员">
  6. <!-- #ifndef MP-WEIXIN -->
  7. <button
  8. class="button white-btn"
  9. @click="handleSave">
  10. 保存
  11. </button>
  12. <!-- #endif -->
  13. </wk-nav-bar>
  14. <view class="container">
  15. <wk-form
  16. ref="form"
  17. :fields="fieldArr"
  18. @change="formChange" />
  19. </view>
  20. <!-- #ifdef MP-WEIXIN -->
  21. <view class="footer-btn-group">
  22. <button class="button" @click="handleSave">
  23. 保存
  24. </button>
  25. </view>
  26. <!-- #endif -->
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import {AddMembers as CustomerAdd} from 'API/crm/customer'
  32. import {AddMembers as BusinessAdd} from 'API/crm/business'
  33. import {AddMembers as ContractAdd} from 'API/crm/contract'
  34. import Fields from '@/utils/fields.js'
  35. export default {
  36. name: 'GroupAdd',
  37. data() {
  38. return {
  39. id: null,
  40. type: null,
  41. apiMap: {
  42. customer: {fn: CustomerAdd, fields: 'customerId'},
  43. business: {fn: BusinessAdd, fields: 'businessId'},
  44. contract: {fn: ContractAdd, fields: 'contractId'}
  45. },
  46. fieldArr: [],
  47. loading: false
  48. }
  49. },
  50. onLoad(options) {
  51. this.routerQuery = options
  52. this.id = options.id
  53. this.type = options.type
  54. this.initForm()
  55. },
  56. methods: {
  57. initForm() {
  58. this.fieldArr = []
  59. const powerOptions = [
  60. {label: '只读', value: 1},
  61. {label: '读写', value: 2}
  62. ]
  63. const changeTypeOptions = [
  64. {label: '联系人', value: '1'},
  65. {label: '商机', value: '2'},
  66. {label: '合同', value: '3'},
  67. ]
  68. const timeOptions = [
  69. { label: '不限', value: '0' },
  70. { label: '截止到', value: '1' }
  71. ]
  72. let arr = [
  73. new Fields({name: '团队成员', formType: 'user', fieldName: 'memberIds', isNull: 1 }),
  74. new Fields({name: '成员权限', formType: 'select', fieldName: 'power', isNull: 1, defaultValue: [powerOptions[0]], setting: powerOptions})
  75. ]
  76. if (this.type === 'customer') {
  77. arr.push(new Fields({
  78. name: '添加到其他相关团队',
  79. formType: 'checkbox',
  80. fieldName: 'changeType',
  81. setting: changeTypeOptions,
  82. maxlength: 2
  83. }))
  84. }
  85. const arr0 = [
  86. new Fields({
  87. name: '有效时间',
  88. formType: 'select',
  89. fieldName: 'expiresTime',
  90. defaultValue: [timeOptions[0]],
  91. setting: timeOptions,
  92. isNull: 1,
  93. optionsData: {
  94. 1: [1001]
  95. },
  96. remark: 'options_type'
  97. }),
  98. new Fields({
  99. name: '',
  100. formAssistId: 1001,
  101. formType: 'date',
  102. fieldName: 'time',
  103. defaultValue: null,
  104. setting: []
  105. })
  106. ]
  107. arr = arr.concat(arr0)
  108. this.fieldArr = arr
  109. },
  110. formChange(data) {
  111. if (data.field.fieldName === 'expiresTime') {
  112. if (this.$isEmpty(data.value)) {
  113. this.$refs.form.setFormVal('expiresTime', [{ label: '不限', value: '0' }])
  114. }
  115. }
  116. },
  117. handleSave() {
  118. if (this.loading) return
  119. this.loading = true
  120. this.$refs.form.getForm().then(form => {
  121. // console.log('form: ', form)
  122. form = form.entity
  123. const params = {
  124. power: form.power,
  125. memberIds: form.memberIds.split(',') || [],
  126. ids: [this.id]
  127. }
  128. if (this.type === 'customer' && !this.$isEmpty(form.changeType)) {
  129. params.changeType = form.changeType.split(',')
  130. }
  131. if (form.expiresTime === '1') {
  132. if (this.$isEmpty(form.time)) {
  133. this.$toast('截止时间不能为空')
  134. this.loading = false
  135. return
  136. }
  137. params.expiresTime = form.time
  138. } else {
  139. params.expiresTime = ''
  140. }
  141. this.apiMap[this.type].fn(params).then(response => {
  142. this.$toast('添加成功')
  143. this.loading = false
  144. this.$refreshAndToPrev(this)
  145. }).catch(() => {
  146. this.loading = false
  147. })
  148. }).catch(() => {
  149. this.loading = false
  150. })
  151. }
  152. }
  153. }
  154. </script>
  155. <style scoped lang="scss">
  156. .container {
  157. width: 100%;
  158. flex: 1;
  159. padding-bottom: 20rpx;
  160. margin-top: 20rpx;
  161. }
  162. </style>