BaseForm.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="800"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. @cancel="handleCancel"
  8. >
  9. <a-form :form="form">
  10. <a-form-item v-show="false" >
  11. <a-input v-decorator="['id']" type="hidden"/>
  12. <a-input v-decorator="['sbId']" type="hidden"/>
  13. </a-form-item>
  14. <a-form-item
  15. label="维修单id"
  16. :labelCol="BaseTool.Constant.labelCol"
  17. :wrapperCol="BaseTool.Constant.wrapperCol"
  18. v-show="false"
  19. >
  20. <a-input
  21. v-decorator="['repairId']" />
  22. </a-form-item>
  23. <a-form-item
  24. label="维修单号"
  25. :labelCol="BaseTool.Constant.labelCol"
  26. :wrapperCol="BaseTool.Constant.wrapperCol"
  27. >
  28. <a-input
  29. disabled
  30. style="width:70%"
  31. v-decorator="['repairNo']" />
  32. <a-button style="width: 30%;" type="primary" @click="handleAppNoSelect">选择</a-button>
  33. </a-form-item>
  34. <a-form-item
  35. label="委外单号"
  36. :labelCol="BaseTool.Constant.labelCol"
  37. :wrapperCol="BaseTool.Constant.wrapperCol"
  38. >
  39. <a-input
  40. v-decorator="['no']" />
  41. </a-form-item>
  42. <a-form-item
  43. label="费用金额"
  44. :labelCol="BaseTool.Constant.labelCol"
  45. :wrapperCol="BaseTool.Constant.wrapperCol"
  46. >
  47. <a-input-number
  48. style="width: 100%"
  49. :min="0"
  50. :step="0.01"
  51. :formatter="BaseTool.Amount.formatter"
  52. :parser="BaseTool.Amount.parser"
  53. v-decorator="['fee', {rules: [{required: true, message: '费用金额不能为空'}]}]" />
  54. </a-form-item>
  55. <a-form-item
  56. label="货币单位"
  57. :labelCol="BaseTool.Constant.labelCol"
  58. :wrapperCol="BaseTool.Constant.wrapperCol"
  59. >
  60. <a-select v-decorator="['moneyType', {rules: [{required: true, message: '货币单位不能为空'}]}]" placeholder="请选择">
  61. <a-select-option
  62. v-for="(label,value) in moneyTypeMap"
  63. :key="value"
  64. :label="label"
  65. :value="value">{{ label }}
  66. </a-select-option>
  67. </a-select>
  68. </a-form-item>
  69. <a-form-item
  70. label="费用类别"
  71. :labelCol="BaseTool.Constant.labelCol"
  72. :wrapperCol="BaseTool.Constant.wrapperCol"
  73. >
  74. <a-select v-decorator="['type', {rules: [{required: true, message: '费用类别不能为空'}]}]" placeholder="请选择">
  75. <a-select-option
  76. v-for="(label,value) in typeMap"
  77. :key="value"
  78. :label="label"
  79. :value="parseInt(value)">{{ label }}
  80. </a-select-option>
  81. </a-select>
  82. </a-form-item>
  83. <a-form-item
  84. label="费用日期"
  85. :labelCol="BaseTool.Constant.labelCol"
  86. :wrapperCol="BaseTool.Constant.wrapperCol"
  87. >
  88. <a-date-picker
  89. style="width: 100%"
  90. :format="BaseTool.Date.PICKER_NORM_DATE_PATTERN"
  91. v-decorator="['feeDate']" />
  92. </a-form-item>
  93. <a-form-item
  94. label="费用原因"
  95. :labelCol="BaseTool.Constant.labelCol"
  96. :wrapperCol="BaseTool.Constant.wrapperCol"
  97. >
  98. <a-textarea
  99. v-decorator="['reason']" />
  100. </a-form-item>
  101. <a-form-item
  102. label="费用描述"
  103. :labelCol="BaseTool.Constant.labelCol"
  104. :wrapperCol="BaseTool.Constant.wrapperCol"
  105. >
  106. <a-textarea
  107. v-decorator="['descripition']" />
  108. </a-form-item>
  109. <a-form-item
  110. label="备注"
  111. :labelCol="BaseTool.Constant.labelCol"
  112. :wrapperCol="BaseTool.Constant.wrapperCol"
  113. >
  114. <a-textarea
  115. v-decorator="['remark']" />
  116. </a-form-item>
  117. <a-form-item
  118. label="图片"
  119. :labelCol="BaseTool.Constant.labelCol"
  120. :wrapperCol="BaseTool.Constant.wrapperCol"
  121. >
  122. <a-upload
  123. :action="uploadUrl"
  124. :multiple="true"
  125. list-type="picture"
  126. :file-list="defaultImageList"
  127. @change="handleImageFileChange"
  128. accept="image/*"
  129. :headers="headers"
  130. >
  131. <a-button> <a-icon type="upload" /> 上传图片 </a-button>
  132. </a-upload>
  133. </a-form-item>
  134. <a-form-item
  135. label="附件"
  136. :labelCol="BaseTool.Constant.labelCol"
  137. :wrapperCol="BaseTool.Constant.wrapperCol"
  138. >
  139. <a-upload
  140. :action="uploadUrl"
  141. :multiple="true"
  142. :file-list="defaultFileList"
  143. @change="handleFileChange"
  144. :headers="headers"
  145. >
  146. <a-button> <a-icon type="upload" /> 上传文件 </a-button>
  147. </a-upload>
  148. </a-form-item>
  149. </a-form>
  150. <template slot="footer">
  151. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  152. </template>
  153. <repair-application-form-select-modal ref="rafSelectModal" @selected="handleAppNoSelected"/>
  154. </a-modal>
  155. </template>
  156. <script>
  157. import pick from 'lodash.pick'
  158. import { addRepairFee, updateRepairFee } from '@/api/repair/fee'
  159. import { uploadUrl } from '@/api/upms/file'
  160. import Vue from 'vue'
  161. import { ACCESS_TOKEN } from '@/store/mutation-types'
  162. import RepairApplicationFormSelectModal from '@/views/repair/application-form/modules/RepairApplicationFormSelectModal'
  163. export default {
  164. name: 'BaseRepairFee',
  165. data () {
  166. return {
  167. sbId: null,
  168. confirmLoading: false,
  169. modalTitle: null,
  170. defaultImageList: [],
  171. imageList: [],
  172. moneyTypeMap: {},
  173. defaultFileList: [],
  174. fileList: [],
  175. uploadUrl: uploadUrl,
  176. headers: {
  177. Authorization: 'Bearer ' + Vue.ls.get(ACCESS_TOKEN)
  178. },
  179. form: this.$form.createForm(this),
  180. visible: false,
  181. // 下拉框map
  182. typeMap: {}
  183. }
  184. },
  185. components: {
  186. RepairApplicationFormSelectModal
  187. },
  188. props: {
  189. },
  190. created () {
  191. // 下拉框map
  192. this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_FEE_TYPE)
  193. this.moneyTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.MONEY_TYPE)
  194. },
  195. methods: {
  196. base (record, repairForm = {}) {
  197. this.visible = true
  198. // 如果是空标识添加
  199. const { form: { setFieldsValue } } = this
  200. if (this.BaseTool.Object.isBlank(record)) {
  201. if (repairForm != null) {
  202. this.sbId = repairForm.sbId
  203. this.$nextTick(() => {
  204. setFieldsValue({
  205. 'sbId': repairForm.sbId,
  206. 'repairId': repairForm.id,
  207. 'repairNo': repairForm.no
  208. })
  209. })
  210. }
  211. this.imageList = []
  212. this.fileList = []
  213. this.defaultImageList = []
  214. this.defaultFileList = []
  215. this.modalTitle = '添加'
  216. return
  217. }
  218. this.imageList = record.imageList
  219. this.fileList = record.fileList
  220. this.defaultImageList = this.BaseTool.UPLOAD.transImg(this.imageList)
  221. this.defaultFileList = this.BaseTool.UPLOAD.transImg(this.fileList)
  222. this.modalTitle = '编辑'
  223. if (record.feeDate != null) {
  224. record.feeDate = this.BaseTool.Moment(record.feeDate, this.BaseTool.Date.PICKER_NORM_DATE_PATTERN)
  225. this.$nextTick(() => {
  226. setFieldsValue(Object.assign(pick(record, [
  227. 'feeDate'
  228. ])))
  229. })
  230. }
  231. // 日期处理
  232. this.$nextTick(() => {
  233. setFieldsValue(Object.assign(pick(record, [
  234. 'id',
  235. 'repairId',
  236. 'sbId',
  237. 'no',
  238. 'repairNo',
  239. 'fee',
  240. 'moneyType',
  241. 'type',
  242. 'reason',
  243. 'descripition',
  244. 'remark'
  245. ])))
  246. })
  247. },
  248. save () {
  249. const { form: { validateFieldsAndScroll } } = this
  250. this.confirmLoading = true
  251. validateFieldsAndScroll((errors, values) => {
  252. if (errors) {
  253. this.confirmLoading = false
  254. return
  255. }
  256. values.feeDate = this.BaseTool.Date.formatter(values.feeDate, this.BaseTool.Date.PICKER_NORM_DATE_PATTERN)
  257. // 上传文件
  258. values.imageList = this.imageList
  259. values.fileList = this.fileList
  260. // 日期处理
  261. if (this.BaseTool.String.isBlank(values.id)) {
  262. addRepairFee(values)
  263. .then(() => {
  264. this.handleCancel(values)
  265. }).catch(() => {
  266. this.confirmLoading = false
  267. })
  268. } else {
  269. updateRepairFee(values)
  270. .then(() => {
  271. this.handleCancel(values)
  272. }).catch(() => {
  273. this.confirmLoading = false
  274. })
  275. }
  276. })
  277. },
  278. handleImageFileChange (info) {
  279. this.defaultImageList = info.fileList
  280. this.imageList = this.setFileList(info, 18)
  281. },
  282. handleFileChange (info) {
  283. this.defaultFileList = info.fileList
  284. this.fileList = this.setFileList(info, 19)
  285. },
  286. setFileList (info, type) {
  287. const file = info.file
  288. const fileList = info.fileList
  289. if (file.status === 'done') {
  290. return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
  291. } else if (file.status === 'removed') {
  292. return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
  293. } else if (file.status === 'error') {
  294. this.$message.error('上传失败')
  295. return []
  296. }
  297. },
  298. handleAppNoSelect () {
  299. this.$refs.rafSelectModal.base(null, { sbId: this.sbId })
  300. },
  301. handleAppNoSelected (record, keys, rows) {
  302. console.log(keys, rows)
  303. const [ key ] = keys
  304. const [ row ] = rows
  305. const { form: { setFieldsValue } } = this
  306. this.$nextTick(() => {
  307. setFieldsValue(Object.assign({
  308. 'repairId': key,
  309. 'repairNo': row.no
  310. }))
  311. })
  312. },
  313. handleCancel (values) {
  314. this.visible = false
  315. this.confirmLoading = false
  316. this.form.resetFields()
  317. if (this.BaseTool.Object.isNotBlank(values)) {
  318. this.$emit('ok', values)
  319. }
  320. }
  321. }
  322. }
  323. </script>