baseDataModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. expenseTypeName: undefined, // 费用类型1
  137. expenseTypeName2: undefined, // 费用类型2
  138. expenseDate: moment().locale('zh-cn').format('YYYY-MM'), // 费用产生月
  139. title: '', // 主题
  140. content: '' // 费用说明
  141. },
  142. rules: {
  143. applyPersonSn: [
  144. { required: true, message: '请选择申请人', trigger: 'change' }
  145. ],
  146. applyDepartmentSn: [
  147. { required: true, message: '请选择申请部门', trigger: 'change' }
  148. ],
  149. expenseType: [
  150. { required: true, message: '请选择费用类型', trigger: 'change' }
  151. ],
  152. expenseDate: [
  153. { required: true, message: '请选择费用产生月', trigger: 'change' }
  154. ],
  155. title: [
  156. { required: true, message: '请输入主题', trigger: 'blur' }
  157. ],
  158. content: [
  159. { required: true, message: '请输入详细说明', trigger: 'blur' }
  160. ]
  161. }
  162. }
  163. },
  164. methods: {
  165. cancel () {
  166. this.spinning = false
  167. this.$emit('close')
  168. },
  169. pageInit () {
  170. this.$nextTick(() => {
  171. if (this.expenseAccountSn) { // 编辑页
  172. this.getDetail()
  173. this.title = '编辑费用报销单'
  174. }else{
  175. this.title = '新增费用报销单'
  176. }
  177. })
  178. },
  179. retsetForm(){
  180. this.form = {
  181. applyPersonSn: undefined, // 申请人
  182. applyDepartmentSn: undefined, // 申请部门
  183. expenseType: undefined, // 费用类型1
  184. expenseType2: undefined, // 费用类型2
  185. expenseTypeName: undefined, // 费用类型1
  186. expenseTypeName2: undefined, // 费用类型2
  187. expenseDate: moment().locale('zh-cn').format('YYYY-MM'), // 费用产生月
  188. title: '', // 主题
  189. content: '' // 费用说明
  190. }
  191. this.attachList = []
  192. this.form.expenseAccountFilesList = ''
  193. this.$refs.attachList.setFileList('')
  194. this.$refs.ruleForm.resetFields()
  195. this.expenseTypes = []
  196. },
  197. // 申请人员
  198. employeeChange (v, r) {
  199. if (r.departmentSn) {
  200. this.form.applyDepartmentSn = r.departmentSn
  201. }
  202. this.$nextTick(() => {
  203. this.$refs.ruleForm.validateField(['applyPersonSn', 'applyDepartmentSn'])
  204. })
  205. },
  206. departementChange () {
  207. this.$nextTick(() => {
  208. this.$refs.ruleForm.validateField('applyDepartmentSn')
  209. })
  210. },
  211. expenseDateChange (v, d) {
  212. this.form.expenseDate = d
  213. },
  214. disabledDate (current) {
  215. return current && current > moment().endOf('day')
  216. },
  217. expenseChange (val, opts) {
  218. console.log(val, opts)
  219. this.expenseTypes = val || []
  220. this.form.expenseType = val && val[0] ? val[0] : ''
  221. this.form.expenseType2 = val && val[1] ? val[1] : ''
  222. // 名称
  223. this.form.expenseTypeName = opts && opts[0] ? opts[0].name : ''
  224. this.form.expenseTypeName2 = opts && opts[1] ? opts[1].name : ''
  225. },
  226. // 附件上传
  227. changeAttach (file) {
  228. this.attachList = JSON.parse(file)
  229. this.attachList.map(item => {
  230. item.fileType = item.extName
  231. })
  232. },
  233. // 设置数据
  234. setDetail(data, from){
  235. console.log(data)
  236. this.spinning = false
  237. this.disabled = false
  238. this.fromPage = from
  239. this.form = Object.assign(this.form, data)
  240. // 获取附件列表
  241. if(this.$refs.attachList){
  242. this.form.expenseAccountFilesList = ''
  243. this.attachList = data.expenseAccountFilesList
  244. this.$refs.attachList.setFileList(this.attachList)
  245. }
  246. setTimeout(()=>{
  247. this.expenseTypes = data.expenseType ? [this.form.expenseType, this.form.expenseType2] : []
  248. }, 500)
  249. },
  250. // 详情
  251. getDetail () {
  252. this.spinning = true
  253. this.disabled = true
  254. expenseAccountDetail({ expenseAccountSn: this.expenseAccountSn }).then(res => {
  255. if (res.status == 200) {
  256. this.setDetail(res.data)
  257. } else {
  258. this.$refs.ruleForm.resetFields()
  259. }
  260. this.spinning = false
  261. this.disabled = false
  262. })
  263. },
  264. // 保存基础信息
  265. handleSubmit (e) {
  266. e.preventDefault()
  267. const _this = this
  268. this.$refs.ruleForm.validate(valid => {
  269. if (valid) {
  270. const form = JSON.parse(JSON.stringify(_this.form))
  271. form.expenseDate = form.expenseDate + '-01'
  272. form.expenseAccountFilesList = this.attachList
  273. _this.spinning = true
  274. console.log(form)
  275. // 从销售单转的费用
  276. if(_this.fromPage=='sales'){
  277. _this.$emit('expenseSaveOk',form)
  278. return false
  279. }
  280. expenseAccountSave(form).then(res => {
  281. if (res.status == 200) {
  282. _this.$message.success(res.message)
  283. setTimeout(() => {
  284. if (this.expenseAccountSn) {
  285. _this.$emit('refashData')
  286. } else {
  287. _this.$router.push({ name: 'expenseReimbursementEdit', params: { sn: res.data.expenseAccountSn } })
  288. }
  289. _this.spinning = false
  290. _this.cancel()
  291. }, 200)
  292. } else {
  293. _this.spinning = false
  294. }
  295. })
  296. } else {
  297. return false
  298. }
  299. })
  300. }
  301. },
  302. watch: {
  303. show (newValue, oldValue) {
  304. this.opened = newValue
  305. if (newValue) {
  306. this.pageInit()
  307. }else{
  308. this.retsetForm()
  309. }
  310. },
  311. itemSn (a, b) {
  312. this.expenseAccountSn = a
  313. }
  314. }
  315. }
  316. </script>