epenseCdfModal.vue 11 KB

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