methods.js 1.8 KB
"use strict";
var common_vendor = require("../common/vendor.js");
var methods = {
  upload(url, callBack) {
    let arr = {};
    common_vendor.index.chooseImage({
      success: (chooseImageRes) => {
        const tempFilePaths = chooseImageRes.tempFilePaths;
        arr["avatar"] = tempFilePaths[0];
        common_vendor.index.uploadFile({
          url,
          filePath: tempFilePaths[0],
          name: "file",
          formData: {
            user: "test",
            token: common_vendor.index.getStorageSync("token")
          },
          success: (uploadFileRes) => {
            console.log(JSON.parse(uploadFileRes.data), "\u56FE\u7247\u8DEF\u5F84");
            arr["upImg"] = JSON.parse(uploadFileRes.data).data.url;
            callBack(arr);
          }
        });
      }
    });
  },
  pay(res) {
    if (res.appId) {
      common_vendor.index.requestPayment({
        provider: "wxpay",
        timeStamp: res.timeStamp,
        nonceStr: res.nonceStr,
        package: res.package,
        signType: res.signType,
        appid: res.appId,
        paySign: res.paySign,
        success(res2) {
          console.log("\u652F\u4ED8\u6210\u529F");
          common_vendor.index.showToast({ title: "\u652F\u4ED8\u6210\u529F~" });
          setTimeout(() => {
            common_vendor.index.navigateBack();
          }, 1500);
        },
        fail(e) {
          console.log("\u652F\u4ED8\u5931\u8D25", e);
          common_vendor.index.showToast({ title: "\u652F\u4ED8\u53D6\u6D88~", icon: "none" });
          setTimeout(() => {
            common_vendor.index.navigateBack();
          }, 1500);
        }
      });
    }
  },
  showTN(title) {
    common_vendor.index.showToast({ title, icon: "none" });
    setTimeout(() => {
      common_vendor.index.navigateBack();
    }, 1e3);
  }
};
exports.methods = methods;