KtCommonTable.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. <template>
  2. <div style="position: relative" ref="commonTable">
  3. <!--表格栏-->
  4. <el-table id="commonTable" ref="doLayout" :data="data.content" :highlight-current-row="highlightCurrentRow"
  5. @selection-change="selectionChange" @row-click="rowClick" @current-change="handleCurrentChange"
  6. :element-loading-text="$t('action.loading')" :border="border" :stripe="stripe" :show-summary="showSummary"
  7. :summary-method="getSummaries" :show-overflow-tooltip="showOverflowTooltip"
  8. :height="tableHeights ? tableHeights : tableHeight" :size="size" :align="align" :header-cell-style="{
  9. background: '#F2F7FC',
  10. fontWeight: '900',
  11. color: '#606266',
  12. }" style="width: 100%" :row-class-name="tableRowClassName">
  13. <el-table-column type="expand" v-if="showSysUserAccountCardList" style="display: flex;">
  14. <template slot-scope="scope">
  15. <el-table :data="scope.row.sysUserAccountCardList" size="small" :header-cell-style="{
  16. background: '#ccc',
  17. fontWeight: '900',
  18. color: '#606266',
  19. }" style="width: 55%">
  20. <el-table-column type="index" width="50" align="center" label="序号">
  21. </el-table-column>
  22. <el-table-column prop="bankAccount" label="银行" style="flex: 1">
  23. </el-table-column>
  24. <el-table-column prop="bankAddress" label="开户行" style="flex: 1">
  25. </el-table-column>
  26. <el-table-column prop="bankNumber" label="银行卡号" style="flex: 1">
  27. </el-table-column>
  28. </el-table>
  29. </template>
  30. </el-table-column>
  31. <el-table-column type="selection" width="50" fixed align="center" v-if="showBatchDelete ||
  32. showBatchSettled ||
  33. showBatchPrint ||
  34. customToolseletted
  35. "></el-table-column>
  36. <el-table-column v-if="SerialShow" label="序号" type="index" width="50" align="center"></el-table-column>
  37. <template v-for="column in columns">
  38. <el-table-column header-align="center" align="center" :prop="column.prop" :label="column.label"
  39. :width="column.width" :min-width="column.minWidth" :fixed="column.fixed" :key="column.prop" :type="column.type"
  40. :formatter="column.formatter" :sortable="column.sortable ? column.sortable : false"
  41. v-if="column.signIcon || column.isImg || column.isBtn">
  42. <template slot-scope="scope">
  43. <el-switch :disabled="column.isDisabled" v-if="column.signIcon" v-model="scope.row[column.prop]"
  44. active-value="1" inactive-value="0" @change="signStateChanged(scope.$index, scope.row)"></el-switch>
  45. <img v-if="column.isImg" :width="column.imgWidth" :height="column.imgHeight" :src="scope.row[column.prop]" />
  46. <kt-button v-if="column.isBtn" icon="fa fa-edit" :label="column.btnName" :size="size"
  47. :perms="column.permsEdit" @click="handleBtnEdit(scope.$index, scope.row)" />
  48. </template>
  49. </el-table-column>
  50. <el-table-column header-align="center" align="center" :prop="column.prop" :label="column.label"
  51. :width="column.width" :min-width="column.minWidth" :fixed="column.fixed" :key="column.prop" :type="column.type"
  52. :formatter="column.formatter" :sortable="column.sortable ? column.sortable : false" v-else>
  53. <template v-for="columnchildren in column.children">
  54. <el-table-column v-if="columnchildren" header-align="center" align="center" :prop="columnchildren.prop"
  55. :label="columnchildren.label" :width="columnchildren.width" :min-width="columnchildren.minWidth"
  56. :fixed="columnchildren.fixed" :key="columnchildren.prop" :type="columnchildren.type"
  57. :formatter="columnchildren.formatter" :sortable="columnchildren.sortable == null ? true : columnchildren.sortable
  58. ">
  59. </el-table-column>
  60. </template>
  61. </el-table-column>
  62. </template>
  63. <el-table-column :label="$t('action.operation')" :width="operationWidth" fixed="right" v-if="showOperation"
  64. header-align="center" align="center">
  65. <template slot-scope="scope">
  66. <kt-button type="primary" v-if="editButtonName" icon="fa fa-edit" :label="editButtonName" :perms="permsEdit"
  67. :size="size" @click="handleEdit(scope.$index, scope.row)" />
  68. <kt-button v-if="deleteButtonName" icon="fa fa-trash" :label="deleteButtonName" :perms="permsDelete"
  69. :size="size" type="danger" @click="handleDeleteFlag(scope.$index, scope.row)" />
  70. <kt-button :style="{
  71. background: button1Background + '',
  72. border: '1px solid' + button1Background,
  73. color: '#fff',
  74. }" v-if="button1Name" :label="button1Name" :perms="permsButton1" :size="size" :icon="button1Icon"
  75. @click="handleButton1(scope.$index, scope.row)" />
  76. <kt-button v-if="button2Name" :label="button2Name" :style="button2style" :perms="permsButton2" :size="size" :type="button2Type"
  77. :icon="button2Icon" @click="handleButton2(scope.$index, scope.row)" />
  78. <kt-button v-if="button3Name" :label="button3Name" :style="button3style" :perms="permsButton3" :size="size" :type="button3Type"
  79. :icon="button3Icon" @click="handleButton3(scope.$index, scope.row)" />
  80. <kt-button v-if="button4Name" :icon="button4Icon" :style="button4style" :type="button4Type" :label="button4Name" :perms="permsButton4"
  81. :size="size" @click="handleButton4(scope.$index, scope.row)" />
  82. <kt-button v-if="button5Name" :label="button5Name" :style="button5style" :size="size" :type="button5Type" :icon="button5Icon"
  83. @click="handleButton5(scope.$index, scope.row)" />
  84. <kt-button v-if="button6Name" :label="button6Name" :size="size" :type="button6Type"
  85. @click="handleButton6(scope.$index, scope.row)" />
  86. <el-button type="text" size="small" v-if="buttonDropdown.length > 0">
  87. <el-dropdown trigger="click">
  88. <span class="el-dropdown-link">
  89. 更多
  90. <i class="el-icon-arrow-down el-icon--right"></i>
  91. </span>
  92. <el-dropdown-menu slot="dropdown">
  93. <el-dropdown-item v-for="val in buttonDropdown" :key="val.label">
  94. <el-button style="width:100%" size="mini" type="text"
  95. v-if="!val.hide || (val.hide && val.hide(scope.row))" @click="val.click(scope.row)">{{ val.label
  96. }}</el-button>
  97. </el-dropdown-item>
  98. </el-dropdown-menu>
  99. </el-dropdown>
  100. </el-button>
  101. </template>
  102. </el-table-column>
  103. </el-table>
  104. <!--分页栏-->
  105. <!-- 底部分页 -->
  106. <div class="bottomFixed " ref="bottomFixed">
  107. <div>
  108. <kt-button :label="customToolName" :perms="permscustomTool" :size="size" @click="customToolMethod()"
  109. :disabled="selections.length === 0" style="float: left;" v-if="customToolseletted" />
  110. <kt-button class="debutton" :label="deleteName" :perms="permsDelete" :size="size" @click="handleBatchDelete()"
  111. :disabled="selections.length === 0" style="float: left" v-if="showBatchDelete & showOperation" />
  112. <kt-button :label="settledName" :perms="permsSettled" :size="size" @click="handleBatchSettled()"
  113. :disabled="selections.length === 0" style="float: left" v-if="showBatchSettled" />
  114. <kt-button label="导出Excel" :perms="permsExcel" :size="size" @click="handleBatchPrint()" style="float: left"
  115. v-if="showBatchPrint" />
  116. </div>
  117. <el-pagination @size-change="handleSizeChange" background layout="total, sizes, prev, pager, next, jumper"
  118. @current-change="refreshPageRequest" :current-page="data.pageNum" :page-size="data.pageSize"
  119. :page-sizes="[10, 20, 50, 100, 200, 300, 400, 500]" :total="data.totalSize" style="float: right; "
  120. v-if="isshowpagination">
  121. </el-pagination>
  122. </div>
  123. </div>
  124. </template>
  125. <script>
  126. import KtButton from "@/views/Core/KtButton";
  127. import BigNumber from "bignumber.js";
  128. export default {
  129. name: "KtCommonTable",
  130. components: {
  131. KtButton,
  132. },
  133. props: {
  134. tableHeights: {
  135. type: Number,
  136. },
  137. operationWidth: {
  138. type: Number,
  139. default: 200,
  140. },
  141. showBatchSettled: {
  142. //显示批量结算
  143. type: Boolean,
  144. default: false,
  145. },
  146. SerialShow: {
  147. type: Boolean,
  148. default: true,
  149. },
  150. customToolName: {
  151. type: String,
  152. },
  153. permscustomTool: {
  154. type: String,
  155. },
  156. customToolseletted: {
  157. // 自定义操作组件
  158. type: Boolean,
  159. default: false,
  160. },
  161. settledName: {
  162. //批量按钮name
  163. type: String,
  164. },
  165. deleteName: {
  166. type: String,
  167. },
  168. showBatchPrint: {
  169. //显示批量导出
  170. type: Boolean,
  171. default: false,
  172. },
  173. //显示合计
  174. showSummary: {
  175. type: Boolean,
  176. default: false,
  177. },
  178. button1Name: {
  179. type: String,
  180. },
  181. button2Name: {
  182. type: String,
  183. },
  184. button3Name: {
  185. type: String,
  186. },
  187. button4Name: {
  188. type: String,
  189. },
  190. button5Name: {
  191. type: String,
  192. },
  193. button6Name: {
  194. type: String,
  195. },
  196. buttonDropdown: {
  197. type: Array,
  198. default: () => [],
  199. },
  200. permsButton1: {
  201. type: String,
  202. },
  203. permsButton2: {
  204. type: String,
  205. },
  206. permsButton3: {
  207. type: String,
  208. },
  209. permsButton4: {
  210. type: String,
  211. },
  212. button1Background: {
  213. type: String,
  214. default: "#f56c6c",
  215. },
  216. button2Background: {
  217. type: String,
  218. default: "rgb(222, 80, 76)",
  219. },
  220. button3Background: {
  221. type: String,
  222. default: "rgb(14, 194, 22)",
  223. },
  224. button4Background: {
  225. type: String,
  226. default: "#1e87ed",
  227. },
  228. button1Icon: {
  229. type: String,
  230. default: "fa fa-trash",
  231. },
  232. button2Icon: {
  233. type: String,
  234. default: "",
  235. },
  236. button3Icon: {
  237. type: String,
  238. default: "",
  239. },
  240. button4Icon: {
  241. type: String,
  242. default: "",
  243. },
  244. button5Icon: {
  245. type: String,
  246. default: "",
  247. },
  248. button2Type: {
  249. type: String,
  250. default: "primary",
  251. },
  252. button3Type: {
  253. type: String,
  254. default: "primary",
  255. },
  256. button4Type: {
  257. type: String,
  258. default: "primary",
  259. },
  260. button5Type: {
  261. type: String,
  262. default: "primary",
  263. },
  264. button6Type: {
  265. type: String,
  266. default: "primary",
  267. },
  268. editButtonName: {
  269. type: String,
  270. },
  271. deleteButtonName: {
  272. type: String,
  273. },
  274. isshowpagination: {
  275. //是否显示分页栏
  276. type: Boolean,
  277. default: true,
  278. },
  279. showSummaryFieldList: Array, //自定义合计列配置
  280. keyName: String, //主键字段名
  281. columns: Array, // 表格列配置
  282. data: {}, // 表格分页数据
  283. permsEdit: String, // 编辑权限标识
  284. permsDelete: String, // 底部按钮标识
  285. permsSettled: String, // 底部按钮标识
  286. permsExcel: String, // 底部按钮标识
  287. size: {
  288. // 尺寸样式
  289. type: String,
  290. default: "small ",
  291. },
  292. align: {
  293. // 文本对齐方式
  294. type: String,
  295. default: "left",
  296. },
  297. // maxHeight: { // 表格最大高度
  298. // type: Number,
  299. // default: 1420
  300. // },
  301. // height: { // 表格最大高度
  302. // type: Number,
  303. // default: 250
  304. // },
  305. showOperation: {
  306. // 是否显示操作组件
  307. type: Boolean,
  308. default: true,
  309. },
  310. border: {
  311. // 是否显示边框
  312. type: Boolean,
  313. default: true,
  314. },
  315. stripe: {
  316. // 是否显示斑马线
  317. type: Boolean,
  318. default: true,
  319. },
  320. highlightCurrentRow: {
  321. // 是否高亮当前行
  322. type: Boolean,
  323. default: true,
  324. },
  325. showOverflowTooltip: {
  326. // 是否单行显示
  327. type: Boolean,
  328. default: true,
  329. },
  330. showBatchDelete: {
  331. // 是否显示操作组件
  332. type: Boolean,
  333. default: false,
  334. },
  335. showSysUserAccountCardList: {
  336. // 是否显示二级列组件
  337. type: Boolean,
  338. default: false,
  339. },
  340. button1style: {
  341. type: Object,
  342. default: () => ({ }),
  343. },
  344. button2style: {
  345. type: Object,
  346. default: () => ({ }),
  347. },
  348. button3style: {
  349. type: Object,
  350. default: () => ({}),
  351. },
  352. button4style: {
  353. type: Object,
  354. default: () => ({ }),
  355. },
  356. button5style: {
  357. type: Object,
  358. default: () => ({ }),
  359. }
  360. },
  361. data() {
  362. return {
  363. tableHeight: 0,
  364. loading: false, // 加载标识
  365. selections: [], // 列表选中列
  366. pageRequest: {
  367. pageNum: 1,
  368. pageSize: 20,
  369. },
  370. };
  371. },
  372. methods: {
  373. tableRowClassName(row, rowIndex) {
  374. // if (!!row.fieldName24 && row.fieldName24.indexOf("未") >= 0) {
  375. // return "warningRow";
  376. // } else if (!!row.fieldName24 && row.fieldName24.indexOf("已") >= 0) {
  377. // return "successRow";
  378. // }
  379. this.$emit("tableRowClassName", row);
  380. // return '';
  381. },
  382. getSummaries(param) {
  383. const { columns, data } = param;
  384. const sums = [];
  385. columns.forEach((column, index) => {
  386. if (index === 0) {
  387. sums[index] = "合计"; // 假设第一列显示文本'合计'
  388. return;
  389. }
  390. if (this.showSummaryFieldList) {
  391. // 如果当前列名不在需要计算的列名数组中,直接返回空值或其他标记
  392. if (!this.showSummaryFieldList.includes(column.property)) {
  393. sums[index] = "-";
  394. return;
  395. }
  396. }
  397. let sum = new BigNumber(0);
  398. data.forEach((item) => {
  399. let value = item[column.property];
  400. let number = new BigNumber(value);
  401. if (!number.isNaN()) {
  402. sum = sum.plus(number);
  403. }
  404. });
  405. sums[index] = sum.toFixed(); // 转换成字符串避免精度问题
  406. });
  407. return sums;
  408. },
  409. // 分页查询
  410. findPage: function () {
  411. this.loading = true;
  412. let callback = (res) => {
  413. this.loading = false;
  414. //解决操作栏位置偏移问题
  415. this.$nextTick(() => {
  416. this.$refs.doLayout.doLayout();
  417. }, 200);
  418. };
  419. this.$emit("findPage", {
  420. pageRequest: this.pageRequest,
  421. callback: callback,
  422. });
  423. },
  424. hideLoading() {
  425. this.loading = false;
  426. },
  427. // 选择切换
  428. selectionChange: function (selections) {
  429. this.selections = selections;
  430. this.$emit("selectionChange", {
  431. selections: selections,
  432. });
  433. },
  434. // 选择切换
  435. handleCurrentChange: function (val) {
  436. this.$emit("handleCurrentChange", {
  437. val: val,
  438. });
  439. },
  440. rowClick: function (row) {
  441. this.$emit("rowClick", {
  442. row: row,
  443. });
  444. },
  445. // 换页刷新
  446. refreshPageRequest: function (pageNum) {
  447. this.pageRequest.pageNum = pageNum;
  448. this.pageRequest.pageSize = 20;
  449. this.findPage();
  450. },
  451. // 每页条数发生改变
  452. handleSizeChange(pageSize) {
  453. this.pageRequest.pageSize = pageSize;
  454. this.findPage();
  455. },
  456. signStateChanged(index, row) {
  457. this.$emit("signStateChanged", {
  458. index: index,
  459. row: row,
  460. });
  461. },
  462. // 按钮编辑
  463. handleBtnEdit: function (index, row) {
  464. this.$emit("handleBtnEdit", {
  465. index: index,
  466. row: row,
  467. });
  468. },
  469. // 编辑
  470. handleEdit: function (index, row) {
  471. this.$emit("handleEdit", {
  472. index: index,
  473. row: row,
  474. });
  475. // this.$emit('findLeftTreeData')
  476. },
  477. // 删除
  478. handleDelete: function (index, row) {
  479. let _keyName = "id";
  480. if (!!this.keyName) {
  481. _keyName = this.keyName;
  482. }
  483. this.delete(row[_keyName]);
  484. },
  485. handleButton1: function (index, row) {
  486. this.$emit("handleButton1", {
  487. index: index,
  488. row: row,
  489. });
  490. },
  491. handleButton2: function (index, row) {
  492. this.$emit("handleButton2", {
  493. index: index,
  494. row: row,
  495. });
  496. },
  497. handleButton3: function (index, row) {
  498. this.$emit("handleButton3", {
  499. index: index,
  500. row: row,
  501. });
  502. },
  503. handleButton4: function (index, row) {
  504. this.$emit("handleButton4", {
  505. index: index,
  506. row: row,
  507. });
  508. },
  509. handleButton5: function (index, row) {
  510. this.$emit("handleButton5", {
  511. index: index,
  512. row: row,
  513. });
  514. },
  515. handleButton6: function (index, row) {
  516. this.$emit("handleButton6", {
  517. index: index,
  518. row: row,
  519. });
  520. },
  521. handleButton: function (index, row) {
  522. this.$emit("handleButton", {
  523. index: index,
  524. row: row,
  525. });
  526. },
  527. //删除单个
  528. handleDeleteFlag: function (index, row) {
  529. this.$emit("handleDeleteFlag", { index: index, row: row });
  530. // var _keyName = "id";
  531. // if (!!this.keyName) {
  532. // _keyName = this.keyName;
  533. // }
  534. // let ids = row[_keyName];
  535. // this.$confirm("确认删除吗?", "提示", {
  536. // type: "warning",
  537. // })
  538. // .then(() => {
  539. // let params = [];
  540. // let idArray = (ids + "").split(",");
  541. // for (var i = 0; i < idArray.length; i++) {
  542. // var obj = {};
  543. // obj[_keyName] = idArray[i];
  544. // params.push(obj);
  545. // }
  546. // this.loading = true;
  547. // let callback = (res) => {
  548. // if (res.code == 200) {
  549. // this.$message({
  550. // message: "操作成功",
  551. // type: "success",
  552. // });
  553. // this.findPage();
  554. // // this.$emit('findLeftTreeData')
  555. // } else {
  556. // this.$message({
  557. // message: "操作失败, " + res.msg,
  558. // type: "error",
  559. // });
  560. // }
  561. // };
  562. // this.$emit("handleDeleteFlag", {
  563. // params: params,
  564. // callback: callback,
  565. // });
  566. // this.loading = false;
  567. // })
  568. // .catch(() => {
  569. // this.loading = false;
  570. // });
  571. },
  572. // 批量删除
  573. handleBatchDelete: function () {
  574. let idlist = [];
  575. this.selections.map((item) => idlist.push(item.id));
  576. this.$emit("handleDelete", idlist);
  577. },
  578. //自定义批量操作按钮
  579. customToolMethod() {
  580. let idlist = [];
  581. this.selections.map((item) => idlist.push(item.id));
  582. this.$emit("customTool", idlist);
  583. },
  584. // 删除操作
  585. delete: function (ids) {
  586. var _keyName = "id";
  587. if (!!this.keyName) {
  588. _keyName = this.keyName;
  589. }
  590. this.$confirm("确认删除吗?", "提示", {
  591. type: "warning",
  592. })
  593. .then(() => {
  594. let params = [];
  595. let idArray = (ids + "").split(",");
  596. for (var i = 0; i < idArray.length; i++) {
  597. var obj = {};
  598. obj[_keyName] = idArray[i];
  599. params.push(obj);
  600. }
  601. let callback = (res) => {
  602. if (res.code == 200) {
  603. this.$message({
  604. message: "操作成功",
  605. type: "success",
  606. });
  607. this.findPage();
  608. // this.$emit('findLeftTreeData')
  609. } else {
  610. this.$message({
  611. message: "操作失败, " + res.msg,
  612. type: "error",
  613. });
  614. }
  615. };
  616. this.$emit("handleDelete", {
  617. params: params,
  618. callback: callback,
  619. });
  620. })
  621. .catch(() => { });
  622. },
  623. //批量结算
  624. handleBatchSettled: function () {
  625. let _keyName = "orderno";
  626. if (!!this.keyName) {
  627. _keyName = this.keyName;
  628. }
  629. let idlist = [];
  630. this.selections.map((item) => idlist.push(item[_keyName]));
  631. this.$emit("handleSettled", idlist);
  632. },
  633. //批量打印
  634. handleBatchPrint: function () {
  635. // let _keyName = "orderno";
  636. // if(!!this.keyName){
  637. // _keyName = this.keyName;
  638. // }
  639. // let ids = this.selections.map(item => item[_keyName]).toString()
  640. // console.log(ids);
  641. this.$emit("handlePrint");
  642. },
  643. },
  644. mounted() {
  645. const that = this;
  646. that.refreshPageRequest(1);
  647. setTimeout(() => {
  648. let tableTop = that.$refs.commonTable.offsetTop;
  649. let bottomTop = that.$refs.bottomFixed.offsetTop;
  650. that.tableHeight = bottomTop - tableTop - 120 + "px";
  651. }, 10);
  652. // window.onresize = function () {
  653. // let tableTop = that.$refs.commonTable.offsetTop;
  654. // let bottomTop = that.$refs.bottomFixed.offsetTop;
  655. // that.tableHeight = bottomTop - tableTop - 120 + "px";
  656. // };
  657. },
  658. };
  659. </script>
  660. <style scoped>
  661. /* 底部固定分页 */
  662. .bottomFixed {
  663. height: 40px;
  664. bottom: 0;
  665. width: 100%;
  666. background: #fff;
  667. margin-top: 10px;
  668. }
  669. .el-table .warningRow {
  670. background: oldlace;
  671. }
  672. .el-table .successRow {
  673. background: #f0f9eb;
  674. }
  675. .el-dropdown-link {
  676. cursor: pointer;
  677. color: var(--themeColor);
  678. font-size: 12px;
  679. }
  680. </style>