浏览代码

调整时间

zhulizhen 5 年之前
父节点
当前提交
c14550e47f
共有 3 个文件被更改,包括 98 次插入46 次删除
  1. 33 0
      src/utils/helper.js
  2. 59 46
      src/views/doBusiness/index.vue
  3. 6 0
      src/views/strategy/animationBox.vue

+ 33 - 0
src/utils/helper.js

@@ -0,0 +1,33 @@
+/**
+ * 将 类似的时间‘20190910081000’,转化成时间戳
+ * @param {String} str eg: 20190910081000
+ * @return 时间戳
+ */
+export function toTimestamp(str) {
+    const arr = str.match(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/)
+    return +new Date(arr[1], arr[2], arr[3], arr[4], arr[5], arr[6])
+}
+
+/**
+ * 将时间戳转化成 类似的时间 ‘20190910081000’
+ * @param {Number} timestamp 时间戳
+ */
+export function timestamp2String(timestamp) {
+    const date = new Date(timestamp)
+    const year = date.getFullYear()
+    const month = add0(date.getMonth() + 1)
+    const day = add0(date.getDate())
+    const hours = add0(date.getHours()) 
+    const minutes = add0(date.getMinutes())
+    const seconds = add0(date.getSeconds())
+    return `${year}${month}${day}${hours}${minutes}${seconds}`
+}
+
+/**
+ * 将 9 变为 ‘09’, 10 变为 ‘10’
+ * @param {NUmber, String} num 
+ * @returns String
+ */
+function add0(num) {
+    return Number(num) > 10 ? num : '0' + num
+}

+ 59 - 46
src/views/doBusiness/index.vue

@@ -7,19 +7,20 @@
     </div>
     <el-calendar class="doBusinessContainer" :first-day-of-week="7">
       <template slot="dateCell" slot-scope="{date, data}">
-        <div class="time-duration">
+        <div class="time-duration" v-for="(item,index) in content" :key="index">
           <el-time-picker
+            v-if="date.getFullYear()+''+(Number(date.getMonth()+1)>10?Number(date.getMonth()+1):'0'+(Number(date.getMonth()+1)))+''+(date.getDate()>10?date.getDate():'0'+date.getDate())==item.date"
             is-range
-            v-model="value1"
+            v-model="item.timeRange"
             size="mini"
             range-separator="-"
             start-placeholder="开始时间"
             end-placeholder="结束时间"
-            placeholder="选择时间范围"
-            format="hh:mm"
-            value-format="hh:mm"
+            format="HH:mm"
+            value-format="timestamp"
             @change="setHours"
-          ></el-time-picker>
+            placeholder="选择时间范围">
+          </el-time-picker>
         </div>
         <div class="dataJoin">{{ data.day.split('-').slice(2).join('')}}</div>
       </template>
@@ -29,68 +30,80 @@
 <script>
 import Head from "../main/index";
 import MonthTemp from "./monthTemp";
-import { queryHours, updateHours } from "@/api/doBusiness/business.js";
+import {queryHours,updateHours} from '@/api/doBusiness/business.js'
+import {toTimestamp,timestamp2String} from '@/utils/helper.js'
 export default {
   data() {
     return {
       headText: "营业时间调整",
-      value1: [new Date(), new Date()],
-      date: "",
-      today: ""
+      content:[],
+      date:timestamp2String(+new Date())
     };
   },
   components: {
     Head,
     MonthTemp
   },
+  computed:{
+    gte(){
+      let month = parseInt(this.date.slice(4,6))-1
+      return this.date.slice(0,4) + (month > 10 ? month : ('0'+month) )+ this.date.slice(6,8)
+     
+    },
+    lt(){
+       let month = parseInt(this.date.slice(4,6))+1
+       return this.date.slice(0,4) + (month > 10 ? month : ('0'+month) )+ this.date.slice(6,8)
+    }
+  },
+
   methods: {
-    formatTime() {
-      let year = new Date().getFullYear();
-      let month =
-        new Date().getMonth() + 1 > 10
-          ? new Date().getMonth() + 1
-          : "0" + (new Date().getMonth() + 1);
-      let date =
-        new Date().getDate() > 10
-          ? new Date().getDate()
-          : "0" + new Date.getDate();
-      return (this.today = year + "" + month + "" + date);
+    translate(){
+      this.content.forEach(el=>{
+        this.$set(el, 'timeRange', [new Date(toTimestamp(el.date+''+el.openTime)), new Date(toTimestamp(el.date+''+el.endTime))])
+      })
     },
     pickerVal(val) {
-      this.date = val;
+      console.log(val);
+      this.date = val
     },
-    getHours() {
+    getHours(){
+      console.log(this.date)
       let params = {
-        postParams: {
-          criteria: {
-            projectId: "Pj4419000005",
-            date: this.today
+        postParams:{
+          criteria:{
+            projectId:'Pj4419000005',
+            date:{
+              "$gte":this.gte,
+              "$lt": this.lt
+            }
           }
         }
-      };
-      queryHours(params).then(res => {});
+      }
+      queryHours(params).then(res=>{
+        this.content= res.content?res.content:[]
+        if(this.content.length>0){
+            this.translate()
+        }
+       
+      })
     },
-    setHours() {
+    setHours(val){
+      console.log(val)
       let params = {
-        postParams: {
-          projectId: "Pj4419000005",
-          date: this.today,
-          openTime:
-            this.value1.split("-")[0].slice(0, 2) +
-            "" +
-            this.value1.split("-")[0].slice(2, 4),
-          endTime:
-            this.value1.split("-")[1].slice(0, 2) +
-            "" +
-            this.value1.split("-")[1].slice(2, 4)
+        postParams:{
+          projectId:'Pj4419000005',
+          date: timestamp2String(val[0]).substr(0,8),
+          openTime:timestamp2String(val[0]).substr(8,6),
+          endTime: timestamp2String(val[1]).substr(8,6),
         }
-      };
-      updateHours(params).then(res => {});
+      }
+      updateHours(params).then(res=>{
+        console.log(res)
+      })
     }
   },
-  mounted() {
-    this.formatTime();
-    this.getHours();
+  mounted(){
+    this.getHours()
   }
 };
 </script>

+ 6 - 0
src/views/strategy/animationBox.vue

@@ -81,6 +81,9 @@ export default {
         tooltip: {
           trigger: "axis"
         },
+        title:{
+          text:'室内外温度'
+        },
         legend: {
           data: ["室外温度", "室内平均温度", "室内最高温度"]
         },
@@ -150,6 +153,9 @@ export default {
           bottom: "3%",
           containLabel: true
         },
+        title:{
+          text:'预测冷量'
+        },
         xAxis: {
           type: "category",
           data: this.loadX