<template>
  <view class="content">
	<view>请在PC浏览器输入后台登录网址：</view>  
	<view>https://ng.xazhima.com/ ；</view>
	<view>使用下方“扫一扫”功能扫码登录</view>
    
	<view class="options">
      <view  v-for="(item, idx) in list" :key="idx" class="options-item" @click="goDetailFn(idx, item.url)"  v-if="item.isShow">
        <view class="img-box">
          <img :src="item.icon" alt="" class="options-item-img" />
        </view>
        <view class="options-item-name">
          {{ item.name }}
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import md5 from "@/common/md5.js";
export default {
	components: {
	},
  data() {
    return {
      isAuth: true,
      userHeadImg: "",
      userNickName: "",
	  userscanCode:"",
      list: [
		 {
		   icon: "/static/scan.png", 
		   name: "扫一扫" ,
		   // url: "/pages/index/scanCode/index",
		   isShow:true,
		  },
      ],
    };
  },
  onLoad() {
  },
  onShow() {
  },
  methods: {
    codeReg(strs){
			let reg = /\[(.*?)\]/gi;
			let str = strs;
			let tmp = str.match(reg) , result = '';
			if (tmp) {
				for (let i = 0; i < tmp.length; i++) {
					 result = tmp[i].replace(reg, "$1")
				}
			} else {
				console.log("no match.");
			}
			 console.log(result)
			this.getScanCode(result)
    },
	getScanCode(codeRes) {
	    let md5Sign = md5(
	      "method=" +
	        "user" +
	        "&timestamp=" +
	        getApp().globalData.globalTimestamp +
	        "&secret=" +
	        getApp().globalData.secret
	    );
	    let url =
	      getApp().globalData.shareUrl +
	      "api/api.php" +
	      "?method=user&action=qrcode_login&timestamp=" +
	      getApp().globalData.globalTimestamp +
	      "&sign=" +
	      md5Sign;
	    uni.request({
	      url: url,
	      method: "POST",
	      header: {
	        "content-type": "application/x-www-form-urlencoded",
	      },
	      data: {
	        openid:getApp().globalData.open_id,
			qrcode:codeRes
	      },
	      success: (res) => {
	        if (res.data.code === 200) {
				uni.showToast({
					title:res.data.msg,
					icon:'none'
				})
	        } else {
				uni.showToast({
					title:res.data.msg,
					icon:'none'
				})
			}
	      },
	      fail: () => {
	        console.log("连接失败");
	      },
	    });
	  },		
    goDetailFn(index, url) {
      let that = this;
	  uni.scanCode({
	      success: function (res) {
	          console.log('条码类型：' + res.scanType);
	          console.log('条码内容：' + res.result);
	  		  that.codeReg(res.result)
	      }
	  });
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
	display: flex;
    flex-direction: column;
    padding: 40rpx;
    color: #444;
    font-size: 30rpx;
  .options {
     margin-top: 15%;
    .options-item {
		background-color: #fff;
		display: flex;
		box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
		border-radius: 10rpx;
		height: 120rpx;
		align-items: center;
      .img-box {
        margin-left: 40rpx;
        .options-item-img {
          width: 56rpx;
          height: 56rpx;
        }
      }
      .options-item-name {
        margin-left: 40rpx;
        font-weight: 600;
        font-size: 30rpx;
        margin-bottom: 10rpx;
      }
    }
  }
}
.fontGrey {
  color: $uni-text-color-grey;
}
</style>