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.scanCode({
      success: function (val) {
        console.log(val.result);
        if (util.isJSON(val.result)) {
          let value = JSON.parse(val.result);
          if (value.END == 'C' && value.TYPE == 'memberCode' && value.ID.length >= 18) {
            Http.postRequest(config.api.memScan, app.globalData.token, '加载中', {
              memCode: value.ID
            }, (res) => {
              console.log(res, 9999999999)
              if (res.code == 200) {
                if (res.data.discountRate != 100) {
                  var discountRate = res.data.discountRate / 10;
                } else {
                  var discountRate = "暂无折扣";
                }
                tt.navigateTo({
                  url: `/pages/Add/index?address=${res.data.address}&id=${res.data.id}&levelName=${res.data.levelName}&nickName=${res.data.nickName}&name=${res.data.name}&phone=${res.data.phone}&score=${res.data.score}&discountRate=${discountRate}&credit=${res.data.credit}`
                })
              } 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.navigateTo({
      url: '/pages/memberPhone/index?a=1',
    })
  },
})

