baseDataModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. <expenseType
  33. id="expenseReimbursement-expenseType"
  34. v-model="expenseTypes"
  35. @change="expenseChange"
  36. placeholder="请选择费用类型"
  37. ></expenseType>
  38. </a-form-model-item>
  39. </a-col>
  40. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  41. <a-form-model-item label="费用产生月" prop="expenseDate">
  42. <a-month-picker
  43. placeholder="请选择月份"
  44. v-model="form.expenseDate"
  45. locale="zh-cn"
  46. @change="expenseDateChange"
  47. :disabled-date="disabledDate"
  48. style="width: 100%;"/>
  49. </a-form-model-item>
  50. </a-col>
  51. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  52. <a-form-model-item label="主题" prop="title" :label-col="{span:3}" :wrapper-col="{span:19}">
  53. <a-textarea
  54. id="expenseReimbursementAdd-title"
  55. :maxLength="100"
  56. :rows="3"
  57. v-model.trim="form.title"
  58. placeholder="请输入费用报销主题(最多100个字符)"
  59. allowClear />
  60. </a-form-model-item>
  61. </a-col>
  62. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  63. <a-form-model-item label="详细说明" prop="content" :label-col="{span:3}" :wrapper-col="{span:19}">
  64. <a-textarea
  65. id="expenseReimbursementAdd-content"
  66. placeholder="请详细描述费用报销内容(最多500个字符)"
  67. v-model.trim="form.content"
  68. :rows="3"
  69. :maxLength="500"
  70. allowClear/>
  71. </a-form-model-item>
  72. </a-col>
  73. </a-row>
  74. <a-row>
  75. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  76. <a-form-model-item label="附件" help="(支持图片、word、excel、PDF等格式,最多10个附件)" :label-col="{span:3}" :wrapper-col="{span:19}">
  77. <Upload
  78. style="height: 100%;"
  79. id="noticeEdit-attachList"
  80. v-model="form.expenseAccountFilesList"
  81. ref="attachList"
  82. :fileSize="10"
  83. :maxNums="10"
  84. fileType="*"
  85. uploadType="attach"
  86. :action="attachAction"
  87. @change="changeAttach"
  88. upText="上传附件"></Upload>
  89. </a-form-model-item>
  90. </a-col>
  91. </a-row>
  92. <div style="text-align: center;margin-top: 20px;">
  93. <a-button @click="cancel" style="margin-right: 15px" id="chooseCustom-btn-back">取消</a-button>
  94. <a-button type="primary" :loading="spinning" @click="handleSubmit" id="chooseCustom-btn-submit">保存</a-button>
  95. </div>
  96. </a-form-model>
  97. </a-spin>
  98. </a-modal>
  99. </template>
  100. <script>
  101. import { VSelect, Upload, STable } from '@/components'
  102. import moment from 'moment'
  103. import department from './department.js'
  104. import employee from './employee.js'
  105. import expenseType from '@/views/common/expenseType.js'
  106. import { expenseAccountDetail, expenseAccountSave } from '@/api/expenseManagement.js'
  107. export default {
  108. name: 'BaseDataModal',
  109. components: { VSelect, Upload, STable, department, employee, expenseType },
  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. fromPage: null,
  128. attachList: [],
  129. attachAction: process.env.VUE_APP_API_BASE_URL + '/uploadGetFileInfo',
  130. expenseTypes: [],
  131. form: {
  132. applyPersonSn: undefined, // 申请人
  133. applyDepartmentSn: undefined, // 申请部门
  134. expenseType: undefined, // 费用类型1
  135. expenseType2: undefined, // 费用类型2
  136. expenseType3: undefined, // 费用类型3
  137. expenseTypeName: undefined, // 费用类型1
  138. expenseTypeName2: undefined, // 费用类型2
  139. expenseTypeName3: undefined, // 费用类型3
  140. expenseDate: moment().locale('zh-cn').format('YYYY-MM'), // 费用产生月
  141. title: '', // 主题
  142. content: '' // 费用说明
  143. },
  144. rules: {
  145. applyPersonSn: [
  146. { required: true, message: '请选择申请人', trigger: 'change' }
  147. ],
  148. applyDepartmentSn: [
  149. { required: true, message: '请选择申请部门', trigger: 'change' }
  150. ],
  151. expenseType: [
  152. { required: true, message: '请选择费用类型', trigger: 'change' }
  153. ],
  154. expenseDate: [
  155. { required: true, message: '请选择费用产生月', trigger: 'change' }
  156. ],
  157. title: [
  158. { required: true, message: '请输入主题', trigger: 'blur' }
  159. ],
  160. content: [
  161. { required: true, message: '请输入详细说明', trigger: 'blur' }
  162. ]
  163. }
  164. }
  165. },
  166. methods: {
  167. cancel () {
  168. this.spinning = false
  169. this.$emit('close')
  170. },
  171. pageInit () {
  172. this.$nextTick(() => {
  173. if (this.expenseAccountSn) { // 编辑页
  174. this.getDetail()
  175. this.title = '编辑费用报销单'
  176. } else {
  177. this.title = '新增费用报销单'
  178. }
  179. })
  180. },
  181. retsetForm () {
  182. this.form = {
  183. applyPersonSn: undefined, // 申请人
  184. applyDepartmentSn: undefined, // 申请部门
  185. expenseType: undefined, // 费用类型1
  186. expenseType2: undefined, // 费用类型2
  187. expenseType3: undefined, // 费用类型3
  188. expenseTypeName: undefined, // 费用类型1
  189. expenseTypeName2: undefined, // 费用类型2
  190. expenseTypeName3: undefined, // 费用类型3
  191. expenseDate: moment().locale('zh-cn').format('YYYY-MM'), // 费用产生月
  192. title: '', // 主题
  193. content: '' // 费用说明
  194. }
  195. this.attachList = []
  196. this.form.expenseAccountFilesList = ''
  197. this.$refs.attachList.setFileList('')
  198. this.$refs.ruleForm.resetFields()
  199. this.expenseTypes = []
  200. },
  201. // 申请人员
  202. employeeChange (v, r) {
  203. if (r.departmentSn) {
  204. this.form.applyDepartmentSn = r.departmentSn
  205. }
  206. this.$nextTick(() => {
  207. this.$refs.ruleForm.validateField(['applyPersonSn', 'applyDepartmentSn'])
  208. })
  209. },
  210. departementChange () {
  211. this.$nextTick(() => {
  212. this.$refs.ruleForm.validateField('applyDepartmentSn')
  213. })
  214. },
  215. expenseDateChange (v, d) {
  216. this.form.expenseDate = d
  217. },
  218. disabledDate (current) {
  219. return current && current > moment().endOf('day')
  220. },
  221. expenseChange (val, opts) {
  222. console.log(val, opts)
  223. this.expenseTypes = val || []
  224. this.form.expenseType = val && val[0] ? val[0] : ''
  225. this.form.expenseType2 = val && val[1] ? val[1] : ''
  226. this.form.expenseType3 = val && val[2] ? val[2] : ''
  227. // 名称
  228. this.form.expenseTypeName = opts && opts[0] ? opts[0].name : ''
  229. this.form.expenseTypeName2 = opts && opts[1] ? opts[1].name : ''
  230. this.form.expenseTypeName3 = opts && opts[2] ? opts[2].name : ''
  231. },
  232. // 附件上传
  233. changeAttach (file) {
  234. this.attachList = JSON.parse(file)
  235. this.attachList.map(item => {
  236. item.fileType = item.extName
  237. })
  238. },
  239. // 设置数据
  240. setDetail (data, from) {
  241. console.log(data)
  242. this.spinning = false
  243. this.disabled = false
  244. this.fromPage = from
  245. this.form = Object.assign(this.form, data)
  246. // 获取附件列表
  247. if (this.$refs.attachList) {
  248. this.form.expenseAccountFilesList = ''
  249. this.attachList = data.expenseAccountFilesList
  250. this.$refs.attachList.setFileList(this.attachList)
  251. }
  252. setTimeout(() => {
  253. this.expenseTypes = data.expenseType ? [this.form.expenseType, this.form.expenseType2, this.form.expenseType3] : []
  254. }, 500)
  255. },
  256. // 详情
  257. getDetail () {
  258. this.spinning = true
  259. this.disabled = true
  260. expenseAccountDetail({ expenseAccountSn: this.expenseAccountSn }).then(res => {
  261. if (res.status == 200) {
  262. this.setDetail(res.data)
  263. } else {
  264. this.$refs.ruleForm.resetFields()
  265. }
  266. this.spinning = false
  267. this.disabled = false
  268. })
  269. },
  270. // 保存基础信息
  271. handleSubmit (e) {
  272. e.preventDefault()
  273. const _this = this
  274. this.$refs.ruleForm.validate(valid => {
  275. if (valid) {
  276. const form = JSON.parse(JSON.stringify(_this.form))
  277. form.expenseDate = form.expenseDate + '-01'
  278. form.expenseAccountFilesList = this.attachList
  279. console.log(form)
  280. _this.spinning = true
  281. // 从销售单转的费用
  282. if (_this.fromPage == 'sales') {
  283. _this.$emit('expenseSaveOk', form, this.fromPage)
  284. return false
  285. }
  286. // 从销售单转的费用,并合并提交
  287. if (_this.fromPage == 'salesMearge') {
  288. _this.$emit('expenseSaveOk', form, this.fromPage)
  289. return false
  290. }
  291. // 手动建的费用单
  292. expenseAccountSave(form).then(res => {
  293. if (res.status == 200) {
  294. _this.$message.success(res.message)
  295. setTimeout(() => {
  296. if (this.expenseAccountSn) {
  297. _this.$emit('refashData')
  298. } else {
  299. _this.$router.push({ name: 'expenseReimbursementEdit', params: { sn: res.data.expenseAccountSn } })
  300. }
  301. _this.spinning = false
  302. _this.cancel()
  303. }, 200)
  304. } else {
  305. _this.spinning = false
  306. }
  307. })
  308. } else {
  309. return false
  310. }
  311. })
  312. }
  313. },
  314. watch: {
  315. show (newValue, oldValue) {
  316. this.opened = newValue
  317. if (newValue) {
  318. this.pageInit()
  319. } else {
  320. this.retsetForm()
  321. }
  322. },
  323. itemSn (a, b) {
  324. this.expenseAccountSn = a
  325. }
  326. }
  327. }
  328. </script>