const config = require('../../config/config.js')
const Http = require('../../utils/http.js')
const HttpBasics = require('../../utils/HttpBasics.js')
const util = require('../../utils/util.js')
import * as echarts from '../../ec-canvas/echarts';
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  gotoSaoyiSao: function () { //扫码核销、识别会员码
    tt.setStorageSync("verifyRemark", 12)
    tt.scanCode({
      success: function (val) {
        console.log(val.result);
        if (util.isJSON(val.result)) {
          let value = JSON.parse(val.result);
          console.log(value, 'value');
          if (value.END == 'C' && value.TYPE == 'couponorder' && value.ID.length >= 18) {
            Http.getRequest(config.api.couponOrderDetail, app.globalData.token, '加载中', {
              couponOrderId: value.ID,
              couponTenantId: value.couponTenantId
            }, (res) => {
              tt.setStorageSync("verifyRemark", 12)
              tt.setStorageSync("couponOrderId", value.ID)
              tt.setStorageSync("couponTenantId", value.couponTenantId)
              if (res.code == 200) {
                tt.navigateTo({
                  url: `/pages/writeoffPage/writeoffPage`
                })
              } else {
                tt.reLaunch({
                  url: `/pages/errorPage/errorPage?errTitle=${res.message}`,
                })
              }
            })
          } else if (value.END == 'C' && value.TYPE == 'memberCode' && value.ID.length >= 18) {
            Http.postRequest(config.api.memScan, app.globalData.token, '加载中', {
              memCode: value.ID
            }, (res) => {
              if (res.code == 200) {
                if (res.data.discountRate != 100) {
                  var discountRate = res.data.discountRate / 10;
                } else {
                  var discountRate = "暂无折扣";
                }
                tt.navigateTo({
                  url: `/pages/member/member?address=${res.data.address}&avatarUrl=${tt.getStorageSync("avatarUrl")}&levelName=${res.data.levelName}&name=${res.data.name}&phone=${res.data.phone}&score=${res.data.score}&discountRate=${discountRate}`
                })
              } else {
                tt.showModal({
                  title: "抱歉",
                  content: res.message,
                  showCancel: false
                })
              }
            })
          } else {
            tt.showToast({
              title: '请扫描正确的二维码',
              icon: 'none',
              duration: 1300
            })
          }
        } else {
          tt.showToast({
            title: '请扫描正确的二维码',
            icon: 'none',
            duration: 1300
          })
        }
      },
      fail: function () {
        tt.showToast({
          title: '请扫描正确的二维码',
          icon: 'none',
          duration: 1300
        })
      }
    })
  },
  // 跳转到手动核销
  aoto: function () {
    tt.setStorageSync("verifyRemark", 11)
    tt.setStorageSync
    tt.navigateTo({
      url: '/pages/write0ff/write0ff',
    })
  },
})