epenseCdfModal.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <div>
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <div>
  5. <div class="epenseCdfModal-con">
  6. <!-- 列表 -->
  7. <a-table
  8. class="sTable fixPagination"
  9. ref="table"
  10. :scroll="{ y: 300 }"
  11. size="small"
  12. :rowKey="(record,index) => 'cdfTable-'+index"
  13. :columns="columns"
  14. :data-source="dataList"
  15. :pagination="false"
  16. bordered>
  17. <div slot="customTitle1"><span style="color: red;">*</span>费用承担方类型</div>
  18. <div slot="customTitle2"><span style="color: red;">*</span>费用承担方</div>
  19. <div slot="customTitle3"><span style="color: red;">*</span>费用承担金额</div>
  20. <!-- 费用承担方类型 -->
  21. <template slot="fycdftype" slot-scope="text,record,index">
  22. <v-select
  23. :id="'cdfTable-splitObjType-'+index"
  24. code="EXPENSE_ACCOUNT_DETAIL_SPLIT_OBJ_TYPE"
  25. allowClear
  26. style="width: 100%;"
  27. :isEnable="true"
  28. v-model="record.splitObjType"
  29. @change="splitObjTypeChange(index)"
  30. placeholder="请选择承担方类型"
  31. ></v-select>
  32. </template>
  33. <!-- 费用承担方 -->
  34. <template slot="fycdf" slot-scope="text,record,index">
  35. <!-- 部门 -->
  36. <department :id="'cdfTable-department-'+index" v-show="record.splitObjType=='DEPARTMENT'" style="width: 100%;" placeholder="请选择承担方" v-model="record.splitObjSn"></department>
  37. <!-- 经销商 -->
  38. <custList
  39. v-show="record.splitObjType=='CUSTOMER'"
  40. cooperateFlag="1"
  41. @change="custChange"
  42. :id="'cust-'+index"
  43. :ref="'custList-'+record.no"
  44. placeholder="请选择(输入名称搜索)"></custList>
  45. <!-- 供应商 -->
  46. <supplier
  47. v-show="record.splitObjType=='SUPPLIER'"
  48. style="width: 100%;"
  49. enableFlag="1"
  50. :id="'cdfTable-supplier-'+index"
  51. v-model="record.splitObjSn"
  52. placeholder="请选择(输入名称搜索)"></supplier>
  53. <!-- 其它往来 -->
  54. <otherTransactions
  55. style="width: 100%;"
  56. :id="'cdfTable-otherTransactions-'+index"
  57. v-show="record.splitObjType=='OTHER_ORG'"
  58. v-model="record.splitObjSn"
  59. placeholder="请选择(输入名称搜索)"></otherTransactions>
  60. <span v-if="!record.splitObjType">--</span>
  61. </template>
  62. <!-- 费用承担金额 -->
  63. <template slot="amount" slot-scope="text,record,index">
  64. <a-input-number
  65. :id="'cdfTable-splitAmount-'+index"
  66. v-show="record.splitObjType"
  67. style="width: 100%;"
  68. v-model="record.splitAmount"
  69. @change="splitAmountChange"
  70. :precision="2"
  71. :min="0"
  72. :max="99999999"
  73. placeholder="请输入"
  74. />
  75. <span v-if="!record.splitObjType">--</span>
  76. </template>
  77. <!-- 承担人员 -->
  78. <template slot="cdry" slot-scope="text,record,index">
  79. <div
  80. style="display: flex;align-items: center;width: 100%;padding: 5px 0;border-bottom: 1px solid #eee;"
  81. v-for="(item,idx) in record.childDetailSplitList"
  82. :id="item.id"
  83. :key="item.id">
  84. <employee style="width: 40%;" placeholder="请选择承担人员" v-model="item.splitObjSn"></employee>
  85. -
  86. <a-input-number
  87. :id="'cdfTable-childsplitAmount-'+index"
  88. style="width: 40%;"
  89. v-model="item.splitAmount"
  90. :precision="2"
  91. :min="0"
  92. :max="99999999"
  93. placeholder="请输入费用"
  94. />
  95. <div style="padding-left: 15px;" v-if="record.childDetailSplitList&&record.childDetailSplitList.length>1">
  96. <a-button
  97. @click="handleDelCdry(record,idx)"
  98. :id="'cdfTable-childsplitAmoun-del-'+index"
  99. title="删除"
  100. size="small"
  101. type="danger"
  102. shape="circle"
  103. icon="delete" />
  104. </div>
  105. <div v-if="record.childDetailSplitList&&idx == record.childDetailSplitList.length - 1">
  106. <a-button
  107. @click="handleAddCdry(record,idx)"
  108. :id="'cdfTable-childsplitAmoun-add-'+index"
  109. title="添加承担人员"
  110. size="small"
  111. type="primary"
  112. class="button-info"
  113. shape="circle"
  114. icon="plus" />
  115. </div>
  116. </div>
  117. <span v-if="record.childDetailSplitList&&record.childDetailSplitList.length==0">--</span>
  118. </template>
  119. <template slot="action" slot-scope="text,record,index">
  120. <a-button
  121. :id="'cdfTable-del-'+index"
  122. size="small"
  123. type="link"
  124. class="button-error"
  125. @click="handleDelRow(record,index)"
  126. >删除</a-button>
  127. </template>
  128. <template slot="footer" slot-scope="currentPageData">
  129. <a-button
  130. :id="'cdfTable-add-'+index"
  131. type="link"
  132. class="button-info"
  133. block
  134. @click="handleAddRow()"
  135. >+ 新增费用承担方</a-button>
  136. </template>
  137. </a-table>
  138. </div>
  139. </div>
  140. </a-spin>
  141. </div>
  142. </template>
  143. <script>
  144. import { VSelect } from '@/components'
  145. import department from './department.js'
  146. import employee from './employee.js'
  147. import custList from '@/views/common/custList.vue'
  148. import supplier from '@/views/common/supplier.js'
  149. import otherTransactions from '@/views/common/otherTransactions.js'
  150. export default {
  151. components: { VSelect, department, employee, custList, supplier, otherTransactions },
  152. name: 'EpenseCdfModal',
  153. props: {
  154. list: { // 弹框显示状态
  155. type: Array,
  156. default: () => { return [] }
  157. }
  158. },
  159. watch: {
  160. // 费用明细列表
  161. list (newValue, oldValue) {
  162. this.dataList = JSON.parse(JSON.stringify(newValue))
  163. this.dataList.map(item => {
  164. item.no = item.id
  165. // 部门
  166. if (item.splitObjType == 'DEPARTMENT' && (!item.childDetailSplitList || item.childDetailSplitList.length == 0)) {
  167. this.$set(item, 'childDetailSplitList', [{
  168. splitObjType: 'EMPLOYEE',
  169. splitObjSn: undefined,
  170. splitAmount: 0
  171. }])
  172. }
  173. // 客户
  174. if (item.splitObjType == 'CUSTOMER') {
  175. this.$nextTick(() => {
  176. this.$refs['custList-' + item.no].setDufaultVal(item.splitObjName)
  177. })
  178. }
  179. })
  180. // 默认添加一条
  181. if (this.dataList.length == 0) {
  182. this.handleAddRow()
  183. }
  184. }
  185. },
  186. data () {
  187. return {
  188. spinning: false,
  189. dataList: [],
  190. columns: [
  191. { slots: { title: 'customTitle1' }, scopedSlots: { customRender: 'fycdftype' }, align: 'center', width: '15%' },
  192. { slots: { title: 'customTitle2' }, scopedSlots: { customRender: 'fycdf' }, align: 'center', width: '20%' },
  193. { slots: { title: 'customTitle3' }, scopedSlots: { customRender: 'amount' }, align: 'center', width: '15%' },
  194. { title: '承担人员-人员平摊费用', scopedSlots: { customRender: 'cdry' }, align: 'center', width: '40%' },
  195. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  196. ]
  197. }
  198. },
  199. mounted () {
  200. this.handleAddRow()
  201. },
  202. methods: {
  203. // 费用承担方类型
  204. splitObjTypeChange (index) {
  205. const row = this.dataList[index]
  206. console.log(index, row.splitObjType)
  207. row.splitObjSn = undefined
  208. // 只有部门有承担人员
  209. this.$set(row, 'childDetailSplitList', row.splitObjType == 'DEPARTMENT' ? [{
  210. splitObjType: 'EMPLOYEE',
  211. splitObjSn: undefined,
  212. splitAmount: Number(row.splitAmount).toFixed(2)
  213. }] : [])
  214. // 客户
  215. if (row.splitObjType == 'CUSTOMER') {
  216. this.$set(row, 'splitObjSn', undefined)
  217. this.$set(row, 'splitObjName', undefined)
  218. this.$refs['custList-' + row.no].dealerName = []
  219. }
  220. // 供应商
  221. if (row.splitObjType == 'SUPPLIER') {
  222. this.$set(row, 'splitObjSn', undefined)
  223. }
  224. // 费用合计
  225. this.$emit('fyTotal', this.fyTotal())
  226. },
  227. // 选择经销商
  228. custChange (v, obj, id) {
  229. const row = this.dataList[id.split('-')[1]]
  230. this.$set(row, 'splitObjSn', v.key)
  231. this.$set(row, 'splitObjName', obj.dealerName)
  232. this.$emit('fyTotal', this.fyTotal())
  233. },
  234. // 选择承担费用
  235. splitAmountChange () {
  236. this.$emit('fyTotal', this.fyTotal())
  237. },
  238. // 清空数据
  239. clearList () {
  240. this.dataList = []
  241. },
  242. // 获取数据
  243. getList () {
  244. let hasError = 0
  245. const list = this.dataList.filter(item => item.splitObjType && item.splitObjSn && item.splitAmount)
  246. const ret = JSON.parse(JSON.stringify(list))
  247. if (ret.length != this.dataList.length) {
  248. hasError = 1
  249. } else {
  250. ret.map(item => {
  251. // 如果时部门
  252. if (item.splitObjType == 'DEPARTMENT') {
  253. const al = item.childDetailSplitList.filter(a => !a.splitObjSn && a.splitAmount > 0)
  254. if (al.length) {
  255. hasError = 3
  256. } else {
  257. const dl = item.childDetailSplitList.filter(a => a.splitObjSn) || []
  258. // 有承担人员
  259. if (dl && dl.length) {
  260. let t = 0
  261. dl.map(b => t = Number(t) + Number(b.splitAmount))
  262. // console.log(Number(t), Number(item.splitAmount))
  263. hasError = (Number(t) != Number(item.splitAmount)) ? 2 : 0
  264. }
  265. item.childDetailSplitList = dl
  266. }
  267. }
  268. })
  269. }
  270. if (ret.length == 0) {
  271. hasError = 1
  272. }
  273. return [hasError, ret]
  274. },
  275. // 添加人员
  276. handleAddCdry (row, idx) {
  277. const cur = row.childDetailSplitList[idx]
  278. if (!cur.splitObjSn) {
  279. this.$message.info('请选择承担人员')
  280. return
  281. }
  282. if (cur.splitAmount <= 0) {
  283. this.$message.info('请输入平摊费用')
  284. return
  285. }
  286. // 校验承担费用合计是否超过费用承担金额
  287. let totalFy = 0
  288. row.childDetailSplitList.map(item => {
  289. totalFy = totalFy + Number(item.splitAmount)
  290. })
  291. // console.log(totalFy, row.splitAmount)
  292. if (totalFy >= Number(row.splitAmount).toFixed(2)) {
  293. this.$warning({
  294. title: '提示',
  295. content: '人员平摊费用合计必需等于费用承担金额'
  296. })
  297. return
  298. }
  299. // 已使用费用
  300. let ysyAmount = 0
  301. row.childDetailSplitList.map(item => {
  302. ysyAmount = ysyAmount + Number(item.splitAmount)
  303. })
  304. // 添加
  305. row.childDetailSplitList.push({
  306. splitObjType: 'EMPLOYEE',
  307. splitObjSn: undefined,
  308. splitAmount: Number(row.splitAmount - ysyAmount).toFixed(2)
  309. })
  310. },
  311. // 删除人员
  312. handleDelCdry (row, index) {
  313. row.childDetailSplitList.splice(index, 1)
  314. },
  315. // 添加承担费用
  316. handleAddRow () {
  317. this.dataList.push({
  318. no: new Date().getTime(),
  319. splitObjType: '',
  320. splitObjSn: undefined,
  321. splitAmount: 0,
  322. childDetailSplitList: []
  323. })
  324. },
  325. // 删除承担费用
  326. handleDelRow (a, index) {
  327. this.dataList.splice(index, 1)
  328. this.$emit('fyTotal', this.fyTotal())
  329. this.dataList.map(item => {
  330. if (item.splitObjType == 'CUSTOMER') {
  331. this.$nextTick(() => {
  332. this.$refs['custList-' + item.no].setDufaultVal(item.splitObjName)
  333. })
  334. }
  335. })
  336. },
  337. // 费用合计计算
  338. fyTotal: function () {
  339. let total = 0
  340. this.dataList.map(item => { total = total + item.splitAmount })
  341. return total.toFixed(2)
  342. }
  343. }
  344. }
  345. </script>
  346. <style lang="less">
  347. .epenseCdfModal-modal{
  348. .ant-modal-body {
  349. padding: 30px 40px 24px;
  350. }
  351. .epenseCdfModal-con{
  352. text-align: center;
  353. h3{
  354. font-size: 16px;
  355. font-weight: bold;
  356. margin-bottom: 25px;
  357. }
  358. }
  359. .btn-cont {
  360. text-align: center;
  361. margin: 35px 0 10px;
  362. }
  363. }
  364. </style>