baseDataModal.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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="expenseReimbursementAddform-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="expenseReimbursementAddform-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="expenseReimbursementAddform-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. id="expenseReimbursementAddform-expenseDate"
  45. placeholder="请选择月份"
  46. v-model="form.expenseDate"
  47. locale="zh-cn"
  48. @change="expenseDateChange"
  49. :disabled-date="disabledDate"
  50. style="width: 100%;"/>
  51. </a-form-model-item>
  52. </a-col>
  53. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  54. <a-form-model-item
  55. label="费用归属品牌"
  56. prop="productBrandSn"
  57. :required="form.expenseTypeName=='促销费用'"
  58. >
  59. <ProductBrand id="expenseReimbursementAddform-productBrandSn" @change="changeBrand" showAllBrand v-model="form.productBrandSn" placeholder="请选择费用归属品牌(单选)"></ProductBrand>
  60. </a-form-model-item>
  61. </a-col>
  62. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  63. <a-form-model-item
  64. label="费用归属品类"
  65. prop="productTypeSn2"
  66. :required="form.expenseTypeName=='促销费用'"
  67. >
  68. <productTypeAll
  69. :isAll="true"
  70. placeholder="请选择费用归属品类(单选,至少选到二级或三级)"
  71. showAllType
  72. @change="changeProductType"
  73. v-model="productType"
  74. id="expenseReimbursementAddform-productType"></productTypeAll>
  75. </a-form-model-item>
  76. </a-col>
  77. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  78. <a-form-model-item label="主题" prop="title" :label-col="{span:3}" :wrapper-col="{span:19}">
  79. <a-textarea
  80. id="expenseReimbursementAddform-title"
  81. :maxLength="100"
  82. :rows="3"
  83. v-model.trim="form.title"
  84. placeholder="请输入费用报销主题(最多100个字符)"
  85. allowClear />
  86. </a-form-model-item>
  87. </a-col>
  88. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  89. <a-form-model-item label="详细说明" prop="content" :label-col="{span:3}" :wrapper-col="{span:19}">
  90. <a-textarea
  91. id="expenseReimbursementAddform-content"
  92. placeholder="请详细描述费用报销内容(最多500个字符)"
  93. v-model.trim="form.content"
  94. :rows="3"
  95. :maxLength="500"
  96. allowClear/>
  97. </a-form-model-item>
  98. </a-col>
  99. </a-row>
  100. <a-row>
  101. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  102. <a-form-model-item label="附件" help="(支持图片、word、excel、PDF等格式,最多10个附件)" :label-col="{span:3}" :wrapper-col="{span:19}">
  103. <Upload
  104. style="height: 100%;"
  105. id="expenseReimbursementAddform-attachList"
  106. v-model="form.expenseAccountFilesList"
  107. ref="attachList"
  108. :fileSize="10"
  109. :maxNums="10"
  110. fileType="*"
  111. uploadType="attach"
  112. :action="attachAction"
  113. @change="changeAttach"
  114. upText="上传附件"></Upload>
  115. </a-form-model-item>
  116. </a-col>
  117. </a-row>
  118. <div style="text-align: center;margin-top: 20px;">
  119. <a-button @click="cancel" style="margin-right: 15px" id="expenseReimbursementAddform-btn-back">取消</a-button>
  120. <a-button type="primary" :loading="spinning" @click="handleSubmit" id="expenseReimbursementAddform-btn-submit">保存</a-button>
  121. </div>
  122. </a-form-model>
  123. </a-spin>
  124. </a-modal>
  125. </template>
  126. <script>
  127. import { VSelect, Upload, STable } from '@/components'
  128. import moment from 'moment'
  129. import department from './department.js'
  130. import employee from './employee.js'
  131. import expenseType from '@/views/common/expenseType.js'
  132. import ProductBrand from '@/views/common/productBrand.js'
  133. import productTypeAll from '@/views/common/productTypeAll.js'
  134. import { expenseAccountDetail, expenseAccountSave } from '@/api/expenseManagement.js'
  135. export default {
  136. name: 'BaseDataModal',
  137. components: { VSelect, Upload, STable, department, employee, expenseType, ProductBrand, productTypeAll },
  138. props: {
  139. show: [Boolean],
  140. itemSn: {
  141. type: String,
  142. default: ''
  143. }
  144. },
  145. data () {
  146. return {
  147. opened: this.show,
  148. expenseAccountSn: this.itemSn, // 费用报销单sn
  149. spinning: false,
  150. title: '新增费用报销单', // 弹框标题
  151. formItemLayout: {
  152. labelCol: { span: 6 },
  153. wrapperCol: { span: 14 }
  154. },
  155. fromPage: null, // 打开方式,sales:销售单转费用单,salesMearge:合并销售单转,其它手动创建
  156. attachList: [], // 附件列表
  157. attachAction: process.env.VUE_APP_API_BASE_URL + '/uploadGetFileInfo', // 附件上传地址
  158. expenseTypes: [], // 费用类型值
  159. productType: [],
  160. form: {
  161. applyPersonSn: undefined, // 申请人
  162. applyDepartmentSn: undefined, // 申请部门
  163. expenseType: undefined, // 费用类型1
  164. expenseType2: undefined, // 费用类型2
  165. expenseType3: undefined, // 费用类型3
  166. expenseTypeName: undefined, // 费用类型1
  167. expenseTypeName2: undefined, // 费用类型2
  168. expenseTypeName3: undefined, // 费用类型3
  169. productBrandSn: undefined, // 产品品牌
  170. productTypeSn1: '', // 产品一级分类
  171. productTypeSn2: '', // 产品二级分类
  172. productTypeSn3: '', // 产品三级分类
  173. expenseDate: moment().locale('zh-cn').format('YYYY-MM'), // 费用产生月
  174. title: '', // 主题
  175. content: '' // 费用说明
  176. },
  177. rules: {
  178. applyPersonSn: [
  179. { required: true, message: '请选择申请人', trigger: 'change' }
  180. ],
  181. applyDepartmentSn: [
  182. { required: true, message: '请选择申请部门', trigger: 'change' }
  183. ],
  184. expenseType: [
  185. { required: true, message: '请选择费用类型', trigger: 'change' }
  186. ],
  187. expenseDate: [
  188. { required: true, message: '请选择费用产生月', trigger: 'change' }
  189. ],
  190. title: [
  191. { required: true, message: '请输入主题', trigger: 'blur' }
  192. ],
  193. content: [
  194. { required: true, message: '请输入详细说明', trigger: 'blur' }
  195. ]
  196. }
  197. }
  198. },
  199. methods: {
  200. // 关闭弹框
  201. cancel () {
  202. this.spinning = false
  203. this.$emit('close')
  204. },
  205. // 初始化
  206. pageInit () {
  207. this.$nextTick(() => {
  208. if (this.expenseAccountSn) { // 编辑页
  209. this.getDetail()
  210. this.title = '编辑费用报销单'
  211. } else {
  212. this.title = '新增费用报销单'
  213. }
  214. })
  215. },
  216. // 重置表单
  217. retsetForm () {
  218. this.form = {
  219. applyPersonSn: undefined, // 申请人
  220. applyDepartmentSn: undefined, // 申请部门
  221. expenseType: undefined, // 费用类型1
  222. expenseType2: undefined, // 费用类型2
  223. expenseType3: undefined, // 费用类型3
  224. expenseTypeName: undefined, // 费用类型1
  225. expenseTypeName2: undefined, // 费用类型2
  226. expenseTypeName3: undefined, // 费用类型3
  227. productBrandSn: undefined, // 产品品牌
  228. productTypeSn1: '', // 产品一级分类
  229. productTypeSn2: '', // 产品二级分类
  230. productTypeSn3: '', // 产品三级分类
  231. expenseDate: moment().locale('zh-cn').format('YYYY-MM'), // 费用产生月
  232. title: '', // 主题
  233. content: '' // 费用说明
  234. }
  235. this.rules.productBrandSn = []
  236. this.rules.productTypeSn2 = []
  237. this.productType = []
  238. this.attachList = []
  239. this.form.expenseAccountFilesList = ''
  240. this.$refs.attachList.setFileList('')
  241. this.$refs.ruleForm.resetFields()
  242. this.expenseTypes = []
  243. },
  244. // 产品分类 change
  245. changeProductType (val, id, opt) {
  246. console.log(val, opt, '------------')
  247. this.form.productTypeSn1 = val && val[0] ? val[0] : ''
  248. this.form.productTypeSn2 = val && val[1] ? val[1] : ''
  249. this.form.productTypeSn3 = val && val[2] ? val[2] : ''
  250. // 名称
  251. this.form.productTypeName1 = opt && opt[0] ? opt[0].productTypeName : ''
  252. this.form.productTypeName2 = opt && opt[1] ? opt[1].productTypeName : ''
  253. this.form.productTypeName3 = opt && opt[2] ? opt[2].productTypeName : ''
  254. },
  255. // 品牌
  256. changeBrand (val, id, opt) {
  257. this.form.productBrandName = opt ? opt.brandName : ''
  258. },
  259. // 申请人员
  260. employeeChange (v, r) {
  261. if (r.departmentSn) {
  262. this.form.applyDepartmentSn = r.departmentSn
  263. }
  264. this.$nextTick(() => {
  265. this.$refs.ruleForm.validateField(['applyPersonSn', 'applyDepartmentSn'])
  266. })
  267. },
  268. // 申请部门选择
  269. departementChange () {
  270. this.$nextTick(() => {
  271. this.$refs.ruleForm.validateField('applyDepartmentSn')
  272. })
  273. },
  274. // 费用产生月
  275. expenseDateChange (v, d) {
  276. this.form.expenseDate = d
  277. },
  278. // 费用产生月禁止范围
  279. disabledDate (current) {
  280. return current && current > moment().endOf('day')
  281. },
  282. // 费用类型选择
  283. expenseChange (val, opts) {
  284. this.expenseTypes = val || []
  285. this.form.expenseType = val && val[0] ? val[0] : ''
  286. this.form.expenseType2 = val && val[1] ? val[1] : ''
  287. this.form.expenseType3 = val && val[2] ? val[2] : ''
  288. // 名称
  289. this.form.expenseTypeName = opts && opts[0] ? opts[0].name : ''
  290. this.form.expenseTypeName2 = opts && opts[1] ? opts[1].name : ''
  291. this.form.expenseTypeName3 = opts && opts[2] ? opts[2].name : ''
  292. // 校验规则
  293. this.$refs.ruleForm.clearValidate()
  294. this.setValidBrandType()
  295. },
  296. // 判断是否促销费用类型,必填品牌和分类
  297. setValidBrandType () {
  298. if (this.form.expenseTypeName == '促销费用') {
  299. this.rules.productBrandSn = [{ required: true, message: '请选择归属品牌', trigger: 'change' }]
  300. this.rules.productTypeSn2 = [{ required: true, message: '请选择归属分类(至少选择到2级或3级分类)', trigger: 'change' }]
  301. } else {
  302. this.rules.productBrandSn = []
  303. this.rules.productTypeSn2 = []
  304. }
  305. },
  306. // 附件上传
  307. changeAttach (file) {
  308. this.attachList = JSON.parse(file)
  309. this.attachList.map(item => {
  310. item.fileType = item.extName
  311. })
  312. },
  313. // 编辑时设置数据
  314. setDetail (data, from) {
  315. this.spinning = false
  316. this.disabled = false
  317. this.fromPage = from
  318. this.form = Object.assign(this.form, data)
  319. // 获取附件列表
  320. if (this.$refs.attachList) {
  321. this.form.expenseAccountFilesList = ''
  322. this.attachList = data.expenseAccountFilesList
  323. this.$refs.attachList.setFileList(this.attachList)
  324. }
  325. if (data.productTypeSn1) {
  326. this.productType = [data.productTypeSn1, data.productTypeSn2, data.productTypeSn3]
  327. }
  328. if (!data.productBrandSn) {
  329. this.form.productBrandSn = undefined
  330. }
  331. setTimeout(() => {
  332. this.expenseTypes = data.expenseType ? [this.form.expenseType, this.form.expenseType2, this.form.expenseType3] : []
  333. }, 500)
  334. this.setValidBrandType()
  335. },
  336. // 获取详情
  337. getDetail () {
  338. this.spinning = true
  339. this.disabled = true
  340. expenseAccountDetail({ expenseAccountSn: this.expenseAccountSn }).then(res => {
  341. if (res.status == 200) {
  342. this.setDetail(res.data)
  343. } else {
  344. this.$refs.ruleForm.resetFields()
  345. }
  346. this.spinning = false
  347. this.disabled = false
  348. })
  349. },
  350. // 保存基础信息
  351. handleSubmit (e) {
  352. e.preventDefault()
  353. const _this = this
  354. this.$refs.ruleForm.validate(valid => {
  355. if (valid) {
  356. const form = JSON.parse(JSON.stringify(_this.form))
  357. form.expenseDate = form.expenseDate + '-01'
  358. form.expenseAccountFilesList = _this.attachList
  359. // 判断费用归属品类 最少要选择到2级或3级分类
  360. if (_this.form.productTypeSn1 && !_this.form.productTypeSn2) {
  361. _this.$message.warning('请选择归属分类(至少选择到2级或3级分类)')
  362. return false
  363. }
  364. _this.spinning = true
  365. // 从销售单转的费用,直接提交
  366. if (_this.fromPage == 'sales') {
  367. _this.$emit('expenseSaveOk', form, _this.fromPage)
  368. return false
  369. }
  370. // 从销售单转的费用,合并提交
  371. if (_this.fromPage == 'salesMearge') {
  372. _this.$emit('expenseSaveOk', form, _this.fromPage)
  373. return false
  374. }
  375. // 手动建的费用单
  376. expenseAccountSave(form).then(res => {
  377. if (res.status == 200) {
  378. _this.$message.success(res.message)
  379. setTimeout(() => {
  380. if (_this.expenseAccountSn) {
  381. _this.$emit('refashData')
  382. } else {
  383. // 跳转到费用明细单页面
  384. _this.$router.push({ name: 'expenseReimbursementEdit', params: { sn: res.data.expenseAccountSn } })
  385. }
  386. _this.spinning = false
  387. _this.cancel()
  388. }, 200)
  389. } else {
  390. _this.spinning = false
  391. }
  392. })
  393. } else {
  394. return false
  395. }
  396. })
  397. }
  398. },
  399. watch: {
  400. show (newValue, oldValue) {
  401. this.opened = newValue
  402. if (newValue) {
  403. this.pageInit()
  404. } else {
  405. this.retsetForm()
  406. }
  407. },
  408. itemSn (a, b) {
  409. this.expenseAccountSn = a
  410. }
  411. }
  412. }
  413. </script>