haoxuan
2023-08-26 4074ed7aa3b5f45a6cf3148ba0fb140d6b220ea5
src/views/visualization.vue
@@ -1,7 +1,8 @@
<template>
  <div class="home">
    <template v-if="Object.keys(taskData).length > 0">
    <!--  -->
    <template v-if="Object.keys(taskData).length > 0 && taskData.Procedure.ID">
      <div class="left">
        <p class="title">
          生产管理看板
@@ -13,8 +14,10 @@
        </p>
        <div class="statelist">
          <span class="title-item"
            >订单编号:
            <span class="color_4efefa">{{ taskData.Order.orderId || "" }}</span>
            >工单编号:
            <span class="color_4efefa">{{
              taskData.Order.workOrderId || ""
            }}</span>
          </span>
          <span class="title-item"
            >当前工序:
@@ -25,16 +28,24 @@
          <span class="title-item"
            >后道工序:
            <span class="color_4efefa">
              <!-- {{
                taskData.NextProcedure.procedure.procedureName || "--"
              }} -->
              {{
                taskData.Procedure.procedure.nextProcedureName || "--"
              }}
            </span>
          </span>
          <span class="title-item"
            >工作人数:
            <span class="color_4efefa"
              >{{ taskData.Procedure.procedure.workers.length || 0 }}人</span
            >
            <span class="color_4efefa">
              <span
                v-if="
                  taskData.Procedure.procedure &&
                  taskData.Procedure.procedure.workers
                "
                >{{ taskData.Procedure.procedure.workers.length }}</span
              >
              <span v-else>0</span>
              人
            </span>
          </span>
        </div>
        <div class="content">
@@ -76,13 +87,9 @@
                {{ taskData.Procedure.procedure.workHours || "" }}
              </el-descriptions-item>
              <el-descriptions-item label="起止时间"
                >{{
                  formatDate(taskData.Procedure.procedure.startTime) || ""
                }}
                >{{ formatDate(taskData.Order.startTime) || "" }}
                -
                {{
                  formatDate(taskData.Procedure.procedure.endTime)
                }}</el-descriptions-item
                {{ formatDate(taskData.Order.endTime) }}</el-descriptions-item
              >
              <el-descriptions-item label="货物描述">{{
                taskData.Order.orderAttr || ""
@@ -100,19 +107,17 @@
                <el-progress
                  define-back-color="#133EAF"
                  color="#09E5ED"
                  text-color="#fff"
                  :text-inside="true"
                  :stroke-width="30"
                  :percentage="
                    finishNumber && taskData.Order.amount
                      ? parseInt(finishNumber / taskData.Order.amount)
                      : 0
                  "
                  :percentage="taskData.Order?parseInt(finishNumber/taskData.Order.amount*100):0"
                ></el-progress>
              </el-descriptions-item>
              <!-- <el-descriptions-item label="合格率" style="width: 100%">
                  <el-progress
                    define-back-color="#007101"
                    color="#00CC66"
                    text-color="#fff"
                    :text-inside="true"
                    :stroke-width="30"
                    :percentage="passrate"
@@ -194,20 +199,16 @@
                    </div>
                    <div class="card_top-3">
                      <span class="card-top-r-t"
                        >完成进度:{{
                          parseInt(finishNumber / taskData.Order.amount) || 0
                        }}</span
                        >完成进度:{{ taskData.Order?parseInt(finishNumber/taskData.Order.amount*100):0}}</span
                      >
                      <span class="card-top-r-b">
                        <el-progress
                          define-back-color="#133EAF"
                          color="#09E5ED"
                          text-color="#fff"
                          :text-inside="true"
                          :stroke-width="10"
                          :percentage="
                           parseInt(finishNumber / taskData.Order.amount)
                          "
                          :percentage="taskData.Order?parseInt(finishNumber/taskData.Order.amount*100):0"
                          :show-text="false"
                        ></el-progress>
                      </span>
@@ -224,8 +225,18 @@
                    <!-- <div class="card_content">
                      
                    </div> -->
                    <div class="card_top-4"><div>工艺编号:{{ list.number }}</div>
                      <div style="font-size:14px;color:#cfcfcf;line-height:20px">工艺的具体信息请点击控制查看!</div></div>
                    <div class="card_top-4">
                      <div>工艺编号:{{ list.number }}</div>
                      <div
                        style="
                          font-size: 14px;
                          color: #cfcfcf;
                          line-height: 20px;
                        "
                      >
                        工艺的具体信息请点击控制查看!
                      </div>
                    </div>
                  </template>
                </div>
              </el-carousel-item>
@@ -336,12 +347,12 @@
          <div class="right-top-l">作业状态</div>
          <div class="time">
            <dl>
              <dd><span style="font-size: 32px">17:50</span></dd>
              <dd><span style="font-size: 32px">{{ formatTime3 }}</span></dd>
              <dd>
                <span style="font-size: 12px; margin-right: 10px"
                  >2023/02/16</span
                <span style="font-size: 12px; "
                  >{{ formatTime2 }}</span
                >
                <span style="font-size: 14px">星期四</span>
                <!--margin-right: 10px <span style="font-size: 14px">星期四</span> -->
              </dd>
            </dl>
          </div>
@@ -354,11 +365,14 @@
          </span>
        </div>
        <div class="right-top-m-btn">
          <el-button type="primary" @click="controlClick"> 控制</el-button>
          <!-- <el-button type="primary" @click="controlClick"> 控制</el-button> -->
        </div>
        <div class="right_dutyLst">
          <div class="right-small-title">当前值班</div>
          <div class="right-person-box">
          <div
            class="right-person-box"
            v-if="taskData.Procedure.procedure.workers"
          >
            <dl
              class="right-small-person"
              v-for="(item, index) in taskData.Procedure.procedure.workers"
@@ -378,7 +392,7 @@
                style="font-size: 20px; font-weight: 600; margin-right: 10px"
                >{{ item.workerName || "" }}</span
              >
              <span style="color: #666">{{ item.phoneNum || "" }}</span>
              <span>{{ item.phoneNum || "" }}</span>
            </dl>
          </div>
          <!-- <div
@@ -395,7 +409,7 @@
          </div> -->
        </div>
        <div class="right_base">
          <div class="right-small-title" style="line-height:40px;">知识库</div>
          <div class="right-small-title" style="line-height: 40px">知识库</div>
          <Knowledge />
          <div class="right-base-btn call">
            <el-button type="primary"
@@ -405,35 +419,39 @@
        </div>
      </div>
    </template>
    <!--  -->
    <template v-else>
      <div
        style="
          width: 100%;
          height: 100%;
          font-size: 20px;
          text-align: center;
          line-height: 100px;
        "
      >
        <div
          style="
            width: 200px;
            height: 200px;
            margin: 0 auto;
            line-height: 200px;
            margin-top: calc(20% - 100px);
          "
        >
          暂无任务
      <div class="home-img-box">
        <div class="bg-title">
          <img src="../../public/bg-title.png" />
          <span class="bg-title-span">设备实时生产看板</span>
          <div class="bg-date"><span>{{ formatTime3 }}</span><br/>{{formatTime2}}</div>
          <span
            class="font el-icon-setting set-title bg-set"
            @click="setUrl"
          ></span>
        </div>
        <div class="yuan">
          <img src="../../public/yuan.png" />
          <div class="btn-img">
            <div class="font_size_16" style="line-height: 5; margin-top: 18%">
              <span v-if="showCountDown">距离任务开始时间:{{countDownHour}}时 {{countDownMinute}}分</span>
              <span v-else>暂无任务,休息一下吧...</span>
            </div>
            <el-button type="primary" @click="reloadPage">刷新任务</el-button>
          </div>
        </div>
      </div>
    </template>
    <!-- 控制的弹框 -->
    <AddControl ref="control" :id="taskData.Procedure.ID" />
    <AddControl ref="control" :Arr="Arr" />
    <!-- 控制的弹框 -->
    <AddIssue ref="control" :Arr="Arr" :taskData="taskData" :Order="taskData.Order" @getSetProductNumber="getTaskInfo" />
  </div>
</template>
<script>
import {
  getTaskInfo,
  finishTask,
@@ -441,15 +459,18 @@
  saveMiniDict,
  startTask,
  getProgress,
  countdown,
} from "@/api/home/index"; // 产线
import Card from "@/components/Card.vue";
import Knowledge from "../components/Knowledge.vue";
import AddControl from "../components/AddControl.vue";
import AddIssue from "../components/AddIssue.vue";
export default {
  components: {
    Card,
    Knowledge,
    AddControl,
    AddIssue,
  },
  data() {
    return {
@@ -457,28 +478,13 @@
      passrate: 30, //合格率
      production: 25, //生产中
      finishNumber: 0,
      formatTime2:'',
      formatTime3:'',
      // 右侧完成
      finishShow: false,
      inputMaterials: [
        {
          amount: 1,
          materialId: 1,
          materialName: 1,
        },
      ],
      inputMaterials: [],
      outputMaterials: [],
      procedureList: [
        [
        {
            number:10,
            name:'工序'
          },
          {
            number:10,
          },
        ]
      ],
      procedureList: [],
      taskData: {
        Order: {
          amount: "",
@@ -520,6 +526,11 @@
          },
        },
      },
      totalNumber:0,
      showCountDown:false,
      countDownHour:0,
      countDownMinute:0,
      Arr:[],
    };
  },
  mounted() {
@@ -528,36 +539,82 @@
    //   this.passrate = this.getRandomNumber(1, 100);
    //   this.production = this.getRandomNumber(1, 100);
    // }, 3000);
    this.getDate3()
    this.getDate2()
    setInterval(()=>{
       this.getDate3()
       this.getDate2()
    },5000)
    this.getTaskInfo();
    setInterval(() => {
      this.getProgressInfo();
    }, 60000);
  },
  methods: {
    getProgressInfo() {
      getProgress().then((res) => {
    reloadPage() {
      // window.location.reload();
      this.getTaskInfo();
    },
    getcountdown(){
      countdown().then((res) => {
        if (res.code == 200) {
          this.showCountDown=res.data.ShowCountDown?res.data.ShowCountDown:false;
          this.countDownHour=res.data.CountDownHour?res.data.CountDownHour:0
          this.countDownMinute=res.data.CountDownMinute?res.data.CountDownMinute:0
        }
      });
    },
    getDateObj(ms) {
      const now = ms ? new Date(ms) : new Date();
      const y = now.getFullYear();
      let m = now.getMonth() + 1;
      m = m > 9 ? m : "0" + m;
      let d = now.getDate();
      d = d > 9 ? d : "0" + d;
      return { y, m, d };
    getProgressInfo() {
      getProgress().then((res) => {
        if (res.code == 200) {
          this.finishNumber = res.data.finishNumber ? res.data.finishNumber : 0;
        }
      });
    },
    getDateObj(date, fmt) {
      if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(
          RegExp.$1,
          (date.getFullYear() + "").substr(4 - RegExp.$1.length)
        );
      }
      let o = {
        "M+": date.getMonth() + 1,
        "d+": date.getDate(),
        "h+": date.getHours(),
        "m+": date.getMinutes(),
        "s+": date.getSeconds(),
      };
      for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
          let str = o[k] + "";
          fmt = fmt.replace(
            RegExp.$1,
            RegExp.$1.length === 1 ? str : this.padLeftZero(str)
          );
        }
      }
      return fmt;
    },
    padLeftZero(str) {
      return ("00" + str).substr(str.length);
    },
    // 格式化时间 ==> yyyy-mm-dd
    formatDate(value, str) {
    formatDate(value) {
      if (value) {
        const dateObj = this.getDateObj(value);
        return "" + dateObj.y + "-" + dateObj.m + "-" + dateObj.d;
        const now = value ? new Date(value * 1000) : new Date();
        let time = this.getDateObj(now, "yyyy-MM-dd hh:mm:ss");
        return time;
      } else {
        return "";
      }
    },
    getDate3(){
      let  now=  new Date();
      this.formatTime3 = this.getDateObj(now, "hh:mm");
    },
    getDate2(){
      let now =  new Date();
      this.formatTime2 = this.getDateObj(now, "yyyy年MM月dd日");
    },
    setInterCard(value, name) {
      let height = 200;
@@ -593,25 +650,53 @@
    },
    getTaskInfo() {
      this.taskData = {
        Order: {},
        Procedure: {
          procedure: { inputMaterials: [], outputMaterials: [], workers: [] },
        },
      };
      getTaskInfo().then((res) => {
        if (res.code == 200) {
          this.taskData = res.data;
          this.taskData = res.data
            ? res.data
            : {
                Order: {},
                Procedure: {
                  procedure: {
                    inputMaterials: [],
                    outputMaterials: [],
                    workers: [],
                  },
                },
              };
          this.taskData.Procedure.procedure.workers = this.taskData.Procedure
            .procedure.workers
            ? this.taskData.Procedure.procedure.workers
            : [];
          this.procedureList.push([
            {
              name: "工序",
              ...this.taskData.Procedure.procedure,
            },
          ]);
          if (this.taskData.Procedure.ID) {
            startTask({ id: this.taskData.Procedure.ID }).then((res) => {
              if (res.code == 200) {
                // res.data.number
                this.procedureList[0].push({
                  number: res.data.number,
                  number: res.data.Number,
                  name: "工艺",
                });
                this.Arr=res.data.Params?res.data.Params:[];
              }
            });
            this.getProgressInfo();
            setInterval(() => {
              this.getProgressInfo();
            }, 6000);
          }
          console.log(this.procedureList, "===1111procedureList");
          // setTimeout(() => {
@@ -620,28 +705,45 @@
          this.setInterCard("outputMaterials", "cardBox3");
          // }, 5000);
        }
        if(res.code!=200||!this.taskData.Procedure.ID){
          this.getcountdown();
            setInterval(() => {
              this.getcountdown();
            }, 60000);
        }
      });
    },
    // 设置
    setUrl() {
      const { href } = this.$router.resolve({
      // const { href } = this.$router.resolve({
      //   path: "/set",
      // });
      // window.open(href, "_blank");
      this.$router.push({
        path: "/set",
      });
      window.open(href, "_blank");
    },
    // 右侧控制
    controlClick() {
      this.$refs.control.islook = true;
      if (Object.keys(this.taskData).length > 0 && this.taskData.Procedure.ID) {
        this.$refs.control.islook = true;
      } else {
        this.$message.error("当前设备没有工序!");
      }
    },
    // 右侧完成
    finishClick() {
      finishTask({ id: this.taskData.Procedure.ID }).then((res) => {
        if (res.code == 200) {
          this.finishShow = false;
          this.getTaskInfo();
          this.$message.success("操作成功!");
        }
      });
      if (Object.keys(this.taskData).length > 0 && this.taskData.Procedure.ID) {
        finishTask({ id: this.taskData.Procedure.ID }).then((res) => {
          if (res.code == 200) {
            this.finishShow = false;
            this.getTaskInfo();
            this.$message.success("操作成功!");
          }
        });
      } else {
        this.$message.error("当前设备没有工序!");
      }
    },
    getRandomNumber(min, max) {
      return Math.floor(Math.random() * (max - min + 1) + min);
@@ -654,6 +756,77 @@
</script>
<style lang="scss">
.set-title{
  cursor:pointer;
}
.home-img-box {
  width: calc(100% - 40px);
  height: calc(100% - 40px);
  margin: 0 auto;
  overflow: hidden;
  padding: 20px;
  .bg-title {
    width: 90%;
    margin: 0 auto;
    position: absolute;
    img {
      width: 100%;
    }
    .bg-title-span {
      position: absolute;
      width: 30%;
      height: 4rem;
      line-height:2.4;
      font-size: 26px;
      font-weight: 700;
      text-align: center;
      left: 36%;
      top: 1.5rem;
      display: inline-block;
    }
    .bg-set{
      position:absolute;
      right:10%;
      height: 4rem;
      line-height:2.4;
      font-size: 40px;
      font-weight: 700;
      top: 1rem;
    }
    .bg-date{
      position:absolute;
      left:3%;
      height: 100px;
      line-height: 30px;
      font-size: 16px;
      top: 15%;
      span{
        font-size: 35px;
       font-weight: 700;
       line-height: 20px;
      }
    }
  }
  .yuan {
    width: 40%;
    height: 80%;
    margin: 0 auto;
    margin-top: 10%;
    position: relative;
    img {
      width: 100%;
    }
    .btn-img {
      width: 100%;
      height: 50%;
      margin: 0 auto;
      text-align: center;
      position: absolute;
      top: 9rem;
    }
  }
}
.font-arrow-20 {
  font-size: 30px;
  font-weight: 700;
@@ -744,13 +917,12 @@
.small_title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 10px;
}
.right-small-btn {
  margin-top: 10px;
  width: calc(100% - 20px);
  margin:0 auto;
  margin: 0 auto;
  position: absolute;
  bottom: 10px;
  left: 10px;
@@ -779,13 +951,13 @@
  width: 100%;
  height: 100%;
  color: #fff;
  background: rgb(19 35 90);
  background: #12234a;
  overflow: hidden;
  .left {
    width: calc(78% - 60px);
    height: 100%;
    min-height: 100%;
    background: rgb(19 35 90);
    background: #12234a;
    float: left;
    padding: 30px;
    padding-top: 20px;
@@ -977,7 +1149,7 @@
          line-height: 40px;
          color: #fff;
          background: rgb(19, 35, 90);
          font-size:20px;
          font-size: 20px;
        }
        .card-info-box {
          position: absolute;
@@ -1090,7 +1262,8 @@
    }
    .right_dutyLst {
      width: calc(100% - 20px);
      height: 270px;
      // height: 270px;
      height: 310px;
      border-radius: 4px;
      line-height: 30px;
      overflow: hidden;