epenseDetailModal.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <a-modal
  3. centered
  4. class="epenseDetailModal-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. :title="title+'费用明细'"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. width="60%">
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <div>
  13. <div class="epenseDetailModal-con">
  14. <a-form-model
  15. id="epenseDetailModal-form"
  16. ref="ruleForm"
  17. :model="form"
  18. :rules="rules"
  19. :label-col="formItemLayout.labelCol"
  20. :wrapper-col="formItemLayout.wrapperCol">
  21. <a-row>
  22. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  23. <a-form-model-item label="记账类型" prop="accountType">
  24. <v-select
  25. code="EXPENSE_ACCOUNT_TYPE"
  26. id="epenseDetailModal-accountType"
  27. v-model="form.accountType"
  28. allowClear
  29. placeholder="请选择记账类型"
  30. ></v-select>
  31. </a-form-model-item>
  32. </a-col>
  33. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  34. <a-form-model-item label="记账名称" prop="accountNameSn">
  35. <!-- 部门 -->
  36. <department v-show="form.accountType=='INNER_ACCOUNT'" @change="accountNameSnChange" v-model="form.accountNameSn" placeholder="请选择记账名称(输入名称搜索)"></department>
  37. <!-- 经销商 -->
  38. <custList v-show="form.accountType=='CUSTOMER'" cooperateFlag="1" ref="custList" @change="accountNameSnChange" placeholder="请选择记账名称(输入名称搜索)"></custList>
  39. <!-- 供应商 -->
  40. <supplier v-show="form.accountType=='OUT_ACCOUNT'" enableFlag="1" @change="accountNameSnChange" v-model="form.accountNameSn" placeholder="请选择记账名称(输入名称搜索)"></supplier>
  41. <span v-if="!form.accountType">
  42. <a-select style="width: 100%" placeholder="请选择记账名称">
  43. <a-select-option value="" :disabled="true">
  44. 请先选择记账类型
  45. </a-select-option>
  46. </a-select>
  47. </span>
  48. </a-form-model-item>
  49. </a-col>
  50. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  51. <a-form-model-item label="所属区域">
  52. <subarea
  53. id="epenseDetailModal-subarea"
  54. ref="subareaBox"
  55. defValKey="name"
  56. :onlySubarea="true"
  57. :changeOnSelect="false"
  58. @change="subareaChange"
  59. v-model="subareaList"
  60. placeholder="请选择所属区域"
  61. ></subarea>
  62. </a-form-model-item>
  63. </a-col>
  64. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  65. <a-form-model-item label="所属省份" prop="provinceSn">
  66. <Area id="epenseDetailModal-area" @change="provinceChange" placeholder="请选择所属省份" v-model="form.provinceSn"></Area>
  67. </a-form-model-item>
  68. </a-col>
  69. </a-row>
  70. <a-row>
  71. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  72. <a-form-model-item label="所属城市" prop="citySn">
  73. <Area
  74. id="epenseDetailModal-area"
  75. ref="city"
  76. @change="cityChange"
  77. placeholder="请选择所属城市"
  78. leve="city"
  79. :parentId="form.provinceSn"
  80. v-model="form.citySn"></Area>
  81. </a-form-model-item>
  82. </a-col>
  83. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  84. <a-form-model-item label="记账费用">
  85. <a-input
  86. style="width: 100%;color: red;font-weight: bold;"
  87. id="epenseDetailModal-expense"
  88. :disabled="true"
  89. :value="Math.abs(form.expense) * -1"
  90. />
  91. </a-form-model-item>
  92. </a-col>
  93. </a-row>
  94. <a-row>
  95. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  96. <a-form-model-item label="备注" prop="remarks" :label-col="{span:2}" :wrapper-col="{span:20}">
  97. <a-textarea placeholder="请输入备注(最多500个字符)" v-model="form.remarks" :rows="4" :maxLength="500"/>
  98. </a-form-model-item>
  99. </a-col>
  100. </a-row>
  101. </a-form-model>
  102. <!-- 费用承担方 -->
  103. <epenseCdfModal ref="epenseCdf" :list="form.detailSplitList" @fyTotal="getFyTotal"></epenseCdfModal>
  104. </div>
  105. <div class="btn-cont">
  106. <a-button id="epenseDetailModal-back" @click="isShow = false" style="margin-right: 15px;">取消</a-button>
  107. <a-button type="primary" id="epenseDetailModal-save" @click="handleSave">确定</a-button>
  108. </div>
  109. </div>
  110. </a-spin>
  111. </a-modal>
  112. </template>
  113. <script>
  114. import { VSelect } from '@/components'
  115. import epenseCdfModal from './epenseCdfModal.vue'
  116. import subarea from '@/views/common/subarea.js'
  117. import Area from '@/views/common/area.js'
  118. import custList from '@/views/common/custList.vue'
  119. import supplier from '@/views/common/supplier.js'
  120. import department from './department.js'
  121. import { expenseAcctDetailSave, expenseAcctDetailFindBySn } from '@/api/expenseManagement.js'
  122. export default {
  123. name: 'EpenseDetailModal',
  124. components: { VSelect, subarea, Area, epenseCdfModal, custList, supplier, department },
  125. props: {
  126. openModal: { // 弹框显示状态
  127. type: Boolean,
  128. default: false
  129. },
  130. expenseAccountSn: { // 报销单sn
  131. type: String,
  132. default: ''
  133. },
  134. expenseAccountNo: { // 报销单号
  135. type: String,
  136. default: ''
  137. },
  138. expenseAccountDetailSn: {
  139. type: String,
  140. default: ''
  141. }
  142. },
  143. data () {
  144. return {
  145. spinning: false,
  146. isShow: this.openModal, // 是否打开弹框
  147. title: '',
  148. formItemLayout: {
  149. labelCol: { span: 4 },
  150. wrapperCol: { span: 16 }
  151. },
  152. subareaList: [],
  153. form: {
  154. id: undefined,
  155. accountType: undefined, // 记帐类型
  156. accountNameSn: undefined, // 记账名称
  157. subareaArea: {
  158. subareaName: undefined, // 所属区域
  159. subareaAreaName: undefined // 分区
  160. },
  161. provinceSn: undefined, // 省份
  162. provinceName: '',
  163. citySn: undefined, // 市
  164. cityName: '',
  165. remarks: '', // 备注
  166. expense: 0, // 记账费用
  167. expenseAccountSn: '', // 报销单SN
  168. expenseAccountNo: '', // 报销单号
  169. expenseAccountDetailSn: '', // 报销明细sn
  170. detailSplitList: []
  171. },
  172. rules: {
  173. accountType: [
  174. { required: true, message: '请选择记帐类型', trigger: 'change' }
  175. ],
  176. accountNameSn: [
  177. { required: true, message: '请选择记账名称', trigger: 'change' }
  178. ]
  179. }
  180. }
  181. },
  182. methods: {
  183. // 费用合计
  184. getFyTotal (expense) {
  185. this.form.expense = expense
  186. },
  187. // 记账名称变化时
  188. accountNameSnChange (v, row) {
  189. console.log(v, row)
  190. if (this.form.accountType == 'CUSTOMER') {
  191. if (row) {
  192. this.form.accountNameSn = v.key
  193. this.form.provinceSn = row.provinceSn
  194. this.form.citySn = row.citySn
  195. this.form.provinceName = row.provinceName
  196. this.form.cityName = row.cityName
  197. this.form.subareaArea.subareaName = row.subareaArea.subareaName
  198. this.form.subareaArea.subareaAreaName = row.subareaArea.subareaAreaName
  199. this.subareaList = [row.subareaArea.subareaName, row.subareaArea.subareaAreaName]
  200. } else {
  201. this.form.accountNameSn = ''
  202. this.form.provinceSn = ''
  203. this.form.citySn = ''
  204. this.form.provinceName = ''
  205. this.form.cityName = ''
  206. this.form.subareaArea.subareaName = ''
  207. this.form.subareaArea.subareaAreaName = ''
  208. this.$refs.subareaBox.clearData()
  209. this.subareaList = []
  210. }
  211. }
  212. this.$nextTick(() => {
  213. this.$refs.ruleForm.validateField('accountNameSn')
  214. })
  215. },
  216. // 分区
  217. subareaChange (val, row) {
  218. this.form.subareaArea.subareaName = val[0] ? val[0] : ''
  219. this.form.subareaArea.subareaAreaName = val[1] ? val[1] : ''
  220. },
  221. // 省
  222. provinceChange (v, row) {
  223. console.log(v, row)
  224. this.form.provinceName = row ? row.name : ''
  225. this.form.provinceSn = v || ''
  226. this.form.citySn = undefined
  227. this.form.cityName = ''
  228. this.$refs.city.clearData()
  229. },
  230. // 市
  231. cityChange (v, row) {
  232. this.form.cityName = row ? row.name : ''
  233. this.form.citySn = v || ''
  234. },
  235. // 详情
  236. getExpenseAccountDetail () {
  237. this.spinning = true
  238. expenseAcctDetailFindBySn({ detailSn: this.expenseAccountDetailSn }).then(res => {
  239. this.$nextTick(() => {
  240. this.form = Object.assign(this.form, res.data || {})
  241. this.form.provinceSn = this.form.provinceSn ? this.form.provinceSn : undefined
  242. this.form.citySn = this.form.citySn ? this.form.citySn : undefined
  243. setTimeout(() => {
  244. this.form.accountNameSn = res.data.accountNameSn
  245. if (res.data.accountType == 'CUSTOMER') {
  246. this.$refs.custList.setDufaultVal(res.data.accountName)
  247. }
  248. this.form.subareaArea.subareaName = res.data.subareaNames || ''
  249. this.form.subareaArea.subareaAreaName = res.data.subareaAreaName || ''
  250. this.subareaList = res.data.subareaNames ? [res.data.subareaNames, res.data.subareaAreaName] : undefined
  251. }, 200)
  252. this.spinning = false
  253. })
  254. })
  255. },
  256. // 确定
  257. handleSave (e) {
  258. e.preventDefault()
  259. const _this = this
  260. this.$refs.ruleForm.validate(valid => {
  261. if (valid) {
  262. const form = JSON.parse(JSON.stringify(_this.form))
  263. const cdfList = this.$refs.epenseCdf.getList()
  264. if (cdfList[0] == 1) {
  265. this.$warning({
  266. title: '是否存在以下情况,请按照要求填写',
  267. content: <div><p>1、费用承担方至少有一个</p><p>2、带星号的列为必填项,不能为空</p></div>,
  268. centered: true
  269. })
  270. return
  271. }
  272. if (cdfList[0] == 3) {
  273. this.$warning({
  274. title: '提示',
  275. content: '请检查每行承担人员是否已经选择',
  276. centered: true
  277. })
  278. return
  279. }
  280. if (cdfList[0] == 2) {
  281. this.$warning({
  282. title: '提示',
  283. content: '请检查每行人员平摊费用合计是否等于承担金额',
  284. centered: true
  285. })
  286. return
  287. }
  288. // 获取承担人列表数据
  289. form.detailSplitList = cdfList[1]
  290. form.provinceName = form.provinceName ? form.provinceName : ''
  291. form.provinceSn = form.provinceSn ? form.provinceSn : ''
  292. form.citySn = form.citySn ? form.citySn : ''
  293. form.cityName = form.cityName ? form.cityName : ''
  294. form.expense = Math.abs(form.expense)
  295. console.log(form)
  296. _this.spinning = true
  297. expenseAcctDetailSave(form).then(res => {
  298. if (res.status == 200) {
  299. _this.$message.success(res.message)
  300. setTimeout(() => {
  301. _this.$emit('ok')
  302. _this.spinning = false
  303. }, 200)
  304. } else {
  305. _this.spinning = false
  306. }
  307. })
  308. } else {
  309. return false
  310. }
  311. })
  312. },
  313. resetForm () {
  314. this.$nextTick(() => {
  315. this.$refs.ruleForm.resetFields()
  316. this.$refs.city.clearData()
  317. this.$refs.subareaBox.clearData()
  318. })
  319. this.form = {
  320. id: undefined,
  321. accountType: undefined, // 记帐类型
  322. accountNameSn: undefined, // 记账名称
  323. subareaArea: {
  324. subareaName: undefined, // 所属区域
  325. subareaAreaName: undefined // 分区
  326. },
  327. provinceSn: undefined, // 省份
  328. provinceName: '',
  329. citySn: undefined, // 市
  330. cityName: '',
  331. remarks: '', // 备注
  332. expense: 0, // 记账费用
  333. expenseAccountSn: '', // 报销单SN
  334. expenseAccountNo: '', // 报销单号
  335. expenseAccountDetailSn: '', // 报销明细sn
  336. detailSplitList: []
  337. }
  338. this.form.provinceSn = undefined
  339. this.form.provinceName = ''
  340. this.form.citySn = undefined
  341. this.form.cityName = ''
  342. this.form.expenseAccountSn = this.expenseAccountSn
  343. this.form.expenseAccountNo = this.expenseAccountNo
  344. this.subareaList = []
  345. }
  346. },
  347. watch: {
  348. 'form.accountType' (newValue, oldValue) {
  349. this.form.accountNameSn = undefined
  350. this.$refs.custList.dealerName = []
  351. },
  352. // 父页面传过来的弹框状态
  353. openModal (newValue, oldValue) {
  354. this.isShow = newValue
  355. },
  356. // 重定义的弹框状态
  357. isShow (newValue, oldValue) {
  358. if (!newValue) {
  359. this.$emit('close')
  360. this.resetForm()
  361. } else {
  362. this.form.expenseAccountSn = this.expenseAccountSn
  363. this.form.expenseAccountNo = this.expenseAccountNo
  364. if (this.expenseAccountDetailSn) {
  365. this.title = '编辑'
  366. this.form.expenseAccountDetailSn = this.expenseAccountDetailSn || ''
  367. this.getExpenseAccountDetail()
  368. } else {
  369. this.resetForm()
  370. this.title = '新增'
  371. }
  372. }
  373. }
  374. }
  375. }
  376. </script>
  377. <style lang="less">
  378. .epenseDetailModal-modal{
  379. .ant-modal-body {
  380. padding: 30px 40px 24px;
  381. }
  382. .btn-cont {
  383. text-align: center;
  384. margin: 35px 0 10px;
  385. }
  386. }
  387. </style>