
var content = {
  'cn':{
    item1:'订单',
    btn:'订单确定',
    btn1:'订单取消',
    serial:'订单号:',
    merchantSerial:'商户流水号:',
    amount:'金额:',
    cny:"人民币:",
    UserName: "户名:",
    BankName: "银行名称:",
    BankCardNum: "银行卡号:",
    bankBranchName: "开户支行名称:",
    BankAddr: "支行地址:",
    SwiftCode: "Swift Code:",
    BankCode: "银行Code:",
    expireTime: "过期时间:",
    success:'成功',
    timeout:'订单已过期！',
    orderTip:'找不到该订单或订单已过期！',
    orderSuccess:'收款方核实中，请耐心等待入账，详情请登录会员中心查询资金明细！',
  },
  'en':{
    item1:'Order',
    btn:'Order Confirmation',
    btn1:'Order Cancellation',
    serial:'Serial:',
    merchantSerial:'Merchant Serial:',
    amount:'Amount:',
    cny:"CNY:",
    UserName: "User Name:",
    BankName: "Bank Name:",
    BankCardNum: "Bank Card Number:",
    bankBranchName: "Bank Branch Name:",
    BankAddr: "Bank Addr:",
    SwiftCode: "Swift Code:",
    BankCode: "Bank Code:",
    expireTime: "ExpireTime:",
    success:'success',
    timeout:'订单已过期！',
    orderTip:'找不到该订单或订单已过期！',
    orderSuccess:'收款方核实中，请耐心等待入账，详情请登录会员中心查询资金明细！',
  }
};
let config = {
  Pattern: {
    Password: /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?!.*([~!@&%$^\\(\\)#_]).*\\1.*\\1.*\\1)[A-Za-z0-9~!@&%$^\\(\\)#_]{8,16}$/,
  }
};


let vm = new Vue({
    el: "#forget",
  data(){
      return{
        ho:'',
        //多语言
        langList: {
          en: "ENGLISH",
          cn: "中文简体"
        },
        language: "cn",
        lang:{},

        flag:false,
        serial:'',
        pictLoading:false,

        params: {
          amount: "",
          bankAddr:'',
          bankBranchName:'',
          bankCardNum:'',
          bankCode:'',
          bankName:'',
          bankUname:'',
          cny:'',
          expireTime:'',
          merchantSerial:'',
          pickupUrl:'',
          serial:'',
          swiftCode:'',
          payType:'ALIPAY',
          alipayUrl:'',
          payMsg:'',
        },

        time:'',
        timer:null,
        timeStatus:0,

        rules: {
          
        }
    }
  },
  computed: {
    
  },
    methods: {
      // 语言切换函数
      chooseLang (key) {
        this.lang = content[key];
        this.language = key;
      },

      // 复制分享链接
      CopyShareLink (val) {
        // 模拟 输入框
        var cInput = document.createElement("input");
        cInput.value = val;
        document.body.appendChild(cInput);
        cInput.select(); // 选取文本框内容

        // 执行浏览器复制命令
        // 复制命令会将当前选中的内容复制到剪切板中（这里就是创建的input标签）
        // Input要在正常的编辑状态下原生复制方法才会生效

        document.execCommand("copy");

        this.$message({
          type: "success",
          message: "复制成功"
        });
      // 复制成功后再将构造的标签 移除
        document.body.removeChild(cInput);
      },

      // 发送
      send: async function () {
        this.pictLoading = true;
        axios.get(this.ho + '/pay/order/get?serial=' + this.serial, {
          //参数
        }).then(res => {//请求成功后的处理函数
          if (res.data.code == 200) {
            this.$message({
              message: this.lang.success,
              type: 'success'
            });
            this.params = res.data.data;
          } else {
            // 过期或者单号不对前端来提示不用后端的字段
            // this.$message.error(res.data.msg);
            this.$message.error(this.lang['orderTip']);
          }
          this.timer = setInterval(() => {this.getDate()}, 1000);
        }).catch(err => {
          //请求失败后的处理函数

        })
        setTimeout(() => {
          this.pictLoading = false;
        }, 1000);
      },

      confirm: async function (val) {
        if (this.flag) {
          return
        } else {
          this.flag = true;
        }
        axios.post(this.ho + '/pay/order/submit', {
          serial:this.params.serial,
          customStatus:val,
          //参数
        }).then(res => {//请求成功后的处理函数
          if (res.data.code == 200) {
            if (val == 1){
              this.$message({
                  message: this.lang.orderSuccess,
                  type: 'success'
              });
            }
            setTimeout(()=>{
              window.location.href = 'about:blank'
            },5000)

            // setTimeout(() => {
            //   window.location.href = this.params.pickupUrl
            // }, 2000);
          } else {
            this.$message.error(res.data.msg);
          }
          this.flag = false;
        }).catch(err => {                 //请求失败后的处理函数

        })
      },

      //时间
      getDate () {

        var newyear=new Date(this.params.expireTime.replace(/-/g,"/"));
        var date1=new Date();
        var now=newyear-date1;

        let mm = 0, ss = 0;
        if( now > 0 ) {
          mm = Math.floor( now/1000/60%60 );
          ss = Math.floor( now/1000%60 );
          this.timeStatus = 1;
        } else {
          this.timeStatus = 2;
          clearInterval(this.timer)
        }

        let clock;

        if (mm < 10) {
          mm = "0" + mm;
        }
        if (ss < 10) {
          ss = "0" + ss;
        }

        clock = mm + ":" + ss;

        this.time = clock;

        
      },
      
    },
    mounted() {
      // this.ho ='http://192.168.0.21:15233';
      this.ho = window.location.origin;
      // this.params.token = window.location.search.split('?token=')[1];
      this.serial = window.location.search.split('?serial=')[1];

      this.lang = content['cn'];
      this.send();

      
    },
    destroyed() {
      clearInterval(this.timer)
    }
});