epenseCdfModal.vue 12 KB

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