25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

193 lines
4.7 KiB

  1. <template>
  2. <view class="page">
  3. <view v-if="ready">
  4. <l-select
  5. @input="setValue('F_CustomerId', $event)"
  6. :value="getValue('F_CustomerId')"
  7. :disabled="!edit"
  8. :range="dataSource.lr_crm_invoice.F_CustomerId"
  9. title="客户名称"
  10. required
  11. />
  12. <l-textarea
  13. @input="setValue('F_InvoiceContent', $event)"
  14. :value="getValue('F_InvoiceContent')"
  15. :readonly="!edit"
  16. title="开票信息"
  17. required
  18. />
  19. </view>
  20. <view v-if="ready" class="padding-lr bg-white margin-tb padding-tb">
  21. <l-button v-if="edit" @click="action('save')" class="block" size="lg" color="green" block>提交保存</l-button>
  22. <l-button v-if="!edit && mode !== 'create'" @click="action('edit')" class="block" size="lg" line="orange" block>
  23. 编辑本页
  24. </l-button>
  25. <l-button
  26. v-if="edit && mode !== 'create'"
  27. @click="action('reset')"
  28. class="block margin-top"
  29. size="lg"
  30. line="red"
  31. block
  32. >
  33. 取消编辑
  34. </l-button>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import get from 'lodash/get'
  40. import set from 'lodash/set'
  41. import moment from 'moment'
  42. import customPageMixins from '@/common/custompage.js'
  43. export default {
  44. mixins: [customPageMixins],
  45. data() {
  46. return {
  47. // 页面参数
  48. mode: null,
  49. edit: null,
  50. ready: false,
  51. // 表单数据对象
  52. current: null,
  53. origin: null,
  54. // 表单项数据结构
  55. scheme: {
  56. lr_crm_invoice: {
  57. F_CustomerId: {
  58. type: 'select',
  59. title: '客户名称',
  60. dataSource: '1',
  61. dataSourceId: 'crmCustomer,f_fullname,f_customerid'
  62. },
  63. F_InvoiceContent: { type: 'texteditor', title: '开票信息' }
  64. }
  65. },
  66. // 数据源
  67. dataSource: {
  68. lr_crm_invoice: {
  69. F_CustomerId: []
  70. }
  71. }
  72. }
  73. },
  74. async onLoad({ type }) {
  75. await this.init(type)
  76. },
  77. methods: {
  78. // 页面初始化
  79. async init(type = 'create') {
  80. this.LOADING('加载数据中…')
  81. this.mode = type
  82. this.edit = ['create', 'edit'].includes(this.mode)
  83. // 加载所有数据源
  84. await Promise.all([
  85. this.FETCH_DATASOURCE('crmCustomer').then(result => {
  86. this.dataSource.lr_crm_invoice.F_CustomerId = result.data.map(t => ({
  87. text: t.f_fullname,
  88. value: t.f_customerid
  89. }))
  90. }),
  91. this.fetchForm()
  92. ])
  93. this.ready = true
  94. this.HIDE_LOADING()
  95. },
  96. // 加载表单数据(新建表单的场合,获取一个初始化的空表单)
  97. async fetchForm() {
  98. if (this.mode === 'create') {
  99. this.origin = {
  100. keyValue: '',
  101. entity: {
  102. F_CustomerId: '',
  103. F_InvoiceContent: '',
  104. F_CustomerName: ''
  105. }
  106. }
  107. } else {
  108. this.origin = this.GET_PARAM()
  109. }
  110. this.current = this.COPY(this.origin)
  111. },
  112. // 点击「编辑、重置、保存、删除」按钮
  113. async action(type) {
  114. switch (type) {
  115. case 'edit':
  116. this.edit = true
  117. break
  118. case 'reset':
  119. this.current = this.COPY(this.origin)
  120. this.edit = false
  121. break
  122. case 'save':
  123. const verifyResult = this.verifyForm()
  124. if (verifyResult.length > 0) {
  125. this.CONFIRM('表单验证失败', verifyResult.join('\n'))
  126. return
  127. }
  128. if (!(await this.CONFIRM('提交确认', '确定要提交本页表单内容吗?', true))) {
  129. return
  130. }
  131. this.LOADING('正在提交…')
  132. const F_CustomerName = this.dataSource.lr_crm_invoice.F_CustomerId.find(
  133. t => t.value === this.current.F_CustomerId
  134. ).text
  135. const postData = {
  136. keyValue: this.current.F_InvoiceId || '',
  137. entity: {
  138. F_CustomerId: this.current.F_CustomerId,
  139. F_InvoiceContent: this.current.F_InvoiceContent,
  140. F_CustomerName
  141. }
  142. }
  143. this.HTTP_POST('/crm/invoice/save', postData, '表单提交保存失败').then(success => {
  144. this.HIDE_LOADING()
  145. if (!success) {
  146. return
  147. }
  148. this.EMIT('invoice-list-change')
  149. this.NAV_BACK()
  150. this.TOAST('提交保存成功', 'success')
  151. })
  152. break
  153. default:
  154. break
  155. }
  156. },
  157. // 获取表单值
  158. getValue(path) {
  159. return get(this.current, path)
  160. },
  161. // 设置表单值
  162. setValue(path, val) {
  163. set(this.current, path, val)
  164. }
  165. }
  166. }
  167. </script>