CarfareModal.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <a-modal
  3. :title="title"
  4. :width="1600"
  5. :visible="visible"
  6. :maskClosable="false"
  7. :confirmLoading="confirmLoading"
  8. @ok="handleOk"
  9. @cancel="handleCancel">
  10. <a-spin :spinning="confirmLoading">
  11. <!-- 主表单区域 -->
  12. <a-form :form="form">
  13. <a-row>
  14. <a-col :span="8">
  15. <a-form-item label="登记人" :labelCol="labelCol" :wrapperCol="wrapperCol">
  16. <j-popup
  17. v-decorator="['registrant', validatorRules.registrant]"
  18. placeholder="请选择登记人"
  19. :trigger-change="true"
  20. org-fields="realname,depart_name"
  21. dest-fields="registrant,registrantDept"
  22. code="user_dept"
  23. @callback="popupCallback"/>
  24. </a-form-item>
  25. </a-col>
  26. <a-col :span="8">
  27. <a-form-item label="登记部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
  28. <a-input v-decorator="[ 'registrantDept', validatorRules.registrantDept]" placeholder="请输入登记部门" disabled></a-input>
  29. </a-form-item>
  30. </a-col>
  31. <a-col :span="8">
  32. <a-form-item label="报销总额" :labelCol="labelCol" :wrapperCol="wrapperCol">
  33. <a-input-number v-decorator="[ 'totalAmount', validatorRules.totalAmount]" placeholder="请输入报销总额" style="width: 100%" disabled/>
  34. </a-form-item>
  35. </a-col>
  36. <a-col :span="8">
  37. <a-form-item label="财务经办人" :labelCol="labelCol" :wrapperCol="wrapperCol">
  38. <j-popup
  39. v-decorator="['financeOperator', validatorRules.financeOperator]"
  40. placeholder="请选择财务经办人"
  41. :trigger-change="true"
  42. org-fields="realname,depart_name"
  43. dest-fields="financeOperator,financeDept"
  44. code="user_dept"
  45. @callback="popupCallback"/>
  46. </a-form-item>
  47. </a-col>
  48. <a-col :span="8">
  49. <a-form-item label="财务经办部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
  50. <a-input v-decorator="[ 'financeDept', validatorRules.financeDept]" placeholder="请输入财务经办部门" disabled></a-input>
  51. </a-form-item>
  52. </a-col>
  53. <a-col :span="8">
  54. <a-form-item label="财务负责人" :labelCol="labelCol" :wrapperCol="wrapperCol">
  55. <a-input v-decorator="[ 'financeHead', validatorRules.financeHead]" placeholder="请输入财务负责人" disabled></a-input>
  56. </a-form-item>
  57. </a-col>
  58. </a-row>
  59. </a-form>
  60. <!-- 子表单区域 -->
  61. <a-tabs v-model="activeKey" @change="handleChangeTabs">
  62. <a-tab-pane tab="车辆费用报销明细" :key="refKeys[0]" :forceRender="true">
  63. <j-editable-table
  64. :ref="refKeys[0]"
  65. :loading="carfareDetailTable.loading"
  66. :columns="carfareDetailTable.columns"
  67. :dataSource="carfareDetailTable.dataSource"
  68. :maxHeight="300"
  69. :rowNumber="true"
  70. :rowSelection="true"
  71. :actionButton="true"
  72. @valueChange="calculateTotal"
  73. />
  74. </a-tab-pane>
  75. </a-tabs>
  76. </a-spin>
  77. </a-modal>
  78. </template>
  79. <script>
  80. import { httpAction, getAction } from '@/api/manage'
  81. import pick from 'lodash.pick'
  82. import { FormTypes,getRefPromise } from '@/utils/JEditableTableUtil'
  83. import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
  84. import { validateDuplicateValue } from '@/utils/util'
  85. export default {
  86. name: 'CarfareModal',
  87. mixins: [JEditableTableMixin],
  88. components: {
  89. },
  90. data() {
  91. return {
  92. labelCol: {
  93. span: 6
  94. },
  95. wrapperCol: {
  96. span: 16
  97. },
  98. labelCol2: {
  99. span: 3
  100. },
  101. wrapperCol2: {
  102. span: 20
  103. },
  104. // 新增时子表默认添加几行空数据
  105. addDefaultRowNum: 1,
  106. validatorRules: {
  107. registrant: {rules: [
  108. {required: true, message: '请选择登记人!'},
  109. ]},
  110. registrantDept: {rules: [
  111. ]},
  112. totalAmount: {rules: [
  113. {required: true, message: '请填写完整报销明细!'},
  114. ]},
  115. financeOperator: {rules: [
  116. {required: true, message: '请选择财务经办人!'},
  117. ]},
  118. financeDept: {rules: [
  119. ]},
  120. financeHead: {rules: [
  121. {required: true, message: '请输入财务负责人!'},
  122. ]},
  123. },
  124. refKeys: ['carfareDetail', ],
  125. tableKeys:['carfareDetail', ],
  126. activeKey: 'carfareDetail',
  127. // 车辆费用报销明细
  128. carfareDetailTable: {
  129. loading: false,
  130. dataSource: [],
  131. columns: [
  132. {
  133. title: '报销日期',
  134. key: 'reimbursementDate',
  135. type: FormTypes.date,
  136. width:"200px",
  137. placeholder: '请输入${title}',
  138. defaultValue: '',
  139. },
  140. {
  141. title: '支付凭证编号',
  142. key: 'paymentNo',
  143. type: FormTypes.input,
  144. width:"200px",
  145. placeholder: '请输入${title}',
  146. defaultValue: '',
  147. },
  148. {
  149. title: '车牌号',
  150. key: 'carNo',
  151. type: FormTypes.input,
  152. width:"200px",
  153. placeholder: '请输入${title}',
  154. defaultValue: '',
  155. },
  156. {
  157. title: '报销人',
  158. key: 'submitter',
  159. type: FormTypes.popup,
  160. popupCode:"user_dept",
  161. destFields:"submitter,dept",
  162. orgFieldse:"realname,depart_name",
  163. width:"200px",
  164. placeholder: '请输入${title}',
  165. defaultValue: '',
  166. },
  167. {
  168. title: '部门',
  169. key: 'dept',
  170. type: FormTypes.input,
  171. width:"200px",
  172. placeholder: '请输入${title}',
  173. defaultValue: '',
  174. disabled: true
  175. },
  176. {
  177. title: '报销内容',
  178. key: 'content',
  179. type: FormTypes.input,
  180. width:"200px",
  181. placeholder: '请输入${title}',
  182. defaultValue: '',
  183. },
  184. {
  185. title: '金额',
  186. key: 'amount',
  187. type: FormTypes.input,
  188. width:"200px",
  189. placeholder: '请输入${title}',
  190. defaultValue: '',
  191. validateRules: [
  192. { pattern: /^\d+(\.\d{1,2})?$/, message: '请输入金额(保留两位小数)' },
  193. ]
  194. },
  195. {
  196. title: '附件',
  197. key: 'attachment',
  198. type: FormTypes.file,
  199. token:true,
  200. responseName:"message",
  201. width:"200px",
  202. placeholder: '请选择文件',
  203. defaultValue: '',
  204. },
  205. {
  206. title: '备注',
  207. key: 'remark',
  208. type: FormTypes.input,
  209. width:"200px",
  210. placeholder: '请输入${title}',
  211. defaultValue: '',
  212. },
  213. ]
  214. },
  215. url: {
  216. add: "/oa/carfare/add",
  217. edit: "/oa/carfare/edit",
  218. carfareDetail: {
  219. list: '/oa/carfare/queryCarfareDetailByMainId'
  220. },
  221. user:{
  222. queryFinanceManager: '/sys/user/queryFinanceManager'
  223. }
  224. }
  225. }
  226. },
  227. methods: {
  228. getAllTable() {
  229. let values = this.tableKeys.map(key => getRefPromise(this, key))
  230. return Promise.all(values)
  231. },
  232. /** 调用完edit()方法之后会自动调用此方法 */
  233. editAfter() {
  234. let fieldval = pick(this.model,'registrant','registrantDept','totalAmount','financeOperator','financeDept','financeHead')
  235. this.$nextTick(() => {
  236. this.form.setFieldsValue(fieldval)
  237. })
  238. // 加载子表数据
  239. if (this.model.id) {
  240. let params = { id: this.model.id }
  241. this.requestSubTableData(this.url.carfareDetail.list, params, this.carfareDetailTable)
  242. }
  243. },
  244. /** 整理成formData */
  245. classifyIntoFormData(allValues) {
  246. let main = Object.assign(this.model, allValues.formValue)
  247. return {
  248. ...main, // 展开
  249. carfareDetailList: allValues.tablesValue[0].values,
  250. }
  251. },
  252. validateError(msg){
  253. this.$message.error(msg)
  254. },
  255. popupCallback(row){
  256. this.form.setFieldsValue(pick(row,'registrant','registrantDept','totalAmount','financeOperator','financeDept','financeHead'))
  257. },
  258. initFinanceManager(){
  259. getAction(this.url.user.queryFinanceManager, { position: '财务经理' }).then((res) => {
  260. if (res.success) {
  261. this.$nextTick(() => {
  262. this.form.setFieldsValue({
  263. financeHead: res.result.realname,
  264. })
  265. })
  266. }
  267. })
  268. },
  269. calculateTotal({ type, row, column, value, target }){
  270. if(column.key == 'amount'){
  271. this.$refs.carfareDetail.getValues((error, values) => {
  272. let totalAmount = 0
  273. totalAmount = values.map(v=>{
  274. return Number(v.amount || 0)
  275. }).reduce((sum,v)=>{
  276. return sum+v
  277. },0)
  278. this.form.setFieldsValue({
  279. totalAmount: totalAmount.toFixed(2),
  280. })
  281. })
  282. }
  283. }
  284. }
  285. }
  286. </script>
  287. <style scoped>
  288. </style>