DatePackage.vue 11.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
<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 () {
    localStorage.removeItem('selectedContactArr')
    // date 日期
    const date = this.$route.query.date;
    if (date) {
      this.date = date
      this.defaultDate = new Date(date)
    }
    // 缓存中读取排期
    let packageData = localStorage.getItem('packageData')
    if (packageData) {
      this.packageData = JSON.parse(packageData)

      console.log(this.packageData)
      if (this.date) {
        this.setComboList()
      }
    }
    // 当前的商品信息
    let showCourseData = localStorage.getItem('showCourseData')
    if (showCourseData) {
      this.showCourseData = JSON.parse(showCourseData)
    }
    console.log(showCourseData)
  },
  methods: {
    // 获取库存
    GetOrderPayCount () {
      let showCourseData = JSON.parse(localStorage.getItem('showCourseData'))
      this.mgop({
        api: 'mgop.sz.hswsy.OrderPayCount', // 必须
        host: 'https://mapi.zjzwfw.gov.cn/',
        dataType: 'JSON',
        type: 'GET',
        appKey: 'fuxgnukl+2001895516+edccpx', // 必须
        headers: {
          //   'isTestUrl': '1'
        },
        data: {
          "productId": showCourseData.id,
          "startDate": this.date,
        },
        onSuccess: res => {
          if (res.data.data) {
            this.numOne = res.data.data
          }
        },
        onFail: err => {
          console.log('err', err)
        }
      });
    },
    // 获取库存第二个参数
    getSurplusComboCount (bindId) {
      let showCourseData = JSON.parse(localStorage.getItem('showCourseData'))
      this.mgop({
        api: 'mgop.sz.hswsy.SurplusComboCount', // 必须
        host: 'https://mapi.zjzwfw.gov.cn/',
        dataType: 'JSON',
        type: 'GET',
        appKey: 'fuxgnukl+2001895516+edccpx', // 必须
        headers: {
          //   'isTestUrl': '1'
        },
        data: {
          "bindId": bindId,
          "productId": showCourseData.id,
          "startDate": this.date,
        },
        onSuccess: res => {
          if (res.data.data) {
            this.numSecond = res.data.data
          }
        },
        onFail: err => {
          console.log('err', err)
        }
      });
    },
    // 选择排期
    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 () {
      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
        }
        localStorage.setItem('selectCombo', JSON.stringify(this.comboList[this.active]))
        this.$router.push({ name: 'ServiceCheckOrder', query: query })
      }
    },
  }
}
</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>
<style lang="scss">
.elder {
  #datePackage {
    .tag_item {
      .tag_title {
        font-size: 44px;
      }
      .package_name {
        font-size: 40px;
      }
      .period .period_item {
        font-size: 40px;
      }
      .tag_title_flex .count {
        font-size: 40px;
      }
      .package_num {
        font-size: 40px;
        .tint {
          font-size: 40px;
        }
      }
    }
    .Collection {
      .box1 p {
        font-size: 56px;
        span {
          font-size: 40px;
        }
        del {
          font-size: 40px;
        }
      }
      .box > span {
        font-size: 44px;
      }
    }
  }
}
</style>