gaoluyang
2024-07-31 38e6f27a8082e1173e3c02a33da5da39b6c6872c
src/components/do/b3-work-time-management/work-time-management.vue
@@ -1,7 +1,7 @@
<template>
  <div class="work-time-management">
    <div class="search">
      <div class="search_thing">
      <!-- <div class="search_thing">
            <div class="search_label">周次:</div>
            <div class="search_input" style="display: flex;align-items: center;">
          <el-input size="small" placeholder="开始周次" clearable
@@ -10,7 +10,7 @@
          <el-input size="small" placeholder="结束周次" clearable
                  v-model="entity.week2"></el-input>
        </div>
         </div>
         </div> -->
         <div class="search_thing" style="width: 200px;">
            <div class="search_label">星期:</div>
            <el-select v-model="entity.weekDay" placeholder="全部" size="small" @change="refreshTable()" clearable>
@@ -18,7 +18,7 @@
               </el-option>
            </el-select>
         </div>
         <div class="search_thing">
         <div class="search_thing" style="width: 390px;">
            <div class="search_label" style="width: 90px;">时间范围:</div>
            <div class="search_input">
          <el-date-picker
@@ -27,8 +27,8 @@
            size="small"
            type="daterange"
            range-separator="至"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            start-placeholder="开始日期"
            end-placeholder="结束日期" @change="refreshTable()" clearable>
          </el-date-picker>
@@ -63,20 +63,23 @@
      </el-radio-group>
      <div style="display: flex;align-items: center;">
        <p style="font-size: 14px;margin-right: 30px;">
          总工时汇总:<span style="font-size: 16px;color: #3A7BFA;">{{ (totalInfo['产量工时汇总']+totalInfo['辅助工时汇总'])? (totalInfo['产量工时汇总']+totalInfo['辅助工时汇总']):0 }}</span>&nbsp;&nbsp;&nbsp;&nbsp;产量工时汇总:<span style="font-size: 16px;color: #3A7BFA;">{{totalInfo['产量工时汇总']?totalInfo['产量工时汇总']:0}}</span>&nbsp;&nbsp;&nbsp;&nbsp;辅助工时汇总:<span style="font-size: 16px;color: #3A7BFA;">{{totalInfo['辅助工时汇总']?totalInfo['辅助工时汇总']:0}}</span>
          总工时汇总:<span style="font-size: 16px;color: #3A7BFA;" v-if="totalInfo">{{ (totalInfo['产量工时汇总']+totalInfo['辅助工时汇总'])? Number((totalInfo['产量工时汇总']+totalInfo['辅助工时汇总'])).tofixed(4):0 }}</span>&nbsp;&nbsp;&nbsp;&nbsp;产量工时汇总:<span style="font-size: 16px;color: #3A7BFA;" v-if="totalInfo">{{totalInfo['产量工时汇总']?Number(totalInfo['产量工时汇总']).tofixed(4):0}}</span>&nbsp;&nbsp;&nbsp;&nbsp;辅助工时汇总:<span style="font-size: 16px;color: #3A7BFA;" v-if="totalInfo">{{totalInfo['辅助工时汇总']?Number(totalInfo['辅助工时汇总']).tofixed(4):0}}</span>
        </p>
        <el-button size="small" type="primary" style="margin-right: 16px;" @click="openAdd" v-show="currentTable == 'ValueTable0'">录入数据</el-button>
        <el-button size="small" type="primary" @click="handleOut" :loading="outLoading">导 出</el-button>
        <el-button size="small" type="primary" @click="openAdd" v-show="currentTable == 'ValueTable0'&&add">录入数据</el-button>
        <el-button size="small" type="primary"
        v-if="down"
        @click="handleOut" :loading="outLoading">导 出</el-button>
        <el-button size="small" type="primary" v-show="currentTable == 'ValueTable0'&&add" @click="openBatchCheck(0)">批量审核</el-button>
        <el-button size="small" type="primary" v-show="currentTable == 'ValueTable0'&&add" @click="openBatchCheck(1)">批量批准</el-button>
      </div>
    </div>
    <div class="table">
      <ValueTable ref="ValueTable0"
        v-if="currentTable == 'ValueTable0'"
        v-if="currentTable == 'ValueTable0'" :isColumnWidth="true"
            :url="$api.auxiliaryWorkingHoursDay.selectAuxiliaryWorkingHoursDay"
            :delUrl="$api.auxiliaryWorkingHoursDay.deleteAuxiliaryWorkingHoursDay" :componentData="componentData" :key="upIndex"
        @delete="handleDelete" />
      <ValueTable ref="ValueTable1"
      v-if="currentTable == 'ValueTable1'"
      <ValueTable ref="ValueTable1" v-if="currentTable == 'ValueTable1'" :isColumnWidth="true"
            :url="$api.auxiliaryOutputWorkingHours.selectAuxiliaryOutputWorkingHours" :componentData="componentData1" :key="upIndex1" />
    </div>
    <el-dialog :title="formData.id?'编辑':'录入数据'" :visible.sync="addVisible" width="600px" :before-close="handleClose">
@@ -158,13 +161,16 @@
              </el-select>
            </el-form-item>
            <el-form-item label="姓名:">
              <el-input v-model="formData0.nameUser" size="small" disabled></el-input>
              <el-input v-model="formData0.name" size="small" disabled></el-input>
            </el-form-item>
            <el-form-item label="班次:">
              <el-select v-model="formData0.shift" placeholder="请选择" size="small" :disabled="title=='批准'">
                <el-option v-for="item in classType" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="复核说明:">
              <el-input v-model="formData0.reviewerRemark" type="textarea" :rows="3" size="small" :disabled="title=='批准'"></el-input>
            </el-form-item>
          </el-form>
            </el-col>
@@ -174,6 +180,9 @@
              <el-input v-model="formData0.number" size="small" :disabled="title=='批准'"></el-input>
            </el-form-item>
            <el-form-item label="数量:" required>
              <el-input v-model="formData0.amount" size="small" :disabled="title=='批准'"></el-input>
            </el-form-item>
            <el-form-item label="复核数量:" required>
              <el-input v-model="formData0.reviewerNumber" size="small" :disabled="title=='批准'"></el-input>
            </el-form-item>
            <el-form-item label="核准工时:">
@@ -188,12 +197,6 @@
          </el-form>
            </el-col>
         </el-row>
      <el-form :model="formData0" label-width="90px">
        <el-form-item label="复核说明:">
          <el-input v-model="formData0.reviewerRemark" type="textarea"
  :rows="3" size="small" :disabled="title=='批准'"></el-input>
        </el-form-item>
      </el-form>
         <span slot="footer" class="dialog-footer">
            <el-row>
               <el-button @click="submitCheck(0)" :loading="checkLoadN">{{title=='审核'?'不通过':'不批准'}}</el-button>
@@ -201,6 +204,17 @@
            </el-row>
         </span>
      </el-dialog>
    <el-dialog
      :title="batchCheckTitle"
      :visible.sync="batchCheckDialog"
      width="30%"
      :before-close="closeBatchCheckDialog">
      <span>{{batchCheckDialogMessage}}</span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="batchCheckDialog = false">{{batchCheckTitle=='批量审核'?'不通过':'不批准'}}</el-button>
    <el-button type="primary" @click="batchCheck">{{batchCheckTitle=='批量审核'?'通 过':'批 准'}}</el-button>
  </span>
    </el-dialog>
  </div>
</template>
@@ -215,99 +229,111 @@
  },
  data () {
    return{
      entity:{},
      entity:{
        dateTime: []
      },
      down:false,
      add:false,
      componentData: {
               entity: {
                  week: null,
                  weekDay: null,
                  dateTime: null,
            name:null,
                  orderBy: {
                     field: 'id',
                     order: 'desc'
                  }
               },
               isIndex: true,
               showSelect: false,
               select: false,
               do: [{
                  id: 'delete',
                  font: '删除',
                  type: 'text',
                  method: 'doDiy'
               }, {
                  id: 'handleEdit',
                  font: '编辑',
                  type: 'text',
                  method: 'handleEdit'
               },{
                  id: 'handleCheck',
                  font: '审核',
                  type: 'text',
                  method: 'handleCheck'
               }, {
                  id: 'handleRatify',
                  font: '批准',
                  type: 'text',
                  method: 'handleRatify'
               }],
               tagField: {
            shift:{
              select:[]
            },
            state:{
              select:[
                {
                  label:'已提交',
                  value:'已提交',
                  type:'primary'
                },
                {
                  label:'已审核',
                  value:'已审核',
                  type:'warning'
                },
                {
                  label:'已批准',
                  value:'已批准',
                  type:'success'
                },
              ]
            },
            weekDay:{
              select:[]
            }
        entity: {
          week: null,
          weekDay: null,
          dateTime: null,
          name:null,
          orderBy: {
            field: 'id',
            order: 'desc'
          }
        },
        isIndex: true,
        showSelect: true,
        select: true,
        selectMethod: 'handleChangeTask',
        do: [{
          id: 'delete',
          font: '删除',
          type: 'text',
          method: 'doDiy'
        }, {
          id: 'handleEdit',
          font: '编辑',
          type: 'text',
          method: 'handleEdit'
        },{
          id: 'handleCheck',
          font: '审核',
          type: 'text',
          method: 'handleCheck',
          disabFun: (row, index) => {
            return row.state === '已审核' || row.state === '已批准'
          }
        }, {
          id: 'handleRatify',
          font: '批准',
          type: 'text',
          method: 'handleRatify',
          disabFun: (row, index) => {
            return row.state === '已批准'
          }
        }],
        tagField: {
          shift:{
            select:[]
          },
               linkEvent: {},
               selectField: {
            shift:{
              select:[]
            },
            state:{
              select:[
                {
                  label:'已提交',
                  value:'已提交',
                  type:'primary'
                },
                {
                  label:'已审核',
                  value:'已审核',
                  type:'warning'
                },
                {
                  label:'已批准',
                  value:'已批准',
                  type:'success'
                },
              ]
            },
            weekDay:{
              select:[]
            }
          state:{
            select:[
              {
                label:'已提交',
                value:'已提交',
                type:'primary'
              },
              {
                label:'已审核',
                value:'已审核',
                type:'warning'
              },
              {
                label:'已批准',
                value:'已批准',
                type:'success'
              },
            ]
          },
               requiredAdd: [],
               requiredUp: []
          weekDay:{
            select:[]
          }
        },
        linkEvent: {},
        selectField: {
          shift:{
            select:[]
          },
          state:{
            select:[
              {
                label:'已提交',
                value:'已提交',
                type:'primary'
              },
              {
                label:'已审核',
                value:'已审核',
                type:'warning'
              },
              {
                label:'已批准',
                value:'已批准',
                type:'success'
              },
            ]
          },
          weekDay:{
            select:[]
          }
        },
        requiredAdd: [],
        requiredUp: [],
        needSort: ['createTime', 'name']
         },
      entityCopy: {},
         upIndex: 0,
@@ -315,7 +341,7 @@
               entity: {
                  week: null,
                  weekDay: null,
                  dateTime: null,
                  dateTime: [],
            name:null,
                  orderBy: {
                     field: 'id',
@@ -333,16 +359,17 @@
               requiredAdd: [],
               requiredUp: []
         },
      addFileVisible:false,
      entityCopy1: {},
      upIndex1:100,
      weekList:[
        {label: '星期一', value: '1',type:'primary'},
        {label: '星期二', value: '2',type:'primary'},
        {label: '星期三', value: '3',type:'primary'},
        {label: '星期四', value: '4',type:'primary'},
        {label: '星期五', value: '5',type:'primary'},
        {label: '星期六', value: '6',type:'primary'},
        {label: '星期日', value: '7',type:'primary'}
        {label: '周一', value: '周一',type:'primary'},
        {label: '周二', value: '周二',type:'primary'},
        {label: '周三', value: '周三',type:'primary'},
        {label: '周四', value: '周四',type:'primary'},
        {label: '周五', value: '周五',type:'primary'},
        {label: '周六', value: '周六',type:'primary'},
        {label: '周日', value: '周日',type:'primary'}
      ],
      currentTable:'ValueTable0',
      addVisible:false,
@@ -373,6 +400,8 @@
        reviewerNonproductiveTime:'',
        auxiliaryProject:'',
        reviewerRemark:'',
        nameUser: '',
        name: ''
      },
      checkVisible:false,
      checkLoadN:false,
@@ -393,9 +422,13 @@
          label:'已批准'
        },
      ],
      totalInfo:{},
      totalInfo:null,
      auxiliaryWorking:null,
      outLoading:false
      outLoading:false,
      batchCheckTitle: '批量审核',
      batchCheckDialog: false,
      ValueTable0Selected: [],
      batchCheckDialogMessage: ''
    }
  },
  watch:{
@@ -449,6 +482,9 @@
      }
    }
  },
  created() {
    this.setDate()
  },
  mounted(){
    this.getCurrentWeekNumber()
    this.selectEnumByCategory()
@@ -458,12 +494,72 @@
    this.entityCopy1 = this.HaveJson(this.componentData1.entity);
    this.componentData.tagField.weekDay.select = this.weekList
    this.componentData.selectField.weekDay.select = this.weekList
    this.getPower()
  },
  methods:{
    /** 将时间选择器默认选为当天的日期 */
    setDate(){
      let currentDate = new Date();
      let year = currentDate.getFullYear();
      let month = String(currentDate.getMonth() + 1).padStart(2, '0');
      let day = String(currentDate.getDate()).padStart(2, '0');
      let formattedDate1 = `${year}-${month}-${day}`;
      let formattedDate2 = `${year}-${month}-${day}`;
      this.entity.dateTime.push(formattedDate1);
      this.entity.dateTime.push(formattedDate2);
      this.componentData1.entity.dateTime.push(formattedDate1);
      this.componentData1.entity.dateTime.push(formattedDate2);
      this.componentData1.entity.dateTime = JSON.stringify(this.componentData1.entity.dateTime)
      this.refreshTable()
    },
    getPower(){
      let power = JSON.parse(sessionStorage.getItem('power'))
        let del = false
        let down = false
        let add = false
        let up = false
        let check = false
        let ratify = false
        for (var i = 0; i < power.length; i++) {
               if (power[i].menuMethod == 'exportWorkingHours') {
                  down = true
               }
               if (power[i].menuMethod == 'deleteAuxiliaryWorkingHoursDay') {
                  del = true
               }
          if (power[i].menuMethod == 'insertAuxiliaryWorkingHoursDay') {
                  add = true
               }
          console.log(add)
          if (power[i].menuMethod == 'updateAuxiliaryWorkingHoursDay') {
                  up = true
               }
          if (power[i].menuMethod == 'check') {
                  check = true
               }
          if (power[i].menuMethod == 'approve') {
                  ratify = true
               }
            }
        if (!ratify) {
               this.componentData.do.splice(3, 1)
            }
        if (!check) {
               this.componentData.do.splice(2, 1)
            }
        if (!up) {
               this.componentData.do.splice(1, 1)
            }
        if (!del) {
               this.componentData.do.splice(0, 1)
            }
        this.down = down
        this.add = add
    },
    getYearAndMonthAndDays(date){
      return getYearAndMonthAndDays(date)
    },
    refreshTable(){
    refreshTable(e){
      let entity = {}
      if(this.entity.week1&&this.entity.week2){
        entity.week = JSON.stringify([this.entity.week1,this.entity.week2])
@@ -480,11 +576,14 @@
      if(this.currentTable=='ValueTable0'){
        entity.state = this.entity.state
        this.componentData.entity = {...this.componentData.entity,...entity}
        this.$refs['ValueTable0'].selectList()
        this.$nextTick(() => {
          this.$refs['ValueTable0'].selectList(e)
        })
      }else{
        this.componentData1.entity = {...this.componentData1.entity,...entity}
        this.$refs['ValueTable1'].selectList()
        this.$refs['ValueTable1'].selectList(e)
      }
      this.collectWorkingHours()
    },
    refresh(){
      this.entity = {}
@@ -544,8 +643,14 @@
            this.addLoad = false
            if (res.code == 201) return
            this.$message.success('已提交')
            this.addVisible = false
            this.refreshTable()
            this.formData.number = ''
            this.formData.amount = ''
            this.formData.remarks = ''
            this.formData.approvedWorkingHour = ''
            this.formData.nonproductiveTime = ''
            this.formData.auxiliaryProject = ''
            // this.addVisible = false
            this.refreshTable('page')
            this.collectWorkingHours()
          })
      }else{
@@ -559,8 +664,14 @@
            this.addLoad = false
            if (res.code == 201) return
            this.$message.success('操作成功')
            this.addVisible = false
            this.refreshTable()
            this.formData.number = ''
            this.formData.amount = ''
            this.formData.remarks = ''
            this.formData.approvedWorkingHour = ''
            this.formData.nonproductiveTime = ''
            this.formData.auxiliaryProject = ''
            // this.addVisible = false
            this.refreshTable('page')
            this.collectWorkingHours()
          })
      }
@@ -569,11 +680,52 @@
      this.title = '审核'
      this.formData0 = row;
      this.checkVisible = true
      this.formData0.reviewerNumber = this.formData0.amount
    },
    handleRatify(row){
      this.title = '批准'
      this.formData0 = row;
      this.checkVisible = true
      this.formData0.reviewerNumber = this.formData0.amount
    },
    handleChangeTask (row) {
      this.ValueTable0Selected = JSON.parse(JSON.stringify(row))
    },
    openBatchCheck (e) {
      if (this.ValueTable0Selected.length > 0) {
        const isChecked = this.ValueTable0Selected.every(item => item.state === '已提交')
        const isApprove = this.ValueTable0Selected.every(item => item.state !== '已批准')
        console.log('this.isApprove---', isApprove)
        this.batchCheckTitle = e === 0 ? '批量审核' : '批量批准'
        this.batchCheckDialogMessage = e === 0 ? '是否全部通过审核?' : '是否全部通过批准?'
        if (this.batchCheckTitle === '批量审核') {
          if (isChecked) {
            this.batchCheckDialog = true
          } else {
            this.$message.error('请选择未审核或未批准的数据')
          }
        } else {
          if (isApprove) {
            this.batchCheckDialog = true
          } else {
            this.$message.error('请选择未批准的数据')
          }
        }
      } else {
        this.$message.error('请选择至少一条数据')
      }
    },
    batchCheck () {
      const e = this.batchCheckTitle === '批量审核' ? 0 : 1
      this.$refs.ValueTable0.batchCheck(e)
    },
    closeBatchCheckDialog () {
      this.batchCheckDialog = false
    },
    submitBatchCheckDialog () {
      this.batchCheckDialog = false
      this.refreshTable('page')
      this.collectWorkingHours()
    },
    submitCheck(e){
      if(!this.formData0.number){
@@ -611,7 +763,7 @@
          if (res.code == 201) return
          this.$message.success('操作成功')
          this.checkVisible = false
          this.refreshTable()
          this.refreshTable('page')
          this.collectWorkingHours()
        })
      }else{
@@ -636,7 +788,7 @@
          if (res.code == 201) return
          this.$message.success('操作成功')
          this.checkVisible = false
          this.refreshTable()
          this.refreshTable('page')
          this.collectWorkingHours()
        })
      }
@@ -677,9 +829,28 @@
      return String(d)
    },
    collectWorkingHours(){
      this.$axios.post(this.$api.auxiliaryOutputWorkingHours.collectWorkingHours).then(res => {
        this.totalInfo = res.data
      })
      let entity = {}
      if(this.entity.week1&&this.entity.week2){
        entity.week = JSON.stringify([this.entity.week1,this.entity.week2])
      }else{
        entity.week = ''
      }
      if(this.entity.dateTime){
        entity.dateTime = JSON.stringify(this.entity.dateTime)
      }else{
        entity.dateTime = ''
      }
      entity.weekDay = this.entity.weekDay
      entity.name = this.entity.name
      this.$axios.post(this.$api.auxiliaryOutputWorkingHours.collectWorkingHours,{
    entity:entity
   }, {
  headers: {
 'Content-Type': 'application/json'
 }
 }).then(res => {
 this.totalInfo = res.data
 })
    },
    selectshiftByUser(){
      this.$axios.post(this.$api.auxiliaryWorkingHoursDay.selectshiftByUser).then(res => {
@@ -702,35 +873,16 @@
    },
    handleOut(){
      this.outLoading = true
      this.$axios.post(this.$api.auxiliaryOutputWorkingHours.exportWorkingHours,{responseType: 'blob'}).then(res => {
      this.$axios.get(this.$api.auxiliaryOutputWorkingHours.exportWorkingHours,{responseType: "blob"}).then(res => {
        this.outLoading = false
        this.$message.success('导出成功')
        // let fileName="日工时汇总表";
        // const blob = new Blob([res], {
        //   type: 'application/force-download'
        // })
        // const filename = decodeURI(fileName+'.xlsx')
        // // 创建一个超链接,将文件流赋进去,然后实现这个超链接的单击事件
        // const elink = document.createElement('a')
        // elink.download = filename
        // elink.style.display = 'none'
        // elink.href = URL.createObjectURL(blob)
        // document.body.appendChild(elink)
        // elink.click()
        // URL.revokeObjectURL(elink.href) // 释放URL 对象
        // document.body.removeChild(elink)
        const blob = new Blob([res], {
          type: 'application/force-download'
        })
        const link = document.createElement('a')
        link.href = URL.createObjectURL(blob)
        link.download = decodeURI('日工时汇总表'+'.xlsx')
        document.body.appendChild(link)
        link.click()
        window.setTimeout(function () {
            URL.revokeObjectURL(blob)
            document.body.removeChild(link)
        }, 0)
        const blob = new Blob([res]);
        console.log(blob)
        const url = URL.createObjectURL(blob);
        const link = document.createElement('a');
        link.href = url;
        link.download = '日工时汇总表.xlsx';
        link.click();
      })
    },
  }