haoxuan
2024-04-24 47e51078a55706950c21b54ca49e64b7444cdb60
src/components/makepager/CommonFormTableView.vue
@@ -9,6 +9,7 @@
        :summary-method="getSummaries"
        :span-method="arraySpanMethod"
        style="width: 100%"
        :header-cell-style="{ background: '#f1f3f8', color: '#000009', 'font-size': '14px', 'font-family': 'PingFangSC' }"
        @selection-change="handleSelectionChange"
        :row-key="(row) => row.productId"
      >
@@ -16,14 +17,18 @@
        </el-table-column>
        <el-table-column v-if="tableList.isReturn" type="index" label="#" width="50" align="center"></el-table-column>
        <el-table-column
          align="center"
          v-for="(item, i) in tableList.tableColumn"
          :key="i"
          :prop="item.prop"
          :label="item.label"
          :width="item.width"
          :min-width="item.min"
          align="center"
        >
          show-overflow-tooltip
          :sortable="item.sortable"
          v-if="(item.isShowColumn&&colOpenShow)||item.isShowColumn==undefined"
        >
        <!-- 所有的表格修改为可配置表头的之后 v-if修改为v-if="item.isShowColumn" -->
          <!-- 表头样式 -->
          <template slot="header">
            <span v-if="item.isRequird" style="color: #f56c6c">*</span>
@@ -199,13 +204,20 @@
            <span v-else style="text-align: right">{{ scope.row[item.prop] }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="40" v-if="!detailEnter" align="center">
        <el-table-column label="操作" width="70" v-if="!detailEnter" align="center" fixed='right'>
          <template slot-scope="scope">
            <el-button type="text" size="small" :disabled="!isOperate" @click="deleteClick(scope)">删除</el-button>
          </template>
        </el-table-column>
        <slot name="tableButton" />
      </el-table>
      <div class="styleBtn" v-if="colOpenShow">
        <i @click="checkCol()"  class="label">...</i>
        <el-checkbox-group v-model="showcol" v-show="iscolopen" class="checkbox-group" @change="selectCheckBoxList">
          <el-checkbox v-for="item in tableList.allcol" :label="item" :key="item">{{ item }} </el-checkbox>
        </el-checkbox-group>
      </div>
    </el-form>
    <div v-if="!detailEnter" style="margin: 10px">
      <el-button size="small" type="primary" :disabled="!isOperate" @click="add">新增</el-button>
@@ -250,6 +262,11 @@
      type: Boolean,
      default: false
    },
    // 是否可以配置列表 表头
    colOpenShow: {
      type: Boolean,
      default: false,
    },
    selectBox: {
      type: Boolean,
      default: false
@@ -284,6 +301,8 @@
        return {
          tableData: [], // 接口返回数据
          isReturn: false,
          allcol: [],
          showcol: [],
          tableColumn: [
            // table表单
            { label: "", prop: "", min: 200, tooltip: true }
@@ -316,7 +335,10 @@
        infomation: {}
      },
      productIndex: 0,
      isRecalculate: true
      isRecalculate: true,
      iscolopen: false,
      showcol: [],
      mergeNumber:1
    }
  },
  created() {
@@ -328,13 +350,40 @@
  watch:{
    "productTableList": {
      handler() {
        this.showcol = this.productTableList.showcol
        this.getTableInfo()
      },
      immediate: true
    }
    },
    "productTableList.showcol": {
      handler(newVal) {
        this.showcol = newVal
        this.getMergeNumber()
      },
      immediate: true
    },
  },
  computed: {},
  methods: {
    getMergeNumber(){
      let pattern=new RegExp("[0-9]+");
        if(pattern.test(this.showSummary.mergeNumber)){
          this.mergeNumber=this.showSummary.mergeNumber
        }else{
          for(let i in this.showcol){
            if(this.showcol[i]==this.showSummary.mergeNumber){
              this.mergeNumber=Number(i)+1;
            }
          }
        }
    },
    checkCol() {
      this.iscolopen = !this.iscolopen
    },
    selectCheckBoxList(val) {
      this.getMergeNumber()
      this.$emit("selTableCol", val)
    },
    getTableInfo(){
      this.tableList = this.productTableList
      if (this.tableList.tableData.length === 1 && this.tableList.tableData[0].name === "") {
@@ -373,11 +422,11 @@
          if (this.$refs.table) {
            var current = this.$refs.table.querySelector(".el-table__footer-wrapper").querySelector(".el-table__footer")
            var cell = current.rows[0].cells
            for (let i = 0; i < this.showSummary.mergeNumber; i++) {
            for (let i = 0; i < this.mergeNumber; i++) {
              cell[i].style.display = "none"
            }
            cell[this.showSummary.mergeNumber].classList.remove("is-left")
            cell[this.showSummary.mergeNumber].colSpan = this.showSummary.mergeNumber.toString()
            cell[this.mergeNumber].classList.remove("is-left")
            cell[this.mergeNumber].colSpan = this.mergeNumber.toString()
          }
        })
      }
@@ -388,7 +437,7 @@
      const sums = []
      columns.forEach((column, index) => {
        // // 更改行名称
        if (index === this.showSummary.mergeNumber) {
        if (index === this.mergeNumber) {
          sums[index] = "小计:"
          return
        }
@@ -617,6 +666,7 @@
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.page-view {
  position: relative;
  .el-form-item {
    margin-bottom: 0;
    .custom-name {
@@ -645,9 +695,47 @@
  .el-table th.el-table__cell > .cell {
    padding: 0 5px;
  }
  .el-table__fixed-footer-wrapper tbody td.el-table__cell{
    background:#fff;
  }
  .el-input__inner {
    // text-align: left;
    text-align: center !important;
  }
  .styleBtn {
    position: absolute;
    width: 30px;
    height: 48px;
    // line-height: 26px;
    // background: #06c062;
    top: 0;
    right: -6px;
    z-index: 11;
    .label {
      position: absolute;
      top: 11px;
      font-size: 20px;
      // line-height: 5px;
      cursor: pointer;
      color: #000;
      transform: rotate(-90deg);
    }
    .checkbox-group {
      width: 160px;
      height: 180px;
      overflow: auto;
      display: flex;
      flex-direction: column;
      line-height: 25px;
      background: #ffffff;
      border-radius: 16px;
      padding: 12px;
      position: absolute;
      right: 0;
      top: 30px;
      z-index: 99;
      box-shadow: 0 0 2px 2px #f8f8f8;
    }
  }
}
</style>