baseDataModal.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <a-modal
  3. v-model="opened"
  4. :title="title"
  5. centered
  6. :maskClosable="false"
  7. :width="800"
  8. :footer="null"
  9. @cancel="cancel"
  10. >
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <a-form-model
  13. id="expenseReimbursementAddform"
  14. ref="ruleForm"
  15. :model="form"
  16. :rules="rules"
  17. :label-col="formItemLayout.labelCol"
  18. :wrapper-col="formItemLayout.wrapperCol">
  19. <a-row>
  20. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  21. <a-form-model-item label="申请人" prop="applyPersonSn">
  22. <employee style="width: 100%;" @change="employeeChange" id="expenseReimbursement-Employee" v-model="form.applyPersonSn"></employee>
  23. </a-form-model-item>
  24. </a-col>
  25. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  26. <a-form-model-item label="申请部门" prop="applyDepartmentSn">
  27. <department style="width: 100%;" @change="departementChange" id="expenseReimbursement-Department" v-model="form.applyDepartmentSn"></department>
  28. </a-form-model-item>
  29. </a-col>
  30. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  31. <a-form-model-item label="费用类型" prop="expenseType">
  32. <v-select
  33. code="EXPENSE_TYPE"
  34. id="expenseReimbursement-expenseType"
  35. v-model="form.expenseType"
  36. allowClear
  37. placeholder="请选择费用类型"
  38. ></v-select>
  39. </a-form-model-item>
  40. </a-col>
  41. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  42. <a-form-model-item label="费用产生月" prop="expenseDate">
  43. <a-month-picker
  44. placeholder="请选择月份"
  45. v-model="form.expenseDate"
  46. locale="zh-cn"
  47. @change="expenseDateChange"
  48. :disabled-date="disabledDate"
  49. style="width: 100%;"/>
  50. </a-form-model-item>
  51. </a-col>
  52. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  53. <a-form-model-item label="主题" prop="title">
  54. <a-textarea
  55. id="expenseReimbursementAdd-title"
  56. :maxLength="100"
  57. :rows="3"
  58. v-model.trim="form.title"
  59. placeholder="请输入(最多100个字符)"
  60. allowClear />
  61. </a-form-model-item>
  62. </a-col>
  63. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  64. <a-form-model-item label="详细说明" prop="content">
  65. <a-textarea
  66. id="expenseReimbursementAdd-content"
  67. placeholder="请输入详细说明(最多500个字符)"
  68. v-model.trim="form.content"
  69. :rows="3"
  70. :maxLength="500"
  71. allowClear/>
  72. </a-form-model-item>
  73. </a-col>
  74. </a-row>
  75. <a-row>
  76. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  77. <a-form-model-item label="附件" help="说明:单个文件小于10Mb,最多10个附件。">
  78. <Upload
  79. style="height: 100%;"
  80. id="noticeEdit-attachList"
  81. v-model="form.expenseAccountFilesList"
  82. ref="attachList"
  83. :fileSize="10"
  84. :maxNums="10"
  85. fileType="*"
  86. uploadType="attach"
  87. :action="attachAction"
  88. @change="changeAttach"
  89. upText="上传附件"></Upload>
  90. </a-form-model-item>
  91. </a-col>
  92. </a-row>
  93. <div style="text-align: center;margin-top: 20px;">
  94. <a-button type="primary" :loading="spinning" @click="handleSubmit" id="chooseCustom-btn-submit">保存</a-button>
  95. <a-button @click="cancel" style="margin-left: 15px" id="chooseCustom-btn-back">取消</a-button>
  96. </div>
  97. </a-form-model>
  98. </a-spin>
  99. </a-modal>
  100. </template>
  101. <script>
  102. import { VSelect, Upload, STable } from '@/components'
  103. import moment from 'moment'
  104. import department from './department.js'
  105. import employee from './employee.js'
  106. import { expenseAccountDetail, expenseAccountSave } from '@/api/expenseManagement.js'
  107. export default {
  108. name: 'BaseDataModal',
  109. components: { VSelect, Upload, STable, department, employee },
  110. props: {
  111. show: [Boolean],
  112. itemSn: {
  113. type: String,
  114. default: ''
  115. }
  116. },
  117. data () {
  118. return {
  119. opened: this.show,
  120. expenseAccountSn: this.itemSn,
  121. spinning: false,
  122. title: '新增费用报销单',
  123. formItemLayout: {
  124. labelCol: { span: 6 },
  125. wrapperCol: { span: 14 }
  126. },
  127. attachList: [],
  128. attachAction: process.env.VUE_APP_API_BASE_URL + '/uploadGetFileInfo',
  129. form: {
  130. applyPersonSn: undefined, // 申请人
  131. applyDepartmentSn: undefined, // 申请部门
  132. expenseType: undefined, // 费用类型
  133. expenseDate: moment().locale('zh-cn').format('YYYY-MM'), // 费用产生月
  134. title: '', // 主题
  135. content: '' // 费用说明
  136. },
  137. rules: {
  138. applyPersonSn: [
  139. { required: true, message: '请选择申请人', trigger: 'change' }
  140. ],
  141. applyDepartmentSn: [
  142. { required: true, message: '请选择申请部门', trigger: 'change' }
  143. ],
  144. expenseType: [
  145. { required: true, message: '请选择费用类型', trigger: 'change' }
  146. ],
  147. expenseDate: [
  148. { required: true, message: '请选择费用产生月', trigger: 'change' }
  149. ],
  150. title: [
  151. { required: true, message: '请输入主题', trigger: 'blur' }
  152. ],
  153. content: [
  154. { required: true, message: '请输入详细说明', trigger: 'blur' }
  155. ]
  156. }
  157. }
  158. },
  159. methods: {
  160. cancel () {
  161. this.$emit('close')
  162. },
  163. pageInit () {
  164. this.$nextTick(() => {
  165. this.$refs.attachList.setFileList('')
  166. this.$refs.ruleForm.resetFields()
  167. if (this.expenseAccountSn) { // 编辑页
  168. this.getDetail()
  169. this.title = '编辑费用报销单'
  170. }
  171. })
  172. },
  173. // 申请人员
  174. employeeChange (v, r) {
  175. if (r.departmentSn) {
  176. this.form.applyDepartmentSn = r.departmentSn
  177. }
  178. this.$nextTick(() => {
  179. this.$refs.ruleForm.validateField(['applyPersonSn', 'applyDepartmentSn'])
  180. })
  181. },
  182. departementChange () {
  183. this.$nextTick(() => {
  184. this.$refs.ruleForm.validateField('applyDepartmentSn')
  185. })
  186. },
  187. expenseDateChange (v, d) {
  188. this.form.expenseDate = d
  189. },
  190. disabledDate (current) {
  191. return current && current > moment().endOf('day')
  192. },
  193. // 附件上传
  194. changeAttach (file) {
  195. this.attachList = JSON.parse(file)
  196. this.attachList.map(item => {
  197. item.fileType = item.extName
  198. })
  199. },
  200. // 详情
  201. getDetail () {
  202. this.spinning = true
  203. this.disabled = true
  204. expenseAccountDetail({ expenseAccountSn: this.expenseAccountSn }).then(res => {
  205. if (res.status == 200) {
  206. const data = res.data
  207. this.form = Object.assign(this.form, data)
  208. // 获取附件列表
  209. this.form.expenseAccountFilesList = ''
  210. this.attachList = res.data.expenseAccountFilesList
  211. this.$refs.attachList.setFileList(this.attachList)
  212. } else {
  213. this.$refs.ruleForm.resetFields()
  214. }
  215. this.spinning = false
  216. this.disabled = false
  217. })
  218. },
  219. // 保存基础信息
  220. handleSubmit (e) {
  221. e.preventDefault()
  222. const _this = this
  223. this.$refs.ruleForm.validate(valid => {
  224. if (valid) {
  225. const form = JSON.parse(JSON.stringify(_this.form))
  226. form.expenseDate = form.expenseDate + '-01'
  227. form.expenseAccountFilesList = this.attachList
  228. _this.spinning = true
  229. console.log(form)
  230. expenseAccountSave(form).then(res => {
  231. if (res.status == 200) {
  232. _this.$message.success(res.message)
  233. setTimeout(() => {
  234. if (this.expenseAccountSn) {
  235. _this.$emit('refashData')
  236. } else {
  237. _this.$router.push({ name: 'expenseReimbursementEdit', params: { sn: res.data.expenseAccountSn } })
  238. }
  239. _this.spinning = false
  240. _this.cancel()
  241. }, 200)
  242. } else {
  243. _this.spinning = false
  244. }
  245. })
  246. } else {
  247. return false
  248. }
  249. })
  250. }
  251. },
  252. watch: {
  253. show (newValue, oldValue) {
  254. this.opened = newValue
  255. if (newValue) {
  256. this.pageInit()
  257. }
  258. },
  259. itemSn (a, b) {
  260. this.expenseAccountSn = a
  261. }
  262. }
  263. }
  264. </script>