configureTask.vue 8.11 KB
<!--长课程配置  -->
<template>
  <div class="long-wrap">
    <div class="long-first-section">
      <!-- 搜索 -->
      <div class="long-wrap-search">
        <div class="tabs">
          <div
            :class="{
              'tabs-item': true,
              'tabs-item-active': index === activeIndex
            }"
            v-for="(item, index) in conditionList"
            :key="index"
            @click="handleClick(index)"
          >
            {{ item.confValue }}
          </div>
        </div>
        <week-time-picker @changeWeek="changeWeek"></week-time-picker>
      </div>
      <div class="analysis-index-wrap">
        配课分析指标
        <div class="analysis-index-list">
          <div
            :class="[
              'analysis-index-item',
              analysisActiveIndex == index ? 'active' : ''
            ]"
            v-for="(analyse, index) in analysisList"
            v-if="analyse.isshow"
            :key="index"
            @click="handleAnalysisClick(index)"
          >
            {{ analyse.name }}({{ analyse.value }})
          </div>
        </div>
      </div>

      <!-- 门店指标数据 -->
      <store-indicators
        @openWindow="openWindow"
        :longForm="longForm"
      ></store-indicators>
    </div>
    <!-- 课程任务配置 -->
    <course-config
      ref="couseConfig"
      @openWindow="openWindow"
      :longAllData="longAllData"
      :longForm="longForm"
      @changeBrand="changeBrand"
    ></course-config>
    <!--上周学习复盘 -->
    <last-week-replay
      :longForm="longForm"
      :lastForm="lastForm"
      ref="lastWeekReplay"
      :configId="configId"
    ></last-week-replay>
  </div>
</template>
<script>
import weekTimePicker from "./components/weekTimePicker"
// import monthTimePicker from "./components/monthTimePicker"
import storeIndicators from "./components/storeIndicators"
import courseConfig from "./components/courseConfig"
import lastWeekReplay from "./components/lastWeekReplay"
import { findAllConfig } from "@/api/serviceCentre"
import { long_businessOpt } from "@/common/constants.js"
export default {
  components: {
    weekTimePicker,
    storeIndicators,
    courseConfig,
    lastWeekReplay
    // monthTimePicker
  },
  data() {
    return {
      longAllData: {},
      configId: "", //品牌id
      longForm: {
        scene: 1,
        startTime: "",
        endTime: "",
        isDisabled: true
      },
      lastForm: {
        startTime: "",
        endTime: ""
      },
      analysisActiveIndex: 0,
      activeIndex: 0,
      conditionList: long_businessOpt,
      analysisList: [
        {
          name: "上周数据",
          value: "2025/6/30-2025/7/6",
          isshow: true
        },
        {
          name: "当月数据",
          value: "2025/7/1-2025/7/31",
          isshow: true
        }
      ]
    }
  },
  created() {
    //查询所有配置
    this.findAllConfigData()
  },
  watch: {
    analysisList: {
      handler(val) {
        this.handleSetTime()
      },
      deep: true
    }
  },
  methods: {
    changeBrand(val) {
      this.configId = val
      this.$refs.lastWeekReplay && this.$refs.lastWeekReplay.handleClick()
    },
    handleRegExp(time) {
      return time.replace(/\//g, "-")
    },
    findAllConfigData() {
      findAllConfig()
        .then((res) => {
          this.longAllData = res
          console.log(res, 111)
          this.$refs.couseConfig.findAllItemByConfigIdData &&
            this.$refs.couseConfig.findAllItemByConfigIdData()
        })
        .catch((err) => {
          new Error(err)
        })
    },
    getPreviousWeekMonthToLastSunday(weekOffset) {
      const start = this.getStartOfWeek(weekOffset)
      // 获取“前一周”的周日
      const lastSunday = new Date(start)
      lastSunday.setDate(lastSunday.getDate() - 1) // 上周日

      // 获取该周所在的月份
      const targetMonth = new Date(lastSunday)

      const firstDayOfTargetMonth = new Date(
        targetMonth.getFullYear(),
        targetMonth.getMonth(),
        1
      )
      return `${this.formatDate(firstDayOfTargetMonth)}-${this.formatDate(
        lastSunday
      )}`
      //   return {
      //     start: this.formatDate(firstDayOfTargetMonth),
      //     end: this.formatDate(lastSunday)
      //   }
    },
    getStartOfWeek(weekOffset) {
      const date = new Date()
      date.setDate(date.getDate() + weekOffset * 7)
      const day = date.getDay()
      const diff = date.getDate() - day + (day === 0 ? -6 : 1)
      return new Date(date.setDate(diff))
    },
    formatDate(date) {
      const year = date.getFullYear()
      const month = String(date.getMonth() + 1).padStart(2, "0")
      const day = String(date.getDate()).padStart(2, "0")
      return `${year}/${month}/${day}`
    },
    changeWeek(data) {
      console.log(data, "data")
      let { weekOffset } = data
      let analysisObj = {
        0: (weekOffset) => {
          const start = this.getStartOfWeek(weekOffset - 1)
          const end = new Date(start)
          end.setDate(start.getDate() + 6)
          return `${this.formatDate(start)}-${this.formatDate(end)}`
        },
        1: (weekOffset) => {
          return this.getPreviousWeekMonthToLastSunday(weekOffset)
        }
      }
      //   analysisActiveIndex 0:上周 1:当月
      this.analysisList[0].value = analysisObj[0](weekOffset)
      this.analysisList[1].value = analysisObj[1](weekOffset)
      this.longForm.isDisabled = data.isDisabled
      this.handleSetTime()
    },
    handleClick(index) {
      this.activeIndex = index
      this.longForm.scene = this.conditionList[index].confId
      this.analysisActiveIndex = 0
      this.handleSetTime()
      this.analysisList[1].isshow = index != 0 ? false : true
    },
    handleSetTime() {
      let [start, end] =
        this.analysisList[this.analysisActiveIndex].value.split("-")
      let [start1, end1] = this.analysisList[0].value.split("-")
      this.longForm.startTime = this.handleRegExp(start.trim())
      this.longForm.endTime = this.handleRegExp(end.trim())
      this.lastForm.startTime = this.handleRegExp(start1.trim())
      this.lastForm.endTime = this.handleRegExp(end1.trim())
    },
    handleAnalysisClick(index) {
      this.analysisActiveIndex = index
      this.handleSetTime()
    },
    openWindow(data) {
      console.log(data)
      this.$emit("openWindow", data)
    }
  }
}
</script>
<style lang="scss" scoped>
.long-wrap {
  margin: 0 20px;
  height: 82vh;
  overflow-y: scroll;
  overflow-x: hidden;
  .long-first-section {
    background: #fff;
    padding: 16px 20px 4px 20px;
    box-sizing: border-box;
  }
  .long-wrap-search {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .tabs {
      display: flex;
      align-items: center;
      background: #fff;
      border: 1px solid #dbdbdb;
      border-radius: 2px;
      .tabs-item {
        padding: 8px 20px;
        cursor: pointer;
        font-size: 12px;
        font-weight: 400;
        color: #1d1d1d;
        border-right: 1px solid #dbdbdb;
      }
      .tabs-item-active {
        color: #ffffff;
        background: #2a58ad;
      }
      .tabs-item:last-child {
        border-right: none;
      }
    }
  }
  .count-down {
    display: flex;
    align-items: center;
    width: 376px;
    height: 32px;
    border-radius: 2px;
    opacity: 1;
    background: #f47f131a;
    padding: 6px 11px;
    box-sizing: border-box;
    color: #666666;
    font-size: 12px;
    font-weight: 400;
    margin: 12px 0;
    .error-circle {
      width: 14px;
      height: 14px;
      margin-right: 8px;
    }
  }
  .analysis-index-wrap {
    display: flex;
    align-items: center;
    color: #111111;
    font-size: 16px;
    font-weight: 500;
    margin-top: 16px;
    .analysis-index-list {
      display: flex;
      align-items: center;
      margin-left: 13px;
      .analysis-index-item {
        padding: 6px 12px;
        color: #1d1d1d;
        font-size: 12px;
        font-weight: 400;
        margin-right: 8px;
        border-radius: 0 2px 2px 0;
        background: #f2f3f5;
        cursor: pointer;
      }
      .active {
        background: #2a58ad26;
        color: #2a58ad;
      }
    }
  }
}
</style>