<template>
  <view class="skip">
    <view class="bg">
    </view>
    <view class="text">
      {{ tip }}
    </view>
  </view>
</template>

<script>
  import {
    mapState,
    mapMutations
  } from "vuex";
  import Base64 from "../../util/base64.js"
  import Parse from "../../util/parse.js"

  export default {
    data() {
      return {
        tip: "跳转中，请稍后..."
      }
    },
    computed: {
      // ...mapState(["appId", "stationId", "phoneNumber", "countryCode", "purePhoneNumber", "openId", "unionId",
      //   "userInfo"
      // ]),
    },
    created() {
      uni.showLoading({
        title: '跳转中...',
        mask: true
      });
    },
    async onLoad(e) {
      console.log(e)
      // #ifdef  MP-WEIXIN
      const res = decodeURIComponent(e.q)
      // #endif
      // #ifdef  MP-ALIPAY
      const res = e.qrCode
      // #endif
      const parse = new Parse.getInstance();
      const info = await parse.parseCode(res).catch((e) => {
        uni.hideLoading()
        return parse.scanCode(true, {
          title: '( •̀ ω •́ )✧',
          showCancel: false,
          content: '亲，您扫的码不对哦~',
          confirmText: '重新扫码',
        })
      })
      this.goIndex();
    },
    methods: {
      ...mapMutations(["updateStationId", "updateLabelId", "updateEmployeeId"]),
      goIndex() {
        uni.hideLoading();
        uni.redirectTo({
          url: "/pages/index/index"
        })
      },
      goList() {
        uni.hideLoading();
        uni.redirectTo({
          url: "/pages/list/list"
        })
      },
      async parseCode(msg) {
        const showModalPro = await uni.showModal({
          title: '( •̀ ω •́ )✧',
          showCancel: false,
          content: '亲，扫码错误哦~',
          confirmText: '重新扫码',
        })
        const scanCodePro = await uni.scanCode({
          onlyFromCamera: true
        })
        // try {
        //   const parse = new Parse.getInstance();
        //   const info = await parse.start(res)
        //   return Promise.resolve(info)
        // } catch (e) {
        //   const showModalPro = await uni.showModal({
        //     title: '(～￣▽￣)～',
        //     showCancel: false,
        //     content: '您扫的二维码错误~',
        //     confirmText: '重新扫码',
        //   })
        //   const scanCodePro = await uni.scanCode({
        //     onlyFromCamera: true
        //   })
        //   this.scanCode();
        // }
      },
      async scanCode() {
        const showModalPro = await uni.showModal({
          title: '(～￣▽￣)～',
          showCancel: !!this.stationId,
          content: msg || '此站点只能扫码进入~',
          cancelText: '返回',
          confirmText: '立刻扫码',
        })
        const parse = Parse.getInstance()
        if (showModalPro[1].cancel) {
          uni.navigateBack({
            delta: 1
          })
        } else if (showModalPro[1].confirm) {
          const parse = Parse.getInstance()
          return parse.scanCode().catch((err) => {
            return this.scanCode(err)
          });
        }
      }
    }
  }
</script>

<style lang="scss">
  page {
    .skip {
      position: relative;

      .bg {
        // background: url(../../static/icon/1_b01_down.2x.png) no-repeat 0px 0px;
        background: url(../../static/icon/goto.png) no-repeat 0px 0px;
        background-size: 100% 100%;
        width: 182rpx;
        height: 216rpx;
        position: absolute;
        top: 238rpx;
        left: 270rpx;
      }

      .text {
        font-size: 40rpx;
        width: 750rpx;
        text-align: center;
        font-weight: 550;
        color: #000000;
        line-height: 56rpx;
        position: absolute;
        top: 522rpx;
      }
    }
  }
</style>
