<template>
  <div>
    <Myheader></Myheader>
     <tabs></tabs>
    <div class="rc-main">
      <div class="rc-usermain">
        <div class="rc-header">
          <span
            v-for="(item, index) in discountlist"
            :key="index"
            @click="selectGoods(item, index)"
            :class="activeIndex == index ? 'active' : 'unactive'"
          >
            {{ item.title }}
          </span>
          <!-- <span @click="tanchu()">弹出</span> -->
        </div>
        <div class="rs-dis">
          <div
            class="rc-discount"
            v-for="(item, index) in newlist"
            :key="index"
          >
            <img :src="userimage" alt="" />
            <div class="rc-contair">
              <div class="rc-left" ref="userleft" id="userleft">
                <div>
                  <i>￥</i><span>{{ item.couponAmount }}</span>
                </div>
                <strong>{{ item.couponName }}</strong>
              </div>
              <div class="rc-right">
                <i>
                  {{ item.couponDesc }}
                </i>
                <div class="rc-main" id="rc-main">
                  <span>有效期{{item.validFrom}}至</span>
                  <em>{{ item.validTo }}</em>
                </div>
                   <nuxt-link :to="`/`">
                <div class="rc-footer" v-if="userload">
                  <span @click="usertiao()">立即使用</span>
                </div>
                </nuxt-link>
              </div>

       
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>


<script>
 import {allConfig,getdraw} from "../../ajax/getData";
 import tabs from "@/components/tabs.vue";
export default {
     middleware: 'metaTitle',
    // middleware: 'metaTitle',
  meta: {title: '优惠券'},
  data() {
    return {
      userload: true,
      pastdue: false,
      unused: false,
      usermessage:[],
      userstates:0,
      userimage: require("../../assets/image/unused.png"),
      newlist: [
        {
          price: "30",
          pricestype: "新客优惠券",
          special: "全场每满299-30",
          period: "有效期",
          starttime: "2021.11.29-2022.01.28",
          catimage: require("../../assets/image/unused.png"),
        },
        {
          price: "30",
          pricestype: "新客优惠券",
          special: "全场每满299-30",
          period: "有效期",
          starttime: "2021.11.29-2022.01.28",
          catimage: require("../../assets/image/unused.png"),
        },
        {
          price: "30",
          pricestype: "新客优惠券",
          special: "全场每满299-30",
          period: "有效期",
          starttime: "2021.11.29-2022.01.28",
          catimage: require("../../assets/image/unused.png"),
        },
        {
          price: "30",
          pricestype: "新客优惠券",
          special: "全场每满299-30",
          period: "有效期",
          starttime: "2021.11.29-2022.01.28",
        },
        {
          price: "30",
          pricestype: "新客优惠券",
          special: "全场每满299-30",
          period: "有效期",
          starttime: "2021.11.29-2022.01.28",
        },
        {
          price: "30",
          pricestype: "新客优惠券",
          special: "全场每满299-30",
          period: "有效期",
          starttime: "2021.11.29-2022.01.28",
        },
        {
          price: "30",
          pricestype: "新客优惠券",
          special: "全场每满299-30",
          period: "有效期",
          starttime: "2021.11.29-2022.01.28",
        },
        {
          price: "30",
          pricestype: "新客优惠券",
          special: "全场每满299-30",
          period: "有效期",
          starttime: "2021.11.29-2022.01.28",
        },
        {
          price: "30",
          pricestype: "新客优惠券",
          special: "全场每满299-30",
          period: "有效期",
          starttime: "2021.11.29-2022.01.28",
        },
        {
          price: "30",
          pricestype: "新客优惠券",
          special: "全场每满299-30",
          period: "有效期",
          starttime: "2021.11.29-2022.01.28",
        },
      ],
      discountlist: [
        {
          title: "未使用",
        },
        {
          title: "已使用",
        },
        {
          title: "已过期",
        },
      ],

      preferential: [
        {
          price: "30",
          pricestype: "新客优惠券",
          special: "全场每满299-30",
          period: "有效期",
          starttime: "2021.11.29-2022.01.28",
        },
        {
          price: "30",
          pricestype: "新客优惠券",
          special: "全场每满299-30",
          period: "有效期",
          starttime: "2021.11.29-2022.01.28",
        },
        {
          price: "30",
          pricestype: "新客优惠券",
          special: "全场每满299-30",
          period: "有效期",
          starttime: "2021.11.29-2022.01.28",
        },
      ],
      userdiscount:[],
      activeIndex: 0,
    };
  },
  methods: {

         //获取用户领取的优惠券
          async userdraw(mobile,states) {
      let data = await getdraw(mobile,states);
      if(data){
       console.log(data);
       this.newlist=data.data;
       console.log(this.newlist);
      }
            
    },
    selectGoods(item, index) {
      this.activeIndex = index;
      if (this.activeIndex == 1) {
        this.userload = false;
        this.pastdue = true;
        this.userimage = require("../../assets/image/hasused.png");
        this.userstates=1
        this.userdraw(this.usermessage.data.mobile,1)
      }
      if (this.activeIndex == 0) {
        this.userload = true;
        this.pastdue = false;
        this.userdraw(this.usermessage.data.mobile,0)

        this.userstates=0
        this.userimage = require("../../assets/image/unused.png");
      }
      if (this.activeIndex == 2) {
        this.userload = false;
        this.pastdue = true;
        this.userdraw(this.usermessage.data.mobile,2)
        this.userstates=2
        this.userimage = require("../../assets/image/expired.png");
      }
      console.log(index);
    },

    usertiao(){
           this.$router.push({
        path: "/",
        query: {
          stype: 1,
        },
      });
    },


    
    //    tanchu() {
    //        console.log('---')
    // var option = {
    // customer: {id: '', name: '', email: '', mobile: '', memberId: '999999'}
    // }
    // dis_livchat(option);
    // }
  },
  mounted() {
   if(this.usermessage!=='' ||this.usermessage.data!==undefined){
     this.usermessage= JSON.parse(localStorage.getItem("userInfo"));

   }
     
       this.userdraw(this.usermessage.data.mobile,);
  },
  components: {
    Myheader,
    tabs
  },
};
import Myheader from "~/components/header.vue";
</script>

<style lang="less" scoped>
// 手机端
@media screen and(min-width: 320px) and(max-width:768px) {
  .active {
    font-size: 14px;
    color: #e2001a;

  }
  .unactive {
    font-size: 14px;
    color: #444444;

  }
  .rc-header {
    height: 64px;
    display: flex;
    align-items: center;
    margin-left: 23px;
    span {
      display: block;
      margin-left: 32px;
    
    }
    span:first-child {
      margin-left: 0;
    }
  }

  .rc-discount {
    margin-left: 23px;
    display: flex;
    margin-top: 16px;
    width: 335px;
    background: #ffffff;
    position: relative;
    height: 120px;
    img {
      display: block;
      width: 100%;
      height: 100%;
    }
    .rc-contair {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
    }
    .rc-left {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      color: #e1001a;
      padding-right: 21px;
      width: 30%;
      float: left;
      height: 100%;
      i {
        font-style: normal;
        font-size: 12px;
      }
      span {
        font-size: 26px;
      }
      strong {
        font-style: normal;
        font-size: 12px;
        display: block;
        margin-top: 8px;
      }
    }
    .rc-right {
      display: flex;
      flex-direction: column;
      margin-left: 36px;
      justify-content: center;
      height: 100%;
      i {
        font-style: normal;
        font-size: 14px;
        color: #e1001a;
      }
      .rc-main {
        color: #999999;
        font-size: 12px;
      }
      span {
        display: block;
        margin-top: 8px;
      }
      em {
        font-style: normal;
      }
    }
    .rc-footer {
      display: flex;
     justify-content: flex-end;
      span {
        width: 72px;
        height: 25px;
        background: #e2001a;
        text-align: center;
        line-height: 25px;
        font-size: 12px;
        color: #ffffff;
        margin-bottom: 8px;
        border-radius: 100px;
        margin-right: 30px;
      }
    }

    
  }
}
// //    /* 最小768px最大1920 *pc端/
@media screen and (min-width: 768px) and (max-width: 1920px) {
  .rc-main {
    width: 100%;
    .rc-usermain {
      width: 92%;
      margin: 0 auto;
    }
  }
  .active {
    font-size: 16px;
    color: #e2001a;
    cursor: pointer;
  }
  .unactive {
    font-size: 16px;
    color: #444444;
    cursor: pointer;
  }
  .rc-header {
    height: 64px;
    display: flex;
    align-items: center;
    margin-left: 23px;
    justify-content: center;
    span {
      display: block;
      margin-left: 32px;
    }
    span:first-child {
      margin-left: 0;
    }
  }
  .rs-dis {
    margin-top: 70px;
  }
  .rc-discount {
    margin-left: 50px;
    display: flex;
    margin-top: 40px;
    width: 335px;
    background: #ffffff;
    position: relative;
    height: 120px;
    float: left;
    img {
      display: block;
      width: 100%;
      height: 100%;
    }
    .rc-contair {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
    }
    .rc-left {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      color: #e1001a;
      padding-right: 21px;
      width: 30%;
      float: left;
      height: 100%;
      i {
        font-style: normal;
        font-size: 12px;
      }
      span {
        font-size: 26px;
      }
      strong {
        font-style: normal;
        font-size: 12px;
        display: block;
        margin-top: 8px;
      }
    }
    .rc-right {
      display: flex;
      flex-direction: column;
      margin-left: 36px;
      justify-content: center;
      height: 100%;
      i {
        font-style: normal;
        font-size: 16px;
        color: #e1001a;
      }
      .rc-main {
        color: #999999;
        font-size: 12px;
      }
      span {
        display: block;
        margin-top: 8px;
      }
      em {
        font-style: normal;  
      }
    }
    .rc-footer {
      display: flex;
      justify-content: flex-end;
      margin-right: 10px;
      span {
        width: 72px;
        height: 25px;
        background: #e2001a;
        text-align: center;
        line-height: 25px;
        font-size: 12px;
        color: #ffffff;
        margin-bottom: 8px;
        border-radius: 100px;
        margin-right: 30px;
      }
    }
 
    .rc-userright {
      display: flex;
      align-items: center;
      width: 78px;
      justify-content: center;
      height: 78px;
      border: 2px solid #999999;
      border-radius: 50%;
      span {
        width: 60px;
        height: 60px;
        border: 1px solid #999999;
        border-radius: 50%;
        display: flex;
        align-items: center;
        text-align: center;
        justify-content: center;
      }
    }
  }
}
</style>