KtCommonTable.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. <template>
  2. <div style="position: relative" ref="commonTable">
  3. <!--表格栏-->
  4. <el-table id="commonTable" :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"
  7. :show-overflow-tooltip="showOverflowTooltip" :height="tableHeight" :size="size" :align="align" :header-cell-style="{
  8. background: '#F2F7FC',
  9. fontWeight: '900',
  10. color: '#606266',
  11. }" style="width: 100%" :row-class-name="tableRowClassName">
  12. <el-table-column type="selection" width="40" fixed
  13. v-if="showBatchDelete || showBatchSettled || showBatchPrint"></el-table-column>
  14. <el-table-column label="序号" type="index" width="50" align="center"></el-table-column>
  15. <template v-for="column in columns">
  16. <el-table-column header-align="center" align="center" :prop="column.prop" :label="column.label"
  17. :width="column.width" :min-width="column.minWidth" :fixed="column.fixed" :key="column.prop" :type="column.type"
  18. :formatter="column.formatter" :sortable="column.sortable ? column.sortable : false"
  19. v-if="column.signIcon || column.isImg || column.isBtn">
  20. <template slot-scope="scope">
  21. <el-switch :disabled="column.isDisabled" v-if="column.signIcon" v-model="scope.row[column.prop]"
  22. active-value="1" inactive-value="0" @change="signStateChanged(scope.$index, scope.row)"></el-switch>
  23. <img v-if="column.isImg" :width="column.imgWidth" :height="column.imgHeight" :src="scope.row[column.prop]" />
  24. <kt-button v-if="column.isBtn" icon="fa fa-edit" :label="column.btnName" :size="size"
  25. :perms="column.permsEdit" @click="handleBtnEdit(scope.$index, scope.row)" />
  26. </template>
  27. </el-table-column>
  28. <el-table-column header-align="center" align="center" :prop="column.prop" :label="column.label"
  29. :width="column.width" :min-width="column.minWidth" :fixed="column.fixed" :key="column.prop" :type="column.type"
  30. :formatter="column.formatter" :sortable="column.sortable ? column.sortable : false " v-else>
  31. <template v-for="columnchildren in column.children">
  32. <el-table-column v-if="columnchildren" header-align="center" align="center" :prop="columnchildren.prop"
  33. :label="columnchildren.label" :width="columnchildren.width" :min-width="columnchildren.minWidth"
  34. :fixed="columnchildren.fixed" :key="columnchildren.prop" :type="columnchildren.type"
  35. :formatter="columnchildren.formatter" :sortable="columnchildren.sortable == null ? true : columnchildren.sortable
  36. ">
  37. </el-table-column>
  38. </template>
  39. </el-table-column>
  40. </template>
  41. <el-table-column :label="$t('action.operation')" :width="operationWidth" fixed="right" v-if="showOperation"
  42. header-align="center" align="center">
  43. <template slot-scope="scope">
  44. <kt-button style="
  45. background: #1e87ed;
  46. border: 1px solid #1e87ed;
  47. color: #ffffff;
  48. " v-if="editButtonName" icon="fa fa-edit" :label="editButtonName" :perms="permsEdit" :size="size"
  49. @click="handleEdit(scope.$index, scope.row)" />
  50. <kt-button v-if="deleteButtonName" icon="fa fa-trash" :label="deleteButtonName" :perms="permsDelete"
  51. :size="size" type="danger" @click="handleDeleteFlag(scope.$index, scope.row)" />
  52. <kt-button :style="{ background: button1Background+'', border: '1px solid'+button1Background, color:'#fff'}" v-if="button1Name" :label="button1Name" :perms="permsButton1" :size="size"
  53. @click="handleButton1(scope.$index, scope.row)" />
  54. <kt-button :style="{ background: button2Background, border: '1px solid'+button2Background, color:'#fff'}" v-if="button2Name" :label="button2Name" :perms="permsButton2" :size="size"
  55. @click="handleButton2(scope.$index, scope.row)" />
  56. <kt-button :style="{ background: button3Background, border: '1px solid'+button3Background, color:'#fff'}" v-if="button3Name" :label="button3Name" :perms="permsButton3" :size="size" :icon="button3Icon"
  57. @click="handleButton3(scope.$index, scope.row)" />
  58. <kt-button :style="{ background: button4Background, border: '1px solid'+button4Background, color:'#fff'}" v-if="button4Name" :label="button4Name" :perms="permsButton4" :size="size" :icon="button2Icon"
  59. @click="handleButton2(scope.$index, scope.row)" />
  60. <kt-button :style="{
  61. background:button1Background,
  62. border: '1px solid '+button1Background,
  63. color:'#ffffff',
  64. }
  65. " :icon="button1Icon" v-if="button1Name" :label="button1Name" :perms="permsButton1" :size="size"
  66. @click="handleButton1(scope.$index, scope.row)" />
  67. <kt-button :style="{
  68. background:button4Background,
  69. border: '1px solid '+button4Background,
  70. color:'#ffffff',
  71. }
  72. " v-if="button4Name" :icon="button4Icon" :label="button4Name" :perms="permsButton4" :size="size"
  73. @click="handleButton4(scope.$index, scope.row)" />
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <!--分页栏-->
  78. <!-- 底部分页 -->
  79. <div class="bottomFixed" ref="bottomFixed">
  80. <kt-button class="debutton" :label="$t('action.batchDelete')" :perms="permsDelete" :size="size" type="danger"
  81. @click="handleBatchDelete()" :disabled="selections.length === 0" style="float: left"
  82. v-if="showBatchDelete & showOperation" />
  83. <kt-button :label="settledName" :perms="permsDelete" :size="size" type="danger" @click="handleBatchSettled()"
  84. :disabled="selections.length === 0" style="float: left" v-if="showBatchSettled" />
  85. <kt-button label="导出Excel" :perms="permsDelete" :size="size" type="danger" @click="handleBatchPrint()"
  86. :disabled="selections.length === 0" style="float: left" v-if="showBatchPrint" />
  87. <el-pagination @size-change="handleSizeChange" layout="total, sizes, prev, pager, next, jumper"
  88. @current-change="refreshPageRequest" :current-page="data.pageNum" :page-size="data.pageSize"
  89. :page-sizes="[10, 20, 50, 100, 200, 300, 400, 500]" :total="data.totalSize" style="float: left; margin-left: 20px"
  90. v-if="isshowpagination">
  91. </el-pagination>
  92. </div>
  93. </div>
  94. </template>
  95. <script>
  96. import KtButton from "@/views/Core/KtButton";
  97. export default {
  98. name: "KtCommonTable",
  99. components: {
  100. KtButton,
  101. },
  102. props: {
  103. operationWidth: {
  104. type: Number,
  105. default: 200,
  106. },
  107. showBatchSettled: {
  108. //显示批量结算
  109. type: Boolean,
  110. default: false,
  111. },
  112. settledName:{
  113. //批量按钮name
  114. type: String,
  115. },
  116. showBatchPrint: {
  117. //显示批量导出
  118. type: Boolean,
  119. default: false,
  120. },
  121. button1Name: {
  122. type: String,
  123. },
  124. button2Name: {
  125. type: String,
  126. },
  127. button3Name: {
  128. type: String,
  129. },
  130. button4Name: {
  131. type: String,
  132. },
  133. permsButton1: {
  134. type: String,
  135. },
  136. permsButton2: {
  137. type: String,
  138. },
  139. permsButton3: {
  140. type: String,
  141. },
  142. permsButton4: {
  143. type: String,
  144. },
  145. button1Background: {
  146. type: String,
  147. default: "#f56c6c",
  148. },
  149. button2Background: {
  150. type: String,
  151. default: "rgb(222, 80, 76)",
  152. },
  153. button3Background: {
  154. type: String,
  155. default: "rgb(14, 194, 22)",
  156. },
  157. button4Background: {
  158. type: String,
  159. default: "#1e87ed",
  160. },
  161. button1Icon: {
  162. type: String,
  163. default: "fa fa-trash",
  164. },
  165. button2Icon: {
  166. type: String,
  167. default: "fa fa-edit",
  168. },
  169. button3Icon: {
  170. type: String,
  171. default: "fa fa-edit",
  172. },
  173. button4Icon: {
  174. type: String,
  175. default: "fa fa-trash",
  176. },
  177. button4Background: {
  178. type: String,
  179. default: "rgb(14, 194, 22)",
  180. },
  181. button4Background: {
  182. type: String,
  183. default: "#1e87ed",
  184. },
  185. button1Icon: {
  186. type: String,
  187. default: "fa fa-trash",
  188. },
  189. button2Icon: {
  190. type: String,
  191. default: "fa fa-edit",
  192. },
  193. button3Icon: {
  194. type: String,
  195. default: "fa fa-edit",
  196. },
  197. button4Icon: {
  198. type: String,
  199. default: "fa fa-trash",
  200. },
  201. editButtonName: {
  202. type: String,
  203. },
  204. deleteButtonName: {
  205. type: String,
  206. },
  207. isshowpagination: {
  208. //是否显示分页栏
  209. type: Boolean,
  210. default: true,
  211. },
  212. keyName: String, //主键字段名
  213. columns: Array, // 表格列配置
  214. data: {}, // 表格分页数据
  215. permsEdit: String, // 编辑权限标识
  216. permsDelete: String, // 删除权限标识
  217. size: {
  218. // 尺寸样式
  219. type: String,
  220. default: "small ",
  221. },
  222. align: {
  223. // 文本对齐方式
  224. type: String,
  225. default: "left",
  226. },
  227. // maxHeight: { // 表格最大高度
  228. // type: Number,
  229. // default: 1420
  230. // },
  231. // height: { // 表格最大高度
  232. // type: Number,
  233. // default: 250
  234. // },
  235. showOperation: {
  236. // 是否显示操作组件
  237. type: Boolean,
  238. default: true,
  239. },
  240. border: {
  241. // 是否显示边框
  242. type: Boolean,
  243. default: true,
  244. },
  245. stripe: {
  246. // 是否显示斑马线
  247. type: Boolean,
  248. default: true,
  249. },
  250. highlightCurrentRow: {
  251. // 是否高亮当前行
  252. type: Boolean,
  253. default: true,
  254. },
  255. showOverflowTooltip: {
  256. // 是否单行显示
  257. type: Boolean,
  258. default: true,
  259. },
  260. showBatchDelete: {
  261. // 是否显示操作组件
  262. type: Boolean,
  263. default: false,
  264. },
  265. },
  266. data() {
  267. return {
  268. tableHeight: 0,
  269. // 分页信息
  270. pageRequest: {
  271. pageNum: 1,
  272. pageSize: 10,
  273. },
  274. loading: false, // 加载标识
  275. selections: [], // 列表选中列
  276. };
  277. },
  278. methods: {
  279. tableRowClassName({ row, rowIndex }) {
  280. if (!!row.fieldName24 && row.fieldName24.indexOf("未") >= 0) {
  281. return "warningRow";
  282. } else if (!!row.fieldName24 && row.fieldName24.indexOf("已") >= 0) {
  283. return "successRow";
  284. }
  285. // return '';
  286. },
  287. // 分页查询
  288. findPage: function () {
  289. this.loading = true;
  290. let callback = (res) => {
  291. this.loading = false;
  292. };
  293. this.$emit("findPage", {
  294. pageRequest: this.pageRequest,
  295. callback: callback,
  296. });
  297. },
  298. hideLoading() {
  299. this.loading = false;
  300. },
  301. // 选择切换
  302. selectionChange: function (selections) {
  303. this.selections = selections;
  304. this.$emit("selectionChange", {
  305. selections: selections,
  306. });
  307. },
  308. // 选择切换
  309. handleCurrentChange: function (val) {
  310. this.$emit("handleCurrentChange", {
  311. val: val,
  312. });
  313. },
  314. rowClick: function (row) {
  315. this.$emit("rowClick", {
  316. row: row,
  317. });
  318. },
  319. // 换页刷新
  320. refreshPageRequest: function (pageNum) {
  321. this.pageRequest.pageNum = pageNum;
  322. this.findPage();
  323. },
  324. // 每页条数发生改变
  325. handleSizeChange(pageSize) {
  326. this.pageRequest.pageSize = pageSize;
  327. this.findPage();
  328. },
  329. signStateChanged(index, row) {
  330. this.$emit("signStateChanged", {
  331. index: index,
  332. row: row,
  333. });
  334. },
  335. // 按钮编辑
  336. handleBtnEdit: function (index, row) {
  337. this.$emit("handleBtnEdit", {
  338. index: index,
  339. row: row,
  340. });
  341. },
  342. // 编辑
  343. handleEdit: function (index, row) {
  344. this.$emit("handleEdit", {
  345. index: index,
  346. row: row,
  347. });
  348. // this.$emit('findLeftTreeData')
  349. },
  350. // 删除
  351. handleDelete: function (index, row) {
  352. let _keyName = "id";
  353. if (!!this.keyName) {
  354. _keyName = this.keyName;
  355. }
  356. this.delete(row[_keyName]);
  357. },
  358. handleButton1: function (index, row) {
  359. this.$emit("handleButton1", {
  360. index: index,
  361. row: row,
  362. });
  363. },
  364. handleButton2: function (index, row) {
  365. this.$emit("handleButton2", {
  366. index: index,
  367. row: row,
  368. });
  369. },
  370. handleButton3: function (index, row) {
  371. this.$emit("handleButton3", {
  372. index: index,
  373. row: row,
  374. });
  375. },
  376. handleButton4: function (index, row) {
  377. this.$emit("handleButton4", {
  378. index: index,
  379. row: row,
  380. });
  381. },
  382. //删除单个
  383. handleDeleteFlag: function (index, row) {
  384. this.$emit("handleDeleteFlag", { index: index, row: row });
  385. // var _keyName = "id";
  386. // if (!!this.keyName) {
  387. // _keyName = this.keyName;
  388. // }
  389. // let ids = row[_keyName];
  390. // this.$confirm("确认删除吗?", "提示", {
  391. // type: "warning",
  392. // })
  393. // .then(() => {
  394. // let params = [];
  395. // let idArray = (ids + "").split(",");
  396. // for (var i = 0; i < idArray.length; i++) {
  397. // var obj = {};
  398. // obj[_keyName] = idArray[i];
  399. // params.push(obj);
  400. // }
  401. // this.loading = true;
  402. // let callback = (res) => {
  403. // if (res.code == 200) {
  404. // this.$message({
  405. // message: "操作成功",
  406. // type: "success",
  407. // });
  408. // this.findPage();
  409. // // this.$emit('findLeftTreeData')
  410. // } else {
  411. // this.$message({
  412. // message: "操作失败, " + res.msg,
  413. // type: "error",
  414. // });
  415. // }
  416. // };
  417. // this.$emit("handleDeleteFlag", {
  418. // params: params,
  419. // callback: callback,
  420. // });
  421. // this.loading = false;
  422. // })
  423. // .catch(() => {
  424. // this.loading = false;
  425. // });
  426. },
  427. // 批量删除
  428. handleBatchDelete: function () {
  429. let _keyName = "id";
  430. if (!!this.keyName) {
  431. _keyName = this.keyName;
  432. }
  433. //let ids = this.selections.map(item => item.id).toString()
  434. let ids = this.selections.map((item) => item[_keyName]).toString();
  435. this.delete(ids);
  436. },
  437. // 删除操作
  438. delete: function (ids) {
  439. var _keyName = "id";
  440. if (!!this.keyName) {
  441. _keyName = this.keyName;
  442. }
  443. this.$confirm("确认删除吗?", "提示", {
  444. type: "warning",
  445. })
  446. .then(() => {
  447. let params = [];
  448. let idArray = (ids + "").split(",");
  449. for (var i = 0; i < idArray.length; i++) {
  450. var obj = {};
  451. obj[_keyName] = idArray[i];
  452. params.push(obj);
  453. }
  454. let callback = (res) => {
  455. if (res.code == 200) {
  456. this.$message({
  457. message: "操作成功",
  458. type: "success",
  459. });
  460. this.findPage();
  461. // this.$emit('findLeftTreeData')
  462. } else {
  463. this.$message({
  464. message: "操作失败, " + res.msg,
  465. type: "error",
  466. });
  467. }
  468. };
  469. this.$emit("handleDelete", {
  470. params: params,
  471. callback: callback,
  472. });
  473. })
  474. .catch(() => {
  475. });
  476. },
  477. //批量结算
  478. handleBatchSettled: function () {
  479. let _keyName = "orderno";
  480. if (!!this.keyName) {
  481. _keyName = this.keyName;
  482. }
  483. let idlist=[];
  484. this.selections.map((item) => idlist.push(item.policyno));
  485. this.$emit("handleSettled", idlist);
  486. },
  487. //批量打印
  488. handleBatchPrint: function () {
  489. // let _keyName = "orderno";
  490. // if(!!this.keyName){
  491. // _keyName = this.keyName;
  492. // }
  493. // let ids = this.selections.map(item => item[_keyName]).toString()
  494. // console.log(ids);
  495. this.$emit("handlePrint");
  496. },
  497. },
  498. mounted() {
  499. const that = this;
  500. that.refreshPageRequest(1);
  501. setTimeout(() => {
  502. let tableTop = that.$refs.commonTable.offsetTop;
  503. let bottomTop = that.$refs.bottomFixed.offsetTop;
  504. that.tableHeight = bottomTop - tableTop - 120 + "px";
  505. }, 10);
  506. // window.onresize = function () {
  507. // let tableTop = that.$refs.commonTable.offsetTop;
  508. // let bottomTop = that.$refs.bottomFixed.offsetTop;
  509. // that.tableHeight = bottomTop - tableTop - 120 + "px";
  510. // };
  511. },
  512. };
  513. </script>
  514. <style scoped>
  515. /* 底部固定分页 */
  516. .bottomFixed {
  517. height: 40px;
  518. position: fixed;
  519. bottom: 0;
  520. width: 100%;
  521. background: #fff;
  522. /* margin-top: 10px; */
  523. /* box-shadow: 0 -2px 0 0 #efefef; */
  524. }
  525. .el-table .warningRow {
  526. background: oldlace;
  527. }
  528. .el-table .successRow {
  529. background: #f0f9eb;
  530. }
  531. </style>