baseDataModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <a-modal
  3. v-drag
  4. v-model="opened"
  5. :title="title"
  6. centered
  7. :maskClosable="false"
  8. :width="800"
  9. :footer="null"
  10. @cancel="cancel"
  11. >
  12. <a-spin :spinning="spinning" tip="Loading...">
  13. <a-form-model
  14. id="expenseReimbursementAddform"
  15. ref="ruleForm"
  16. :model="form"
  17. :rules="rules"
  18. :label-col="formItemLayout.labelCol"
  19. :wrapper-col="formItemLayout.wrapperCol">
  20. <a-row>
  21. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  22. <a-form-model-item label="申请人" prop="applyPersonSn">
  23. <employee style="width: 100%;" @change="employeeChange" id="expenseReimbursement-Employee" v-model="form.applyPersonSn"></employee>
  24. </a-form-model-item>
  25. </a-col>
  26. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  27. <a-form-model-item label="申请部门" prop="applyDepartmentSn">
  28. <department style="width: 100%;" @change="departementChange" id="expenseReimbursement-Department" v-model="form.applyDepartmentSn"></department>
  29. </a-form-model-item>
  30. </a-col>
  31. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  32. <a-form-model-item label="费用类型" prop="expenseType">
  33. <expenseType
  34. id="expenseReimbursement-expenseType"
  35. v-model="expenseTypes"
  36. @change="expenseChange"
  37. placeholder="请选择费用类型"
  38. ></expenseType>
  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="24" :lg="24" :xl="24">
  53. <a-form-model-item label="主题" prop="title" :label-col="{span:3}" :wrapper-col="{span:19}">
  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="24" :lg="24" :xl="24">
  64. <a-form-model-item label="详细说明" prop="content" :label-col="{span:3}" :wrapper-col="{span:19}">
  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="24" :lg="24" :xl="24">
  77. <a-form-model-item label="附件" help="(支持图片、word、excel、PDF等格式,最多10个附件)" :label-col="{span:3}" :wrapper-col="{span:19}">
  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 @click="cancel" style="margin-right: 15px" id="chooseCustom-btn-back">取消</a-button>
  95. <a-button type="primary" :loading="spinning" @click="handleSubmit" id="chooseCustom-btn-submit">保存</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 expenseType from '@/views/common/expenseType.js'
  107. import { expenseAccountDetail, expenseAccountSave } from '@/api/expenseManagement.js'
  108. export default {
  109. name: 'BaseDataModal',
  110. components: { VSelect, Upload, STable, department, employee, expenseType },
  111. props: {
  112. show: [Boolean],
  113. itemSn: {
  114. type: String,
  115. default: ''
  116. }
  117. },
  118. data () {
  119. return {
  120. opened: this.show,
  121. expenseAccountSn: this.itemSn,
  122. spinning: false,
  123. title: '新增费用报销单',
  124. formItemLayout: {
  125. labelCol: { span: 6 },
  126. wrapperCol: { span: 14 }
  127. },
  128. fromPage: null,
  129. attachList: [],
  130. attachAction: process.env.VUE_APP_API_BASE_URL + '/uploadGetFileInfo',
  131. expenseTypes: [],
  132. form: {
  133. applyPersonSn: undefined, // 申请人
  134. applyDepartmentSn: undefined, // 申请部门
  135. expenseType: undefined, // 费用类型1
  136. expenseType2: undefined, // 费用类型2
  137. expenseType3: undefined, // 费用类型3
  138. expenseTypeName: undefined, // 费用类型1
  139. expenseTypeName2: undefined, // 费用类型2
  140. expenseTypeName3: undefined, // 费用类型3
  141. expenseDate: moment().locale('zh-cn').format('YYYY-MM'), // 费用产生月
  142. title: '', // 主题
  143. content: '' // 费用说明
  144. },
  145. rules: {
  146. applyPersonSn: [
  147. { required: true, message: '请选择申请人', trigger: 'change' }
  148. ],
  149. applyDepartmentSn: [
  150. { required: true, message: '请选择申请部门', trigger: 'change' }
  151. ],
  152. expenseType: [
  153. { required: true, message: '请选择费用类型', trigger: 'change' }
  154. ],
  155. expenseDate: [
  156. { required: true, message: '请选择费用产生月', trigger: 'change' }
  157. ],
  158. title: [
  159. { required: true, message: '请输入主题', trigger: 'blur' }
  160. ],
  161. content: [
  162. { required: true, message: '请输入详细说明', trigger: 'blur' }
  163. ]
  164. }
  165. }
  166. },
  167. methods: {
  168. cancel () {
  169. this.spinning = false
  170. this.$emit('close')
  171. },
  172. pageInit () {
  173. this.$nextTick(() => {
  174. if (this.expenseAccountSn) { // 编辑页
  175. this.getDetail()
  176. this.title = '编辑费用报销单'
  177. } else {
  178. this.title = '新增费用报销单'
  179. }
  180. })
  181. },
  182. retsetForm () {
  183. this.form = {
  184. applyPersonSn: undefined, // 申请人
  185. applyDepartmentSn: undefined, // 申请部门
  186. expenseType: undefined, // 费用类型1
  187. expenseType2: undefined, // 费用类型2
  188. expenseType3: undefined, // 费用类型3
  189. expenseTypeName: undefined, // 费用类型1
  190. expenseTypeName2: undefined, // 费用类型2
  191. expenseTypeName3: undefined, // 费用类型3
  192. expenseDate: moment().locale('zh-cn').format('YYYY-MM'), // 费用产生月
  193. title: '', // 主题
  194. content: '' // 费用说明
  195. }
  196. this.attachList = []
  197. this.form.expenseAccountFilesList = ''
  198. this.$refs.attachList.setFileList('')
  199. this.$refs.ruleForm.resetFields()
  200. this.expenseTypes = []
  201. },
  202. // 申请人员
  203. employeeChange (v, r) {
  204. if (r.departmentSn) {
  205. this.form.applyDepartmentSn = r.departmentSn
  206. }
  207. this.$nextTick(() => {
  208. this.$refs.ruleForm.validateField(['applyPersonSn', 'applyDepartmentSn'])
  209. })
  210. },
  211. departementChange () {
  212. this.$nextTick(() => {
  213. this.$refs.ruleForm.validateField('applyDepartmentSn')
  214. })
  215. },
  216. expenseDateChange (v, d) {
  217. this.form.expenseDate = d
  218. },
  219. disabledDate (current) {
  220. return current && current > moment().endOf('day')
  221. },
  222. expenseChange (val, opts) {
  223. console.log(val, opts)
  224. this.expenseTypes = val || []
  225. this.form.expenseType = val && val[0] ? val[0] : ''
  226. this.form.expenseType2 = val && val[1] ? val[1] : ''
  227. this.form.expenseType3 = val && val[2] ? val[2] : ''
  228. // 名称
  229. this.form.expenseTypeName = opts && opts[0] ? opts[0].name : ''
  230. this.form.expenseTypeName2 = opts && opts[1] ? opts[1].name : ''
  231. this.form.expenseTypeName3 = opts && opts[2] ? opts[2].name : ''
  232. },
  233. // 附件上传
  234. changeAttach (file) {
  235. this.attachList = JSON.parse(file)
  236. this.attachList.map(item => {
  237. item.fileType = item.extName
  238. })
  239. },
  240. // 设置数据
  241. setDetail (data, from) {
  242. console.log(data)
  243. this.spinning = false
  244. this.disabled = false
  245. this.fromPage = from
  246. this.form = Object.assign(this.form, data)
  247. // 获取附件列表
  248. if (this.$refs.attachList) {
  249. this.form.expenseAccountFilesList = ''
  250. this.attachList = data.expenseAccountFilesList
  251. this.$refs.attachList.setFileList(this.attachList)
  252. }
  253. setTimeout(() => {
  254. this.expenseTypes = data.expenseType ? [this.form.expenseType, this.form.expenseType2, this.form.expenseType3] : []
  255. }, 500)
  256. },
  257. // 详情
  258. getDetail () {
  259. this.spinning = true
  260. this.disabled = true
  261. expenseAccountDetail({ expenseAccountSn: this.expenseAccountSn }).then(res => {
  262. if (res.status == 200) {
  263. this.setDetail(res.data)
  264. } else {
  265. this.$refs.ruleForm.resetFields()
  266. }
  267. this.spinning = false
  268. this.disabled = false
  269. })
  270. },
  271. // 保存基础信息
  272. handleSubmit (e) {
  273. e.preventDefault()
  274. const _this = this
  275. this.$refs.ruleForm.validate(valid => {
  276. if (valid) {
  277. const form = JSON.parse(JSON.stringify(_this.form))
  278. form.expenseDate = form.expenseDate + '-01'
  279. form.expenseAccountFilesList = this.attachList
  280. console.log(form)
  281. _this.spinning = true
  282. // 从销售单转的费用
  283. if (_this.fromPage == 'sales') {
  284. _this.$emit('expenseSaveOk', form, this.fromPage)
  285. return false
  286. }
  287. // 从销售单转的费用,并合并提交
  288. if (_this.fromPage == 'salesMearge') {
  289. _this.$emit('expenseSaveOk', form, this.fromPage)
  290. return false
  291. }
  292. // 手动建的费用单
  293. expenseAccountSave(form).then(res => {
  294. if (res.status == 200) {
  295. _this.$message.success(res.message)
  296. setTimeout(() => {
  297. if (this.expenseAccountSn) {
  298. _this.$emit('refashData')
  299. } else {
  300. _this.$router.push({ name: 'expenseReimbursementEdit', params: { sn: res.data.expenseAccountSn } })
  301. }
  302. _this.spinning = false
  303. _this.cancel()
  304. }, 200)
  305. } else {
  306. _this.spinning = false
  307. }
  308. })
  309. } else {
  310. return false
  311. }
  312. })
  313. }
  314. },
  315. watch: {
  316. show (newValue, oldValue) {
  317. this.opened = newValue
  318. if (newValue) {
  319. this.pageInit()
  320. } else {
  321. this.retsetForm()
  322. }
  323. },
  324. itemSn (a, b) {
  325. this.expenseAccountSn = a
  326. }
  327. }
  328. }
  329. </script>