DatePackage.vue 11.1 KB
<template>
  <div id="datePackage">
    <!-- <div class="tag_item">
      <p class="tag_title">商品名称</p>
      <p class="package_name">{{showCourseData.course_name}}</p>
    </div> -->
    <div class="tag_item">
      <p class="tag_title">活动日期</p>
      <p class="package_name" :class="date?'active':''" @click="showCalendar=true">{{date||'选择日期'}}</p>
      <van-calendar v-model="showCalendar" :default-date="defaultDate" @confirm="chooseDate" :show-confirm="false" color="#3F92FF" :formatter="formatCalendar" />
    </div>
    <div class="tag_item" v-if="comboList[active]">
      <p class="tag_title">成团情况<span class="pintuan_status" v-if="comboList[active].clusterName">{{comboList[active].clusterName}}</span></p>
      <p class="package_name">最低拼团数 {{comboList[active].peopleCount}}人 已报名人数{{numOne}}/{{comboList[active].stockCount}}人</p>
    </div>
    <div class="tag_item">
      <p class="tag_title">天数</p>
      <p class="package_name">{{days}}天</p>
    </div>
    <div class="tag_item" v-if="date">
      <p class="tag_title">套餐</p>
      <div class="period">
        <!-- <span class="period_item" :class="active==index?'active':''" v-for="(item,index) in comboList" :key="index" @click="choosePeriod(index)">{{item.comboName}} ¥{{item.actualPrice}}</span> -->
        <div class="period_item" :class="active==index?'active':''" v-for="(item,index) in comboList" :key="index" @click="choosePeriod(index)">套餐{{index + 1}} :{{item.comboName}} ¥{{item.actualPrice}}</div>
      </div>
    </div>
    <div class="tag_item">
      <div class="tag_title tag_title_flex">
        <span>数量</span>
        <div class="tag_title_right">
          <span class="btn" @click="countReduce">-</span>
          <span class="count">{{count}}</span>
          <span class="btn" @click="count++">+</span>
        </div>
      </div>
      <div class="package_num">
        <span>库存数量({{numSecond}} /</span>
        <span class="tint">{{numOne+numSecond}})</span>
      </div>
    </div>
    <div class="Collection">
      <div class="box box1">
        <p v-if="active>-1&&comboList[active]"><span>¥</span>{{comboList[active].actualPrice*1000*count/1000}} <del>{{comboList[active].productPrice*1000*count/1000}}</del></p>
      </div>
      <div class="box box2">
        <span @click="checkOrder()">去支付</span>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'ServiceDatePackage',
  data () {
    return {
      date: null,
      defaultDate: null,
      packageData: '',
      showCourseData: '',
      comboList: '',
      active: 0,//选中的排期
      showCalendar: false,
      count: 1,
      days: 1,
      numOne: 0,
      numSecond: 0,
    }
  },
  mounted () {
    sessionStorage.removeItem('selectedContactArr')
    // date 日期
    const date = this.$route.query.date;
    if (date) {
      this.date = date
      this.defaultDate = new Date(date)
    }
    // 缓存中读取排期
    let packageData = sessionStorage.getItem('packageData')
    if (packageData) {
      this.packageData = JSON.parse(packageData)

      console.log(this.packageData)
      if (this.date) {
        this.setComboList()
      }
    }
    // 当前的商品信息
    let showCourseData = sessionStorage.getItem('showCourseData')
    if (showCourseData) {
      this.showCourseData = JSON.parse(showCourseData)
    }
    console.log(showCourseData)
  },
  methods: {
    // 获取库存
    GetOrderPayCount () {
      let showCourseData = JSON.parse(sessionStorage.getItem('showCourseData'))
      this.yxAxios.get(`${this.yanxueUrl}/api/Product/OrderPayCount/ByBindId?productId=${showCourseData.id}&startDate=${this.date}`).then((res) => {
        if (res.data) {
          this.numOne = res.data.data
          // console.log(this.numOne)
        }
      })
    },
    // 获取库存第二个参数
    getSurplusComboCount (bindId) {
      let showCourseData = JSON.parse(sessionStorage.getItem('showCourseData'))
      this.yxAxios.get(`${this.yanxueUrl}/api/Product/SurplusComboCount/ByBindId?bindId=${bindId}&productId=${showCourseData.id}&startDate=${this.date}`).then((res) => {
        if (res.data) {
          this.numSecond = res.data.data
          // console.log(this.numSecond)
        }
      })

    },
    // 选择排期
    choosePeriod (index) {
      this.active = index;
      this.days = this.packageData['0'].days ? this.packageData[index].days : 0
      let bindId = this.packageData['0'].comboList[index].id ? this.packageData['0'].comboList[index].id : ''
      let dateBindComboId = this.packageData['0'].comboList[index].dateBindComboId
      this.GetOrderPayCount(bindId)
      this.getSurplusComboCount(dateBindComboId)
    },
    // 选择日期
    chooseDate (date) {
      let canChoose = false
      for (let i in this.packageData) {
        if (this.Moment(date, 'YYYY-MM-DD').format('YYYY-MM-DD') == this.Moment(this.packageData[i].dayName, 'YYYY-MM-DD').format('YYYY-MM-DD')) {
          canChoose = true;
        }
      }
      if (!canChoose) {
        this.$toast('当前日期无可选套餐')
        return;
      }
      this.date = this.Moment(date, 'YYYY-MM-DD').format('YYYY-MM-DD')
      this.active = 0;
      this.showCalendar = false;
      this.setComboList()
    },
    // 设置日历文字
    formatCalendar (day) {
      // console.log(day)
      for (let i in this.packageData) {
        if (this.Moment(day.date, 'YYYY-MM-DD').format('YYYY-MM-DD') == this.Moment(this.packageData[i].dayName, 'YYYY-MM-DD').format('YYYY-MM-DD')) {
          day.bottomInfo = '¥' + this.packageData[i].comboList[0].actualPrice;
        }
      }
      return day;
    },
    // 根据日期设置套餐
    setComboList () {
      let bindId = this.packageData['0'].comboList['0'].id ? this.packageData['0'].comboList['0'].id : ''
      let dateBindComboId = this.packageData['0'].comboList['0'].dateBindComboId
      this.days = this.packageData['0'].days ? this.packageData['0'].days : 0
      this.GetOrderPayCount(bindId)
      this.getSurplusComboCount(dateBindComboId)
      for (let i in this.packageData) {
        if (this.Moment(this.packageData[i].dayName, 'YYYY-MM-DD').format(('YYYY-MM-DD')) == this.date) {
          this.comboList = this.packageData[i].comboList;
          break;
        }
      }
    },
    // 减少数量
    countReduce () {
      if (this.count > 1) {
        this.count--
      }
    },

    checkOrder () {
      let isLogin = this.checkLogin()
      if (!isLogin) return;
      if (this.count > this.numSecond) {
        this.$toast('库存不足');

      }
      else if (!this.date) {
        this.$toast('请选择日期');
      } else if (this.active == -1) {
        this.$toast('请选择时间段');
      } else {
        const query = {
          date: this.date,
          count: this.count
        }
        sessionStorage.setItem('selectCombo', JSON.stringify(this.comboList[this.active]))
        this.$router.push({ name: 'ServiceCheckOrder', query: query })
      }
    },
    // 判断是否已登录
    checkLogin () {
      if (process.env.NODE_ENV != "production") return true;
      
      const userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
      const publicName = sessionStorage.getItem('publicName')
      if (!userInfo?.phone) {
        sessionStorage.setItem('prePage', 'ServiceDatePackage');
        sessionStorage.setItem('prePageQuery', JSON.stringify({ date:this.date }));
        this.$router.push({ name: 'LoginPublic', query: { publicName: publicName } })
        return false;
      }
      return true;
    },
  }
}
</script>
<style lang="scss" scoped>
#datePackage {
  padding-top: 40px;
  .tag_item {
    padding: 22px;
    .tag_title {
      font-size: 34px;
      font-weight: bold;
      margin-top: 0;
      margin-bottom: 32px;
      display: flex;
      align-items: center;
      .pintuan_status {
        font-size: 24px;
        padding: 2px 10px;
        background: #ffe9b1;
        border-radius: 6px;
        margin-left: 12px;
      }
    }
    .package_name {
      font-size: 28px;
      width: 100%;
      background: #f5f6fa;
      border-radius: 12px;
      padding: 20px 18px;
      box-sizing: border-box;
      margin: 0;
      &.active {
        background: #3f92ff;
        color: #fff;
      }
    }
    // 时间段
    .period {
      .period_item {
        padding: 10px 20px;
        font-size: 28px;
        margin-bottom:15px;
        text-align: left;
        background: #f5f6fa;
        border-radius: 10px;
        box-sizing: border-box;
        &.active {
          background: #3f92ff;
          color: #fff;
        }
      }
    }
    .tag_title_flex {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 0;
      padding: 50px 0;
      .tag_title_right {
        display: flex;
        align-items: center;
      }
      .btn {
        width: 48px;
        height: 48px;
        background: #f5f6fa;
        border-radius: 10px;
        font-size: 32px;
        line-height: 48px;
        text-align: center;
      }
      .count {
        width: 100px;
        text-align: center;
        font-size: 32px;
      }
    }
    .package_num {
      font-size: 30px;
      width: 50%;
      float: right;
      text-align: right;
      border-radius: 12px;
      padding: 0px 18px;
      box-sizing: border-box;
      .tint {
        font-size: 30px;
        font-weight: normal;
        color: #909399;
      }
    }
  }
  .Collection {
    background-color: white;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 28px 22px;
    box-sizing: border-box;
    padding-bottom: 50px;
    z-index: 500;
    box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.34);

    .box {
      display: inline-block;
      vertical-align: middle;
      color: #666666;
      .icon {
        display: inline-block;
        width: 45%;
        text-align: center;
        font-size: 24px;
        p {
          // margin: 0;
          color: #999999;
          margin-top: 8px;
        }
        i {
          font-size: 48px;
          color: rgb(45, 45, 45);
          font-weight: bold;
        }
      }

      > span {
        display: inline-block;
        width: 100%;
        line-height: 92px;
        box-sizing: border-box;
        border-radius: 100px;
        color: white;
        font-size: 32px;
        background: #4092ff;
        text-align: center;
        box-shadow: 0px 10px 40px 0px #a0c9ff;
        b {
          display: inline-block;
          vertical-align: middle;
          margin-left: 20px;
          color: white;
        }
        i {
          vertical-align: middle;
          font-size: 44px;
          font-weight: bold;
        }
      }
    }
    .box1 {
      width: 40%;
      p {
        font-size: 49px;
        font-weight: bold;
        color: #f64c37;
      }
      span {
        font-size: 32px;
      }
      del {
        font-size: 20px;
        color: #999;
      }
    }
    .box2 {
      width: 60%;
    }
  }
}
::v-deep .van-calendar__bottom-info {
  color: #f95555;
}
::v-deep .van-calendar__selected-day {
  background: #ecf2fc !important;
  border: 4px solid #79abff;
  box-sizing: border-box;
  color: #333;
}
</style>