epenseDetailModal.vue 13 KB

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