Table.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <el-dialog v-model="dialogTableVisible" title="员工信息" width="1200" draggable :close-on-click-modal="false"
  3. :before-close="dialogBeforeClose">
  4. <div style="padding: 10px;">
  5. <el-input v-model="searchText2" style="color: #000 !important;" size="small" placeholder="请输入姓名搜索" clearable :clear-icon="CloseBold" />
  6. </div>
  7. <el-table :data="tableData" style="height: 500px; overflow: auto;" >
  8. <el-table-column
  9. v-for="item in modelFieldList"
  10. :key="item.id"
  11. :fixed="item.name == 'c_xm' ? true : false"
  12. :property="item.name"
  13. :label="item.alias"
  14. :width="150"
  15. show-overflow-tooltip
  16. />
  17. <el-table-column fixed="right" label="操作" min-width="120" v-if="$getUserType() == 3">
  18. <template #default="scope">
  19. <el-button link type="primary" size="small" @click="handleEditClick(scope.row)">
  20. 编辑
  21. </el-button>
  22. </template>
  23. </el-table-column>
  24. </el-table>
  25. <!-- 分页控件 -->
  26. <div class="pagination-section">
  27. <span class="total-text">共{{ total }}条</span>
  28. <el-pagination
  29. layout="prev, pager, next"
  30. :total="total"
  31. :current-page="currentPage"
  32. :page-size="pageSize"
  33. @current-change="handleCurrentChange"
  34. >
  35. </el-pagination>
  36. </div>
  37. </el-dialog>
  38. </template>
  39. <script>
  40. export default {
  41. components: {
  42. },
  43. data() {
  44. return {
  45. dialogTableVisible: false,
  46. modelFieldList:[],
  47. currentPage: 1,
  48. pageSize: this.pageSize,
  49. searchText2:"",
  50. }
  51. },
  52. props: {
  53. tableData: {
  54. type: Array,
  55. default: []
  56. },
  57. columnModel: {
  58. type: Array,
  59. default: []
  60. },
  61. isview: {
  62. type: Boolean,
  63. default: false
  64. },
  65. searchText:{
  66. type: String,
  67. default: ''
  68. },
  69. close: Function,
  70. total: Number,
  71. pageSize: Number,
  72. page: Number,
  73. handlePageChange: Function,
  74. },
  75. watch: {
  76. tableData: {
  77. handler: function (newVal, oldVal) {
  78. // console.log("newVal:", newVal);
  79. this.updateTableData();
  80. },
  81. deep: true
  82. },
  83. searchText2: {
  84. handler: function (newVal, oldVal) {
  85. this.currentPage = 1;
  86. this.handlePageChange(this.currentPage-1,this.pageSize,newVal);
  87. },
  88. deep: true
  89. }
  90. },
  91. created() {
  92. let that = this;
  93. that.searchText2 = that.searchText;
  94. that.dialogTableVisible = that.isview;
  95. let modelFields = JSON.parse(this.columnModel.fieldList);
  96. // 无序
  97. let keys = Object.keys(modelFields);
  98. for (let i = 0; i < keys.length; i++) {
  99. let obj = modelFields[keys[i]];
  100. if (!obj.name) {
  101. obj = JSON.parse(obj);
  102. }
  103. if (obj.name.includes("c_")) {
  104. let itemkey = obj.name.replace(/c_/g, "");
  105. obj.name = 'c_' + itemkey;
  106. }
  107. that.modelFieldList.push(obj);
  108. }
  109. // console.log("that.modelFieldList:", that.modelFieldList);
  110. this.modelFieldList.sort((a, b) => {
  111. return a.index > b.index ? 1 : -1;
  112. });
  113. },
  114. mounted() {
  115. this.updateTableData();
  116. },
  117. methods: {
  118. updateTableData(){
  119. this.tableData.forEach((data) => {
  120. data.sfzhm = data.c_sfzhm;
  121. data.sjhm = data.c_sjhm;
  122. data.c_sfzhm = this.formatCardNumber(data.c_sfzhm);
  123. data.c_sjhm = this.formatPhoneNumber(data.c_sjhm);
  124. })
  125. },
  126. handleSizeChange(val) {
  127. this.pageSize = val;
  128. this.currentPage = 1;
  129. this.handlePageChange(this.currentPage-1,this.pageSize,this.searchText2);
  130. },
  131. handleCurrentChange(val) {
  132. this.currentPage = val;
  133. this.handlePageChange(this.currentPage-1,this.pageSize,this.searchText2);
  134. },
  135. formatCardNumber(cardNumber) {
  136. if (!cardNumber) return "";
  137. return cardNumber.replace(/(.{8})$/, '*'.repeat(8));
  138. },
  139. formatPhoneNumber(phone) {
  140. if (!phone) return "";
  141. return phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
  142. },
  143. handleEditClick(row) {
  144. this.$parent.getContentById(row);
  145. },
  146. dialogBeforeClose() {
  147. this.close();
  148. },
  149. }
  150. }
  151. </script>
  152. <style >
  153. /* 分页控件 */
  154. .pagination-section {
  155. display: flex;
  156. justify-content: space-between;
  157. align-items: center;
  158. margin: 0px 15px 0px 10px;
  159. }
  160. .total-text {
  161. font-size: 14px;
  162. }
  163. </style>
  164. <style lang="less" scoped>
  165. /deep/.el-input__inner{
  166. color: #000;
  167. }
  168. </style>