KtCommonTable.vue 16 KB

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