create.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. <wk-audit-add
  20. v-if="showAudit"
  21. ref="wkAuditAdd" />
  22. <view class="empty-box" />
  23. </view>
  24. </view>
  25. <!-- #ifdef MP-WEIXIN -->
  26. <view class="footer-btn-group">
  27. <button
  28. v-if="productField"
  29. class="button choose-product-btn"
  30. @click="handleAddProduct">
  31. 添加产品
  32. </button>
  33. <button class="button" @click="handleSave">
  34. 保存
  35. </button>
  36. </view>
  37. <!-- #endif -->
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. QueryFieldList,
  44. AddReceivables,
  45. UpdateReceivables
  46. } from 'API/crm/received'
  47. import {
  48. GetList as GetContractList,
  49. QueryProduct as ContractProduct
  50. } from 'API/crm/contract'
  51. import CreateMixins from '../mixins/create.js'
  52. import { deepCopy } from '@/utils/lib.js'
  53. export default {
  54. name: 'CreateReceivables',
  55. mixins: [CreateMixins],
  56. data() {
  57. return {
  58. moduleType: 'receivables',
  59. crmType: ''
  60. }
  61. },
  62. onLoad(options) {
  63. this.crmType = options.crmType
  64. this.getFieldList()
  65. },
  66. methods: {
  67. getFieldList() {
  68. const params = { type: 1 }
  69. if (this.id) params.id = this.id
  70. QueryFieldList(params)
  71. .then(res => {
  72. res.forEach(field => {
  73. // 自动编号为非必填
  74. if (field.autoGeneNumber === 1) {
  75. field.isNull = 0
  76. }
  77. if (!this.$isEmpty(field.authLevel)) {
  78. // 判断字段权限,如果没有权限则直接禁止修改
  79. field.disabled = this.getDisabledStatusByAuth(field)
  80. if (field.disabled) {
  81. if (field.sys_config) {
  82. field.sys_config.disabledMsg = ''
  83. }
  84. }
  85. }
  86. // 客户下合同
  87. if (field.fieldName === 'contractId') {
  88. field.disabled = true
  89. field.sys_config = {
  90. request: GetContractList,
  91. otherParams: {},
  92. disabledMsg: '请先选择客户',
  93. optionsConfig: {
  94. labelField: 'num',
  95. valueField: 'contractId'
  96. }
  97. }
  98. } else if (field.fieldName === 'receivablesPlanId') {
  99. field.disabled = true
  100. field.sys_config = {
  101. otherParams: {},
  102. disabledMsg: '请先选择合同'
  103. }
  104. }
  105. field.value = this.mixinsFormatFieldValue(field)
  106. })
  107. // 合同字段
  108. let findIndex = -1
  109. let fieldItem = null
  110. const customerField = res.find(o => o.formType === 'customer')
  111. if (customerField) {
  112. findIndex = res.findIndex(o => o.fieldName === 'contractId')
  113. if (findIndex !== -1) {
  114. fieldItem = deepCopy(res[findIndex])
  115. if (customerField.value.length > 0) {
  116. fieldItem.sys_config.otherParams = {
  117. searchList: [
  118. {
  119. formType: 'text',
  120. name: 'customer_id',
  121. type: 1,
  122. values: [customerField.value[0].customerId]
  123. },
  124. {
  125. formType: 'checkStatus',
  126. name: 'checkStatus',
  127. type: 1,
  128. values: [1, 10]
  129. }
  130. ]
  131. }
  132. fieldItem.disabled = false
  133. } else {
  134. fieldItem.sys_config.otherParams = {}
  135. fieldItem.disabled = true
  136. fieldItem.value = []
  137. }
  138. res[findIndex] = fieldItem
  139. }
  140. }
  141. // 回款计划字段
  142. findIndex = res.findIndex(o => o.fieldName === 'receivablesPlanId')
  143. if (findIndex !== -1) {
  144. const findRes = res.find(o => o.fieldName === 'contractId')
  145. if (findRes) {
  146. const field = res[findIndex]
  147. if (findRes.value.length) {
  148. field.sys_config.otherParams = {
  149. contractId: findRes.value[0].contractId,
  150. receivablesId: this.id
  151. }
  152. field.disabled = false
  153. } else {
  154. field.sys_config.otherParams = {}
  155. field.disabled = true
  156. field.value = []
  157. }
  158. }
  159. }
  160. this.fieldArr = res
  161. this.setForm()
  162. this.getAuditList()
  163. })
  164. .catch(() => {
  165. })
  166. },
  167. /**
  168. * 去选择产品
  169. */
  170. handleAddProduct() {
  171. this.$nextTick(() => {
  172. if (this.$refs.product) {
  173. this.$refs.product.handleChoose()
  174. }
  175. })
  176. },
  177. /**
  178. * 获取商机下产品
  179. * @param {Object} id
  180. */
  181. getProductList(id) {
  182. if (!id) return
  183. BusinessProduct({
  184. businessId: id,
  185. pageType: 0,
  186. })
  187. .then(response => {
  188. response.product = response.list
  189. delete response.list
  190. this.$set(this.productField, 'value', response)
  191. })
  192. .catch(() => {})
  193. },
  194. /**
  195. * 确认选择的产品
  196. * @param {Object} data
  197. */
  198. handleChangeProduct(data) {
  199. console.log('change product: ', data)
  200. if (this.$refs.form) {
  201. this.$refs.form.setFormVal('money', data.totalMoney)
  202. }
  203. },
  204. /**
  205. * 表单值发生改变
  206. * @param {Object} data
  207. */
  208. handleValueChange(data) {
  209. console.log('value change: ', data)
  210. this.changeAuditFlow(data.field, data.value)
  211. let findIndex = -1
  212. const bridge = getApp().globalData.formBridge
  213. const bridgeDefault = bridge.default || {}
  214. // 回款
  215. if (data.field.formType === 'customer') {
  216. findIndex = this.fieldArr.findIndex(o => o.fieldName === 'contractId')
  217. if (findIndex !== -1) {
  218. const fieldItem = deepCopy(this.fieldArr[findIndex])
  219. if (data.value.length > 0) {
  220. fieldItem.sys_config.otherParams = {
  221. searchList: [
  222. {
  223. formType: 'text',
  224. name: 'customer_id',
  225. type: 1,
  226. values: [data.value[0].customerId]
  227. },
  228. {
  229. formType: 'checkStatus',
  230. name: 'checkStatus',
  231. type: 1,
  232. values: [1, 10]
  233. }
  234. ]
  235. }
  236. fieldItem.disabled = false
  237. } else {
  238. fieldItem.sys_config.otherParams = {}
  239. fieldItem.disabled = true
  240. fieldItem.value = []
  241. }
  242. if (!this.crmType || this.crmType === 'customer') {
  243. this.$refs.form.updateFields(findIndex, fieldItem)
  244. }
  245. // this.$nextTick(() => {
  246. // this.handleValueChange({
  247. // field: fieldItem,
  248. // index: findIndex,
  249. // value: fieldItem.value || []
  250. // })
  251. // })
  252. }
  253. } else if (data.field.formType === 'contract') {
  254. findIndex = this.fieldArr.findIndex(o => o.fieldName === 'receivablesPlanId')
  255. if (findIndex !== -1) {
  256. const fieldItem = deepCopy(this.fieldArr[findIndex])
  257. if (data.value.length > 0) {
  258. const otherParams = {
  259. contractId: data.value[0].contractId
  260. }
  261. if (this.id) {
  262. otherParams.receivablesId = this.id
  263. }
  264. fieldItem.sys_config.otherParams = otherParams
  265. fieldItem.disabled = false
  266. } else {
  267. fieldItem.sys_config.otherParams = {}
  268. fieldItem.disabled = true
  269. fieldItem.value = []
  270. }
  271. this.$refs.form.updateFields(findIndex, fieldItem)
  272. }
  273. } else if (data.field.fieldName === 'receivablesPlanId') {
  274. if (data.value.length > 0) {
  275. this.$nextTick(function() {
  276. this.$refs.form.setForm({
  277. returnTime: data.value[0].returnDate,
  278. money: data.value[0].money,
  279. returnType: [{
  280. label: data.value[0].returnType,
  281. value: data.value[0].returnType
  282. }]
  283. })
  284. })
  285. } else {
  286. this.$nextTick(function() {
  287. this.$refs.form.setForm({
  288. returnTime: '',
  289. money: '',
  290. returnType: []
  291. })
  292. })
  293. }
  294. }
  295. },
  296. /**
  297. * 保存
  298. */
  299. handleSave() {
  300. this.loading = true
  301. this.$refs.form.getForm().then(async form => {
  302. if (this.productField) {
  303. const productData = this.$refs.product.getForm()
  304. form.product = productData.product
  305. form.entity = {
  306. ...form.entity,
  307. discountRate: productData.discountRate,
  308. totalPrice: productData.totalPrice
  309. }
  310. }
  311. this.baseGetAuditSaveData(form)
  312. this.baseFormatSaveData(form)
  313. console.log('save: ', form)
  314. // this.loading = false
  315. // return
  316. if (!form.examineFlowData) {
  317. this.$toast('请完善审批信息')
  318. this.loading = false
  319. return
  320. }
  321. const request = this.id ? UpdateReceivables : AddReceivables
  322. request(form).then(() => {
  323. this.$toast(this.id ? '修改成功' : '添加成功')
  324. this.$refreshAndToPrev(this)
  325. }).catch(() => {
  326. this.loading = false
  327. })
  328. }).catch(() => {
  329. this.loading = false
  330. })
  331. }
  332. }
  333. }
  334. </script>
  335. <style scoped lang="scss">
  336. @import '../style/create.scss';
  337. </style>