Liuyi
2024-11-20 681efe897b7fb4dbe8bec5fa5056209e3e0edfdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"use strict";
const common_vendor = require("../../common/vendor.js");
const api_index = require("../../api/index.js");
if (!Array) {
  const _easycom_navbar2 = common_vendor.resolveComponent("navbar");
  _easycom_navbar2();
}
const _easycom_navbar = () => "../../components/navbar/navbar.js";
if (!Math) {
  _easycom_navbar();
}
const _sfc_main = {
  __name: "index",
  setup(__props) {
    const choosedMoney = common_vendor.ref(50);
    const disabled = common_vendor.ref(true);
    const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
    const moneyList = common_vendor.ref([
      { value: 50, active: true },
      { value: 100, active: false },
      { value: 200, active: false },
      { value: 500, active: false },
      { value: 1e3, active: false },
      { value: "其他金额", active: false }
    ]);
    const activeStyle = common_vendor.ref({
      backgroundColor: "#5EADFF",
      color: "#fff"
    });
    function chooseMoney(index1) {
      moneyList.value.forEach((item, index) => {
        if (item.active == true) {
          item.active = false;
        }
      });
      moneyList.value[index1].active = true;
      if (index1 == 5) {
        disabled.value = false;
        choosedMoney.value = "";
      } else {
        choosedMoney.value = moneyList.value[index1].value;
        otherMoney.value = "";
        disabled.value = true;
      }
    }
    const otherMoney = common_vendor.ref();
    common_vendor.ref();
    const payList = common_vendor.ref([
      // {text:"支付宝支付",value:1,checked:true,img:'../../static/images/recharge/pay.png'},
      { text: "微信支付", value: 2, checked: true, img: "../../static/images/recharge/wx.png" }
      // {text:"余额",value:3,checked:false,img:'../../static/images/recharge/balance.png'},
    ]);
    async function submit() {
      let money = "";
      if (disabled.value) {
        money = choosedMoney.value;
      } else {
        money = Number(otherMoney.value);
      }
      let data = {
        cardNumber: userInfo.waterCardNumber,
        paymentMethod: 1,
        rechargeAmount: money
      };
      await api_index.rechargeApi(data).then(async (res) => {
        if (res.code == 200) {
          let data2 = {
            businessType: 1,
            businessNo: res.data
          };
          await wxPay(data2);
        }
      });
    }
    async function wxPay(data) {
      await api_index.wxPayApi(data).then((res) => {
        if (res.code == 200) {
          common_vendor.wx$1.requestPayment({
            //预支付订单信息
            // appId: res.data.appId,
            timeStamp: res.data.timeStamp,
            //时间戳 
            nonceStr: res.data.nonceStr,
            //随机串     
            package: res.data.package,
            //prepay_id
            signType: res.data.signType,
            //签名算法MD5        
            paySign: res.data.paySign,
            //微信签名 
            success(res2) {
              if (res2.errMsg == "requestPayment:ok") {
                console.log("支付成功", res2);
                common_vendor.index.showToast({
                  title: "支付成功",
                  duration: 2e3
                });
                common_vendor.index.navigateBack();
              } else {
                common_vendor.index.showToast({
                  title: "支付失败",
                  duration: 2e3,
                  icon: "none"
                });
              }
            },
            fail(res2) {
              common_vendor.index.showToast({
                title: "微信支付失败",
                duration: 2e3,
                icon: "none"
              });
            }
          });
        }
      });
    }
    return (_ctx, _cache) => {
      return {
        a: common_vendor.p({
          title: "账户充值"
        }),
        b: common_vendor.f(moneyList.value, (item, index, i0) => {
          return {
            a: common_vendor.t(item.value),
            b: common_vendor.s(item.active ? activeStyle.value : ""),
            c: common_vendor.o(($event) => chooseMoney(index), index),
            d: index
          };
        }),
        c: disabled.value,
        d: !disabled.value,
        e: otherMoney.value,
        f: common_vendor.o(($event) => otherMoney.value = $event.detail.value),
        g: common_vendor.f(payList.value, (item, index, i0) => {
          return {
            a: item.img,
            b: common_vendor.t(item.text),
            c: item.value,
            d: item.checked
          };
        }),
        h: common_vendor.o(($event) => submit())
      };
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-f06186df"]]);
wx.createPage(MiniProgramPage);