addOrUpdate.vue 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view
  5. :class="{'has-product': !!productField}"
  6. class="main-container">
  7. <wk-nav-bar :title="navTitle">
  8. <!-- #ifndef MP-WEIXIN -->
  9. <button class="button white-btn" @click="handleSave">
  10. 保存
  11. </button>
  12. <!-- #endif -->
  13. </wk-nav-bar>
  14. <view class="container">
  15. <view class="scroll-content">
  16. <wk-form
  17. ref="form"
  18. :fields="fieldArr"
  19. :batch-id="batchId"
  20. @change="handleValueChange" />
  21. <template v-if="routerQuery && routerQuery.type === 'invoice'">
  22. <view class="invoice-desc">
  23. 发票信息
  24. <text class="control-btn" @click="handleToChooseInvoice">
  25. 选择发票信息
  26. </text>
  27. </view>
  28. <wk-form
  29. ref="invoiceForm"
  30. :fields="invoiceFieldArr"
  31. @change="invoiceFormChange" />
  32. </template>
  33. <product-choose-add
  34. v-if="productField"
  35. ref="product"
  36. :default-value="productField.value"
  37. @change="handleChangeProduct" />
  38. <wk-audit-add
  39. v-if="showAudit"
  40. ref="wkAuditAdd" />
  41. <view class="empty-box" />
  42. </view>
  43. </view>
  44. </view>
  45. <!-- #ifdef MP-WEIXIN -->
  46. <view class="footer-btn-group">
  47. <button
  48. v-if="productField"
  49. class="button choose-product-btn"
  50. @click="handleAddProduct">
  51. 添加产品
  52. </button>
  53. <button class="button" @click="handleSave">
  54. 保存
  55. </button>
  56. </view>
  57. <!-- #endif -->
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import { QueryField, CheckOnlyField } from 'API/base'
  63. import { PreviewFiledName } from 'API/examine'
  64. import { QueryBusinessSetting } from 'API/crm/flow'
  65. import {
  66. QueryFieldList as LeadsQueryFieldList,
  67. AddLeads,
  68. UpdateLeads,
  69. } from 'API/crm/leads'
  70. import {
  71. QueryFieldList as CustomerQueryFieldList,
  72. AddCustomer,
  73. UpdateCustomer
  74. } from 'API/crm/customer'
  75. import {
  76. QueryFieldList as ContactsQueryFieldList,
  77. AddContacts,
  78. UpdateContacts
  79. } from 'API/crm/concat'
  80. import {
  81. QueryFieldList as ReceivablesQueryFieldList,
  82. AddReceivables,
  83. UpdateReceivables
  84. } from 'API/crm/received'
  85. import {
  86. QueryFieldList as ProductQueryFieldList,
  87. AddProduct,
  88. UpdateProduct
  89. } from 'API/crm/product'
  90. import {
  91. QueryFieldList as BusinessQueryFieldList,
  92. AddBusiness,
  93. UpdateBusiness,
  94. QueryProduct as BusinessProduct
  95. } from 'API/crm/business'
  96. import {
  97. QueryFieldList as ContractQueryFieldList,
  98. AddContract,
  99. UpdateContract,
  100. GetList as GetContractList,
  101. QueryProduct as ContractProduct
  102. } from 'API/crm/contract'
  103. import {
  104. QueryFieldList as ReceivablesPlanQueryFieldList,
  105. AddReceivablesPlan,
  106. UpdateReceivablesPlan
  107. } from 'API/crm/receivedPlan'
  108. import {
  109. QueryFieldList as InvoiceQueryFieldList,
  110. AddInvoice,
  111. UpdateInvoice
  112. } from 'API/crm/invoice'
  113. import {
  114. QueryBusiness as QueryBusinessByCustomerId,
  115. QueryContacts as QueryContactsByCustomerId,
  116. QueryContract as QueryContractByCustomerId,
  117. QueryInvoiceInfo as QueryInvoiceInfoByCustomerId
  118. } from 'API/crm/customer'
  119. import ProductChooseAdd from './components/baseAdd/productChooseAdd.vue'
  120. import formMixins from '@/mixins/formMixins.js'
  121. import { deepCopy } from '@/utils/lib.js'
  122. import { isArray, isObject } from '@/utils/types.js'
  123. import invoiceField from './invoiceField.js'
  124. import moment from 'moment'
  125. export default {
  126. name: 'AddOrUpdate',
  127. components: {
  128. ProductChooseAdd
  129. },
  130. mixins: [formMixins],
  131. data() {
  132. return {
  133. id: null,
  134. batchId: null,
  135. guid: null,
  136. showForm: true,
  137. routerQuery: {},
  138. fieldArr: [],
  139. invoiceFieldArr: invoiceField,
  140. productField: null,
  141. defaultProductList: {},
  142. businessStatusList: [],
  143. showAudit: false,
  144. auditUser: null,
  145. authInfo: {},
  146. auditConditionFields: [],
  147. selectedInvoiceInfo: [],
  148. loading: false,
  149. timer: null,
  150. typeMap: {
  151. leads: {
  152. addFn: AddLeads,
  153. updateFn: UpdateLeads,
  154. fieldFn: LeadsQueryFieldList,
  155. field: 'leadsId',
  156. label: 1,
  157. value: '线索'
  158. },
  159. customer: {
  160. addFn: AddCustomer,
  161. updateFn: UpdateCustomer,
  162. fieldFn: CustomerQueryFieldList,
  163. field: 'customerId',
  164. label: 2,
  165. value: '客户'
  166. },
  167. contacts: {
  168. addFn: AddContacts,
  169. updateFn: UpdateContacts,
  170. fieldFn: ContactsQueryFieldList,
  171. field: 'contactsId',
  172. label: 3,
  173. value: '联系人'
  174. },
  175. business: {
  176. addFn: AddBusiness,
  177. updateFn: UpdateBusiness,
  178. fieldFn: BusinessQueryFieldList,
  179. field: 'businessId',
  180. label: 5,
  181. value: '商机'
  182. },
  183. contract: {
  184. addFn: AddContract,
  185. updateFn: UpdateContract,
  186. fieldFn: ContractQueryFieldList,
  187. field: 'contractId',
  188. label: 6,
  189. value: '合同'
  190. },
  191. receivables: {
  192. addFn: AddReceivables,
  193. updateFn: UpdateReceivables,
  194. fieldFn: ReceivablesQueryFieldList,
  195. field: 'receivablesId',
  196. label: 7,
  197. value: '回款'
  198. },
  199. product: {
  200. addFn: AddProduct,
  201. updateFn: UpdateProduct,
  202. fieldFn: ProductQueryFieldList,
  203. field: 'productId',
  204. label: 4,
  205. value: '产品'
  206. },
  207. receivables_plan: {
  208. addFn: AddReceivablesPlan,
  209. updateFn: UpdateReceivablesPlan,
  210. fieldFn: ReceivablesPlanQueryFieldList,
  211. field: 'receivablesPlanId',
  212. label: 8,
  213. value: '回款计划'
  214. },
  215. invoice: {
  216. addFn: AddInvoice,
  217. updateFn: UpdateInvoice,
  218. fieldFn: InvoiceQueryFieldList,
  219. field: 'invoiceId',
  220. label: 18,
  221. value: '发票'
  222. }
  223. },
  224. }
  225. },
  226. computed: {
  227. navTitle() {
  228. const str = {
  229. leads: '线索',
  230. customer: '客户',
  231. contacts: '联系人',
  232. business: '商机',
  233. contract: '合同',
  234. receivables: '回款',
  235. receivables_plan: '回款计划',
  236. product: '产品',
  237. invoice: '发票'
  238. }[this.routerQuery.type]
  239. const actionStr = this.routerQuery.id ? '编辑' : '新建'
  240. return actionStr + str
  241. }
  242. },
  243. onLoad(options) {
  244. this.routerQuery = options || {}
  245. this.id = options.id
  246. this.batchId = options.batchId
  247. this.guid = this.$guid()
  248. if (options.type === 'business' && options.id) {
  249. QueryBusinessSetting().then(res => {
  250. this.businessStatusList = res
  251. this.getFieldList()
  252. }).catch()
  253. } else {
  254. this.getFieldList()
  255. }
  256. },
  257. onUnload() {
  258. getApp().globalData.formBridge = {}
  259. },
  260. methods: {
  261. getFieldList() {
  262. const request = this.typeMap[this.routerQuery.type].fieldFn
  263. if (!request) return
  264. const params = { type: 1 }
  265. if (this.routerQuery.id) params.id = this.routerQuery.id
  266. request(params).then(res => {
  267. let findIndex = res.findIndex(o => o.formType === 'product')
  268. if (findIndex !== -1) {
  269. this.productField = res.splice(findIndex, 1)[0]
  270. }
  271. res = this.formatFieldArr(res)
  272. res.forEach(field => {
  273. // 自动编号为非必填
  274. if (field.autoGeneNumber === 1) {
  275. field.isNull = 0
  276. }
  277. if (this.routerQuery.type === 'business' && this.id && field.value) {
  278. // 商机下 商机状态组
  279. if (field.formType === 'business_type') {
  280. field.value = this.businessStatusList.filter(o => o.flowId === field.value)
  281. } else {
  282. field.value = this.mixinsFormatFieldValue(field)
  283. }
  284. } else if (this.routerQuery.type === 'receivables' && this.id && field.value) {
  285. // 回款下 合同和回款计划
  286. field.value = this.mixinsFormatFieldValue(field)
  287. if (field.fieldName === 'customerId') {
  288. const findRes = res.find(o => o.fieldName === 'contractId')
  289. if (findRes) {
  290. const fieldItem = deepCopy(this.fieldArr[findIndex])
  291. if (field.value.length > 0) {
  292. findRes.sys_config.otherParams = {
  293. searchList: [
  294. {
  295. formType: 'text',
  296. name: 'customer_id',
  297. type: 1,
  298. values: [field.value[0].customerId]
  299. },
  300. {
  301. formType: 'checkStatus',
  302. name: 'checkStatus',
  303. type: 1,
  304. values: [1, 10]
  305. }
  306. ]
  307. }
  308. findRes.disabled = false
  309. } else {
  310. findRes.sys_config.otherParams = {}
  311. findRes.disabled = true
  312. findRes.value = []
  313. }
  314. }
  315. } else if (field.fieldName === 'receivablesPlanId') {
  316. const findRes = res.find(o => o.formType === 'contract')
  317. if (findRes) {
  318. if (findRes.value.length > 0) {
  319. field.sys_config.otherParams = {
  320. contractId: findRes.value[0].contractId,
  321. receivablesId: this.id
  322. }
  323. field.disabled = false
  324. } else {
  325. field.sys_config.otherParams = {}
  326. field.disabled = true
  327. field.value = []
  328. }
  329. }
  330. } else {
  331. field.value = this.mixinsFormatFieldValue(field)
  332. }
  333. } else if (this.routerQuery.type === 'product' && this.id && field.value) {
  334. // 产品下上下架状态
  335. if (field.fieldName === 'status') {
  336. field.value = field.setting.filter(o => o.value == field.value)
  337. } else {
  338. field.value = this.mixinsFormatFieldValue(field)
  339. }
  340. } else {
  341. field.value = this.mixinsFormatFieldValue(field)
  342. }
  343. // if (!this.$isEmpty(field.authLevel) && !field.disabled) {
  344. if (!this.$isEmpty(field.authLevel)) {
  345. // 判断字段权限,如果没有权限则直接禁止修改
  346. field.disabled = this.getDisabledStatusByAuth(field)
  347. if (field.disabled) {
  348. if (field.sys_config) {
  349. field.sys_config.disabledMsg = ''
  350. }
  351. }
  352. }
  353. })
  354. this.fieldArr = res
  355. this.setForm()
  356. if ([
  357. 'receivables',
  358. 'contract',
  359. 'invoice'
  360. ].includes(this.routerQuery.type)) {
  361. this.getAuditList()
  362. }
  363. }).catch(() => {})
  364. },
  365. /**
  366. * 根据权限判断字段是否可编辑
  367. * @param {Object} field
  368. */
  369. getDisabledStatusByAuth(field) {
  370. const crmType = this.routerQuery.type
  371. if (crmType === 'business' && ['business_type', 'business_status'].includes(field.formType)) return false
  372. if (crmType === 'contract' && ['business', 'contacts', 'customer'].includes(field.formType)) return false
  373. if (crmType === 'receivables' && ['contract', 'customer'].includes(field.formType)) return false
  374. if (crmType === 'visit' && ['business', 'contacts', 'customer'].includes(field.formType)) return false
  375. if (crmType === 'invoice' && ['contractId', 'contractMoney'].includes(field.fieldName)) return true
  376. // 1 不能查看不能编辑 2 可查看 3 可查看可编辑
  377. return field.authLevel !== 3 // false 可编辑
  378. },
  379. /**
  380. * 注入字段配置信息
  381. * @param {Object} res
  382. */
  383. formatFieldArr(res) {
  384. const crmType = this.routerQuery.type
  385. if (crmType === 'business') {
  386. // 如果有商机阶段则删掉该字段,商机阶段只能在详情中进行修改
  387. const findIndex = res.findIndex(o => o.formType === 'business_status')
  388. if (findIndex !== -1) {
  389. res.splice(findIndex, 1)
  390. }
  391. } else if (crmType === 'contract') {
  392. let findRes = res.find(o => o.fieldName === 'businessId')
  393. if (findRes) {
  394. // 客户下商机
  395. findRes.disabled = true
  396. findRes.sys_config = {
  397. request: QueryBusinessByCustomerId,
  398. otherParams: {},
  399. disabledMsg: '请先选择客户'
  400. }
  401. }
  402. findRes = res.find(o => o.fieldName === 'contactsId')
  403. if (findRes) {
  404. // 客户下联系人
  405. findRes.disabled = true
  406. findRes.sys_config = {
  407. request: QueryContactsByCustomerId,
  408. otherParams: {},
  409. disabledMsg: '请先选择客户'
  410. }
  411. }
  412. findRes = res.find(o => o.autoGeneNumber === 1)
  413. if (findRes) {
  414. findRes.isNull = 0
  415. }
  416. } else if (crmType === 'receivables') {
  417. let findRes = res.find(o => o.fieldName === 'contractId')
  418. if (findRes) {
  419. // 客户下合同
  420. findRes.disabled = true
  421. findRes.sys_config = {
  422. request: GetContractList,
  423. otherParams: {},
  424. disabledMsg: '请先选择客户',
  425. optionsConfig: {
  426. labelField: 'num',
  427. valueField: 'contractId'
  428. }
  429. }
  430. }
  431. findRes = res.find(o => o.fieldName === 'planId')
  432. if (findRes) {
  433. // 合同下回款计划
  434. findRes.disabled = true
  435. findRes.sys_config = {
  436. otherParams: {},
  437. disabledMsg: '请先选择合同'
  438. }
  439. }
  440. } else if (crmType === 'product') {
  441. let findRes = res.find(o => o.fieldName === 'status')
  442. if (findRes) {
  443. // 产品上下架
  444. findRes.sys_config = {
  445. optionsConfig: {
  446. labelField: 'name',
  447. valueField: 'value'
  448. }
  449. }
  450. }
  451. } else if (crmType === 'invoice') {
  452. let findRes = res.find(o => o.fieldName === 'contractId')
  453. if (findRes) {
  454. // 客户下合同
  455. findRes.disabled = true
  456. findRes.sys_config = {
  457. request: GetContractList,
  458. otherParams: {},
  459. disabledMsg: '请先选择客户',
  460. optionsConfig: {
  461. labelField: 'num',
  462. valueField: 'contractId'
  463. }
  464. }
  465. }
  466. findRes = res.find(o => o.fieldName === 'invoiceType')
  467. if (findRes) {
  468. findRes.setting = [
  469. { label: '增值税专用发票', value: 1 },
  470. { label: '增值税普通发票', value: 2 },
  471. { label: '国税通用机打发票', value: 3 },
  472. { label: '地税通用机打发票', value: 4 },
  473. { label: '收据', value: 5 }
  474. ]
  475. }
  476. }
  477. return res
  478. },
  479. setForm() {
  480. const bridge = getApp().globalData.formBridge
  481. // console.log('setForm bridge: ', bridge)
  482. if (!bridge.default) return
  483. this.$nextTick(() => {
  484. this.$refs.form.setForm(bridge.default || {})
  485. Object.keys(bridge.default).forEach(key => {
  486. this.$refs.form.setDisabled(key, true)
  487. this.$refs.form.setConfig(key, { disabledMsg: '' })
  488. })
  489. })
  490. // #ifdef APP-PLUS
  491. // App 偶发会出现字段渲染不上的问题,在此强制刷新页面
  492. this.$nextTick(() => {
  493. if (!this.$isEmpty(bridge.default)) {
  494. this.$refs.form.updateView()
  495. }
  496. })
  497. // #endif
  498. },
  499. /**
  500. * 获取审批流程条件
  501. */
  502. getAuditList() {
  503. const label = {
  504. contract: 1,
  505. receivables: 2,
  506. invoice: 3
  507. }[this.routerQuery.type] || ''
  508. PreviewFiledName({
  509. label
  510. }).then(res => {
  511. this.showAudit = res !== null
  512. if (!this.showAudit) return
  513. const mapIns = new Map()
  514. this.auditConditionFields = res.filter(o => !mapIns.has(o.fieldId) && mapIns.set(o.fieldId, 1))
  515. console.log('PreviewFiledName: ', this.auditConditionFields)
  516. this.$nextTick(() => {
  517. const dataMap = {}
  518. const bridge = getApp().globalData.formBridge || {}
  519. this.auditConditionFields.forEach(o => {
  520. const findRes = this.fieldArr.find(f => f.fieldName === o.fieldName)
  521. if (findRes) {
  522. let value = null
  523. if (bridge.default && bridge.default.hasOwnProperty(o.fieldName)) {
  524. value = bridge.default[o.fieldName]
  525. } else {
  526. value = findRes.value
  527. }
  528. switch (findRes.formType) {
  529. case 'select':
  530. if (this.$isEmpty(value)) value = ''
  531. if (isArray(value)) {
  532. value = value[0].value
  533. }
  534. break
  535. case 'checkbox':
  536. if (this.$isEmpty(value)) value = ''
  537. if (isArray(value)) {
  538. value = value.map(o => o.value).join(',')
  539. }
  540. break
  541. default:
  542. value = this.$isEmpty(value) ? '' : value
  543. }
  544. o._val = value
  545. dataMap[o.fieldName] = value
  546. }
  547. })
  548. this.$refs.wkAuditAdd.getAuditInfo({
  549. label,
  550. dataMap
  551. })
  552. })
  553. }).catch()
  554. },
  555. handleAddProduct() {
  556. this.$nextTick(() => {
  557. if (this.$refs.product) {
  558. this.$refs.product.handleChoose()
  559. }
  560. })
  561. },
  562. getProductList(type, id) {
  563. if (!id) return
  564. if (type === 'business') {
  565. // 获取商机下产品
  566. BusinessProduct({businessId: id, pageType: 0}).then(response => {
  567. response.product = response.list
  568. delete response.list
  569. this.$set(this.productField, 'value', response)
  570. }).catch()
  571. } else if (type === 'contract') {
  572. // 获取合同下产品
  573. ContractProduct({contractId: id, pageType: 0}).then(response => {
  574. response.product = response.list
  575. delete response.list
  576. this.$set(this.productField, 'value', response)
  577. }).catch()
  578. }
  579. },
  580. handleValueChange(data) {
  581. console.log('value change: ', data)
  582. this.changeAuditFlow(data.field, data.value)
  583. let findIndex = -1
  584. const crmType = this.routerQuery.type
  585. const bridge = getApp().globalData.formBridge
  586. const bridgeDefault = bridge.default || {}
  587. if (crmType === 'contract') {
  588. // 合同
  589. if (data.field.formType === 'customer') {
  590. const arr = ['businessId', 'contactsId']
  591. arr.forEach(key => {
  592. findIndex = this.fieldArr.findIndex(o => o.fieldName === key)
  593. if (findIndex !== -1 && !bridgeDefault.hasOwnProperty(key)) {
  594. const fieldItem = deepCopy(this.fieldArr[findIndex])
  595. if (data.value.length > 0) {
  596. fieldItem.sys_config.otherParams = {
  597. customerId: data.value[0].customerId,
  598. pageType: 0
  599. }
  600. fieldItem.disabled = false
  601. } else {
  602. fieldItem.sys_config.otherParams = {}
  603. fieldItem.disabled = true
  604. fieldItem.value = []
  605. }
  606. this.$refs.form.updateFields(findIndex, fieldItem)
  607. }
  608. })
  609. } else if (data.field.formType === 'business') {
  610. if (data.value.length === 0) {
  611. this.$set(this.productField, 'value', {})
  612. } else {
  613. this.getProductList('business', data.value[0].businessId || data.value[0].id)
  614. const money = data.value[0].money
  615. if (this.$isEmpty(money)) return
  616. findIndex = this.fieldArr.findIndex(o => o.fieldName === 'money')
  617. if (findIndex !== -1) {
  618. const fieldItem = deepCopy(this.fieldArr[findIndex])
  619. fieldItem.value = money
  620. this.$refs.form.updateFields(findIndex, fieldItem)
  621. }
  622. }
  623. }
  624. } else if (crmType === 'receivables') {
  625. // 回款
  626. if (data.field.formType === 'customer') {
  627. findIndex = this.fieldArr.findIndex(o => o.fieldName === 'contractId')
  628. if (findIndex !== -1) {
  629. const fieldItem = deepCopy(this.fieldArr[findIndex])
  630. if (data.value.length > 0) {
  631. fieldItem.sys_config.otherParams = {
  632. searchList: [
  633. {
  634. formType: 'text',
  635. name: 'customer_id',
  636. type: 1,
  637. values: [data.value[0].customerId]
  638. },
  639. {
  640. formType: 'checkStatus',
  641. name: 'checkStatus',
  642. type: 1,
  643. values: [1, 10]
  644. }
  645. ]
  646. }
  647. fieldItem.disabled = false
  648. } else {
  649. fieldItem.sys_config.otherParams = {}
  650. fieldItem.disabled = true
  651. fieldItem.value = []
  652. }
  653. this.$refs.form.updateFields(findIndex, fieldItem)
  654. }
  655. } else if (data.field.formType === 'contract') {
  656. findIndex = this.fieldArr.findIndex(o => o.fieldName === 'planId')
  657. if (findIndex !== -1) {
  658. const fieldItem = deepCopy(this.fieldArr[findIndex])
  659. if (data.value.length > 0) {
  660. const otherParams = {
  661. contractId: data.value[0].contractId
  662. }
  663. if (this.id) {
  664. otherParams.receivablesId = this.id
  665. }
  666. fieldItem.sys_config.otherParams = otherParams
  667. fieldItem.disabled = false
  668. } else {
  669. fieldItem.sys_config.otherParams = {}
  670. fieldItem.disabled = true
  671. fieldItem.value = []
  672. }
  673. this.$refs.form.updateFields(findIndex, fieldItem)
  674. }
  675. } else if (data.field.fieldName === 'planId') {
  676. if (data.value.length > 0) {
  677. this.$nextTick(function() {
  678. this.$refs.form.setForm({
  679. returnTime: moment(data.value[0].returnDate).format('YYYY-MM-DD'),
  680. money: data.value[0].money,
  681. returnType: [{
  682. label: data.value[0].returnType,
  683. value: data.value[0].returnType
  684. }]
  685. })
  686. })
  687. } else {
  688. this.$nextTick(function() {
  689. this.$refs.form.setForm({
  690. returnTime: '',
  691. money: '',
  692. returnType: []
  693. })
  694. })
  695. }
  696. }
  697. } else if (crmType === 'invoice') {
  698. // 发票
  699. if (data.field.formType === 'contract') {
  700. const arr = ['contractMoney', 'invoiceMoney']
  701. arr.forEach(fieldName => {
  702. findIndex = this.fieldArr.findIndex(o => o.fieldName === fieldName)
  703. if (findIndex !== -1) {
  704. const fieldItem = deepCopy(this.fieldArr[findIndex])
  705. if (data.value.length > 0) {
  706. fieldItem.value = data.value[0].money || 0
  707. } else {
  708. fieldItem.value = undefined
  709. }
  710. this.$refs.form.updateFields(findIndex, fieldItem)
  711. }
  712. })
  713. } else if (data.field.formType === 'customer') {
  714. findIndex = this.fieldArr.findIndex(o => o.fieldName === 'contractId')
  715. if (findIndex !== -1) {
  716. const fieldItem = deepCopy(this.fieldArr[findIndex])
  717. if (data.value.length > 0) {
  718. fieldItem.sys_config.otherParams = {
  719. searhList: [
  720. {
  721. formType: 'text',
  722. name: 'customer_id',
  723. type: 1,
  724. values: [data.value[0].customerId]
  725. },
  726. {
  727. formType: 'checkStatus',
  728. name: 'checkStatus',
  729. type: 1,
  730. values: [1, 10]
  731. }
  732. ]
  733. }
  734. fieldItem.disabled = false
  735. } else {
  736. fieldItem.sys_config.otherParams = {}
  737. fieldItem.disabled = true
  738. fieldItem.value = []
  739. }
  740. this.$refs.form.updateFields(findIndex, fieldItem)
  741. }
  742. }
  743. }
  744. },
  745. /**
  746. * 根据审批条件变更审批流
  747. */
  748. changeAuditFlow(field, value) {
  749. if (!this.showAudit) return
  750. if (![
  751. 'contract',
  752. 'receivables',
  753. 'invoice'
  754. ].includes(this.routerQuery.type)) return
  755. const findRes = this.auditConditionFields.find(o => o.fieldName === field.fieldName)
  756. if (!findRes) return
  757. if (this.timer) {
  758. clearTimeout(this.timer)
  759. this.timer = null
  760. }
  761. this.timer = setTimeout(() => {
  762. // number floatnumber select checkbox
  763. switch (field.formType) {
  764. case 'select':
  765. if (this.$isEmpty(value)) value = ''
  766. if (isArray(value)) {
  767. value = value[0].value
  768. }
  769. break
  770. case 'checkbox':
  771. if (this.$isEmpty(value)) value = ''
  772. if (isArray(value)) {
  773. value = value.map(o => o.value).join(',')
  774. }
  775. break
  776. default:
  777. value = this.$isEmpty(value) ? '' : value
  778. }
  779. findRes._val = value
  780. const dataMap = {}
  781. this.auditConditionFields.forEach(o => {
  782. if (o.hasOwnProperty('_val')) {
  783. dataMap[o.fieldName] = this.$isEmpty(o._val) ? '' : o._val
  784. } else {
  785. dataMap[o.fieldName] = ''
  786. }
  787. })
  788. this.$nextTick(() => {
  789. const label = {
  790. contract: 1,
  791. receivables: 2,
  792. invoice: 3
  793. }[this.routerQuery.type] || ''
  794. this.$refs.wkAuditAdd.getAuditInfo({
  795. label,
  796. dataMap
  797. })
  798. clearTimeout(this.timer)
  799. this.timer = null
  800. })
  801. }, 500)
  802. },
  803. handleChangeProduct(data) {
  804. console.log('change product: ', data)
  805. if (
  806. this.$refs.form &&
  807. ['business', 'contract'].includes(this.routerQuery.type)
  808. ) {
  809. this.$refs.form.setFormVal('money', data.totalMoney)
  810. }
  811. },
  812. invoiceFormChange(data) {
  813. // console.log('invoiceFormChange: ', data)
  814. if (data.field.fieldName === 'titleType') {
  815. const val = this.$refs.invoiceForm.getValueByFieldName('titleType')
  816. const arr = [
  817. 'taxNumber',
  818. 'depositBank',
  819. 'depositAccount',
  820. 'depositAddress',
  821. ]
  822. arr.forEach(key => {
  823. this.$refs.invoiceForm.updateVisibleStatus(key, val == 1)
  824. })
  825. }
  826. },
  827. /**
  828. * 去选择发票信息
  829. */
  830. handleToChooseInvoice() {
  831. console.log('to choose invoice')
  832. const customerId = this.$refs.form.getValueByFieldName('customerId')
  833. if (!customerId) {
  834. this.$toast('请先选择客户')
  835. return
  836. }
  837. const bridge = getApp().globalData.selectedValBridge
  838. bridge.invoice = {
  839. guid: this.guid,
  840. maxlength: 1,
  841. title: '选择关联发票抬头',
  842. config: {
  843. labelField: 'invoiceTitle',
  844. valueField: 'infoId',
  845. showCreate: false
  846. },
  847. defaultVal: this.selectedInvoiceInfo,
  848. params: { customerId },
  849. request: QueryInvoiceInfoByCustomerId
  850. }
  851. uni.$on('selected-relevance', this.selectedInvoice)
  852. this.$Router.navigateTo({
  853. url: '/pages_common/selectList/relevance',
  854. query: {
  855. type: 'invoice'
  856. }
  857. })
  858. },
  859. /**
  860. * 确认选择的发票
  861. */
  862. selectedInvoice(data) {
  863. if (data.guid === this.guid) {
  864. if (data.data.length > 0) {
  865. this.selectedInvoiceInfo = data.data
  866. const valData = deepCopy(data.data[0])
  867. this.invoiceFieldArr.forEach(field => {
  868. let value = valData[field.fieldName] || ''
  869. if (field.fieldName === 'titleType') {
  870. value = field.setting.filter(o => o.value === valData.titleType)
  871. }
  872. this.$refs.invoiceForm.setFormVal(field.fieldName, value)
  873. })
  874. }
  875. }
  876. uni.$off('selected-relevance')
  877. },
  878. handleSave() {
  879. const apiObj = this.typeMap[this.routerQuery.type] || null
  880. if (!apiObj || this.loading) return
  881. this.loading = true
  882. this.$refs.form.getForm().then(async form => {
  883. if (this.type === 'contract') {
  884. let startTime = form.entity.startTime
  885. let endTime = form.entity.endTime
  886. if (startTime && endTime && startTime > endTime) {
  887. this.$toast('合同的开始时间不能大于结束时间')
  888. this.loading = false
  889. return
  890. }
  891. }
  892. // 审批信息
  893. if (this.showAudit) {
  894. const data = this.$refs.wkAuditAdd.getSaveData()
  895. if (data === null) {
  896. this.loading = false
  897. return
  898. }
  899. const dataMap = {}
  900. this.auditConditionFields.forEach(o => {
  901. if (o.hasOwnProperty('_val')) {
  902. dataMap[o.fieldName] = this.$isEmpty(o._val) ? '' : o._val
  903. }
  904. })
  905. const label = {
  906. contract: 1,
  907. receivables: 2,
  908. invoice: 3
  909. }[this.routerQuery.type] || ''
  910. form.examineFlowData = {
  911. ...data,
  912. label,
  913. dataMap
  914. }
  915. }
  916. if (this.productField) {
  917. const productData = this.$refs.product.getForm()
  918. form.product = productData.product
  919. form.entity = {
  920. ...form.entity,
  921. discountRate: productData.discountRate,
  922. totalPrice: productData.totalPrice
  923. }
  924. }
  925. if (this.id && this.batchId) {
  926. form.entity[apiObj.field] = Number(this.id) || this.id
  927. form.entity.batchId = this.batchId
  928. }
  929. if (this.id && this.type === 'customer') {
  930. if (Number(this.id) === Number(form.entity.superiorCustomerId)) {
  931. this.$toast('上级客户不能为当前客户')
  932. this.loading = false
  933. return
  934. }
  935. }
  936. if (this.id && this.type === 'pContactsId') {
  937. if (Number(this.id) === Number(form.entity.pContactsId)) {
  938. this.$toast('直属上级不能为当前联系人')
  939. this.loading = false
  940. return
  941. }
  942. }
  943. if (!form.hasOwnProperty('field')) {
  944. form.field = []
  945. }
  946. const bridge = getApp().globalData.formBridge || {}
  947. if (bridge.assignForm) {
  948. form = Object.assign(form, bridge.assignForm)
  949. }
  950. const arr = form.field
  951. .filter(o => o.formType !== 'desc_text')
  952. .map(o => {
  953. return {
  954. fieldName: o.fieldName,
  955. name: o.name,
  956. type: o.type,
  957. fieldId: o.fieldId,
  958. value: o.value,
  959. fieldType: o.fieldType
  960. }
  961. })
  962. form.field = arr
  963. if (this.routerQuery.type === 'invoice') {
  964. const invoiceForm = await this.$refs.invoiceForm.getForm()
  965. console.log('invoiceForm: ', invoiceForm)
  966. if (invoiceForm.entity.titleType !== 1) {
  967. const arr = [
  968. 'taxNumber',
  969. 'depositBank',
  970. 'depositAccount',
  971. 'depositAddress',
  972. ]
  973. arr.forEach(key => {
  974. invoiceForm.entity[key] = ''
  975. })
  976. }
  977. Object.assign(form.entity, invoiceForm.entity || {})
  978. }
  979. console.log('save: ', form)
  980. // this.loading = false
  981. // return
  982. const request = this.id ? apiObj.updateFn : apiObj.addFn
  983. request(form).then(() => {
  984. this.$toast(this.id ? '修改成功' : '添加成功')
  985. this.$refreshAndToPrev(this)
  986. }).catch(() => {
  987. this.loading = false
  988. })
  989. }).catch(() => {
  990. this.loading = false
  991. })
  992. }
  993. }
  994. }
  995. </script>
  996. <style scoped lang="scss">
  997. .main-container {
  998. /* #ifndef MP-WEIXIN */
  999. &.has-product {
  1000. padding-bottom: $tabbar-height;
  1001. }
  1002. /* #endif */
  1003. .container {
  1004. flex: 1;
  1005. width: 100%;
  1006. background-color: white;
  1007. margin-top: 20rpx;
  1008. overflow: hidden;
  1009. .scroll-content {
  1010. width: 100%;
  1011. height: 100%;
  1012. overflow: auto;
  1013. .empty-box {
  1014. width: 100%;
  1015. height: 30rpx;
  1016. background-color: white;
  1017. }
  1018. }
  1019. }
  1020. .invoice-desc {
  1021. width: 100%;
  1022. font-size: $wk-font-sm;
  1023. background-color: #F3F5FA;
  1024. padding: 20rpx 24rpx;
  1025. .control-btn {
  1026. color: $theme-color;
  1027. float: right;
  1028. }
  1029. }
  1030. .footer-btn-group {
  1031. .button {
  1032. flex: 1;
  1033. }
  1034. .choose-product-btn {
  1035. color: $theme-color;
  1036. border: 1rpx solid $theme-color;
  1037. background-color: white;
  1038. margin-right: 30rpx;
  1039. }
  1040. }
  1041. }
  1042. </style>