From cc6914dff1a91dd00e3a86d5daae2c3dba2d6ba8 Mon Sep 17 00:00:00 2001
From: gaoluyang <gaoluyang@rengu.cc>
Date: 星期三, 24 七月 2024 16:28:00 +0800
Subject: [PATCH] 检测中心-班次时间配置功能

---
 src/components/view/b3-classes.vue |  318 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 296 insertions(+), 22 deletions(-)

diff --git a/src/components/view/b3-classes.vue b/src/components/view/b3-classes.vue
index 2d9ffd5..12b8b15 100644
--- a/src/components/view/b3-classes.vue
+++ b/src/components/view/b3-classes.vue
@@ -44,12 +44,13 @@
       <el-button size="small" type="primary" @click="refreshTable()">鏌� 璇�</el-button>
     </div>
     <div class="search_thing btns" style="padding-left: 30px;">
-      <el-button size="small" type="primary" v-if="downPower">瀵� 鍑�</el-button>
+      <el-button size="small" type="primary" v-if="downPower" @click="configTime" :loading="downLoading">鏃堕棿閰嶇疆</el-button>
+      <el-button size="small" type="primary" v-if="downPower" @click="handleDown" :loading="downLoading">瀵� 鍑�</el-button>
       <el-button size="small" type="primary" @click="schedulingVisible = true" v-if="addPower">鎺� 鐝�</el-button>
     </div>
   </div>
   <div class="center" v-loading="pageLoading">
-    <scroll-pagination @load="init" :finishLoding="finishLoding" v-show="query.month&&list.length>0" style="height: 100%;" :key="'123'">
+    <scroll-pagination @load="init" :finishLoding="finishLoding" v-show="query.month&&list.length>0" style="height: 100%;" :key="'123'" :list="list">
       <div class="clearfix">
         <div class="fixed-left">
           <div class="content-title" style="padding-left: 16px;box-sizing: border-box;">
@@ -60,7 +61,7 @@
             <div class="user-pic">{{ item.name.charAt(0) }}</div>
             <div class="user-info">
               <p style="font-size: 14px;color: #3A7BFA;line-height: 24px;">{{ item.name }}</p>
-              <p style="color: #999999;font-size: 12px;transform: scale(0.8) translateX(-20px);white-space: nowrap;width: 150px;overflow-x: show;">鏃�: {{ item.day0 }}, 涓�: {{ item.day1 }}, 澶�: {{ item.day2 }}, 浼�: {{ item.day3 }}, 鍋�: {{ item.day4 }}</p>
+              <p style="color: #999999;font-size: 12px;transform: scale(0.8) translateX(-20px);white-space: nowrap;width: 150px;overflow-x: show;">鏃�:{{ item.day0 }},涓�:{{ item.day1 }},澶�:{{ item.day2 }},浼�:{{ item.day3 }},鍋�:{{ item.day4 }},宸�:{{ item.day6 }}</p>
               <p style="margin-top: 4px;"><span style="color: #999999;font-size: 12px;display: inline-block;transform: scale(0.8) translateX(-10px);">鍚堣鍑哄嫟: </span><span style="font-size: 16px;
     color: #FF4902;">{{ query.month?item.monthlyAttendance
 .totalAttendance:item.sidebarAnnualAttendance
@@ -75,7 +76,7 @@
                 <span class="month" style="position: absolute;top: 4px;" v-if="item.week=='鍛ㄦ棩'">{{ item.weekNum }}鍛�</span>
                 <p style="height: 26px;position: absolute;bottom: 12px;">
                   <span class="day">{{ item.day }}</span>
-                  <span class="week">{{ item.week }}</span>
+                  <span class="week">{{ item.week.charAt(1) }}</span>
                 </p>
               </div>
             </div>
@@ -83,25 +84,21 @@
             v-on:mouseenter="onMouseEnter(index)"
           v-on:mouseleave="currentUserIndex=null">
               <div class="content-body-item" v-for="(m,i) in item.list" :key="'d'+i" :class="{hoverType:currentUserIndex==index}">
-                <div class="work-box" :class="{type0:m.shift==='0',type1:m.shift==='1',type2:m.shift==='2',type3:m.shift==='3',type4:m.shift==='4',}">
-                  <!-- <div class="work-box-left">
-                    <span>{{ getShiftByDic(m.shift) }}</span>
-                  </div> -->
-                  <el-dropdown trigger="click" placement="bottom" @command="e=>handleCommand(e,m)" :disabled="!downPower">
-                    <!-- <i class="el-icon-arrow-down el-icon--right" style="font-size: 20px;color: #fff;cursor: pointer;"></i> -->
-                    <span style="cursor: pointer;">{{ getShiftByDic(m.shift) }}</span>
+                <el-dropdown trigger="click" placement="bottom" @command="e=>handleCommand(e,m)" :disabled="!upPower" style="width: 100%;height: 100%;cursor: pointer;">
+                    <div class="work-box" :class="{type0:m.shift==='0',type1:m.shift==='1',type2:m.shift==='2',type3:m.shift==='3',type4:m.shift==='4',type5:m.shift==='5',type6:m.shift==='6'}">
+                    <span style="cursor: pointer;" :style="`opacity: ${getShiftByDic(m.shift)=='鏃�'?0:1};`">{{ getShiftByDic(m.shift) }}</span>
+                  </div>
                     <el-dropdown-menu slot="dropdown">
                       <el-dropdown-item v-for="(n,j) in classType" :key="'h'+j" :command="n.value">{{ n.label }}</el-dropdown-item>
                     </el-dropdown-menu>
                   </el-dropdown>
-                </div>
               </div>
             </div>
           </div>
         </div>
       </div>
     </scroll-pagination>
-    <scroll-pagination @load="initYear" :finishLoding="finishLoding" v-show="!query.month&&yearList.length>0" style="width: 100%;" :key="'111'">
+    <scroll-pagination @load="initYear" :finishLoding="finishLoding" v-show="!query.month&&yearList.length>0" style="width: 100%;" :key="'111'" :list="yearList">
       <div class="clearfix year-table">
       <div class="fixed-left">
         <div class="content-title" style="padding-left: 16px;box-sizing: border-box;">
@@ -112,7 +109,7 @@
             <div class="user-pic">{{ item.name.charAt(0) }}</div>
             <div class="user-info">
               <p style="font-size: 14px;color: #3A7BFA;line-height: 24px;">{{ item.name }}</p>
-              <p style="color: #999999;font-size: 12px;transform: scale(0.8) translateX(-20px);white-space: nowrap;width: 150px;overflow-x: show;">鏃�: {{ item.day0 }}, 涓�: {{ item.day1 }}, 澶�: {{ item.day2 }}, 浼�: {{ item.day3 }}, 鍋�: {{ item.day4 }}</p>
+              <p style="color: #999999;font-size: 12px;transform: scale(0.8) translateX(-20px);white-space: nowrap;width: 150px;overflow-x: show;">鏃�:{{ item.day0 }},涓�:{{ item.day1 }},澶�:{{ item.day2 }},浼�:{{ item.day3 }},鍋�:{{ item.day4 }},宸�:{{ item.day6 }}</p>
               <p style="margin-top: 4px;"><span style="color: #999999;font-size: 12px;display: inline-block;transform: scale(0.8) translateX(-10px);">鍚堣鍑哄嫟: </span><span style="font-size: 16px;
     color: #FF4902;">{{ item.work_time }}澶�</span></p>
             </div>
@@ -139,7 +136,7 @@
               <div class="content-body-item" v-for="(m,i) in item.monthList" :key="'d'+i" :class="{hoverType:currentUserIndex==index}">
                 <p style="color:rgb(153, 153, 153);font-size: 12px;">鍚堣鍑哄嫟锛�<span style="font-size: 14px;color:#000">{{ m.totalMonthAttendance }}</span></p>
                 <p style="color:rgb(153, 153, 153);font-size: 12px;">
-                  鏃�: {{ m.day0 }}, 涓�:  {{ m.day1 }}, 澶�:  {{ m.day2 }}, 浼�:  {{ m.day3 }}, 鍋�:  {{ m.day4 }}
+                  鏃�:{{ m.day0 }},涓�:{{ m.day1 }},澶�:{{ m.day2 }},浼�:{{ m.day3 }},鍋�:{{ m.day4 }},宸�:{{ m.day6 }}
                 </p>
               </div>
             </div>
@@ -150,6 +147,57 @@
     </scroll-pagination>
     <span style="color:#909399;font-size:14px;position: absolute;left:50%;top: 50%;transform: translate(-59%,-50%);" v-if="(query.month&&list.length==0)||(!query.month&&yearList.length==0)">鏆傛棤鏁版嵁</span>
   </div>
+  <el-dialog title="鏃堕棿閰嶇疆" :visible.sync="configTimeVisible" width="620px">
+    <div v-loading="configTimeVisibleLoading" ></div>
+    <div v-if="!configTimeVisibleLoading">
+      <div v-for="(item, index) in timeQuery">
+        <div class="form_title">
+          <span>{{`鐝${transFromNumber(index + 1)}`}}</span>
+          <span style="margin-right: 10px">
+          <i class="el-icon-circle-check" v-if="item.isEdit" style="margin-left: 10px; color: #4b79f2" @click="saveEdit(item, index)"></i>
+          <i class="el-icon-edit" v-if="!item.isEdit" style="margin-left: 10px; color: #4b79f2" @click="item.isEdit = true"></i>
+          <i class="el-icon-delete" v-if="!item.isEdit && timeQuery.length > 1" style="margin-left: 10px; color: #FF4902" @click="deleteTime(item, index)"></i>
+        </span>
+        </div>
+        <div class="form">
+          <div style="margin-bottom: 12px">
+            <span class="form_label">鐝锛�</span>
+            <span v-if="!item.isEdit"> {{item.type}} </span>
+            <span class="form_input" v-if="item.isEdit">
+            <el-select v-model="item.shift" placeholder="璇烽�夋嫨" style="width: 70%;" clearable size="small">
+              <el-option v-for="obj in timeTypeList"
+                         :key="obj.value"
+                         :label="obj.label"
+                         :value="obj.value">
+              </el-option>
+            </el-select>
+          </span>
+          </div>
+          <div>
+            <span class="form_label">鏃堕棿锛�</span>
+            <span v-if="!item.isEdit"> {{item.time === null ? '' : item.time[0] + '~' + item.time[1]}} </span>
+            <span class="form_input" v-if="item.isEdit">
+            <el-time-picker
+              style="width: 70%;"
+              is-range
+              size="small"
+              v-model="item.time"
+              range-separator="~"
+              format="HH:mm"
+              value-format="HH:mm"
+              start-placeholder="寮�濮嬫椂闂�"
+              end-placeholder="缁撴潫鏃堕棿"
+              placeholder="閫夋嫨鏃堕棿鑼冨洿">
+            </el-time-picker>
+          </span>
+          </div>
+          <el-divider></el-divider>
+        </div>
+        <div @click="addTimeForm" style="color: #4b79f2" v-if="index === timeQuery.length - 1">娣诲姞鏃堕棿閰嶇疆</div>
+      </div>
+      <div @click="addTimeForm" style="color: #4b79f2" v-if="timeQuery.length === 0">娣诲姞鏃堕棿閰嶇疆</div>
+    </div>
+  </el-dialog>
   <el-dialog title="鎺掔彮" :visible.sync="schedulingVisible" width="400px">
     <div class="search_thing">
       <div class="search_label" style="width:90px"><span style="color: red;margin-right: 4px;">*</span>鍛ㄦ锛�</div>
@@ -286,7 +334,13 @@
       pageLoading: false, // 缁勪欢loading鐨勫睍绀�,榛樿涓簍rue
       finishLoding: false, // 鍔犺浇瀹屾垚锛屾樉绀哄凡缁忔病鏈夋洿澶氫簡
       monthList:[],
-      yearList:[]
+      yearList:[],
+      downLoading:false,
+      keyMap:{},
+      configTimeVisible: false, // 鏃堕棿閰嶇疆寮规
+      configTimeVisibleLoading: false, // 鏃堕棿閰嶇疆寮规loading
+      timeTypeList: [],
+      timeQuery: [],
     }
   },
   watch: {
@@ -331,6 +385,8 @@
     refresh(){
       this.list = [];
       this.yearList = []
+      this.keyMap = {};
+      this.finishLoding = false;
       this.currentPage = 1
       this.query = {
         userName:'',
@@ -345,7 +401,9 @@
       }
     },
     refreshTable(){
+      this.keyMap = {};
       this.currentPage = 1
+      this.finishLoding = false;
       if(this.query.month){
         this.list = [];
         this.init()
@@ -354,7 +412,32 @@
         this.initYear()
       }
     },
+    transFromNumber(num){
+      let changeNum = ['闆�', '涓�', '浜�', '涓�', '鍥�', '浜�', '鍏�', '涓�', '鍏�', '涔�']; //changeNum[0] = "闆�"
+      let unit = ["", "鍗�", "鐧�", "鍗�", "涓�"];
+      num = parseInt(num);
+      let getWan = (temp) => {
+        let strArr = temp.toString().split("").reverse();
+        let newNum = "";
+        for (var i = 0; i < strArr.length; i++) {
+          newNum = (i == 0 && strArr[i] == 0 ? "" : (i > 0 && strArr[i] == 0 && strArr[i - 1] == 0 ? "" : changeNum[strArr[i]] + (strArr[i] == 0 ? unit[0] : unit[i]))) + newNum;
+        }
+        return newNum;
+      }
+      let overWan = Math.floor(num / 10000);
+      let noWan = num % 10000;
+      if (noWan.toString().length < 4) noWan = "0" + noWan;
+      return overWan ? getWan(overWan) + "涓�" + getWan(noWan) : getWan(num)
+    },
     init(){
+      const key = `_${this.currentPage}`
+      const value = this.keyMap[key]
+      // 濡傛灉value瀛樺湪锛岃〃绀虹紦瀛樻湁鍊硷紝閭d箞闃绘璇锋眰
+      if(value) {
+        return
+      }
+      // value涓嶅瓨鍦紝琛ㄧず绗竴娆¤姹�,璁剧疆鍗犱綅
+      this.keyMap[key] = 'temp'
       if(this.currentPage==1){
         this.pageLoading = true
       }
@@ -405,6 +488,14 @@
         })
     },
     initYear(){
+      const key = `_${this.currentPage}`
+      const value = this.keyMap[key]
+      // 濡傛灉value瀛樺湪锛岃〃绀虹紦瀛樻湁鍊硷紝閭d箞闃绘璇锋眰
+      if(value) {
+        return
+      }
+      // value涓嶅瓨鍦紝琛ㄧず绗竴娆¤姹�,璁剧疆鍗犱綅
+      this.keyMap[key] = 'temp'
       // pageYear
       if(this.currentPage==1){
         this.pageLoading = true
@@ -516,6 +607,128 @@
         this.refresh()
       })
     },
+    configTime () {
+      this.$axios.post(this.$api.enums.selectEnumByCategory, {
+        category: "鐝绫诲瀷"
+      }).then(res => {
+        console.log('res---', res)
+        this.timeTypeList = res.data
+      })
+      this.getTimeList()
+      this.configTimeVisible = true
+    },
+    getTimeList () {
+      this.configTimeVisibleLoading = true
+      this.$axios.post(this.$api.performanceShift.getList).then(res => {
+        if (res.code === 200) {
+          res.data.forEach(item => {
+            item.isEdit = false
+            item.time.push(item.startTime)
+            item.time.push(item.endTime)
+            const index = this.timeTypeList.findIndex(val => val.value === item.shift)
+            if (index > -1) {
+              item.type = this.timeTypeList[index].label
+            }
+          })
+          this.timeQuery = res.data
+        }
+        this.configTimeVisibleLoading = false
+      }).catch(e => {
+        this.configTimeVisibleLoading = false
+        console.log('e--',e)
+      })
+    },
+    addTimeForm () {
+      this.timeQuery.push({
+        type: '',
+        shift: '',
+        time: null,
+        isEdit: true
+      })
+    },
+    saveEdit (item, index) {
+      if (item.shift) {
+        const index = this.timeTypeList.findIndex(val => val.value === item.shift)
+        if (index > -1) {
+          item.type = this.timeTypeList[index].label
+        }
+      }
+      const isEmpty = this.isObjectEmpty(item)
+      if (isEmpty) {
+        this.$message.error('璇峰~鍐欏畬鏁�')
+        return
+      }
+      let newObj = {}
+      let url = ''
+      newObj.shift = item.shift
+      newObj.startTime = item.time[0]
+      newObj.endTime = item.time[1]
+      url = this.$api.performanceShift.shiftAdd
+      if (item.id) {
+        // 鏈塱d涓轰慨鏀�
+        newObj.id = item.id
+        url = this.$api.performanceShift.shiftUpdate
+      }
+      this.$axios.post(url, newObj, {
+        headers: {
+          'Content-Type': 'application/json'
+        }
+      }).then(res => {
+        if (res.code == 201) return
+        this.$message.success('鎿嶄綔鎴愬姛')
+      })
+      this.getTimeList()
+    },
+    deleteTime (item, index) {
+      this.$axios.post(this.$api.performanceShift.shiftRemove, {
+        id: item.id
+      },{
+        headers: {
+          'Content-Type': 'application/json'
+        }
+      }).then(res => {
+        if (res.code == 201) return
+        this.$message.success('鎿嶄綔鎴愬姛')
+      })
+      this.getTimeList()
+    },
+    isObjectEmpty(obj) {
+      return Object.keys(obj).some(key => !obj[key]);
+    },
+    handleDown(){
+      let year = this.query.year.getFullYear()
+      let time = '';
+      if(this.query.month){
+        let month = this.query.month>9?this.query.month:'0'+this.query.month
+        time = year+'-'+month+'-01 00:00:00'
+      }else{
+        time = year+'-01-01 00:00:00'
+      }
+      this.downLoading = true
+      this.$axios.get(this.$api.performanceShift.export+`?time=${time}&userName=${this.query.userName}&laboratory=${this.query.laboratory}&isMonth=${this.query.month?true:false}`,{responseType: 'blob'}).then(res => {
+        this.$message.success('涓嬭浇鎴愬姛')
+        this.downLoading = false
+        const blob = new Blob([res], {
+          type: 'application/force-download'
+        })
+        let fileName="";
+        if(this.query.month){
+          fileName = year +'-'+this.query.month+' 鐝淇℃伅'
+        }else{
+          fileName = year+' 鐝姹囨��'
+        }
+        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)
+      })
+    },
     selectEnumByCategory() {
       this.$axios.post(this.$api.enums.selectEnumByCategory, {
         category: "鐝绫诲瀷"
@@ -524,7 +737,16 @@
       })
     },
     obtainItemParameterList() {
-      this.$axios.get(this.$api.laboratoryScope.obtainItemParameterList).then(res => {
+      if(this.PROJECT == '妫�娴嬩腑蹇�') {
+        this.laboratory = [{
+                            label: '閫氫俊浜у搧瀹為獙瀹�',
+                            value: '閫氫俊浜у搧瀹為獙瀹�'
+                          }, {
+                            label: '鐢靛姏浜у搧瀹為獙瀹�',
+                            value: '鐢靛姏浜у搧瀹為獙瀹�'
+                          }]
+      } else {
+        this.$axios.get(this.$api.laboratoryScope.obtainItemParameterList).then(res => {
         let data = []
         res.data.forEach(a => {
           data.push({
@@ -534,6 +756,8 @@
         })
         this.laboratory = data
       })
+      }
+
     },
     handleCommand(e,m){
       if(e!=m.shift){
@@ -583,13 +807,47 @@
       if(obj){
         return obj.label
       }
-      return '鏈帓鐝�'
+      return '鏃�'
+    },
+    scrollInit() {
+      // 鑾峰彇瑕佺粦瀹氫簨浠剁殑鍏冪礌
+      const nav = document.getElementById("nav")
+      var flag; // 榧犳爣鎸変笅
+      var downX; // 榧犳爣鐐瑰嚮鐨剎涓嬫爣
+      var scrollLeft; // 褰撳墠鍏冪礌婊氬姩鏉$殑鍋忕Щ閲�
+      nav.addEventListener("mousedown", function(event) {
+        flag = true;
+        downX = event.clientX; // 鑾峰彇鍒扮偣鍑荤殑x涓嬫爣
+        scrollLeft = this.scrollLeft; // 鑾峰彇褰撳墠鍏冪礌婊氬姩鏉$殑鍋忕Щ閲�
+      });
+      nav.addEventListener("mousemove", function(event) {
+        if (flag) { // 鍒ゆ柇鏄惁鏄紶鏍囨寜涓嬫粴鍔ㄥ厓绱犲尯鍩�
+          var moveX = event.clientX; // 鑾峰彇绉诲姩鐨剎杞�
+          var scrollX = moveX - downX; // 褰撳墠绉诲姩鐨剎杞翠笅鏍囧噺鍘诲垰鐐瑰嚮涓嬪幓鐨剎杞翠笅鏍囧緱鍒伴紶鏍囨粦鍔ㄨ窛绂�
+          this.scrollLeft = scrollLeft - scrollX // 榧犳爣鎸変笅鐨勬粴鍔ㄦ潯鍋忕Щ閲忓噺鍘诲綋鍓嶉紶鏍囩殑婊戝姩璺濈
+        }
+      });
+      // 榧犳爣鎶捣鍋滄鎷栧姩
+      nav.addEventListener("mouseup", function() {
+        flag = false;
+      });
+      // 榧犳爣绂诲紑鍏冪礌鍋滄鎷栧姩
+      nav.addEventListener("mouseleave", function(event) {
+        flag = false;
+      });
     }
   }
 }
 </script>
 
 <style scoped>
+.form_title {
+  height: 36px;
+  display: flex;
+  flex-direction: row;
+  justify-content: space-between;
+  font-weight: 800;
+}
 .search {
   height: 50px;
   display: flex;
@@ -648,6 +906,7 @@
   min-height: calc(100% - 10px); /* 瑙嗗彛楂樺害 */
   margin-left: 220px;
   overflow-x: scroll;
+  /* overflow-x: hidden; */
 }
 
 .content {
@@ -664,7 +923,7 @@
 }
 .content-title-item{
   height: 100%;
-  width: 60px;
+  width: 50px;
   flex-shrink: 0;
   border-bottom: 1px solid #EEEEEE;
   box-sizing: border-box;
@@ -699,8 +958,9 @@
 }
 .content-body-item{
   height: 70px;
-  width: 60px;
+  width: 50px;
   flex-shrink: 0;
+  font-size: 12px;
   box-sizing: border-box;
   padding: 4px;
   border-right: 1px solid #EEEEEE;
@@ -712,7 +972,7 @@
   display: flex;
   align-items: center;
   justify-content: space-around;
-  background: #F5F7FB;
+  background: #edeff2;
   border-radius: 8px 8px 8px 8px;
   color: #999;
   font-size: 14px;
@@ -751,6 +1011,20 @@
 }
 .work-box.type4 span{
   color: #F56C6C !important;
+}
+.work-box.type5{
+  background: #ff46c145;
+  color: #ff46c0 !important;
+}
+.work-box.type5 span{
+  color: #ff46c0 !important;
+}
+.work-box.type6{
+  background: #00036418;
+  color: #000464 !important;
+}
+.work-box.type6 span{
+  color: #000464 !important;
 }
 /* .el-icon-arrow-down::before{
   color: #c6c4c4;
@@ -800,7 +1074,7 @@
   margin-left: 10px;
 }
 .hoverType{
-  background: rgba(58,123,250,0.05);
+  background: rgba(58,123,250,0.03);
 }
 .year-table{
   width: 100%;

--
Gitblit v1.9.3