<template>
  <div class="myOrders">
    <!-- <van-nav-bar title="" left-text="返回首页" left-arrow @click-left="back" /> -->
    <van-tabs v-model="active" :before-change="beforeTabChange">
      <van-tab title="待付款">
        <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoadpay()">
          <div class="showBoxDPJ" v-for="(item,index) in paylist" :key="index">
            <div class="topLine">
              <div class="topLineL">订单编号:{{item.orderpaynum}}</div>
              <div class="topLineR" style="color:#F64C37">待付款</div>
            </div>
            <div class="top" @click="toEdit(item)">
              <div class="pic">
                <img :src="item.coverUrl ? item.coverUrl : require('@/assets/service/defCoure.jpg')" alt="" style="width:100%;height:100%">
              </div>
              <div class="basefont">
                <div class="titlefont">{{item.baseName}}</div>
                <div class="tcfont">套餐名称:{{item.courseName}}</div>
                <div class="tcfont">数量*{{item.orderCount}}</div>
              </div>
              <div class="priceRight">¥{{item.paymoney}}</div>
            </div>
            <div class="detailsBox">
              <div class="detailsBoxOne">
                <div>订单创建时间</div>
                <div>{{item.intime.replace(/T/,' ')}}</div>
              </div>
            </div>
          </div>
        </van-list>
      </van-tab>
      <van-tab title="待使用">
        <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoadmove()">
          <div class="showBox" v-for="(item,index) in movelist" :key="index">
            <div class="top" @click="toEdit(item)">
              <div class="pic">
                <img :src="item.coverUrl ? item.coverUrl : require('@/assets/service/defCoure.jpg')" alt="" style="width:100%;height:100%">
              </div>
              <div class="basefont">
                <div class="titlefont">{{item.baseName}}</div>
                <div class="tcfont">套餐名称:{{item.courseName}}</div>
                <div class="tcfont">数量*{{item.orderCount}}</div>
              </div>
              <div class="priceRight">¥{{item.paymoney}}</div>
            </div>
            <div class="groupTime">
              <van-icon name="clock-o" /><span class="grey"> 活动日期</span><span> {{item.startDate}} - {{ item.endDate}}</span>
            </div>
            <div class="btnBox">
              <div></div>
              <div>
                <van-button class="btn" type="warning" plain size="small" @click="showPintuanAbout = true" style="margin-right:15px">退款说明</van-button>
                <!-- <van-button type="info" size="small" @click="makeCode(item.id)">核销码</van-button> -->
                <van-button class="btn" type="info" size="small" @click="toCode(item)">核销码</van-button>
              </div>
            </div>
            <div class="detailsBox">
              <div class="detailsBoxOne">
                <div>订单创建时间</div>
                <div>{{item.intime.replace(/T/,' ')}}</div>
              </div>
              <div class="detailsBoxOne">
                <div>订单编号</div>
                <div>{{item.orderpaynum}}</div>
              </div>
            </div>
          </div>
        </van-list>
      </van-tab>
      <van-tab title="待评价">
        <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoadCareer()">
          <div class="showBoxDPJ" v-for="(item,index) in datalist" :key="index">
            <div class="topLine">
              <div class="topLineL">订单编号:{{item.orderpaynum}}</div>
              <div class="topLineR" @click="evaluate(item)">去评价 ></div>
            </div>
            <div class="top" @click="toEdit(item)">
              <div class="pic">
                <img :src="item.coverUrl ? item.coverUrl : require('@/assets/service/defCoure.jpg')" alt="" style="width:100%;height:100%">
              </div>
              <div class="basefont">
                <div class="titlefont">{{item.baseName}}</div>
                <div class="tcfont">套餐名称:{{item.courseName}}</div>
                <div class="tcfont">数量*{{item.orderCount}}</div>
              </div>
              <div class="priceRight">¥{{item.paymoney}}</div>
            </div>
            <div class="detailsBox">
              <div class="detailsBoxOne">
                <div>订单创建时间</div>
                <div>{{item.intime.replace(/T/,' ')}}</div>
              </div>
            </div>
          </div>
        </van-list>
      </van-tab>
      <van-tab title="已评价">
        <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad()">
          <div class="showBoxDPJ showBoxYPJ" v-for="(item,index) in list" :key="index">
            <div class="top">
              <div class="pic">
                <img :src="item.coverUrl ? item.coverUrl : require('@/assets/service/defCoure.jpg')" alt="" style="width:100%;height:100%">
              </div>
              <div class="basefont">
                <div class="titlefont">{{item.baseName}}</div>
                <div class="tcfont">套餐名称:{{item.courseName}}</div>
                <div class="tcfont">数量*{{item.orderCount}}</div>
              </div>
              <div class="priceRight">¥{{item.paymoney}}</div>
            </div>
            <div class="boxdf">
              <div class="title">课程评分</div>
              <div class="fr">
                <van-rate v-model="item.courseScore" void-icon="star" void-color="#eee" color="#FFCC00" :size="16" readonly />
                <span class="rate">{{item.courseScore}}.0</span>
              </div>
            </div>
            <div class="boxdf">
              <div class="title">基地评分</div>
              <div class="fr">
                <van-rate v-model="item.baseScore" void-icon="star" void-color="#eee" color="#FFCC00" :size="16" readonly />
                <span class="rate">{{item.baseScore}}.0</span>
              </div>
            </div>
            <p class="evaluation"><span>评价:</span>{{item.evaluation}}</p>
            <div class="evaluation_img_box">
              <img class="evaluation_img" v-for="(imgItem,index) in item.imageList" :key="index" :src="imgItem.imgUrl" alt="" @click="previewImg(imgItem.imgUrl)">
            </div>
            <!-- <p class="evaluation_time">评价于2020-12-21</p> -->
          </div>
        </van-list>
      </van-tab>
    </van-tabs>

    <!--二维码-->
    <!-- <div class="qrcodeBox" @click.self="qrcodeShow = false" v-show="qrcodeShow">
      <div id="qrcode"></div>
    </div> -->

    <!--退款说明-->
    <van-popup v-model="showPintuanAbout" round>
      <div class="pintuan_about">
        <img class="about_img" src="@/assets/service/tip.png" alt="">
        <p class="about_title">退款说明</p>
        <div class="about_box">
          <p class="about_content">1、凡拼团活动报名人数未达最低成团数,本团活动则不开营,系统将在72小时内,全额退还,且不产生违约风险赔偿。</p>
          <p class="about_content">2、如果您因行程发生变动需要取消预订,建议您尽可能提前与平台商户取得联系,并按商品订购须知或该商户旅游合同条款进行退款。</p>
          <p class="about_content" style="font-weight:bold">如若未声明与明确的,按《浙江省境内旅游合同》条款退款。</p>
          <!-- <p class="about_content">(1)出发前7日至4日,支付旅游费用总额的10%。</p>
        <p class="about_content">(2)出发前3日至1日,支付旅游费用总额的15%。</p>
        <p class="about_content">(3)出发当日,支付旅游费用总额的20%。</p> -->
        </div>
        <p class="about_know" @click="showPintuanAbout=false">我知道了</p>
      </div>
    </van-popup>

    <van-popup v-model="showCode" round get-container="body">
      <div class="codeCss">
        <div class="showBox">
          <div class="top">
            <div class="pic">
              <img :src="codeData.coverUrl ? codeData.coverUrl : require('@/assets/service/defCoure.jpg')" alt="" style="width:100%;height:100%">
            </div>
            <div class="basefont">
              <div class="titlefont">{{codeData.baseName}}</div>
              <div class="tcfont">套餐名称:{{codeData.courseName}}</div>
              <div class="tcfont">数量*{{codeData.orderCount}}</div>
            </div>
            <!-- <div class="priceRight">¥{{codeData.paymoney}}</div> -->
          </div>
          <div class="groupTime">
            <van-icon name="clock-o" /><span class="grey"> 活动日期</span><span> {{codeData.startDate}} - {{ codeData.endDate}}</span>
          </div>
          <div class="qrcodeBox">
            <div id="qrcode" ref="imageWrapper" v-if="!imgUrl"></div>
            <div class="imgBox">
              <img :src="imgUrl" v-if="imgUrl" style="width:100%;height:100%" />
            </div>
          </div>
          <div class="numShow">
            {{codeData.id}}
          </div>
          <div class="fontBottom">请向工作人员出示</div>
        </div>
      </div>
    </van-popup>
    <van-popup v-model="showPreview" round get-container="body">
      <img class="preview_img" :src="previewUrl" alt="">
    </van-popup>
  </div>
</template>

<script>
import QRCode from 'qrcodejs2'  // 引入qrcode
import html2canvas from "html2canvas"
// let Base64 = require('js-base64').Base64;
export default {
  name: 'ServiceOrder',
  data () {
    return {
      userInfo: '',
      active: 1,
      paylist: [], //待付款
      movelist: [],  //待核销
      list: [],  //所有
      datalist: [],  //未评价
      loading: false,
      finished: false,
      pageCareerIndex: 0,
      qrcodeShow: false,
      showPintuanAbout: false,
      showCode: false,
      codeData: {},
      imgUrl: '',
      previewUrl: '',//图片预览
      showPreview: false,
    }
  },
  computed: {
    nicknameUser () {
      return localStorage.getItem('nicknameUser')
    }
  },
  mounted () {
    let userInfo = localStorage.getItem('userInfo');
    if (userInfo) {
      this.userInfo = JSON.parse(userInfo);
    }
    // 进入页面进到第几个tab
    if (this.$route.query.active || this.$route.query.active == 0) {
      this.active = this.$route.query.active
    }
  },
  methods: {
    back () {
      this.$router.push({ name: 'ServiceKQ' })
    },
    beforeTabChange (item) {
      console.log(item)
      this.paylist = [];
      this.movelist = [];
      this.list = [];
      this.datalist = [];
      if (item == 0) {
        this.onLoadpay()
      } else if (item == 1) {
        // this.onLoadCareer()
        this.onLoadmove()
      } else if (item == 2) {
        this.onLoadCareer()
      } else {
        this.onLoad()
      }
      return true;
    },
    //获取待支付
    onLoadpay () {
      this.mgop({
        api: 'mgop.sz.hswsy.GetOrderPayList', // 必须
        host: 'https://mapi.zjzwfw.gov.cn/',
        dataType: 'JSON',
        type: 'GET',
        appKey: 'fuxgnukl+2001895516+edccpx', // 必须
        headers: {
          //   'isTestUrl': '1'
        },
        data: {
          "userId": localStorage.getItem('centerNo'),
          "type": 1,
          "page": 1,
          "pageSize": 999
        },
        onSuccess: res => {
          console.log('待支付:', res)
          if (res.data.status == 1) {
            this.paylist = res.data.data.list;
            this.loading = false;
            this.finished = true;
          } else {
            this.$toast.fail(res.data.message);
          }
        },
        onFail: err => {
          console.log('err', err)
        }
      });
    },
    //获取已支付
    onLoadmove () {
      this.mgop({
        api: 'mgop.sz.hswsy.GetOrderPayList', // 必须
        host: 'https://mapi.zjzwfw.gov.cn/',
        dataType: 'JSON',
        type: 'GET',
        appKey: 'fuxgnukl+2001895516+edccpx', // 必须
        headers: {
          //   'isTestUrl': '1'
        },
        data: {
          "userId": localStorage.getItem('centerNo'),
          "type": 2,
          "page": 1,
          "pageSize": 999
        },
        onSuccess: res => {
          console.log('已支付:', res)
          if (res.data.status == 1) {
            this.movelist = res.data.data.list;
            this.loading = false;
            this.finished = true;
          } else {
            this.$toast.fail(res.data.message);
          }
        },
        onFail: err => {
          console.log('err', err)
        }
      });
    },
    //获取待评价
    onLoadCareer () {
      this.mgop({
        api: 'mgop.sz.hswsy.GetOrderPayList', // 必须
        host: 'https://mapi.zjzwfw.gov.cn/',
        dataType: 'JSON',
        type: 'GET',
        appKey: 'fuxgnukl+2001895516+edccpx', // 必须
        headers: {
          //   'isTestUrl': '1'
        },
        data: {
          "userId": localStorage.getItem('centerNo'),
          "type": 3,
          "page": 1,
          "pageSize": 999
        },
        onSuccess: res => {
          console.log('待评价:', res)
          if (res.data.status == 1) {
            this.datalist = res.data.data.list;
            this.loading = false;
            this.finished = true;
          } else {
            this.$toast.fail(res.data.message);
          }
        },
        onFail: err => {
          console.log('err', err)
        }
      });
    },
    //获取已评价
    onLoad () {
      this.mgop({
        api: 'mgop.sz.hswsy.GetOrderPayList', // 必须
        host: 'https://mapi.zjzwfw.gov.cn/',
        dataType: 'JSON',
        type: 'GET',
        appKey: 'fuxgnukl+2001895516+edccpx', // 必须
        headers: {
          //   'isTestUrl': '1'
        },
        data: {
          "userId": localStorage.getItem('centerNo'),
          "type": 4,
          "page": 1,
          "pageSize": 999
        },
        onSuccess: res => {
          console.log('已评价:', res)
          if (res.data.status == 1) {
            this.list = res.data.data.list;
            this.loading = false;
            this.finished = true;
          } else {
            this.$toast.fail(res.data.message);
          }
        },
        onFail: err => {
          console.log('err', err)
        }
      });
    },
    //生成核销码
    makeCode (id) {
      console.log(id.toString())
      document.getElementById('qrcode').innerHTML = '';
      this.qrcodeShow = true;

      let qrcode = new QRCode('qrcode', {
        width: 200,
        height: 200,
        text: id.toString(), // 二维码地址
      })
      this.canvanqrCode()
    },
    //评价
    evaluate (item) {
      window.localStorage.setItem('courseInfo', JSON.stringify(item))
      this.$router.push({ name: 'evaluateCourse' })
    },
    //核销码
    toCode (item) {
      this.codeData = {}
      this.showCode = true
      this.codeData = item
      this.imgUrl = ''
      setTimeout(() => {
        this.makeCode(item.id)
      }, 1000);
    },
    //跳转
    toEdit (item) {
      this.$router.push({ path: 'abroad_detail', query: { courseId: item.courseId } })
    },
    //二维码转图片
    canvanqrCode () {
      html2canvas(this.$refs.imageWrapper, {
        width: 200,
        height: 200
      }).then(canvas => {
        let dataURL = canvas.toDataURL("image/png");
        this.imgUrl = dataURL;
      });
    },
    // 预览图片
    previewImg (url) {
      this.previewUrl = url;
      this.showPreview = true
    }
  },
  components: {
  }
}
</script>

<style lang="scss" scoped>
.myOrders {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: auto;
  background: #f6f7fa;

  // .qrcodeBox {
  //   position: fixed;
  //   top: 0;
  //   left: 0;
  //   bottom: 0;
  //   right: 0;
  //   background-color: rgba(0, 0, 0, 0.4);

  //   #qrcode {
  //     position: absolute;
  //     top: 50%;
  //     left: 50%;
  //     transform: translate(-50%, -50%);
  //     padding: 20px;
  //     background: #fff;
  //   }
  // }

  .list {
    padding: 20px;
    box-sizing: border-box;

    li:not(:last-child) {
      border-bottom: 1px dashed #eee;
    }

    li {
      margin-bottom: 10px;
      padding-bottom: 10px;

      .baseName {
        padding-left: 50px;
        font-size: 30px;
        background: url("../../assets/service/hoom.png") no-repeat left top;
        background-size: contain;
        margin: 10px 0;
      }
      .career_type {
        font-size: 30px;
        margin: 0;
        margin-top: 10px;
      }
      .career_create {
        color: #ccc;
        font-size: 30px;
        margin: 0;
        margin-top: 10px;
      }
      .course {
        min-height: 60px;

        img {
          object-fit: cover;
          width: 200px;
          float: left;
          margin-right: 10px;
        }

        .courseCont {
          h5 {
            word-break: break-all;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            overflow: hidden;
            font-size: 30px;
            margin: 0;
          }

          p {
            color: #ccc;
            font-size: 30px;
            margin: 0;
            margin-top: 10px;
          }
        }
      }

      .orderCont {
        padding: 40px 0;
        font-size: 28px;

        span {
          color: red;
        }

        .pj {
          float: right;
        }
      }

      .codeBtn {
        text-align: right;
        margin-top: 15px;
      }
    }
  }
  //待审核
  .showBox {
    width: 702px;
    background: #fff;
    border-radius: 16px;
    margin: 30px auto;
    padding: 34px 24px;
    box-sizing: border-box;

    .top {
      display: flex;

      .pic {
        width: 124px;
        height: 124px;
        flex-shrink: 0;
      }
      .basefont {
        padding: 0 20px;
        box-sizing: border-box;
        .titlefont {
          color: #333333;
          font-size: 28px;
          margin-bottom: 18px;
        }
        .tcfont {
          color: #535353;
          font-size: 24px;
        }
      }
      .priceRight {
        width: 110px;
        font-size: 28px;
        color: #f64c37;
        line-height: 200px;
      }
    }
    .groupTime {
      font-size: 28px;
      line-height: 60px;
      height: 60px;
      margin-bottom: 20px;
      // background-color: #f5f6fa;
      padding-left: 10px;
      box-sizing: border-box;

      .grey {
        color: #999999;
      }
    }
    .btnBox {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .detailsBox {
      color: #999999;
      font-size: 28px;
      margin-top: 60px;

      .detailsBoxOne {
        margin-top: 20px;
        display: flex;
        justify-content: space-between;
      }
    }
  }
  //待评价
  .showBoxDPJ {
    width: 702px;
    // height: 330px;
    margin: 30px auto;
    padding: 34px 24px;
    box-sizing: border-box;
    background: #fff;
    border-radius: 16px;
    .topLine {
      height: 60px;
      display: flex;
      justify-content: space-between;
      .topLineL {
        font-size: 23px;
        color: #999999;
      }
      .topLineR {
        font-size: 23px;
      }
    }
    .top {
      display: flex;

      .pic {
        width: 124px;
        height: 124px;
        flex-shrink: 0;
      }
      .basefont {
        padding: 0 20px;
        box-sizing: border-box;
        .titlefont {
          margin-bottom: 18px;
          color: #333333;
          font-weight: bold;
          font-size: 28px;
        }
        .tcfont {
          color: #535353;
          font-size: 24px;
        }
      }
      .priceRight {
        width: 110px;
        font-size: 28px;
        color: #f64c37;
        line-height: 200px;
      }
    }
    .detailsBox {
      color: #999999;
      font-size: 28px;

      .detailsBoxOne {
        margin-top: 20px;
        display: flex;
        justify-content: space-between;
      }
    }
  }
  // 已评价
  .showBoxYPJ {
    .boxdf {
      padding: 10px 0;
      font-size: 5vw;
      display: flex;
      .title {
        font-size: 28px;
        margin-right: 10px;
      }
      .rate {
        color: #ffcc00;
        font-size: 30px;
        margin-left: 10px;
      }
    }
    .evaluation {
      font-size: 30px;
      span {
        font-weight: bold;
      }
    }
    .evaluation_img_box {
      margin-top: 22px;
      .evaluation_img {
        width: 212px;
        height: 212px;
        margin-right: 9px;
        margin-bottom: 9px;
        &:nth-of-type(3n) {
          margin-right: 0;
        }
      }
    }
    .evaluation_time {
      margin-top: 18px;
      text-align: right;
      color: #999999;
      font-size: 28px;
    }
  }

  .pintuan_about {
    width: 592px;
    box-sizing: border-box;
    padding: 0 50px;
    .about_img {
      width: 112px;
      margin: 0 auto;
      margin-top: 30px;
      display: block;
    }
    .about_title {
      font-size: 34px;
      font-weight: bold;
      text-align: center;
    }
    .about_content {
      font-size: 30px;
      margin-top: 20px;
    }
    .about_know {
      font-size: 32px;
      text-align: center;
      color: #3385ff;
      margin-top: 60px;
      margin-bottom: 44px;
    }
  }
}
.codeCss {
  width: 700px;
  height: 850px;
  position: relative;

  .showBox {
    width: 702px;
    // height: 500px;
    // background-color: aquamarine;
    margin: 30px auto;
    padding: 34px 24px;
    box-sizing: border-box;

    .top {
      display: flex;

      .pic {
        width: 124px;
        height: 124px;
        flex-shrink: 0;
      }
      .basefont {
        padding: 0 20px;
        box-sizing: border-box;
        .titlefont {
          color: #333333;
          font-size: 28px;
          margin-bottom: 18px;
        }
        .tcfont {
          color: #535353;
          font-size: 24px;
        }
      }
      .priceRight {
        width: 110px;
        font-size: 28px;
        color: #f64c37;
        line-height: 200px;
      }
    }
    .groupTime {
      font-size: 28px;
      line-height: 60px;
      height: 60px;
      margin-bottom: 20px;
      background-color: #f5f6fa;
      padding-left: 10px;
      box-sizing: border-box;

      .grey {
        color: #999999;
      }
    }
    .qrcodeBox {
      width: 100%;
      height: 430px;

      #qrcode {
        transform: translate(25%, 10%);
        // margin: auto;
      }
      .imgBox {
        width: 370px;
        height: 370px;
        margin: 30px auto 0;
        // transform: translate(25%, 10%);
      }
    }
    .numShow {
      width: 100%;
      font-size: 28px;
      text-align: center;
      color: #999999;
    }
    .fontBottom {
      width: 100%;
      font-weight: bold;
      font-size: 28px;
      text-align: center;
    }
  }
}
.preview_img {
  width: 100vw;
}
</style>
<style lang="scss">
.elder {
  .myOrders {
    .showBoxDPJ {
      .topLine {
        .topLineL,
        .topLineR {
          font-size: 40px;
        }
      }
      .top {
        .basefont {
          .titlefont {
            font-size: 40px;
          }
          .tcfont {
            font-size: 36px;
          }
        }
        .priceRight {
          font-size: 40px;
        }
      }
      .detailsBox {
        font-size: 40px;
        .detailsBoxOne {
          display: block;
        }
      }
    }
    .showBox {
      .top {
        .basefont {
          .titlefont {
            font-size: 40px;
          }
          .tcfont {
            font-size: 36px;
          }
        }
        .priceRight {
          font-size: 40px;
        }
      }
      .detailsBox {
        font-size: 40px;
        .detailsBoxOne {
          display: block;
        }
      }
      .groupTime {
        font-size: 36px;
      }
      .btnBox {
        .btn {
          font-size: 36px;
        }
      }
    }
    .showBoxYPJ {
      .boxdf .title {
        font-size: 36px;
      }
      .evaluation {
        font-size: 36px;
      }
    }
    .pintuan_about {
      .about_title {
        font-size: 44px;
      }
      .about_box {
        height: 600px;
        overflow: auto;
      }
      .about_content {
        font-size: 36px;
      }
      .about_know {
        font-size: 40px;
      }
    }
  }
}
</style>