lxp
2024-08-07 083bc1030f7dda031f04976c7f02109d31eeff0e
src/components/tool/value-table.vue
@@ -49,6 +49,12 @@
  .handleBtn.is-disabled {
    color: #C0C4CC;
  }
  .red{
    color: red !important;
  }
  >>>.el-loading-parent--relative {
    z-index: 1 !important;
  }
</style>
<style>
  /* .value-table .highlight-warning-row-border td {
@@ -95,6 +101,13 @@
    align-items: center;
    justify-content: center;
  }
  .el-table__empty-text{
    text-align: left;
    width: 100%;
    display: inline-block;
    margin-left: 200px;
  }
</style>
<template>
@@ -105,13 +118,13 @@
        @row-click="rowClick" :show-summary="data.countFleid!=undefined && data.countFleid.length > 0"
        :summary-method="getSummaries" :row-class-name="tableRowClassName" :row-key="record=>record.id"
        :current-row-key="data.currentId" :highlight-current-row="data.highlight===undefined||data.highlight"
        :span-method="spanMethod">
        <el-table-column type="selection" width="65" v-if="data.showSelect" :key="Math.random()">
        :span-method="spanMethod" :key="specialKey">
        <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">
        <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" 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'">
@@ -130,7 +143,7 @@
              @click="handleLinkEvent(scope.row,data.linkEvent[a.label])">{{scope.row[a.label]}}</span>
            <img style="width: 40px;height: 40px;margin-top: 10px;" :src="javaApi+'/img/'+scope.row[a.label]"
              v-else-if="showUpload(a.label)&&scope.row[a.label]" alt="">
            <span v-else>{{scope.row[a.label]}}</span>
            <span v-else :class="{red:getRedColor(a.label,scope.row)}" >{{scope.row[a.label]}}</span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" align="center" label="操作" :width="getWidth()" v-if="data.do.length > 0">
@@ -156,7 +169,7 @@
        :total="total">
      </el-pagination>
    </div>
    <el-dialog title="编辑" :visible.sync="upDia" :width="data.row==1?'500px':500+data.row * 200 + 'px'" append-to-body>
    <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;">
@@ -225,14 +238,14 @@
        <el-button type="primary" @click="saveUpData" :loading="upLoad">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="新增" :visible.sync="addDia" :width="data.row==1?'500px':500+data.row * 200 + 'px'" append-to-body>
    <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;">
            <el-col :span="6/data.row" style="text-align: right;"><span class="required-span"
            <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>
            <el-col :span="16/data.row" :offset="1">
            <el-col :span="16/data.row">
              <el-input v-model="upData[a.label]" size="small" clearable :placeholder="`请输入${a.value}`"
                v-if="showType(a.label, data.selectField) == null&&!showUpload(a.label)&&!showCascader(a.label)"></el-input>
              <el-select v-model="upData[a.label]" size="small" v-if="showType(a.label, data.selectField) != null"
@@ -303,7 +316,7 @@
    <el-dialog title="数据导入" :visible.sync="uploadDia" width="500px">
      <div style="margin: 0 auto;">
        <el-upload ref="upload" drag :action="javaApi + inputUrl" :headers="token" :file-list="fileList" name="file"
          :auto-upload="false" accept=".csv" :limit="1" :on-change="beforeUpload" :on-success="onSuccess"
          :auto-upload="false" :accept="data.accept===undefined?'.csv':data.accept" :limit="1" :on-change="beforeUpload" :on-success="onSuccess"
          :on-error="onError" :data="{param: data.uploadStr}">
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
@@ -326,6 +339,22 @@
  } from 'jquery';
  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
      },
@@ -448,7 +477,8 @@
          //   position:0
          // }
        ],
        param: {}
        param: {},
        specialKey:'table-'
      }
    },
    beforeUpdate() {
@@ -465,6 +495,7 @@
      this.token = {
        'token': sessionStorage.getItem('token')
      }
      this.specialKey = this.specialKey+Math.random()*100;
    },
    methods: {
      rowspan(spanArr, position, spanName) {
@@ -556,14 +587,22 @@
      },
      sizeChange(val) {
        this.page.size = val
        this.selectList()
        this.selectList('page')
      },
      currentChange(val) {
        this.page.current = val
        this.selectList()
        this.selectList('page')
      },
      selectList() {
      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 = {
            current: -1,
@@ -585,6 +624,50 @@
          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) {
              this.tableData.map(b => {
@@ -751,7 +834,8 @@
                  return
                }
                this.$message.success('删除成功')
                this.selectList()
                this.selectList('page')
                this.$emit('delete')
              }).catch(e => {
                this.$message.error('删除失败')
              })
@@ -777,21 +861,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'
@@ -803,7 +896,7 @@
          }
          this.$message.success('修改成功')
          this.upDia = false
          this.selectList()
          this.selectList('page')
          this.$refs.eltable.doLayout();
          this.upLoad = false
        }).catch(e => {
@@ -895,7 +988,7 @@
          }
          this.$message.success('添加成功')
          this.addDia = false
          this.selectList()
          this.selectList('page')
          this.addLoad = false
        }).catch(e => {
          this.addDia = false
@@ -952,7 +1045,8 @@
        this.uploadDia = true
      },
      beforeUpload(file, fileList) {
        if (file.raw.type != 'text/csv') {
        console.log(file.raw.type);
        if (file.raw.type != (this.data.inputType===undefined?'text/csv':this.data.inputType)) {
          this.$message.error('上传文件格式不正确');
          this.$refs.upload.clearFiles()
          return false;
@@ -1071,7 +1165,7 @@
                return
              }
              this.$message.success('删除成功')
              this.selectList()
              this.selectList('page')
            }).catch(e => {
              this.$message.error('删除失败')
            })
@@ -1080,6 +1174,42 @@
          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
        }else{
          return false
        }
      }
    }
  }
</script>