create.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. <product-choose-add
  20. v-if="productField"
  21. ref="product"
  22. :default-value="productField.value"
  23. @change="handleChangeProduct" />
  24. </view>
  25. </view>
  26. <!-- #ifdef MP-WEIXIN -->
  27. <view class="footer-btn-group">
  28. <button
  29. v-if="productField"
  30. class="button choose-product-btn"
  31. @click="handleAddProduct">
  32. 添加产品
  33. </button>
  34. <button class="button" @click="handleSave">
  35. 保存
  36. </button>
  37. </view>
  38. <!-- #endif -->
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import { QueryBusinessSetting } from 'API/crm/flow'
  44. import {
  45. QueryFieldList,
  46. AddBusiness,
  47. UpdateBusiness,
  48. QueryProduct as BusinessProduct
  49. } from 'API/crm/business'
  50. import ProductChooseAdd from '../components/baseAdd/productChooseAdd.vue'
  51. import CreateMixins from '../mixins/create.js'
  52. export default {
  53. name: 'CreateBusiness',
  54. components: {
  55. ProductChooseAdd
  56. },
  57. mixins: [CreateMixins],
  58. data() {
  59. return {
  60. moduleType: 'business',
  61. productField: null,
  62. defaultProductList: {},
  63. businessStatusList: [],
  64. }
  65. },
  66. onLoad() {
  67. QueryBusinessSetting().then(res => {
  68. this.businessStatusList = res
  69. this.getFieldList()
  70. }).catch(() => {})
  71. },
  72. methods: {
  73. /**
  74. * 获取表单字段
  75. */
  76. getFieldList() {
  77. const params = { type: 1 }
  78. if (this.id) params.id = this.id
  79. QueryFieldList(params)
  80. .then(res => {
  81. let findIndex = res.findIndex(o => o.formType === 'product')
  82. if (findIndex !== -1) {
  83. this.productField = res.splice(findIndex, 1)[0]
  84. }
  85. // 如果有商机阶段则删掉该字段,商机阶段只能在详情中进行修改
  86. findIndex = res.findIndex(o => o.formType === 'business_status')
  87. if (findIndex !== -1) {
  88. res.splice(findIndex, 1)
  89. }
  90. res.forEach(field => {
  91. // 自动编号为非必填
  92. if (field.autoGeneNumber === 1) {
  93. field.isNull = 0
  94. }
  95. if (!this.$isEmpty(field.authLevel)) {
  96. // 判断字段权限,如果没有权限则直接禁止修改
  97. field.disabled = this.getDisabledStatusByAuth(field)
  98. if (field.disabled) {
  99. if (field.sys_config) {
  100. field.sys_config.disabledMsg = ''
  101. }
  102. }
  103. }
  104. if (
  105. this.id &&
  106. field.formType === 'business_type' &&
  107. field.value
  108. ) {
  109. // 商机下 商机状态组
  110. field.value = this.businessStatusList.filter(o => o.flowId === field.value)
  111. } else {
  112. field.value = this.mixinsFormatFieldValue(field)
  113. }
  114. })
  115. this.fieldArr = res
  116. this.setForm()
  117. })
  118. .catch(() => {
  119. })
  120. },
  121. /**
  122. * 表单值发生改变
  123. * @param {Object} data
  124. */
  125. handleValueChange(data) {
  126. // console.log('value change: ', data)
  127. },
  128. /**
  129. * 去选择产品
  130. */
  131. handleAddProduct() {
  132. this.$nextTick(() => {
  133. if (this.$refs.product) {
  134. this.$refs.product.handleChoose()
  135. }
  136. })
  137. },
  138. /**
  139. * 确认选择产品后
  140. * @param {Object} data
  141. */
  142. handleChangeProduct(data) {
  143. console.log('change product: ', data)
  144. if (this.$refs.form) {
  145. this.$refs.form.setFormVal('money', data.totalMoney)
  146. }
  147. },
  148. /**
  149. * 保存
  150. */
  151. handleSave() {
  152. this.loading = true
  153. this.$refs.form.getForm().then(async form => {
  154. if (this.productField) {
  155. const productData = this.$refs.product.getForm()
  156. form.product = productData.product
  157. form.entity = {
  158. ...form.entity,
  159. discountRate: productData.discountRate,
  160. totalPrice: productData.totalPrice
  161. }
  162. }
  163. this.baseFormatSaveData(form)
  164. console.log('save: ', form)
  165. // this.loading = false
  166. // return
  167. const request = this.id ? UpdateBusiness : AddBusiness
  168. request(form).then(() => {
  169. this.$toast(this.id ? '修改成功' : '添加成功')
  170. this.$refreshAndToPrev(this)
  171. }).catch(() => {
  172. this.loading = false
  173. })
  174. }).catch(() => {
  175. this.loading = false
  176. })
  177. }
  178. }
  179. }
  180. </script>
  181. <style scoped lang="scss">
  182. @import '../style/create.scss';
  183. </style>