create.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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="invoice-desc">
  20. 发票信息
  21. <text class="control-btn" @click="handleToChooseInvoice">
  22. 选择发票信息
  23. </text>
  24. </view>
  25. <wk-form
  26. ref="invoiceForm"
  27. :fields="invoiceFieldArr"
  28. @change="invoiceFormChange" />
  29. <wk-audit-add
  30. v-if="showAudit"
  31. ref="wkAuditAdd" />
  32. <view class="empty-box" />
  33. </view>
  34. </view>
  35. <!-- #ifdef MP-WEIXIN -->
  36. <view class="footer-btn-group">
  37. <button class="button" @click="handleSave">
  38. 保存
  39. </button>
  40. </view>
  41. <!-- #endif -->
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import {
  47. QueryFieldList,
  48. AddInvoice,
  49. UpdateInvoice
  50. } from 'API/crm/invoice'
  51. import {
  52. GetList as GetContractList
  53. } from 'API/crm/contract'
  54. import {
  55. QueryInvoiceInfo as QueryInvoiceInfoByCustomerId
  56. } from 'API/crm/customer'
  57. import formMixins from '@/mixins/formMixins.js'
  58. import { deepCopy } from '@/utils/lib.js'
  59. import invoiceField from './invoiceField.js'
  60. import CreateMixins from '../mixins/create.js'
  61. export default {
  62. name: 'CreateInvoice',
  63. mixins: [CreateMixins, formMixins],
  64. data() {
  65. return {
  66. moduleType: 'invoice',
  67. invoiceFieldArr: invoiceField,
  68. }
  69. },
  70. onLoad() {
  71. this.getFieldList()
  72. },
  73. methods: {
  74. getFieldList() {
  75. const params = { type: 1 }
  76. if (this.id) params.id = this.id
  77. QueryFieldList(params)
  78. .then(res => {
  79. res.forEach(field => {
  80. // 自动编号为非必填
  81. if (field.autoGeneNumber === 1) {
  82. field.isNull = 0
  83. }
  84. if (!this.$isEmpty(field.authLevel)) {
  85. // 判断字段权限,如果没有权限则直接禁止修改
  86. field.disabled = this.getDisabledStatusByAuth(field)
  87. if (field.disabled) {
  88. if (field.sys_config) {
  89. field.sys_config.disabledMsg = ''
  90. }
  91. }
  92. }
  93. if (field.fieldName === 'contractId') {
  94. field.disabled = true
  95. field.sys_config = {
  96. request: GetContractList,
  97. otherParams: {},
  98. disabledMsg: '请先选择客户',
  99. optionsConfig: {
  100. labelField: 'num',
  101. valueField: 'contractId'
  102. }
  103. }
  104. } else if (field.fieldName === 'invoiceType') {
  105. field.setting = [
  106. { label: '增值税专用发票', value: 1 },
  107. { label: '增值税普通发票', value: 2 },
  108. { label: '国税通用机打发票', value: 3 },
  109. { label: '地税通用机打发票', value: 4 },
  110. { label: '收据', value: 5 }
  111. ]
  112. }
  113. if (field.fieldName === 'invoiceType') {
  114. console.log(field)
  115. field.setting.forEach((item) => {
  116. if (item.value == field.value) {
  117. field.value = [item]
  118. }
  119. })
  120. console.log(field)
  121. } else {
  122. field.value = this.mixinsFormatFieldValue(field)
  123. }
  124. })
  125. this.fieldArr = res
  126. this.setForm()
  127. this.getAuditList()
  128. })
  129. .catch(() => {
  130. })
  131. },
  132. /**
  133. * 表单值发生改变
  134. * @param {Object} data
  135. */
  136. handleValueChange(data) {
  137. console.log('value change: ', data)
  138. this.changeAuditFlow(data.field, data.value)
  139. let findIndex = -1
  140. // const bridge = getApp().globalData.formBridge
  141. // const bridgeDefault = bridge.default || {}
  142. // 发票
  143. if (data.field.formType === 'contract') {
  144. const arr = ['contractMoney', 'invoiceMoney']
  145. arr.forEach(fieldName => {
  146. findIndex = this.fieldArr.findIndex(o => o.fieldName === fieldName)
  147. if (findIndex !== -1) {
  148. const fieldItem = deepCopy(this.fieldArr[findIndex])
  149. if (data.value.length > 0) {
  150. fieldItem.value = data.value[0].money || 0
  151. } else {
  152. fieldItem.value = undefined
  153. }
  154. this.$refs.form.updateFields(findIndex, fieldItem)
  155. }
  156. })
  157. } else if (data.field.formType === 'customer') {
  158. findIndex = this.fieldArr.findIndex(o => o.fieldName === 'contractId')
  159. if (findIndex !== -1) {
  160. const fieldItem = deepCopy(this.fieldArr[findIndex])
  161. if (data.value.length > 0) {
  162. fieldItem.sys_config.otherParams = {
  163. searchList: [
  164. {
  165. formType: 'text',
  166. name: 'customer_id',
  167. type: 1,
  168. values: [data.value[0].customerId]
  169. },
  170. {
  171. formType: 'checkStatus',
  172. name: 'checkStatus',
  173. type: 1,
  174. values: [1, 10]
  175. }
  176. ]
  177. }
  178. fieldItem.disabled = false
  179. } else {
  180. fieldItem.sys_config.otherParams = {}
  181. fieldItem.disabled = true
  182. fieldItem.value = []
  183. }
  184. this.$refs.form.updateFields(findIndex, fieldItem)
  185. }
  186. }
  187. },
  188. invoiceFormChange(data) {
  189. // console.log('invoiceFormChange: ', data)
  190. if (data.field.fieldName === 'titleType') {
  191. const val = this.$refs.invoiceForm.getValueByFieldName('titleType')
  192. const arr = [
  193. 'taxNumber',
  194. 'depositBank',
  195. 'depositAccount',
  196. 'depositAddress',
  197. ]
  198. arr.forEach(key => {
  199. this.$refs.invoiceForm.updateVisibleStatus(key, val == 1)
  200. })
  201. }
  202. },
  203. /**
  204. * 去选择发票信息
  205. */
  206. handleToChooseInvoice() {
  207. console.log('to choose invoice')
  208. const customerId = this.$refs.form.getValueByFieldName('customerId')
  209. if (!customerId) {
  210. this.$toast('请先选择客户')
  211. return
  212. }
  213. const bridge = getApp().globalData.selectedValBridge
  214. bridge.invoice = {
  215. guid: this.guid,
  216. maxlength: 1,
  217. title: '选择关联发票抬头',
  218. config: {
  219. labelField: 'invoiceTitle',
  220. valueField: 'infoId',
  221. showCreate: false
  222. },
  223. defaultVal: this.selectedInvoiceInfo,
  224. params: { customerId },
  225. request: QueryInvoiceInfoByCustomerId
  226. }
  227. uni.$on('selected-relevance', this.selectedInvoice)
  228. this.$Router.navigateTo({
  229. url: '/pages_common/selectList/relevance',
  230. query: {
  231. type: 'invoice'
  232. }
  233. })
  234. },
  235. /**
  236. * 确认选择的发票
  237. */
  238. selectedInvoice(data) {
  239. if (data.guid === this.guid) {
  240. if (data.data.length > 0) {
  241. this.selectedInvoiceInfo = data.data
  242. const valData = deepCopy(data.data[0])
  243. this.invoiceFieldArr.forEach(field => {
  244. let value = valData[field.fieldName] || ''
  245. if (field.fieldName === 'titleType') {
  246. value = field.setting.filter(o => o.value === valData.titleType)
  247. }
  248. this.$refs.invoiceForm.setFormVal(field.fieldName, value)
  249. })
  250. }
  251. }
  252. uni.$off('selected-relevance')
  253. },
  254. /**
  255. * 保存
  256. */
  257. handleSave() {
  258. this.loading = true
  259. this.$refs.form.getForm().then(async form => {
  260. this.baseGetAuditSaveData(form)
  261. this.baseFormatSaveData(form)
  262. const invoiceForm = await this.$refs.invoiceForm.getForm()
  263. console.log('invoiceForm: ', invoiceForm)
  264. if (invoiceForm.entity.titleType !== 1) {
  265. const arr = [
  266. 'taxNumber',
  267. 'depositBank',
  268. 'depositAccount',
  269. 'depositAddress',
  270. ]
  271. arr.forEach(key => {
  272. invoiceForm.entity[key] = ''
  273. })
  274. }
  275. Object.assign(form.entity, invoiceForm.entity || {})
  276. console.log('save: ', form)
  277. // this.loading = false
  278. // return
  279. if (!form.examineFlowData) {
  280. this.$toast('请完善审批信息')
  281. this.loading = false
  282. return
  283. }
  284. const request = this.id ? UpdateInvoice : AddInvoice
  285. request(form).then(() => {
  286. this.$toast(this.id ? '修改成功' : '添加成功')
  287. this.$refreshAndToPrev(this)
  288. }).catch(() => {
  289. this.loading = false
  290. })
  291. }).catch(() => {
  292. this.loading = false
  293. })
  294. }
  295. }
  296. }
  297. </script>
  298. <style scoped lang="scss">
  299. @import '../style/create.scss';
  300. </style>