src/components/makepager/TableCommonView.vue
@@ -1,109 +1,147 @@
<!-- eslint-disable vue/no-use-v-if-with-v-for -->
<template>
  <div class="table-view">
  <div class="table-view" v-loading="loading">
    <el-table
      ref="table"
      border
      :data="tableList.tableInfomation"
      tooltip-effect="dark"
      style="width: 100%"
      :height="'calc(100% - 0px)'"
      :max-height="tableList.maxHeight"
      style="width: 100%"
      :lazy="tableList.lazy"
      size="mini"
      :show-summary="showSummary.show"
      :summary-method="getSummaries"
      :span-method="arraySpanMethod"
      @selection-change="handleSelectionChange"
      :header-cell-style="{ background: '#f1f3f8', color: '#000009', 'font-size': '14px' }"
      :highlight-current-row="tableList.highlight"
      :row-class-name="tableRowClassName"
      :header-cell-style="{ background: '#f1f3f8', color: '#000009', 'font-size': '12px', 'font-family': 'PingFangSC' }"
      size="mini"
      @row-click="tableRowClick"
      :row-key="tableList.key"
      :default-expand-all="tableList.isDefaultExpandAll"
      :tree-props="{ children: 'child', hasChildren: 'hasChildren' }"
      :row-class-name="tableRowClassName"
    >
      <el-table-column align="center" v-if="tableList.selectBox" type="selection" width="40"> </el-table-column>
      <el-table-column align="center" v-if="tableList.selectIndex" type="index" label="序号" width="50">
      </el-table-column>
      <template v-for="(item, i) in tableList.tableColumn">
        <el-table-column
          align="center"
          :key="i"
          :prop="item.prop"
          :label="item.label"
          :width="item.width"
          :min-width="item.min"
          show-overflow-tooltip
          :sortable="item.sortable"
          v-if="item.isShowColumn"
        >
          <template slot-scope="scope">
            <span v-if="item.price">{{ "¥" + number_format(scope.row[item.prop], 2, ".", ",") }}</span>
            <div v-else-if="item.status" :class="scope.row.status">{{ scope.row[item.prop] }}</div>
            <span v-else-if="item.isTime">{{
              dateFormat("YYYY-mm-dd HH:MM:SS", scope.row[item.prop]) === "1900-01-01 00:06:26"
                ? "--"
                : dateFormat("YYYY-mm-dd HH:MM:SS", scope.row[item.prop])
      <el-table-column v-if="selectBox" type="selection" width="40" :selectable="selectable"> </el-table-column>
      <el-table-column v-if="tableList.selectIndex" type="index" label="序号" width="50"></el-table-column>
      <el-table-column
        v-for="(item, i) in tableList.tableColumn"
        :key="i"
        :prop="item.prop"
        :label="item.label"
        :width="item.width"
        :min-width="item.min"
        show-overflow-tooltip
        :sortable="item.sortable"
        v-if="item.isShowColumn"
      >
        <template slot-scope="scope">
          <span v-if="item.price">{{ "¥" + number_format(scope.row[item.prop], 2, ".", ",") }}</span>
          <div v-else-if="item.status" :class="scope.row.status">{{ scope.row[item.prop] }}</div>
          <span v-else-if="item.isTime">{{
            dateFormat("YYYY-mm-dd HH:MM:SS", scope.row[item.prop]) === "1900-01-01 00:06:26"
              ? "--"
              : dateFormat("YYYY-mm-dd HH:MM:SS", scope.row[item.prop])
          }}</span>
          <span v-else-if="item.isClick && scope.row[item.prop]" class="sel-name" @click="selNameClick(scope.row)">{{
            scope.row[item.prop]
          }}</span>
          <span v-else-if="item.isFirst">{{ scope.row[item.prop] ? "是" : "否" }}</span>
          <span
            v-else-if="item.isSalesLeadClick && scope.row[item.prop]"
            class="sel-name"
            @click="selSalesLeadClick(scope.row)"
            >{{ scope.row[item.prop] }}</span
          >
          <span
            v-else-if="item.isClientClick && scope.row[item.prop]"
            class="sel-name"
            @click="selClientClick(scope.row)"
            >{{ scope.row[item.prop] ? scope.row[item.prop] : "--" }}</span
          >
          <span
            v-else-if="item.isContactClick && scope.row[item.prop]"
            class="sel-name"
            @click="selContactsClick(scope.row)"
            >{{ scope.row[item.prop] }}</span
          >
          <span
            v-else-if="item.isMasterClick && scope.row[item.prop]"
            class="sel-name"
            @click="selMasterClick(scope.row)"
            >{{ scope.row[item.prop] }}</span
          >
          <span
            v-else-if="item.isServiceOrder && scope.row[item.prop]"
            class="sel-name"
            @click="selServiceOrderClick(scope.row)"
            >{{ scope.row[item.prop] }}</span
          >
          <span
            v-else-if="item.isCommonClick && scope.row[item.prop]"
            class="sel-name"
            @click="selCommonClick(scope.row)"
            >{{ scope.row[item.prop] }}</span
          >
          <div v-else-if="item.isProductName" class="product-view">
            <ul v-if="scope.row.products && scope.row.products.length > 0">
              <li v-for="(item, index) in scope.row.products" :key="index">
                <div class="name-view">
                  {{ item.name }}
                </div>
              </li>
            </ul>
            <div v-else class="no-product">{{ "--" }}</div>
          </div>
          <div v-else-if="item.isProductAmount" class="product-view">
            <ul v-if="scope.row.products && scope.row.products.length > 0">
              <li v-for="(item, index) in scope.row.products" :key="index">
                <div class="name-view">
                  {{ item.amount }}
                </div>
              </li>
            </ul>
            <div v-else class="no-product">{{ "--" }}</div>
          </div>
          <div v-else-if="item.isProductPrice" class="product-view">
            <ul v-if="scope.row.products && scope.row.products.length > 0">
              <li v-for="(item, index) in scope.row.products" :key="index">
                <div class="name-view">
                  {{ item.price }}
                </div>
              </li>
            </ul>
            <div v-else class="no-product">{{ "--" }}</div>
          </div>
          <div v-else-if="item.isProductTotal" class="product-view">
            <ul v-if="scope.row.products && scope.row.products.length > 0">
              <li v-for="(item, index) in scope.row.products" :key="index">
                <div class="name-view">
                  {{ item.total }}
                </div>
              </li>
            </ul>
            <div v-else class="no-product">{{ "--" }}</div>
          </div>
          <!-- 调用方法显示文字 -->
          <div v-else-if="item.isCallMethod">
            <span :class="item.isClass ? item.getClassName(scope.row[item.prop], scope.row) : ''">{{
              item.getCallMethod(scope.row[item.prop], scope.row)
            }}</span>
            <span
              v-else-if="item.isClick && scope.row[item.prop]"
              class="sel-name"
              @click="selCommonClick(scope.row)"
              >{{ scope.row[item.prop] }}</span
            >
            <span v-else-if="item.isFirst">{{ scope.row[item.prop] ? "是" : "否" }}</span>
            <span
              v-else-if="item.isCommonClick && scope.row[item.prop]"
              class="sel-name"
              @click="selCommonClick(scope.row)"
              >{{ scope.row[item.prop] }}</span
            >
            <div v-else-if="item.isProductName" class="product-view">
              <ul v-if="scope.row.products && scope.row.products.length > 0">
                <li v-for="(item, index) in scope.row.products" :key="index">
                  <div :class="scope.row.products.length === 1 ? 'name-view no-bottom' : 'name-view'">
                    {{ item.name }}
                  </div>
                </li>
              </ul>
              <div v-else class="no-product">{{ "--" }}</div>
            </div>
            <div v-else-if="item.isProductAmount" class="product-view">
              <ul v-if="scope.row.products && scope.row.products.length > 0">
                <li v-for="(item, index) in scope.row.products" :key="index">
                  <div :class="scope.row.products.length === 1 ? 'name-view no-bottom' : 'name-view'">
                    {{ item.amount }}
                  </div>
                </li>
              </ul>
              <div v-else class="no-product">{{ "--" }}</div>
            </div>
            <div v-else-if="item.isProductPrice" class="product-view">
              <ul v-if="scope.row.products && scope.row.products.length > 0">
                <li v-for="(item, index) in scope.row.products" :key="index">
                  <div :class="scope.row.products.length === 1 ? 'name-view no-bottom' : 'name-view'">
                    {{ item.price }}
                  </div>
                </li>
              </ul>
              <div v-else class="no-product">{{ "--" }}</div>
            </div>
            <div v-else-if="item.isProductTotal" class="product-view">
              <ul v-if="scope.row.products && scope.row.products.length > 0">
                <li v-for="(item, index) in scope.row.products" :key="index">
                  <div :class="scope.row.products.length === 1 ? 'name-view no-bottom' : 'name-view'">
                    {{ item.total }}
                  </div>
                </li>
              </ul>
              <div v-else class="no-product">{{ "--" }}</div>
            </div>
            <span v-else>{{ scope.row[item.prop] ? scope.row[item.prop] : "--" }}</span>
          </template>
        </el-table-column>
      </template>
          </div>
          <span v-else>
            {{
            scope.row[item.prop]
              ? scope.row[item.prop]
              : scope.row[item.prop] === 0
              ? scope.row[item.prop]
              : "--"}}
          </span>
        </template>
      </el-table-column>
      <slot name="tableButton" />
      <div slot="empty">
        <el-empty description="暂无数据"></el-empty>
      </div>
    </el-table>
    <div class="overSpread1" v-show="iscolopen" @click="onMaskClick"></div>
    <div class="styleBtn">
      <i @click="checkCol()" class="label">...</i>
@@ -118,16 +156,18 @@
export default {
  name: "TableCommonView",
  props: {
    selectBox: {
      type: Boolean,
      default: false
    },
    tableList: {
      type: Object,
      default: () => {
        return {
          selectBox: false,
          selectIndex: false,
          selectIndex: true,
          tableInfomation: [], // 接口返回数据
          showcol: [],
          allcol: [],
          highlight: false,
          tableColumn: [
            // table表单
            { label: "", prop: "", min: 200, tooltip: true }
@@ -141,8 +181,7 @@
        return {
          show: false,
          sumProp: [],
          mergeNumber: 1,
          totalName: "本页总计"
          mergeNumber: 1
        }
      }
    },
@@ -152,14 +191,24 @@
      default: () => {
        return {}
      }
    },
    loading: {
      type: Boolean,
      default: false
    },
    selectBoxList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      iscolopen: false,
      showcol: []
    }
  },
  computed: {},
  watch: {
    "tableList.showcol": {
      handler(newVal) {
@@ -168,7 +217,6 @@
      immediate: true
    }
  },
  computed: {},
  methods: {
    onMaskClick() {
      this.iscolopen = false
@@ -195,10 +243,16 @@
              .querySelector(".el-table__footer")
            var cell = current.rows[0].cells
            for (let i = 0; i < this.showSummary.mergeNumber; i++) {
              cell[i].style.display = "none"
              cell[i] && cell[i].style && (cell[i].style.display = "none")
            }
            cell[this.showSummary.mergeNumber].classList.remove("is-left")
            cell[this.showSummary.mergeNumber].colSpan = this.showSummary.mergeNumber.toString()
            if (cell[this.showSummary.mergeNumber]) {
              if (cell[this.showSummary.mergeNumber].classList) {
                cell[this.showSummary.mergeNumber].classList.remove("is-left")
              }
              if (cell[this.showSummary.mergeNumber].colSpan) {
                cell[this.showSummary.mergeNumber].colSpan = this.showSummary.mergeNumber.toString()
              }
            }
          }
        })
      }
@@ -210,7 +264,7 @@
        const sums = []
        columns.forEach((column, index) => {
          if (index === this.showSummary.mergeNumber) {
            sums[index] = this.showSummary.totalName
            sums[index] = "本页总计"
          }
          const values = data.map((item) => Number(item[column.property]))
          if (this.showSummary.sumProp.includes(column.property)) {
@@ -309,7 +363,31 @@
      }
      return fmt
    },
    // 公共详情
    // 新建编辑选择弹窗
    selNameClick(row) {
      this.$emit("selCommonClick", row)
    },
    // 销售线索
    selSalesLeadClick(row) {
      this.$emit("selSalesLeadClick", row)
    },
    // 客户名称
    selClientClick(row) {
      this.$emit("selClientClick", row)
    },
    // 联系人姓名
    selContactsClick(row) {
      this.$emit("selContactsClick", row)
    },
    // 销售总单
    selMasterClick(row) {
      this.$emit("selMasterClick", row)
    },
    // 客户服务单
    selServiceOrderClick(row) {
      this.$emit("selServiceOrderClick", row)
    },
    // 公共(销售机会、报价单、销售总单、销售子单。。。)
    selCommonClick(row) {
      this.$emit("selCommonClick", row)
    },
@@ -325,13 +403,15 @@
        }
      }
      this.$emit("tableRowClassName", row)
    },
    selectable(row) {
      let list = this.selectBoxList.map((item) => item.number)
      if (list.findIndex((v) => v == row.number) == -1) {
        return true
      } else {
        return false
      }
    }
  },
  //解决表格抖动问题
  beforeUpdate() {
    this.$nextTick(() => {
      this.$refs["table"].doLayout()
    })
  }
}
</script>
@@ -339,9 +419,6 @@
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.table-view {
  // margin-top: 20px;
  // margin-right: 10px;
  // margin-bottom: 40px;
  position: relative;
  height: 100%;
  .blue {
@@ -360,19 +437,22 @@
    margin-left: -10px;
    margin-right: -11px;
    li {
      height: 57px;
      line-height: 57px;
      height: 22px;
      line-height: 22px;
      .name-view {
        padding-left: 10px;
        border-bottom: 1px solid #ebeef5;
      }
      .no-bottom {
        border-bottom: 0px;
        border-bottom: 0;
      }
    }
    li:last-child .name-view {
      border-bottom: none;
    }
    .no-product {
      height: 57px;
      line-height: 57px;
      height: 22px;
      line-height: 22px;
    }
  }
}
@@ -382,6 +462,9 @@
      background-color: #fff;
      font-weight: bold;
    }
  }
  .el-table__fixed-body-wrapper {
    top:37px!important;
  }
}
@@ -406,9 +489,12 @@
  .el-table .cell .el-button--text.el-button--small {
    padding: 4px 0;
  }
  .el-table .onSelect {
    background: #ebf2ff;
  }
}
::v-deep .el-table .el-table__cell {
  padding: 6px 0 !important;
  height: 35px;
  text-align: center;
}
.overSpread1 {
@@ -428,8 +514,8 @@
  // line-height: 26px;
  // background: #06c062;
  top: 0;
  right: 2px;
  z-index: 9999;
  right: -6px;
  z-index: 11;
  .label {
    position: absolute;
    top: 6px;
@@ -441,7 +527,7 @@
  }
  .checkbox-group {
    width: 160px;
    height: 330px;
    height: 300px;
    overflow: auto;
    display: flex;
    flex-direction: column;