infoTable.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <template>
  2. <div>
  3. <el-form ref="form" :model="dialogForm">
  4. <div>
  5. <el-divider direction="vertical"></el-divider>
  6. <span>应收金额:</span>
  7. <span>{{ form.receivableTotalPrice }}</span>
  8. <el-divider direction="vertical"></el-divider>
  9. <span>已收金额:</span>
  10. <span>{{ receivedTotalPrice }}</span>
  11. <el-divider direction="vertical"></el-divider>
  12. <span>未收金额:</span>
  13. <span>{{ unreceiveTotalPrice < 0 ? 0 : unreceiveTotalPrice }}</span>
  14. </div>
  15. <!-- 数据表格 -->
  16. <ele-pro-table
  17. ref="table"
  18. :columns="columns"
  19. :datasource="dialogForm.detailList"
  20. :needPage="false"
  21. :minHeight="100"
  22. tool-class="ele-toolbar-form"
  23. cache-key="collectionDialogTable"
  24. >
  25. <!-- 表头工具栏 -->
  26. <template v-slot:toolbar>
  27. <el-button
  28. v-if="dialogType !== 'view'"
  29. :disabled="unreceiveTotalPrice <= 0"
  30. size="small"
  31. type="primary"
  32. icon="el-icon-plus"
  33. class="ele-btn-icon"
  34. @click="handleAddInfo"
  35. >
  36. 新增收款信息
  37. </el-button>
  38. </template>
  39. <template v-slot:action="{ row, $index }">
  40. <el-link
  41. v-if="
  42. dialogType == 'view' && !row.invoiceStatus && !form.invoiceCode
  43. "
  44. type="primary"
  45. :underline="false"
  46. @click="addInvoice(row)"
  47. >
  48. 新增发票
  49. </el-link>
  50. <el-popconfirm
  51. class="ele-action"
  52. title="确定要删除此信息吗?"
  53. @confirm="handleDelInfo($index)"
  54. v-if="dialogType !== 'view' && !row.invoiceCode"
  55. >
  56. <template v-slot:reference>
  57. <el-link type="danger" :underline="false" icon="el-icon-delete">
  58. 删除
  59. </el-link>
  60. </template>
  61. </el-popconfirm>
  62. </template>
  63. <template
  64. v-slot:receivedDate="{ row, $index }"
  65. v-if="dialogType !== 'view'"
  66. >
  67. <el-form-item
  68. :prop="'detailList.' + $index + '.receivedDate'"
  69. :rules="{
  70. required: true,
  71. message: '请选择',
  72. trigger: ['blur', 'change']
  73. }"
  74. >
  75. <el-date-picker
  76. style="width: 95%"
  77. v-model="row.receivedDate"
  78. type="date"
  79. value-format="yyyy-MM-dd"
  80. placeholder="选择日期"
  81. :disabled="!!row.invoiceCode"
  82. >
  83. </el-date-picker>
  84. </el-form-item>
  85. </template>
  86. <template
  87. v-slot:receivedTotalPrice="{ row, $index }"
  88. v-if="dialogType !== 'view'"
  89. >
  90. <el-form-item
  91. :prop="'detailList.' + $index + '.receivedTotalPrice'"
  92. :rules="{
  93. required: true,
  94. message: '请输入',
  95. trigger: ['blur', 'change']
  96. }"
  97. >
  98. <el-input-number
  99. @change="(val, oldVal) => handlePrice(val, oldVal, row, $index)"
  100. v-model="row.receivedTotalPrice"
  101. :disabled="!!row.invoiceCode"
  102. :controls="false"
  103. :precision="2"
  104. :min="0.0"
  105. ></el-input-number>
  106. </el-form-item>
  107. </template>
  108. <template v-slot:files="{ row, $index }">
  109. <el-form-item :prop="'detailList.' + $index + '.files'">
  110. <fileMain
  111. v-model="row.files"
  112. :type="dialogType == 'view' || row.invoiceCode ? 'view' : 'add'"
  113. ></fileMain>
  114. </el-form-item>
  115. </template>
  116. <template v-slot:remark="{ row, $index }" v-if="dialogType !== 'view'">
  117. <el-form-item>
  118. <el-input
  119. v-model="row.remark"
  120. type="textarea"
  121. :disabled="!!row.invoiceCode"
  122. ></el-input>
  123. </el-form-item>
  124. </template>
  125. <template v-slot:columnRequired="{ column }">
  126. <span class="is-required">{{ column.label }}</span>
  127. </template>
  128. <!-- 开票信息 -->
  129. <template v-slot:invoiceCode="{ row }">
  130. <el-link
  131. type="primary"
  132. :underline="false"
  133. @click="handleInvoiceDetail(row, 'view')"
  134. >
  135. {{ row.invoiceCode }}
  136. </el-link>
  137. </template>
  138. </ele-pro-table>
  139. </el-form>
  140. <add-or-edit-dialog
  141. :add-or-edit-dialog-flag.sync="addOrEditDialogFlag"
  142. ref="addOrEditDialogRef"
  143. v-if="addOrEditDialogFlag"
  144. @reload="reload"
  145. ></add-or-edit-dialog>
  146. <!--开票详情-->
  147. <invoice-detail-dialog
  148. ref="invoiceDetailDialogRef"
  149. v-if="invoiceDetailDialogFlag"
  150. :detailDialogFlag.sync="invoiceDetailDialogFlag"
  151. ></invoice-detail-dialog>
  152. </div>
  153. </template>
  154. <script>
  155. import { deepClone } from '@/utils';
  156. import fileMain from '@/components/addDoc/index.vue';
  157. import addOrEditDialog from '@/views/financialManage/invoiceManage/components/addOrEditDialog.vue';
  158. import invoiceDetailDialog from '@/views/financialManage/invoiceManage/components/detailDialog.vue';
  159. export default {
  160. name: 'relatedInfoTable',
  161. components: { fileMain, addOrEditDialog,invoiceDetailDialog },
  162. props: {
  163. form: {
  164. type: Object,
  165. default: () => {}
  166. },
  167. dialogType: {
  168. type: String,
  169. default: ''
  170. }
  171. },
  172. data() {
  173. return {
  174. editIndex: undefined, //当前修改数据的下标
  175. dialogForm: {
  176. detailList: []
  177. },
  178. receivedTotalPrice: 0,
  179. unreceiveTotalPrice: 0,
  180. oldVal: 0,
  181. MAXPrice: 0,
  182. addOrEditDialogFlag: false,
  183. invoiceDetailDialogFlag: false
  184. };
  185. },
  186. computed: {
  187. columns() {
  188. let list = [
  189. {
  190. columnKey: 'index',
  191. label: '序号',
  192. type: 'index',
  193. width: 55,
  194. align: 'center',
  195. showOverflowTooltip: true,
  196. fixed: 'left'
  197. },
  198. {
  199. minWidth: 120,
  200. prop: 'code',
  201. label: '编码',
  202. align: 'center',
  203. show: this.dialogType == 'view',
  204. showOverflowTooltip: true
  205. },
  206. {
  207. prop: 'receivedDate',
  208. label: '收款时间',
  209. align: 'center',
  210. showOverflowTooltip: true,
  211. minWidth: 120,
  212. slot: 'receivedDate',
  213. headerSlot: 'columnRequired'
  214. },
  215. {
  216. prop: 'receivedTotalPrice',
  217. label: '已收金额',
  218. align: 'center',
  219. showOverflowTooltip: true,
  220. minWidth: 130,
  221. slot: 'receivedTotalPrice',
  222. headerSlot: 'columnRequired'
  223. },
  224. {
  225. minWidth: 120,
  226. prop: 'invoiceCode',
  227. label: '发票编码',
  228. slot: 'invoiceCode',
  229. align: 'center',
  230. showOverflowTooltip: true,
  231. show: !this.form.invoiceCode
  232. },
  233. {
  234. prop: 'files',
  235. label: '附件',
  236. align: 'center',
  237. slot: 'files',
  238. showOverflowTooltip: true,
  239. minWidth: 150
  240. },
  241. {
  242. prop: 'remark',
  243. label: '备注',
  244. align: 'center',
  245. showOverflowTooltip: true,
  246. minWidth: 130,
  247. slot: 'remark'
  248. },
  249. {
  250. columnKey: 'action',
  251. slot: 'action',
  252. label: '操作',
  253. resizable: false,
  254. width: 160,
  255. align: 'center',
  256. showOverflowTooltip: true,
  257. fixed: 'right'
  258. }
  259. ];
  260. // let action = [
  261. // {
  262. // columnKey: 'action',
  263. // slot: 'action',
  264. // label: '操作',
  265. // resizable: false,
  266. // width: 80,
  267. // align: 'center',
  268. // showOverflowTooltip: true,
  269. // fixed: 'right'
  270. // }
  271. // ];
  272. // this.dialogType === 'view'
  273. // ? (list = [...list])
  274. // : (list = [...list, ...action]);
  275. return list;
  276. },
  277. getMAXPrice() {
  278. return this.MAXPrice;
  279. }
  280. },
  281. mounted() {
  282. this.init();
  283. },
  284. methods: {
  285. init() {
  286. this.dialogForm = deepClone(this.form);
  287. this.unreceiveTotalPrice = Number(this.dialogForm.unreceiveTotalPrice);
  288. this.dialogForm.detailList.forEach((item) => {
  289. this.MAXPrice =
  290. this.unreceiveTotalPrice + (Number(item.receivedTotalPrice) || 0);
  291. });
  292. this.receivedTotalPrice = Number(this.dialogForm.receivedTotalPrice);
  293. },
  294. handleInvoiceDetail(row = {}, type) {
  295. this.invoiceDetailDialogFlag = true;
  296. this.$nextTick(() => {
  297. let params = {
  298. id: row.invoiceId
  299. };
  300. this.$refs.invoiceDetailDialogRef.init(params, type);
  301. });
  302. },
  303. //新增关联信息数据
  304. handleAddInfo() {
  305. this.dialogForm.detailList.push({
  306. id: '',
  307. receivableCode: this.dialogForm.code,
  308. receivableId: this.dialogForm.id,
  309. receivedDate: '',
  310. receivedTotalPrice: undefined,
  311. remark: ''
  312. //unreceiveTotalPrice: this.dialogForm.unreceiveTotalPrice
  313. });
  314. },
  315. reload() {
  316. this.$emit('invoiceChange', this.dialogForm.id);
  317. },
  318. addInvoice(row) {
  319. this.addOrEditDialogFlag = true;
  320. this.$nextTick(() => {
  321. this.$refs.addOrEditDialogRef.createInvoice1(
  322. { row, form: this.dialogForm },
  323. 1,
  324. 5
  325. );
  326. });
  327. },
  328. handlePrice(val, oldVal, row, index) {
  329. // this.$set(this.dialogForm.detailList[index], 'unreceiveTotalPrice', this.MAXPrice)
  330. // this.dialogForm.unreceiveTotalPrice = this.form.receivableTotalPrice - this.dialogForm.detailList.reduce((num, row) => {
  331. // num += (Number(row.receivedTotalPrice) || 0)
  332. // return num
  333. // }, 0)
  334. this.MAXPrice = this.unreceiveTotalPrice + (Number(oldVal) || 0);
  335. this.setPrice();
  336. },
  337. setPrice() {
  338. this.$nextTick(() => {
  339. this.receivedTotalPrice = this.dialogForm.detailList.reduce(
  340. (num, row) => {
  341. num += Number(row.receivedTotalPrice) || 0;
  342. return num;
  343. },
  344. 0
  345. );
  346. this.unreceiveTotalPrice =
  347. this.form.receivableTotalPrice - this.receivedTotalPrice;
  348. });
  349. },
  350. handleDelInfo(index) {
  351. let price = this.dialogForm.detailList[index].receivedTotalPrice;
  352. this.dialogForm.detailList.splice(index, 1);
  353. this.dialogForm.detailList.forEach((item) => {
  354. this.MAXPrice =
  355. this.unreceiveTotalPrice +
  356. (Number(price) || 0) +
  357. item.receivedTotalPrice;
  358. });
  359. this.setPrice();
  360. },
  361. //
  362. getTableValidate() {
  363. return new Promise((resolve, reject) => {
  364. if (this.dialogForm.detailList.length == 0)
  365. return this.$message.warning('请至少新增一条收款信息');
  366. this.$refs.form.validate((valid) => {
  367. if (!valid) return this.$message.warning('请填写完整信息');
  368. console.log(this.dialogForm.detailList);
  369. resolve(this.dialogForm.detailList);
  370. });
  371. });
  372. }
  373. }
  374. };
  375. </script>
  376. <style scoped lang="scss">
  377. :deep(.el-form-item) {
  378. margin-bottom: 0;
  379. }
  380. ::v-deep.el-divider {
  381. margin: 10px;
  382. font-weight: bold;
  383. }
  384. </style>