"use strict";
const common_vendor = require("../../common/vendor.js");
const api = require("../../api.js");
const common_assets = require("../../common/assets.js");
const _sfc_main = common_vendor.defineComponent({
  data() {
    return {
      uploadConfig: new UTSJSONObject({
        // 上传地址
        url: "https://gpt.aiym.run/contract/miniapp/file/upload",
        // 文件字段名
        name: "file",
        // 请求头
        header: new UTSJSONObject({}),
        // 附带的表单数据
        formData: new UTSJSONObject({
          "biz": "cert"
        }),
        // 是否开启实际上传
        enabled: true
      }),
      clientInfo: new UTSJSONObject({
        appOrderCarList: [
          new UTSJSONObject({
            buyMoney: 0,
            buyTax: 0,
            buyTime: "",
            carModel: "",
            carNo: "",
            carSeries: "",
            carType: "",
            createBy: "",
            createTime: "",
            engineNo: "",
            id: "",
            mileage: "",
            newCar: 0,
            orderFkId: "",
            sysOrgCode: "",
            updateBy: "",
            updateTime: "",
            useType: "",
            vin: ""
          })
        ],
        appOrderFinanceList: [
          new UTSJSONObject({
            createBy: "",
            createTime: "",
            id: "",
            lender: "",
            lenderMone: 0,
            lenderYear: "",
            orderFkId: "",
            sysOrgCode: "",
            updateBy: "",
            updateTime: ""
          })
        ],
        appOrderVoucherList: [
          new UTSJSONObject({
            assigneeCardNo: "",
            assigneeName: "",
            assigneePhone: "",
            carInsuranceNo: "",
            createBy: "",
            createTime: "",
            dealerAddress: "",
            effectiveTime: "",
            endTime: "",
            equityPackage: "",
            firstBeneficiary: "",
            id: "",
            insuranceName: "",
            orderFkId: "",
            packageMoney: 0,
            payTime: "",
            registeredCity: "",
            serviceMoney: 0,
            serviceYear: "",
            sysOrgCode: "",
            updateBy: "",
            updateTime: ""
          })
        ],
        busLicense: "",
        carPic: "",
        certBack: "",
        certFront: "",
        contractUrl: "",
        createBy: "",
        createTime: "",
        custAddress: "",
        custCardNo: "",
        custName: "",
        custPhone: "",
        custType: 0,
        id: "",
        orderNum: "",
        payType: "全款",
        payVoucherUrl: "",
        payee: "",
        payeeTime: "",
        productContractTemp: "",
        productMone: null,
        productName: "自动填写所选商品服务分类",
        productServiceYear: "",
        saleName: "",
        salePort: "售前",
        status: 0,
        storeName: "自动填写所选择的门店",
        sysOrgCode: "",
        updateBy: "",
        updateTime: ""
      }),
      fileList1: [],
      departments: ["售前", "售后", "二网车"],
      carBrands: [],
      carBrandIndex: -1,
      serviceAges: ["1年", "2年", "3年"],
      serviceAgeIndex: -1,
      payees: [],
      payeeIndex: -1,
      // 扫描
      positiveImg: "/static/image/组件 4 – 1.png",
      // 反面身份证
      reverseImg: "/static/image/组 71663.png",
      // 行车驾驶证
      carImg: "/static/image/组件 2 – 1.png"
      //自己图片路径
    };
  },
  mounted() {
    api.isToken();
    this.clientInfo.storeName = getApp().storeName || "自动填写所选择的门店";
    this.clientInfo.productName = getApp().productName || "自动填写所选商品服务分类";
    for (var index = 0; index < getApp().allMsg.length; index++) {
      this.payees.push(getApp().allMsg[index].storeName);
    }
    this.clientInfo.payee = getApp().storeName;
    this.uploadConfig.header = new UTSJSONObject({
      "X-Access-Token": common_vendor.index.getStorageSync("token")
    });
    api.getChildListBatch().then((res = null) => {
      common_vendor.index.__f__("log", "at pages/index/PayPal.uvue:343", res.result.records);
      this.carBrands = [];
      for (var index2 = 0; index2 < res.result.records.length; index2++) {
        this.carBrands.push(res.result.records[index2].name);
      }
    });
  },
  methods: {
    // 凭证上传函数
    deletePic(event = null) {
      this[`fileList${event.name}`].splice(event.index, 1);
    },
    // 新增图片
    afterRead(event = null) {
      return common_vendor.__awaiter(this, void 0, void 0, function* () {
        let lists = [].concat(event.file);
        let fileListLen = this[`fileList${event.name}`].length;
        lists.map((item) => {
          this[`fileList${event.name}`].push(new UTSJSONObject(Object.assign(Object.assign({}, item), { status: "uploading", message: "上传中" })));
        });
        for (let i = 0; i < lists.length; i++) {
          const result = yield this.uploadFilePromise(lists[i].url);
          let item = this[`fileList${event.name}`][fileListLen];
          this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
            status: "success",
            message: "",
            url: result
          }));
          fileListLen++;
        }
      });
    },
    uploadFilePromise(url = null) {
      let token = common_vendor.index.getStorageSync("token");
      return new Promise((resolve, reject) => {
        common_vendor.index.uploadFile({
          url: "https://gpt.aiym.run/contract/miniapp/file/upload",
          filePath: url,
          name: "file",
          formData: new UTSJSONObject({
            biz: "test"
          }),
          header: new UTSJSONObject({
            "X-Access-Token": token
          }),
          success: (res) => {
            this.clientInfo.payVoucherUrl = UTS.JSON.parse(res.data).message;
            setTimeout(() => {
              resolve(res.data.data);
            }, 1e3);
          }
        });
      });
    },
    get_to() {
      common_vendor.index.__f__("log", "at pages/index/PayPal.uvue:402", "clientInfo", UTS.JSON.parse(UTS.JSON.stringify(this.clientInfo)));
      api.add(UTS.JSON.parse(UTS.JSON.stringify(this.clientInfo))).then((res = null) => {
        common_vendor.index.__f__("log", "at pages/index/PayPal.uvue:404", res);
      });
      common_vendor.index.switchTab({ url: "/pages/index/dingdan" });
    },
    toBack() {
      let canNavBack = getCurrentPages();
      if (canNavBack && canNavBack.length > 1) {
        common_vendor.index.navigateBack();
      } else {
        history.back();
      }
    },
    handleDepartmentChange(e = null) {
      this.clientInfo.salePort = e;
    },
    // 修改车辆品牌
    bindCarBrandChange(e = null) {
      this.carBrandIndex = e.detail.value;
      this.clientInfo.appOrderCarList[0].carSeries = this.carBrands[this.carBrandIndex];
    },
    // 取服务年限
    bindServiceAgeChange(e = null) {
      this.serviceAgeIndex = e.detail.value;
      this.clientInfo.productServiceYear = this.serviceAges[e.detail.value];
    },
    // 选择收款方
    bindPayeeChange(e = null) {
      this.payeeIndex = e.detail.value;
      this.clientInfo.payee = this.payees[e.detail.value];
    },
    // 身份证正面上传
    uploadPositive() {
      common_vendor.index.chooseImage({
        count: 1,
        sizeType: ["original", "compressed"],
        sourceType: ["album", "camera"],
        success: (res) => {
          let filePath = res.tempFilePaths[0];
          let token = common_vendor.index.getStorageSync("token");
          this.uploadIdentify(token, "front", filePath, "sfz");
        }
      });
    },
    // 身份证反面上传
    uploadReverse() {
      common_vendor.index.chooseImage({
        count: 1,
        sizeType: ["original", "compressed"],
        sourceType: ["album", "camera"],
        success: (res) => {
          let filePath = res.tempFilePaths[0];
          let token = common_vendor.index.getStorageSync("token");
          this.uploadIdentify(token, "back", filePath, "sfz");
        }
      });
    },
    uploadCarCert() {
      common_vendor.index.chooseImage({
        count: 1,
        sizeType: ["original", "compressed"],
        sourceType: ["album", "camera"],
        success: (res) => {
          let filePath = res.tempFilePaths[0];
          let token = common_vendor.index.getStorageSync("token");
          this.uploadIdentify(token, "", filePath, "carCert");
        }
      });
    },
    // 上传识别
    uploadIdentify(token = null, side = null, filePath = null, type = null) {
      common_vendor.index.uploadFile({
        url: "https://gpt.aiym.run/contract/miniapp/file/upload",
        filePath,
        name: "file",
        formData: new UTSJSONObject({
          "biz": "cert"
        }),
        header: new UTSJSONObject({
          "X-Access-Token": token
        }),
        success: (res) => {
          if (type == "sfz") {
            api.idCardInfo(new UTSJSONObject({ "side": side, "url": UTS.JSON.parse(res.data).message })).then((res2 = null) => {
              if (res2.success) {
                if (side == "front") {
                  this.clientInfo.custName = res2.result.name;
                  this.clientInfo.custAddress = res2.result.address;
                  this.clientInfo.custCardNo = res2.result.idCard;
                  this.clientInfo.certFront = filePath;
                } else {
                  this.clientInfo.certBack = filePath;
                }
              } else {
                common_vendor.index.showToast({
                  title: "身份证识别错误，请重新上传!",
                  icon: "error",
                  duration: 500,
                  success: (res3) => {
                  },
                  fail: (res3) => {
                  }
                });
              }
            }).catch((err = null) => {
              common_vendor.index.__f__("log", "at pages/index/PayPal.uvue:513", "catch: ", err);
            });
          } else if (type == "carCert") {
            api.carCert(new UTSJSONObject({ "url": UTS.JSON.parse(res.data).message })).then((res2 = null) => {
              if (res2.success) {
                common_vendor.index.__f__("log", "at pages/index/PayPal.uvue:519", "res", res2);
                this.clientInfo.appOrderCarList[0].carSeries = res2.result.CarBrand;
                this.clientInfo.appOrderCarList[0].vin = res2.result.VinNo;
                this.clientInfo.carPic = filePath;
              } else {
                common_vendor.index.showToast({
                  title: "识别错误，请重新上传!",
                  icon: "error",
                  duration: 500,
                  success: (res3) => {
                  },
                  fail: (res3) => {
                  }
                });
              }
            }).catch((err = null) => {
              common_vendor.index.__f__("log", "at pages/index/PayPal.uvue:537", "catch: ", err);
            });
          }
        },
        fail: (err) => {
          common_vendor.index.__f__("log", "at pages/index/PayPal.uvue:544", err);
        }
      });
    },
    onChange(e = null) {
      common_vendor.index.__f__("log", "at pages/index/PayPal.uvue:549", "e", e);
      if (e = "个人") {
        this.clientInfo.custType = 0;
      } else {
        this.clientInfo.custType = 1;
      }
    }
  }
});
if (!Array) {
  const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  const _easycom_l_radio2 = common_vendor.resolveComponent("l-radio");
  const _easycom_l_radio_group2 = common_vendor.resolveComponent("l-radio-group");
  const _easycom_uni_datetime_picker2 = common_vendor.resolveComponent("uni-datetime-picker");
  const _easycom_uv_upload2 = common_vendor.resolveComponent("uv-upload");
  (_easycom_uni_icons2 + _easycom_l_radio2 + _easycom_l_radio_group2 + _easycom_uni_datetime_picker2 + _easycom_uv_upload2)();
}
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
const _easycom_l_radio = () => "../../uni_modules/lime-radio/components/l-radio/l-radio.js";
const _easycom_l_radio_group = () => "../../uni_modules/lime-radio/components/l-radio-group/l-radio-group.js";
const _easycom_uni_datetime_picker = () => "../../uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.js";
const _easycom_uv_upload = () => "../../uni_modules/uv-upload/components/uv-upload/uv-upload.js";
if (!Math) {
  (_easycom_uni_icons + _easycom_l_radio + _easycom_l_radio_group + _easycom_uni_datetime_picker + _easycom_uv_upload)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_vendor.p({
      type: "left",
      size: "30",
      color: "#c2d4de"
    }),
    b: common_vendor.o((...args) => $options.toBack && $options.toBack(...args)),
    c: common_vendor.w(({
      checked
    }, s0, i0) => {
      return {
        a: checked,
        b: !checked,
        c: i0,
        d: s0
      };
    }, {
      name: "icon",
      path: "c",
      vueId: "643091e0-1"
    }),
    d: common_assets._imports_0$4,
    e: common_assets._imports_1$3,
    f: common_vendor.p({
      checked: $data.clientInfo.payType === "全款",
      label: "全款",
      fontSize: "1rem"
    }),
    g: common_vendor.w(({
      checked
    }, s0, i0) => {
      return {
        a: checked,
        b: !checked,
        c: i0,
        d: s0
      };
    }, {
      name: "icon",
      path: "g",
      vueId: "643091e0-3,643091e0-2"
    }),
    h: common_assets._imports_0$4,
    i: common_assets._imports_1$3,
    j: common_vendor.p({
      checked: $data.clientInfo.custType == 0 ? true : false,
      value: "个人",
      label: "个人",
      fontSize: "1rem"
    }),
    k: common_vendor.w(({
      checked
    }, s0, i0) => {
      return {
        a: checked,
        b: !checked,
        c: i0,
        d: s0
      };
    }, {
      name: "icon",
      path: "k",
      vueId: "643091e0-4,643091e0-2"
    }),
    l: common_assets._imports_0$4,
    m: common_assets._imports_1$3,
    n: common_vendor.p({
      checked: $data.clientInfo.custType == 1 ? true : false,
      value: "公司",
      label: "公司",
      fontSize: "1rem"
    }),
    o: common_vendor.o($options.onChange),
    p: $data.clientInfo.certFront == "" ? $data.positiveImg : $data.clientInfo.certFront,
    q: common_vendor.o((...args) => $options.uploadPositive && $options.uploadPositive(...args)),
    r: $data.clientInfo.certBack == "" ? $data.reverseImg : $data.clientInfo.certBack,
    s: common_vendor.o((...args) => $options.uploadReverse && $options.uploadReverse(...args)),
    t: $data.clientInfo.carPic == "" ? $data.carImg : $data.clientInfo.carPic,
    v: common_vendor.o((...args) => $options.uploadCarCert && $options.uploadCarCert(...args)),
    w: common_assets._imports_5,
    x: common_vendor.t($data.clientInfo.productName),
    y: common_vendor.t($data.clientInfo.storeName),
    z: $data.clientInfo.custName,
    A: common_vendor.o(($event) => $data.clientInfo.custName = $event.detail.value),
    B: $data.clientInfo.custAddress,
    C: common_vendor.o(($event) => $data.clientInfo.custAddress = $event.detail.value),
    D: $data.clientInfo.custCardNo,
    E: common_vendor.o(($event) => $data.clientInfo.custCardNo = $event.detail.value),
    F: $data.clientInfo.custPhone,
    G: common_vendor.o(($event) => $data.clientInfo.custPhone = $event.detail.value),
    H: common_vendor.f($data.departments, (item, k0, i0) => {
      return {
        a: common_vendor.w(({
          checked
        }, s1, i1) => {
          return {
            a: checked,
            b: !checked,
            c: i1,
            d: s1
          };
        }, {
          name: "icon",
          path: "H[" + i0 + "].a",
          vueId: "643091e0-6-" + i0 + ",643091e0-5"
        }),
        b: "643091e0-6-" + i0 + ",643091e0-5",
        c: common_vendor.p({
          value: item,
          checked: $data.clientInfo.salePort === item
        }),
        d: common_vendor.t(item),
        e: item
      };
    }),
    I: common_assets._imports_0$4,
    J: common_assets._imports_1$3,
    K: common_vendor.o($options.handleDepartmentChange),
    L: $data.clientInfo.saleName,
    M: common_vendor.o(($event) => $data.clientInfo.saleName = $event.detail.value),
    N: common_assets._imports_5,
    O: common_vendor.t($data.clientInfo.appOrderCarList[0].carSeries || "请选择车辆品牌 >"),
    P: common_vendor.o((...args) => $options.bindCarBrandChange && $options.bindCarBrandChange(...args)),
    Q: $data.carBrandIndex,
    R: $data.carBrands,
    S: $data.clientInfo.appOrderCarList[0].vin,
    T: common_vendor.o(($event) => $data.clientInfo.appOrderCarList[0].vin = $event.detail.value),
    U: common_assets._imports_5,
    V: common_vendor.t($data.clientInfo.productName),
    W: common_vendor.t($data.serviceAges[$data.serviceAgeIndex] || "请选择服务年限 >"),
    X: common_vendor.o((...args) => $options.bindServiceAgeChange && $options.bindServiceAgeChange(...args)),
    Y: $data.serviceAgeIndex,
    Z: $data.serviceAges,
    aa: $data.clientInfo.productMoney,
    ab: common_vendor.o(($event) => $data.clientInfo.productMoney = $event.detail.value),
    ac: common_assets._imports_5,
    ad: common_vendor.t(this.clientInfo.payee || "请选择收款方 >"),
    ae: common_vendor.o((...args) => $options.bindPayeeChange && $options.bindPayeeChange(...args)),
    af: $data.payeeIndex,
    ag: $data.payees,
    ah: common_vendor.o(($event) => $data.clientInfo.payeeTime = $event),
    ai: common_vendor.p({
      type: "datetime",
      clearIcon: false,
      border: false,
      modelValue: $data.clientInfo.payeeTime
    }),
    aj: common_assets._imports_6,
    ak: common_vendor.o($options.afterRead),
    al: common_vendor.o($options.deletePic),
    am: common_vendor.p({
      fileList: $data.fileList1,
      name: "1",
      multiple: true,
      maxCount: 1
    }),
    an: common_vendor.o((...args) => $options.get_to && $options.get_to(...args)),
    ao: common_vendor.sei(_ctx.virtualHostId, "view")
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-643091e0"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/index/PayPal.js.map
