licp
2024-09-06 ed2342a8cadcd9519858ecd5d440fcba4d66a02d
src/components/tool/value-table.vue
@@ -4,6 +4,10 @@
    height: 100%;
    overflow-y: auto;
  }
  >>>.el-table__row {
    cursor: move;
    position: relative;
  }
  .table {
    width: 100%;
@@ -51,6 +55,9 @@
  }
  .red{
    color: red !important;
  }
  >>>.el-loading-parent--relative {
    z-index: 1 !important;
  }
</style>
<style>
@@ -104,6 +111,7 @@
    display: inline-block;
    margin-left: 200px;
  }
</style>
<template>
@@ -112,25 +120,25 @@
      <el-table ref="eltable" :data="tableData" style="width: 100%;" height="100%" tooltip-effect="dark" border
        @selection-change="selectChange" @select="select" v-loading="loading" @sort-change="sortChange"
        @row-click="rowClick" :show-summary="data.countFleid!=undefined && data.countFleid.length > 0"
        :summary-method="getSummaries" :row-class-name="tableRowClassName" :row-key="record=>record.id"
        :summary-method="getSummaries" :row-class-name="tableRowClassName" :row-key="record=>record[rowKey]"
        :current-row-key="data.currentId" :highlight-current-row="data.highlight===undefined||data.highlight"
        :span-method="spanMethod" :key="specialKey">
        <el-table-column type="selection" width="65" v-if="data.showSelect" :key="Math.random()">
        :span-method="spanMethod" :key="specialKey" :class="{sortable:data.sortable}">
        <el-table-column type="selection" :width="selectionWidth" v-if="data.showSelect" :key="Math.random()">
        </el-table-column>
        <el-table-column type="index" align="center" label="序号" width="65" v-if="data.isIndex" :key="Math.random()">
        <el-table-column type="index" align="center" label="序号" :width="selectionWidth" v-if="data.isIndex" :key="Math.random()">
        </el-table-column>
        <el-table-column :prop="a.label" :label="a.value" :sortable="data.sort==false?false:'custom'"
          v-for="(a, ai) in tableHead" :key="ai" show-overflow-tooltip min-width="155" v-if="!data.headNoShow||(data.headNoShow&&data.headNoShow.length==0)||(data.headNoShow&&data.headNoShow.length>0&&!data.headNoShow.find(d=>d==a.label))">
        <el-table-column :prop="a.label" :label="a.value" :sortable="a.sort === 'custom' ? 'custom' : false" :isColumnWidth="isColumnWidth" :isShowZero="isShowZero"
          v-for="(a, ai) in tableHead" :key="ai+'bbbbb'" show-overflow-tooltip :min-width="columnMinWidth" v-if="!data.headNoShow||(data.headNoShow&&data.headNoShow.length==0)||(data.headNoShow&&data.headNoShow.length>0&&!data.headNoShow.find(d=>d==a.label))">
          <template slot-scope="scope">
            <div v-if="showType(a.label, data.tagField) != null">
              <template v-if="typeof(scope.row[a.label]) == 'object'">
                <template v-for="(param, i) in scope.row[a.label]">
                  <el-tag v-for="(b, bi) in data.tagField[a.label].select" :key="bi" v-if="b.value == param"
                  <el-tag v-for="(b, bi) in data.tagField[a.label].select" :key="bi+'cccc'" v-if="b.value == param"
                    :type="b.type" size="medium" style="margin-right: 5px;">{{b.label}}</el-tag>
                </template>
              </template>
              <template v-else>
                <el-tag v-for="(b, bi) in data.tagField[a.label].select" :key="bi" v-if="b.value == scope.row[a.label]"
                <el-tag v-for="(b, bi) in data.tagField[a.label].select" :key="bi+'ddddd'" v-show="b.value == scope.row[a.label]"
                  :type="b.type" size="medium">{{b.label}}</el-tag>
              </template>
            </div>
@@ -144,7 +152,8 @@
        </el-table-column>
        <el-table-column fixed="right" align="center" label="操作" :width="getWidth()" v-if="data.do.length > 0">
          <template slot-scope="scope">
            <el-button v-for="(a, ai) in data.do" :key="ai" :type="a.type"
            <el-button v-for="(a, ai) in data.do" :key="ai
            +'qqqq'" :type="a.type"
              :disabled="a.disabFun ? a.disabFun(scope.row,scope.$index) : false" @click="main(scope.row, a)"
              class="handleBtn">
              <span v-if="a.type!='upload'">{{a.font}}</span>
@@ -168,7 +177,7 @@
    <el-dialog title="编辑" :visible.sync="upDia" :width="data.row==1?'500px':540+data.row * 200 + 'px'" append-to-body>
      <div class="body" style="max-height: 550px;overflow-y: auto;padding: 5px 10px 5px 0;">
        <div v-if="data.row > 1">
          <div v-for="(a, ai) in upHead" :key="ai" style="line-height: 50px;">
          <div v-for="(a, ai) in upHead" :key="ai+'ffff'" style="line-height: 50px;">
            <el-col :span="6/data.row" style="text-align: right;" :offset="1">
              <span class="required-span" v-if="showUpReq(a.label)">* </span>{{a.value}}:
            </el-col>
@@ -179,7 +188,7 @@
              <el-select v-model="upData[a.label]" :multiple="data.selectField[a.label].choose" size="small"
                v-if="showType(a.label, data.selectField) != null" style="width: 100%;" :disabled="isDisabled(a.label)"
                clearable filterable>
                <el-option v-for="(b, bi) in data.selectField[a.label].select" :key="bi" :value="b.value"
                <el-option v-for="(b, bi) in data.selectField[a.label].select" :key="bi+'eeeee'" :value="b.value"
                  :label="b.label">
                </el-option>
              </el-select>
@@ -200,7 +209,7 @@
          </div>
        </div>
        <div v-else>
          <el-row v-for="(a, ai) in upHead" :key="ai" style="line-height: 50px;">
          <el-row v-for="(a, ai) in upHead" :key="ai+'ggggg'" style="line-height: 50px;">
            <el-col :span="6" style="text-align: right;">
              <span class="required-span" v-if="showUpReq(a.label)">* </span>{{a.value}}:
            </el-col>
@@ -211,7 +220,7 @@
              <el-select v-model="upData[a.label]" :multiple="data.selectField[a.label].choose" size="small"
                v-if="showType(a.label, data.selectField) != null" style="width: 100%;" :disabled="isDisabled(a.label)"
                clearable filterable>
                <el-option v-for="(b, bi) in data.selectField[a.label].select" :key="bi" :value="b.value"
                <el-option v-for="(b, bi) in data.selectField[a.label].select" :key="bi+'fffff'" :value="b.value"
                  :label="b.label"></el-option>
              </el-select>
              <el-upload :action="javaApi+data.addUploadConfig.url" v-if="showUpload(a.label)" :multiple="false"
@@ -237,7 +246,7 @@
    <el-dialog title="新增" :visible.sync="addDia" :width="data.row==1?'500px':540+data.row * 200 + 'px'" append-to-body>
      <div class="body" v-if="addDia" style="max-height: 550px;overflow-y: auto;padding: 5px 10px 5px 0;">
        <div v-if="data.row > 1">
          <div v-for="(a, ai) in upHead" :key="ai" style="line-height: 50px;">
          <div v-for="(a, ai) in upHead" :key="ai+'yyyyy'" style="line-height: 50px;">
            <el-col :span="6/data.row" style="text-align: right;" :offset="1"><span class="required-span"
                v-if="showAddReq(a.label)">*
              </span>{{a.value}}:</el-col>
@@ -247,7 +256,7 @@
              <el-select v-model="upData[a.label]" size="small" v-if="showType(a.label, data.selectField) != null"
              :multiple="data.selectField[a.label].choose"
                style="width: 100%;" :placeholder="`请选择${a.value}`" clearable filterable>
                <el-option v-for="(b, bi) in data.selectField[a.label].select" :key="bi" :value="b.value"
                <el-option v-for="(b, bi) in data.selectField[a.label].select" :key="bi+'hhhh'" :value="b.value"
                  :label="b.label"></el-option>
              </el-select>
              <el-upload :action="javaApi+data.addUploadConfig.url" v-if="showUpload(a.label)"
@@ -266,7 +275,7 @@
          </div>
        </div>
        <div v-else>
          <el-row v-for="(a, ai) in upHead" :key="ai" style="line-height: 50px;">
          <el-row v-for="(a, ai) in upHead" :key="ai+'jjjjj'" style="line-height: 50px;">
            <el-col :span="6" style="text-align: right;"><span class="required-span" v-if="showAddReq(a.label)">*
              </span>{{a.value}}:</el-col>
            <el-col :span="16" :offset="1">
@@ -275,7 +284,7 @@
              <el-select v-model="upData[a.label]" size="small" v-if="showType(a.label, data.selectField) != null"
              :multiple="data.selectField[a.label].choose"
                style="width: 100%;" :placeholder="`请选择${a.value}`" clearable>
                <el-option v-for="(b, bi) in data.selectField[a.label].select" :key="bi" :value="b.value"
                <el-option v-for="(b, bi) in data.selectField[a.label].select" :key="bi+'mmmmmm'" :value="b.value"
                  :label="b.label"></el-option>
              </el-select>
              <el-upload :action="javaApi+data.addUploadConfig.url" v-if="showUpload(a.label)"
@@ -327,16 +336,33 @@
</template>
<script>
  import {
    Page
  } from 'iview';
  import {
    data
  } from 'jquery';
  import Sortable from 'sortablejs';
  export default {
    props: {
      selectionWidth: {
        type: String,
        default: () => '65'
      },
      columnMinWidth: {
        type: String,
        default: () => '155'
      },
      isColumnWidth: {
        type: Boolean,
        default: () => false
      },
      isShowZero: {
        type: Boolean,
        default: () => false
      },
      tableRowClassName: {
        type: Function
      },
      rowKey: {
        type: String,
        default: ()=>{
          return 'id'
        }
      },
      url: {
        type: String,
@@ -476,8 +502,37 @@
        'token': sessionStorage.getItem('token')
      }
      this.specialKey = this.specialKey+Math.random()*100;
      // 是否可拖动列表--此功能暂时未实现
      if(this.data.sortable){
        this.$nextTick(() => {
          this.initializeSortable()
        })
      }
    },
    methods: {
      initializeSortable() {
        let className =".el-table__body-wrapper > table > tbody";
        const table= document.querySelector(className);
        const self = this
        Sortable.create(table, {
        animation: 150, //动画时长
        handle: ".el-table__row", //可拖拽区域class
        onEnd({ newIndex, oldIndex }) {
            console.log(3333,newIndex, oldIndex)
            const movedItem = this.tableData[oldIndex];
            this.tableData.splice(oldIndex, 1);
            this.tableData.splice(newIndex, 0, movedItem);
          }
        })
      },
      getUpdatedOrder() {
        // 根据拖拽后的顺序获取更新的数据
        // 这里需要实现你的逻辑
      },
      updateTableData(newOrder) {
        // 根据新的顺序更新表格数据
        // 这里需要实现你的逻辑
      },
      rowspan(spanArr, position, spanName) {
        this.tableData.forEach((item, index) => {
          if (index === 0) {
@@ -574,9 +629,14 @@
        this.selectList('page')
      },
      selectList(val) {
        // console.log('val---', val)
        // console.log('this.page---', this.page)
        this.loading = true
        if(val===undefined){
          this.page.current = 1;
        }
        if (val === 'lastPage') {
          this.page.current = this.page.current - 1 // 例如删除本页最后一条数据,将当前页面定为上一页,除第一页外
        }
        if (this.data.isPage != undefined && this.data.isPage != true) {
          this.page = {
@@ -599,6 +659,49 @@
          this.total = res.data.body.total
          this.tableHead = res.data.head
          this.tableData = res.data.body.records
          if (this.data.needSort !== undefined) {
            for (var i = 0; i < this.data.needSort.length; i++) {
              this.tableHead.forEach(item => {
                if (item.label === this.data.needSort[i]) {
                  item.sort = 'custom'
                }
              })
            }
          }
          if (this.isShowZero) {
            this.tableData.map(item => {
              Object.keys(item).forEach(val => {
                if (item[val] === null && (val.includes('Hours') || val === 'total')) {
                  item[val] = 0
                }
              })
            })
          }
          if (this.tableData.length === 0 && this.page.current > 1) {
            this.selectList('lastPage')
          }
          // if (this.isColumnWidth) {
          //   this.tableHead.forEach(item => {
          //     if(!item.width){
          //       if (item.value.length === 4) {
          //         item.width = 120
          //       } else if (item.value.length === 3){
          //         item.width = item.label.includes('Hours') ? 50 : 100
          //       } else if (item.value.length === 5){
          //         item.width = 130
          //       } else if (item.value.length === 7){
          //         item.width = 160
          //       } else if (item.value.length === 6){
          //         item.width = 150
          //       }  else if (item.value.length === 2){
          //         item.width = item.label.includes('Hours') ? 52 : 86
          //       } else {
          //         item.width = item.label.includes('Hours') ? 46 : 86
          //       }
          //     }
          //   })
          // }
          // console.log(JSON.stringify(this.tableHead)+"---------"+JSON.stringify(this.tableData))
          for (var a in this.data.selectField) {
            if (this.data.selectField[a].choose == true) {
@@ -766,7 +869,7 @@
                  return
                }
                this.$message.success('删除成功')
                this.selectList()
                this.selectList('page')
                this.$emit('delete')
              }).catch(e => {
                this.$message.error('删除失败')
@@ -793,21 +896,30 @@
            return
          }
        }
        this.upLoad = true
        for (var a in this.data.selectField) {
          if (this.data.selectField[a].choose == true) {
            this.upData[a] = JSON.stringify(this.upData[a])
          }
        }
        this.upHead.forEach((item, index) => {
          if (this.data.cascaderField && this.data.cascaderField[item.label]) {
            if (this.upData[item.label]) {
              this.upData[item.label] = JSON.stringify(this.upData[item.label])
            } else {
              this.upData[item.label] = ''
        for (var i = 0; i < this.upHead.length; i++) {
          if(this.upHead[i].label == 'password'){
            if(this.upData[this.upHead[i].label]){
              const reg2 =/^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\d)(?=.*?[~!#@$%^*&()_+{}\[\]|\\;:'",<.>\/?])[a-zA-Z\d~!#@$%^*&()_+{}\[\]|\\;:'",<.>\/?]*$/;
              if (!reg2.test(this.upData[this.upHead[i].label])) {
                this.$message.error('密码必须包括数字、大小写字母以及特殊字符')
                return
              }
            }
          }
        })
          if (this.data.cascaderField && this.data.cascaderField[this.upHead[i].label]) {
            if (this.upData[this.upHead[i].label]) {
              this.upData[this.upHead[i].label] = JSON.stringify(this.upData[this.upHead[i].label])
            } else {
              this.upData[this.upHead[i].label] = ''
            }
          }
        }
        this.upLoad = true
        this.$axios.post(this.upUrl, this.upData, {
          headers: {
            'Content-Type': 'application/json'
@@ -819,7 +931,7 @@
          }
          this.$message.success('修改成功')
          this.upDia = false
          this.selectList()
          this.selectList('page')
          this.$refs.eltable.doLayout();
          this.upLoad = false
        }).catch(e => {
@@ -911,7 +1023,7 @@
          }
          this.$message.success('添加成功')
          this.addDia = false
          this.selectList()
          this.selectList('page')
          this.addLoad = false
        }).catch(e => {
          this.addDia = false
@@ -1088,7 +1200,7 @@
                return
              }
              this.$message.success('删除成功')
              this.selectList()
              this.selectList('page')
            }).catch(e => {
              this.$message.error('删除失败')
            })
@@ -1097,6 +1209,35 @@
          this.$message.error('请选择要删除的数据')
        }
      },
      // 日工时管理辅助工时--批量审核和批准
      batchCheck(e) {
        if (this.multipleSelection && this.multipleSelection.length > 0) {
          const list = JSON.parse(JSON.stringify(this.multipleSelection))
          const url = e === 0 ? this.$api.auxiliaryWorkingHoursDay.check : this.$api.auxiliaryWorkingHoursDay.approve
          const state = e === 0 ? '已审核' : '已批准'
          let auxiliaryWorkingHoursDays = []
          list.forEach(item => {
            delete item.orderBy
            item.state = state
            auxiliaryWorkingHoursDays.push(item)
          })
          this.$axios.post(url, {auxiliaryWorkingHoursDays: auxiliaryWorkingHoursDays
            },{
              headers: {
                'Content-Type': 'application/json'
              }
            }
          ).then(res => {
            if (res.code === 201) {
              return
            }
            this.$parent.submitBatchCheckDialog()
            this.$message.success('操作成功')
          })
        } else {
          this.$message.error('请选择至少一条数据')
        }
      },
      getRedColor(label,row){
        if(this.data.cellSpecialStyle&&this.data.cellSpecialStyle.redColorByKey&&label.includes(this.data.cellSpecialStyle.redColorByKey)&&row[(label.replace(this.data.cellSpecialStyle.redColorByKey, ""))]){
          return true