licp
2024-12-24 e4bb381c896015c4b87faa002ba6875c06a2fd16
src/components/do/b3-work-time-management/work-time-statistics.vue
@@ -9,16 +9,20 @@
            type="month"
            format="yyyy-MM"
            value-format="yyyy-MM"
            placeholder="选择月" size="small" style="width: 100%;">
            placeholder="选择月" size="small" style="width: 100%;"
            :clearable="false"
            @change="refreshTable()">
          </el-date-picker>
        </div>
         </div>
         <div class="search_thing">
            <div class="search_label">员工:</div>
            <el-select v-model="entity.name" placeholder="全部" size="small" @change="refreshTable()">
            <!-- <el-select v-model="entity.name" placeholder="全部" size="small" @change="refreshTable()" clearable>
               <el-option v-for="item in personList" :key="item.id" :label="item.name" :value="item.id">
               </el-option>
            </el-select>
            </el-select> -->
        <el-input size="small" placeholder="请输入" clearable
          v-model="entity.name" @keyup.enter.native="refreshTable()"></el-input>
         </div>
         <div class="search_thing">
            <div class="search_label">部门:</div>
@@ -36,25 +40,28 @@
            <el-button size="small" type="primary" @click="refreshTable()">查 询</el-button>
         </div>
      <div class="search_thing">
        <el-button size="small" type="primary"  @click="handleDown" v-show="currentTable == 'value0'">导 出</el-button>
        <el-button size="small" type="primary" @click="handleUp" v-show="currentTable == 'value1'">导 入</el-button>
        <el-button size="small" type="primary"  @click="handleDown" v-show="currentTable == 'value0'&&down" :loading="outLoading">导 出</el-button>
        <el-button size="small" type="primary"  @click="handleUp" v-show="currentTable == 'value1'&&up">导 入</el-button>
      </div>
      </div>
    <el-radio-group v-model="currentTable" size="small" :key="'111'" style="margin-top: 10px;">
      <el-radio-button label="value0">
        原始工时
      </el-radio-button>
      <el-radio-button label="value1">
        修正工时
      </el-radio-button>
    </el-radio-group>
    <div style="text-align: left">
      <el-radio-group v-model="currentTable" size="small" :key="'111'" style="margin-top: 10px;">
        <el-radio-button label="value0">
          原始工时
        </el-radio-button>
        <el-radio-button label="value1">
          修正工时
        </el-radio-button>
      </el-radio-group>
    </div>
    <div class="table">
      <ValueTable ref="ValueTable0"
        v-if="currentTable == 'value0'"
            :url="$api.auxiliaryWorkingHours.selectAuxiliaryWorkingHours"
            :componentData="componentData" :inputUrl="$api.auxiliaryWorkingHours.selectAuxiliaryWorkingHours" :downUrl="$api.auxiliaryWorkingHours.selectAuxiliaryWorkingHours" :key="upIndex" />
      <ValueTable ref="ValueTable1"
        v-if="currentTable == 'value1'"
        v-if="currentTable == 'value0'" :isColumnWidth="true"
                  :isShowZero="true"
            :url="$api.auxiliaryOriginalHours.selectAuxiliaryOriginalHours"
            :componentData="componentData" :key="upIndex" />
      <ValueTable ref="ValueTable1" :isShowZero="true"
        v-if="currentTable == 'value1'" :isColumnWidth="true"
            :url="$api.auxiliaryCorrectionHours.selectAuxiliaryCorrectionHours"
        :inputUrl="$api.auxiliaryCorrectionHours.upload"
            :componentData="componentData0"
@@ -74,53 +81,56 @@
  },
  data () {
    return{
      down:false,
      up:false,
      componentData: {
               entity: {
                  month: getYearAndMonthAndDays().split('-')[0]+'-'+getYearAndMonthAndDays().split('-')[1],
                  name: null,
                  departLims: null,
                  orderBy: {
                     field: 'id',
                     order: 'desc'
                  }
               },
               isIndex: true,
               showSelect: false,
               select: false,
               do: [],
               tagField: {},
               linkEvent: {},
               selectField: {},
               requiredAdd: [],
               requiredUp: [],
          accept: '.xlsx',
          inputType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        entity: {
          month: getYearAndMonthAndDays().split('-')[0]+'-'+getYearAndMonthAndDays().split('-')[1],
          name: null,
          departLims: null,
        },
        isIndex: true,
        showSelect: false,
        select: false,
        do: [],
        tagField: {},
        linkEvent: {},
        selectField: {},
        requiredAdd: [],
        requiredUp: [],
        accept: '.xlsx',
        inputType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        cellSpecialStyle:{
          redColorByKey:'Hours'
        },
         },
      componentData0: {
               entity: {
                  month: getYearAndMonthAndDays().split('-')[0]+'-'+getYearAndMonthAndDays().split('-')[1],
                  name: null,
                  departLims: null,
                  orderBy: {
                     field: 'id',
                     order: 'desc'
                  }
               },
               isIndex: true,
               showSelect: false,
               select: false,
               do: [],
               tagField: {},
               linkEvent: {
                  },
               selectField: {},
               requiredAdd: [],
               requiredUp: [],
          accept: '.xlsx',
          inputType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        entity: {
          month: getYearAndMonthAndDays().split('-')[0]+'-'+getYearAndMonthAndDays().split('-')[1],
          name: null,
          departLims: null,
          orderBy: {
            field: 'id',
            order: 'desc'
          }
        },
        isIndex: true,
        showSelect: false,
        select: false,
        do: [],
        tagField: {},
        linkEvent: {
        },
        selectField: {},
        requiredAdd: [],
        requiredUp: [],
        accept: '.xlsx',
        inputType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
         },
      entity:{
        month:getYearAndMonthAndDays()
        month:getYearAndMonthAndDays(),
        name:'',
        departLims:''
      },
      entityCopy:{},
      entityCopy0:{},
@@ -128,13 +138,15 @@
      upIndex1:100,
      weekList:[],
      personList:[],
      currentTable:'value0'
      currentTable:'value0',
      outLoading:false
    }
  },
  mounted(){
    this.getUsers()
    this.entityCopy = this.HaveJson(this.componentData.entity);
    this.entityCopy0 = this.HaveJson(this.componentData0.entity);
    this.getPower()
  },
  methods: {
    refresh(){
@@ -152,6 +164,7 @@
    },
    refreshTable(){
      let entity = {...this.entity}
      entity.month = entity.month.split('-')[0]+'-'+entity.month.split('-')[1]
      if(this.currentTable=='value0'){
        this.componentData.entity = {...this.componentData.entity,...entity}
        this.$refs['ValueTable0'].selectList()
@@ -182,10 +195,61 @@
        })
    },
    handleDown(){
      this.$refs.ValueTable0.downFile(false)
      // this.$refs.ValueTable0.downFile(false)
      let entity = {...this.entity}
      entity.month = entity.month.split('-')[0]+'-'+entity.month.split('-')[1]
      this.outLoading = true
      this.$axios.post(this.$api.auxiliaryOriginalHours.exportOriginalHours,{
        ...entity
        // params:entity,
      },{responseType: "blob"}).then(res => {
        this.outLoading = false
        const blob = new Blob([res],{ type: 'application/octet-stream' });
        //将Blob 对象转换成字符串
        let reader = new FileReader();
        reader.readAsText(blob, 'utf-8');
        reader.onload = () => {
          try {
            let result = JSON.parse(reader.result);
            if (result.message) {
              this.$message.error(result.message);
            } else {
              const url = URL.createObjectURL(blob);
              const link = document.createElement('a');
              link.href = url;
              link.download = entity.month+'工时统计表.xlsx';
              link.click();
              this.$message.success('导出成功')
            }
          } catch (err) {
            console.log(err);
            const url = URL.createObjectURL(blob);
            const link = document.createElement('a');
            link.href = url;
            link.download = entity.month+'工时统计表.xlsx';
            link.click();
            this.$message.success('导出成功')
          }
        }
      })
    },
    handleUp(){
      this.$refs.ValueTable1.openUpload()
    },
    getPower(){
      let power = JSON.parse(sessionStorage.getItem('power'))
        let up = false
        let down = false
        for (var i = 0; i < power.length; i++) {
               if (power[i].menuMethod == 'exportOriginalHours') {
                  down = true
               }
               if (power[i].menuMethod == 'upload') {
                  up = true
               }
            }
        this.down = down
        this.up = up
    }
  }
}