Browse Source

更新逻辑

lex-xin 3 years ago
parent
commit
61477872ea
3 changed files with 299 additions and 187 deletions
  1. 2 2
      src/main.js
  2. 17 185
      src/views/trainStatistics/index.vue
  3. 280 0
      src/views/trainStatistics/trainModel.vue

+ 2 - 2
src/main.js

@@ -10,7 +10,7 @@ import { Button, Icon, Tag, Swipe, SwipeItem, Popup, Picker,
     Circle, Field, DatetimePicker, Image, Loading,
     ActionSheet, RadioGroup, Radio, Checkbox, CheckboxGroup,
     CountDown, Panel, Dialog, Sticky, Rate, Switch, ImagePreview, NoticeBar, NavBar, Divider,
-    Grid, GridItem,} from 'vant'
+    Grid, GridItem, Calendar} from 'vant'
 Vue.use(Button).use(Icon).use(Tag).use(Swipe).use(SwipeItem)
    .use(Popup).use(Picker).use(DropdownMenu).use(DropdownItem).use(Search)
    .use(PullRefresh).use(Toast).use(List).use(Collapse).use(CollapseItem)
@@ -18,7 +18,7 @@ Vue.use(Button).use(Icon).use(Tag).use(Swipe).use(SwipeItem)
    .use(Circle).use(Field).use(DatetimePicker).use(Image).use(Loading)
    .use(ActionSheet).use(RadioGroup).use(Radio).use(Checkbox).use(CheckboxGroup)
    .use(CountDown).use(Panel).use(Dialog).use(Sticky).use(Rate).use(Switch).use(ImagePreview).use(NoticeBar)
-   .use(NavBar).use(Divider).use(Grid).use(GridItem)
+   .use(NavBar).use(Divider).use(Grid).use(GridItem).use(Calendar)
 
 Vue.config.productionTip = false
 

+ 17 - 185
src/views/trainStatistics/index.vue

@@ -2,57 +2,14 @@
     <div class="visitList">
         <van-sticky>
             <m-header v-if="headerStatus" :isFixed="false" />
-            <van-tabs v-model="active" title-active-color="#000000" title-inactive-color="#808080" color="#01C1B5" class="van-hairline--bottom">
-                <van-tab title="全部学员" name="all"></van-tab>
-                <van-tab title="待回访学员" name="visited" dot></van-tab>
+            <van-tabs v-model="active" @change="tabChange" title-active-color="#000000" title-inactive-color="#808080" color="#01C1B5" class="van-hairline--bottom">
+                <van-tab title="全部学员" name="all">
+                    <train-model ref="trainModel" :active="active" :defaultTime="0" />
+                </van-tab>
+                <van-tab title="待回访学员" name="visited" dot>
+                    <train-model ref="trainModel" :active="active" :defaultTime="-1" />
+                </van-tab>
             </van-tabs>
-            <div class="visit-tips" v-show="active == 'visited'">
-                <span>学员上周训练时间不足80分钟或训练次数小于4次则需要回访</span>
-            </div>
-            <search @onSearch="search" placeholder="学生姓名或手机号">
-                <template #left>
-                    <van-dropdown-menu style="padding-right: .1rem" :close-on-click-outside="false" active-color="#01C1B5">
-                        <van-dropdown-item title="训练时间" ref="item" class="visitTime">
-                            <van-cell title="开始时间" is-link @click="onChangeDate('showStart')" :value="formatStartTime"></van-cell>
-                            <van-cell title="结束时间" is-link @click="onChangeDate('showEnd')" :value="formatEndTime"></van-cell>
-                            <div class="btnWrap">
-                                <div class="cancelBtn" @click="cancelBtn">重置</div>
-                                <div class="okBtn" @click="okBtn">确定</div>
-                            </div>
-                        </van-dropdown-item>
-                    </van-dropdown-menu>
-                </template>
-            </search>
-            <van-row class="searchArray">
-                <van-col span="6" class="title-style">
-                    训练时长
-                    <div>
-                        <i class="box box-up active" style="margin-bottom: .02rem;"></i>
-                        <i class="box box-down"></i>
-                    </div>
-                </van-col>
-                <van-col span="6" class="title-style">
-                    训练次数
-                    <div>
-                        <i class="box box-up active" style="margin-bottom: .02rem;"></i>
-                        <i class="box box-down"></i>
-                    </div>
-                </van-col>
-                <van-col span="6" class="title-style">
-                    训练天数
-                    <div>
-                        <i class="box box-up active" style="margin-bottom: .02rem;"></i>
-                        <i class="box box-down"></i>
-                    </div>
-                </van-col>
-                <van-col span="6" class="title-style">
-                    评测次数
-                    <div>
-                        <i class="box box-up active" style="margin-bottom: .02rem;"></i>
-                        <i class="box box-down"></i>
-                    </div>
-                </van-col>
-            </van-row>
         </van-sticky>
 
         <van-list
@@ -96,47 +53,21 @@
         </van-list>
         <m-empty v-else msg="暂无训练统计" />
 
-        <van-popup v-model="dataForm.status" position="bottom" :style="{ height: '40%' }">
-            <van-datetime-picker
-                v-model="dataForm.currentDate"
-                :min-date="dataForm.minDate"
-                :max-date="dataForm.maxDate"
-                :formatter="formatter"
-                @cancel="dataForm.status = false"
-                type="date"
-                @confirm="chioseDate"
-            />
-        </van-popup>
     </div>
 </template>
 <script>
 import MHeader from "@/components/MHeader";
 import MEmpty from '@/components/MEmpty';
-import Search from '@/components/Search';
 import dayjs from "dayjs";
 import { browser } from "@/common/common";
 import { countStudentTrain } from './api.js'
+import trainModel from './trainModel.vue'
 export default {
-    components: { MHeader, MEmpty, Search },
+    components: { MHeader, MEmpty, trainModel },
     data() {
         return {
             headerStatus: true,
             active: 'all',
-            dataForm: {
-                // 时间下拉框
-                type: null,
-                status: false,
-                minDate: new Date(2000, 0, 1),
-                maxDate: new Date(2025, 10, 1),
-                currentDate: new Date(),
-            },
-            purposeStatus: true,
-            startDate: null,
-            endDate: null,
-            showStart: false,
-            showEnd: false,
-            formatEndTime: null,
-            formatStartTime: null,
             list: [],
             loading: false,
             finished: false,
@@ -146,6 +77,9 @@ export default {
                 rows: 20,
             },
             dataShow: true,
+            // 类型为回访学员时
+            formatEndTime: null,
+            formatStartTime: null,
         };
     },
     mounted() {
@@ -161,6 +95,9 @@ export default {
         this.getList()
     },
     methods: {
+        tabChange() {
+            this.$refs.trainModel.changeDropDownItemStatus()
+        },
         search(val) {
             this.params.search = val
             this.onResetList()
@@ -184,54 +121,6 @@ export default {
                 }
             })
         },
-        cancelBtn() {
-            this.formatStartTime = null;
-            this.formatEndTime = null;
-            this.onResetList()
-            this.$refs.item.toggle();
-        },
-        okBtn() {
-            // if(this.formatStartTime && this.formatEndTime) {
-            //     }
-            this.onResetList()
-            this.$refs.item.toggle();
-        },
-        onChangeDate(type) {
-            let dataForm = this.dataForm
-            if(type == 'showEnd') {
-                if(this.formatStartTime) {
-                dataForm.minDate = new Date(dayjs(this.formatStartTime))
-                }
-                setTimeout(() => {
-                    dataForm.currentDate = this.formatEndTime ? new Date(dayjs(this.formatEndTime)) : new Date()
-                }, 500)
-            } else if(type == 'showStart') {
-                dataForm.minDate = new Date(2000, 0, 1)
-                setTimeout(() => {
-                    dataForm.currentDate = this.formatStartTime ? new Date(dayjs(this.formatStartTime)) : new Date()
-                }, 500)
-            }
-            dataForm.status = true
-            dataForm.type = type
-        },
-        chioseDate(value) {
-            let dataForm = this.dataForm
-            if(dataForm.type == 'showStart') {
-                this.formatStartTime = dayjs(value).format('YYYY-MM-DD')
-                if(this.formatEndTime && dayjs(value).unix() > dayjs(this.formatEndTime).unix()) {
-                this.formatEndTime = null
-                }
-            } else if(dataForm.type == 'showEnd') {
-                this.formatEndTime = dayjs(value).format('YYYY-MM-DD')
-            }
-            dataForm.status = false
-        },
-        // onTypeChange() {
-        //   this.onResetList()
-        // },
-        onPurposeChange() {
-            this.onResetList()
-        },
         async getList() {
             let params = this.params;
             params.startTime = this.formatStartTime || null
@@ -255,17 +144,7 @@ export default {
                 this.finished = true;
                 this.dataShow = false;
             }
-        },
-        formatter(type, val) {
-        if (type === "year") {
-            return `${val}年`;
-        } else if (type === "month") {
-            return `${val}月`;
-        } else if (type == "day") {
-            return `${val}日`;
         }
-        return val;
-        },
     },
 };
 </script>
@@ -283,61 +162,14 @@ export default {
         box-shadow: none;
     }
 }
-.visit-tips {
-    background-color: #fff;
-    padding: 10px 10px 0;
-    span {
-        display: inline-block;
-        padding: 6px 12px;
-        background-color: #FFF6DE;
-        font-size: 12px;
-        color: #FF802C;
-    }
-}
+
 /deep/.van-tab {
     font-size: .16rem;
 }
 /deep/.search .van-search {
     margin: 10px 0 ;
 }
-.searchArray {
-    font-size: .14rem;
-    padding-top: .15rem;
-    padding-bottom: .12rem;
-    color: #1A1A1A;
-    background-color: #f5f5f5;
-}
-.title-style {
-    display: flex;
-    align-items: center;
-    justify-content: center;
-}
-.box {
-    display: flex;
-    flex-direction: row;
-    align-items: center;
-    margin-left: .02rem;
-}
-.box-up {
-    width: 0;
-    height: 0;
-    border-left: 4px solid transparent;
-    border-right: 4px solid transparent;
-    border-bottom: 5px solid #ccc;
-    &.active {
-        border-bottom-color: #01C1B5;
-    }
-}
-.box-down {
-    width: 0;
-    height: 0;
-    border-left: 4px solid transparent;
-    border-right: 4px solid transparent;
-    border-top: 5px solid #ccc;
-    &.active {
-        border-top-color: #01C1B5;
-    }
-}
+
 .data-content {
     margin: .15rem .15rem 0;
     border-radius: .1rem;

+ 280 - 0
src/views/trainStatistics/trainModel.vue

@@ -0,0 +1,280 @@
+<template>
+    <div class="trainModel">
+        <div class="visit-tips" v-show="activeType == 'visited'">
+            <span>学员上周训练时间不足80分钟或训练次数小于4次则需要回访</span>
+        </div>
+        <search @onSearch="search" placeholder="学生姓名或手机号">
+            <template #left>
+                <van-dropdown-menu style="padding-right: .1rem" :close-on-click-outside="false" active-color="#01C1B5">
+                    <van-dropdown-item title="筛选" ref="item" class="visitTime">
+                        <van-cell title="日期" is-link @click="showCalendar = true" :value="calendarValue" value-class="calendarColor"></van-cell>
+                    </van-dropdown-item>
+                </van-dropdown-menu>
+            </template>
+        </search>
+        <van-row class="searchArray">
+            <van-col span="6" class="title-style">
+                训练时长
+                <div>
+                    <i class="box box-up active" style="margin-bottom: .02rem;"></i>
+                    <i class="box box-down"></i>
+                </div>
+            </van-col>
+            <van-col span="6" class="title-style">
+                训练次数
+                <div>
+                    <i class="box box-up active" style="margin-bottom: .02rem;"></i>
+                    <i class="box box-down"></i>
+                </div>
+            </van-col>
+            <van-col span="6" class="title-style">
+                训练天数
+                <div>
+                    <i class="box box-up active" style="margin-bottom: .02rem;"></i>
+                    <i class="box box-down"></i>
+                </div>
+            </van-col>
+            <van-col span="6" class="title-style">
+                评测次数
+                <div>
+                    <i class="box box-up active" style="margin-bottom: .02rem;"></i>
+                    <i class="box box-down"></i>
+                </div>
+            </van-col>
+        </van-row>
+        <van-calendar
+            v-model="showCalendar"
+            :minDate="minDate"
+            :default-date="defaultDate"
+            :first-day-of-week="1"
+            :formatter="formatterDay"
+            color="#01C1B5"
+            type="range"
+            get-container="body"
+            @select="selectDate"
+            @confirm="onConfirm"
+            @close="onClose"
+        />
+    </div>
+</template>
+
+<script>
+import Search from '@/components/Search';
+import dayjs from "dayjs";
+export function getNowDateAndMonday(time) {
+    let timestamp = new Date(time.replace(/-/g, "/")).getTime();
+    let serverDate = new Date(time);
+    if (serverDate.getDay() == 0) {
+        timestamp -= 7 * 24 * 60 * 60 * 1000;
+    }
+    let mondayTime = timestamp - (serverDate.getDay() - 1) * 24 * 60 * 60 * 1000;
+
+    let mondayData = new Date(mondayTime);
+    //年
+    let mondayY = mondayData.getFullYear();
+    //月
+    let mondayM =
+        mondayData.getMonth() + 1 < 10
+        ? "0" + (mondayData.getMonth() + 1)
+        : mondayData.getMonth() + 1;
+    //日
+    let mondayD =
+        mondayData.getDate() < 10
+        ? "0" + mondayData.getDate()
+        : mondayData.getDate();
+
+    let str = mondayY + "-" + mondayM + "-" + mondayD;
+    return str;
+}
+export function getNowDateAndSunday(time) {
+    let timestamp = new Date(time.replace(/-/g, "/")).getTime();
+    let serverDate = new Date(time);
+
+    let num = 7 - serverDate.getDay();
+    if (num == 7) {
+        num = 0;
+    }
+    let sundayTiem = timestamp + num * 24 * 60 * 60 * 1000;
+    let SundayData = new Date(sundayTiem);
+    //年
+    let tomorrowY = SundayData.getFullYear(); //月
+    let tomorrowM =
+        SundayData.getMonth() + 1 < 10
+        ? "0" + (SundayData.getMonth() + 1)
+        : SundayData.getMonth() + 1;
+    //日
+    let tomorrowD =
+        SundayData.getDate() < 10
+        ? "0" + SundayData.getDate()
+        : SundayData.getDate();
+    let str = tomorrowY + "-" + tomorrowM + "-" + tomorrowD;
+    return str;
+}
+export default {
+    props: {
+        active: {
+            type: String,
+            default: 'all'
+        },
+        defaultTime: {
+            type: Number,
+            default: 0
+        }
+    },
+    components: { Search },
+    data() {
+        return {
+            showCalendar: false,
+            minDate: new Date(2000, 0, 1),
+            defaultDate:[],
+            // 类型为全部时
+            startDay: null,
+            endDay: null,
+            searchType: {
+                
+            }
+        }
+    },
+    async mounted() {
+        let defaultTime = this.defaultTime
+        let day = defaultTime * 7
+        let startTime = new Date(), endTime = new Date()
+        if(day > 0) {
+            startTime = getNowDateAndMonday(dayjs().add(day, 'day').format("YYYY-MM-DD"))
+            endTime = getNowDateAndSunday(dayjs().add(day, 'day').format("YYYY-MM-DD"))
+        } else {
+            startTime = getNowDateAndMonday(dayjs().subtract(Math.abs(day), 'day').format("YYYY-MM-DD"))
+            endTime = getNowDateAndSunday(dayjs().subtract(Math.abs(day), 'day').format("YYYY-MM-DD"))
+        }
+        this.defaultDate = [new Date(startTime), new Date(endTime)]
+        this.startDay = startTime
+        this.endDay = endTime
+        // let startTime = getNowDateAndMonday(dayjs)
+        // let startTime = getNowDateAndMonday(dayjs().format("YYYY-MM-DD"));
+        // let endTime = getNowDateAndSunday(dayjs().format("YYYY-MM-DD"));
+    },
+    computed: {
+        calendarValue() {
+            return `${dayjs(this.startDay).format("YYYY/MM/DD")} - ${dayjs(this.endDay).format("YYYY/MM/DD")}`;
+        },
+        activeType() {
+            return this.active
+        }
+    },
+    methods: {
+        search(val) {
+            this.params.search = val
+            // this.onResetList()
+        },
+        changeDropDownItemStatus() {
+            this.$refs.item.toggle(false)
+        },
+        selectDate(date) {
+            let [start, end] = date;
+            if (start) {
+                const num = dayjs(start).get("day");
+                if (num === 0) {
+                    start = dayjs(start).subtract(6, "day");
+                } else {
+                    start = dayjs(start).subtract(num - 1, "day");
+                }
+            }
+            if (start) {
+                const num = 7 - dayjs(start).get("day");
+                if (num < 7) {
+                    end = dayjs(start).add(num, "day");
+                }
+            }
+            this.defaultDate = [new Date(start.valueOf()),new Date(end.valueOf())]
+        },
+        onConfirm(date) {
+            let [start, end] = date;
+            this.showCalendar = false;
+            if (start) {
+                const num = dayjs(start).get("day");
+                if (num === 0) {
+                start = dayjs(start).subtract(6, "day");
+                } else {
+                start = dayjs(start).subtract(num - 1, "day");
+                }
+            }
+            if (end) {
+                const num = 7 - dayjs(end).get("day");
+                if (num < 7) {
+                end = dayjs(end).add(num, "day");
+                }
+            }
+            this.startDay = dayjs(start).format("YYYY-MM-DD");
+            this.endDay = dayjs(end).format("YYYY-MM-DD");
+        },
+        onClose() {
+            // 关闭弹窗时初始化默认日期
+            this.defaultDate = [new Date(this.startDay), new Date(this.endDay)]
+        },
+        formatterDay(day) {
+            const month = day.date.getMonth() + 1;
+            const date = day.date.getDate();
+            let nowDate = new Date()
+            if(month == nowDate.getMonth() + 1 && date == nowDate.getDate()){
+                day.text = '今天'
+            }
+            return day
+        }
+    }
+}
+</script>
+
+<style lang="less" scoped>
+.calendarColor {
+    color: #333;
+}
+.visit-tips {
+    background-color: #fff;
+    padding: 10px 10px 0;
+    span {
+        display: inline-block;
+        padding: 6px 12px;
+        background-color: #FFF6DE;
+        font-size: 12px;
+        color: #FF802C;
+    }
+}
+.searchArray {
+    font-size: .14rem;
+    padding-top: .15rem;
+    padding-bottom: .12rem;
+    color: #1A1A1A;
+    background-color: #f5f5f5;
+}
+.title-style {
+    display: flex;
+    align-items: center;
+    justify-content: center;
+}
+.box {
+    display: flex;
+    flex-direction: row;
+    align-items: center;
+    margin-left: .02rem;
+}
+.box-up {
+    width: 0;
+    height: 0;
+    border-left: 4px solid transparent;
+    border-right: 4px solid transparent;
+    border-bottom: 5px solid #ccc;
+    &.active {
+        border-bottom-color: #01C1B5;
+    }
+}
+.box-down {
+    width: 0;
+    height: 0;
+    border-left: 4px solid transparent;
+    border-right: 4px solid transparent;
+    border-top: 5px solid #ccc;
+    &.active {
+        border-top-color: #01C1B5;
+    }
+}
+</style>