step4.js 12.9 KB
"use strict";
const common_vendor = require("../../common/vendor.js");
const training_train = require("../train.js");
require("../../common/request.js");
require("../../common/login.js");
require("../../config.js");
require("../../common/aes.js");
if (!Array) {
  const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  (_easycom_uni_icons2 + _easycom_uni_popup2)();
}
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
const _easycom_uni_popup = () => "../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
  (_easycom_uni_icons + _easycom_uni_popup)();
}
const _sfc_main = {
  __name: "step4",
  props: {
    activity: {
      type: Object,
      default: () => {
      }
    },
    personal: {
      type: Object,
      default: () => {
      }
    },
    examList: {
      type: Array,
      default: () => []
    },
    trainList: {
      type: Array,
      default: () => []
    },
    trainId: {
      type: String,
      default: () => {
      }
    }
  },
  emits: ["prev", "publish"],
  setup(__props, { emit }) {
    const props = __props;
    const data = common_vendor.reactive({
      form: {
        trainIds: [],
        examIds: []
      },
      signRules: {},
      bankShow: null,
      totalAmount: null
    });
    const {
      form,
      signRules,
      bankShow,
      totalAmount
    } = common_vendor.toRefs(data);
    const bankInfo = common_vendor.computed(() => {
      if (props.activity.receivingInfo) {
        return JSON.parse(props.activity.receivingInfo);
      } else {
        return {};
      }
    });
    common_vendor.onLoad((options) => {
      getRules();
    });
    function getRules() {
      Promise.all([
        training_train.getCoachRules(),
        training_train.getRefereeRules(),
        training_train.getExaminerJiRules(),
        training_train.getExaminerDuanRules()
      ]).then((res) => {
        common_vendor._.each(res, (r) => common_vendor._.each(r.data, (d) => {
          signRules.value[d.id] = d;
        }));
      });
    }
    common_vendor.watch([() => Object.keys(signRules.value).length, () => props.trainList.length], (val) => {
      if (val[0] && val[1]) {
        checkCanSign(props.trainList, 1);
        checkCanSign(props.examList, 2);
        fillRelateTrain();
        checkRelateTrain();
      }
    });
    function checkCanSign(list, flag) {
      common_vendor._.each(list, (l) => {
        var _a, _b, _c, _d, _e;
        if (l.requiredFlag == "1") {
          l.required = true;
          l.checked = true;
          switch (flag) {
            case 1:
              form.value.trainIds.push(l.id);
              break;
            case 2:
              form.value.examIds.push(l.id);
              break;
          }
        }
        if (l.twoSubjectId && signRules.value[l.twoSubjectId.toString()]) {
          const rule = signRules.value[l.twoSubjectId];
          if (rule.openFlag) {
            let currLevel, currYear;
            const currDuan = parseInt(props.personal.levelDuan || 0);
            switch (l.parentSubjectId) {
              case 100:
                currLevel = parseInt(((_a = props.personal.coachLabel) == null ? void 0 : _a.type) || 0);
                currYear = parseInt(((_b = props.personal.coachLabel) == null ? void 0 : _b.yearLimit) || 0);
                if (!(currLevel >= parseInt(rule.type) && currDuan >= parseInt(rule.duan) && currYear >= parseInt(rule.limit))) {
                  l.disabled = true;
                }
                break;
              case 200:
                currLevel = parseInt(((_c = props.personal.refereeLabel) == null ? void 0 : _c.type) || 0);
                currYear = parseInt(((_d = props.personal.refereeLabel) == null ? void 0 : _d.yearLimit) || 0);
                if (!(currLevel >= parseInt(rule.type) && currDuan >= parseInt(rule.duan) && currYear >= parseInt(rule.limit))) {
                  l.disabled = true;
                }
                break;
              case 300:
                if (!(currDuan >= parseInt(rule.duan))) {
                  l.disabled = true;
                }
                break;
              case 400:
                currLevel = parseInt(((_e = props.personal.examinerDuanLabel) == null ? void 0 : _e.type) || 0);
                if (!(currLevel >= parseInt(rule.type) && currDuan >= parseInt(rule.duan))) {
                  l.disabled = true;
                }
                break;
            }
          }
        }
      });
    }
    function fillRelateTrain() {
      common_vendor._.each(props.examList, (e) => {
        if (e.relateTrainIds) {
          const trainNames = [];
          common_vendor._.each(e.relateTrainIds.split(","), (id) => {
            const train = common_vendor._.find(props.trainList, (t) => t.id == id);
            trainNames.push((train == null ? void 0 : train.name) || "关联错误的培训");
          });
          e.relateTrainNames = trainNames.join(",");
        }
      });
    }
    function checkRelateTrain() {
      common_vendor._.each(props.examList, (e) => {
        e.passRelate = true;
        if (e.relateTrainIds) {
          if (common_vendor._.some(e.relateTrainIds.split(","), (id) => form.value.trainIds.indexOf(id) == -1)) {
            e.passRelate = false;
          }
        }
      });
    }
    function submitForm() {
      console.log(form.value);
      if (form.value.trainIds.length == 0) {
        common_vendor.index.showToast({
          title: "请选择培训科目",
          icon: "none"
        });
        return;
      }
      if (common_vendor._.some(form.value.trainIds, (id) => {
        const train = common_vendor._.find(props.trainList, (t) => t.id == id);
        return train.disabled;
      })) {
        common_vendor.index.showToast({
          title: "选中了不满足报名条件的培训科目",
          icon: "none"
        });
        return;
      }
      if (common_vendor._.some(form.value.examIds, (id) => {
        const exam = common_vendor._.find(props.examList, (t) => t.id == id);
        return exam.disabled || !exam.passRelate;
      })) {
        common_vendor.index.showToast({
          title: "选中了不满足报名条件的考试科目",
          icon: "none"
        });
        return;
      }
      let amount = common_vendor._.chain(props.trainList).filter((t) => form.value.trainIds.indexOf(t.id) > -1).sumBy((t) => parseFloat(t.price)).valueOf();
      amount += common_vendor._.chain(props.examList).filter((e) => form.value.examIds.indexOf(e.id) > -1).sumBy((e) => parseFloat(e.price)).valueOf();
      totalAmount.value = amount.toFixed(2);
      if (totalAmount.value > 0) {
        bankShow.value.open();
      } else {
        sure();
      }
    }
    function sure() {
      form.value.activityId = props.trainId;
      training_train.commitSign(form.value).then(() => {
        common_vendor.index.showToast({
          title: "提交成功,等待审核",
          icon: "none"
        });
        emit("publish");
      });
    }
    function prev() {
      emit("prev");
    }
    function szToHz(num) {
      const hzArr = ["〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"];
      return hzArr[parseInt(num)];
    }
    function changeTrainIds(item) {
      if (item.disabled || item.required) {
        return;
      }
      if (item.checked) {
        item.checked = false;
        if (form.value.trainIds.indexOf(item.id) > -1) {
          common_vendor._.pull(form.value.trainIds, item.id);
        }
      } else {
        item.checked = true;
        form.value.trainIds.push(item.id);
        console.log(form.value.trainIds);
      }
    }
    function changeExamIds(item) {
      if (item.disabled || item.required) {
        return;
      }
      if (item.checked) {
        item.checked = false;
        if (form.value.examIds.indexOf(item.id) > -1) {
          common_vendor._.pull(form.value.examIds, item.id);
        }
      } else {
        item.checked = true;
        form.value.examIds.push(item.id);
        console.log(form.value.examIds);
      }
    }
    function copyPlat() {
      let str = `单位名称:${bankInfo.value.name};开户行:${bankInfo.value.bank};账户:${bankInfo.value.account};打款金额:${totalAmount.value};`;
      common_vendor.index.setClipboardData({
        data: str,
        success: function() {
          common_vendor.index.showToast({
            title: "已复制",
            icon: "none"
          });
        }
      });
    }
    return (_ctx, _cache) => {
      var _a, _b, _c, _d, _e;
      return {
        a: common_vendor.t(__props.personal.name),
        b: common_vendor.t(__props.personal.perCode),
        c: common_vendor.t((_a = __props.personal.validityDate) == null ? void 0 : _a.slice(0, 10)),
        d: common_vendor.t(__props.personal.levelDuan && __props.personal.levelDuan != 0 ? szToHz(__props.personal.levelDuan) + "段/品" : "--"),
        e: common_vendor.t(((_b = __props.personal.coachLabel) == null ? void 0 : _b.name) || "--"),
        f: common_vendor.t(((_c = __props.personal.refereeLabel) == null ? void 0 : _c.name) || "--"),
        g: common_vendor.t(((_d = __props.personal.examinerJiLabel) == null ? void 0 : _d.name) || "--"),
        h: common_vendor.t(((_e = __props.personal.examinerDuanLabel) == null ? void 0 : _e.name) || "--"),
        i: common_vendor.f(__props.trainList, (t, k0, i0) => {
          var _a2, _b2, _c2, _d2, _e2;
          return common_vendor.e({
            a: t.required || t.checked
          }, t.required || t.checked ? {
            b: "f862fc74-0-" + i0,
            c: common_vendor.p({
              color: "#C5161E",
              type: "checkbox-filled",
              size: "30"
            })
          } : {
            d: "f862fc74-1-" + i0,
            e: common_vendor.p({
              type: "circle",
              size: "30"
            })
          }, {
            f: common_vendor.t(t.name),
            g: common_vendor.t(t.price),
            h: (_a2 = common_vendor.unref(signRules)[t.twoSubjectId]) == null ? void 0 : _a2.openFlag
          }, ((_b2 = common_vendor.unref(signRules)[t.twoSubjectId]) == null ? void 0 : _b2.openFlag) ? {
            i: common_vendor.t((_c2 = common_vendor.unref(signRules)[t.twoSubjectId]) == null ? void 0 : _c2.name),
            j: common_vendor.t((_d2 = common_vendor.unref(signRules)[t.twoSubjectId]) == null ? void 0 : _d2.duanStr),
            k: common_vendor.t((_e2 = common_vendor.unref(signRules)[t.twoSubjectId]) == null ? void 0 : _e2.limitStr)
          } : {}, {
            l: common_vendor.o(($event) => changeTrainIds(t), t.id),
            m: t.id,
            n: common_vendor.n(t.required || t.disabled ? "disabled kkitem" : "kkitem")
          });
        }),
        j: common_vendor.f(__props.examList, (t, k0, i0) => {
          var _a2, _b2, _c2, _d2, _e2;
          return common_vendor.e({
            a: t.required || t.checked
          }, t.required || t.checked ? {
            b: "f862fc74-2-" + i0,
            c: common_vendor.p({
              color: "#C5161E",
              type: "checkbox-filled",
              size: "30"
            })
          } : {
            d: "f862fc74-3-" + i0,
            e: common_vendor.p({
              type: "circle",
              size: "30"
            })
          }, {
            f: common_vendor.t(t.name),
            g: common_vendor.t(t.price),
            h: (_a2 = common_vendor.unref(signRules)[t.twoSubjectId]) == null ? void 0 : _a2.openFlag
          }, ((_b2 = common_vendor.unref(signRules)[t.twoSubjectId]) == null ? void 0 : _b2.openFlag) ? {
            i: common_vendor.t((_c2 = common_vendor.unref(signRules)[t.twoSubjectId]) == null ? void 0 : _c2.name),
            j: common_vendor.t((_d2 = common_vendor.unref(signRules)[t.twoSubjectId]) == null ? void 0 : _d2.duanStr),
            k: common_vendor.t((_e2 = common_vendor.unref(signRules)[t.twoSubjectId]) == null ? void 0 : _e2.limitStr)
          } : {}, {
            l: common_vendor.o(($event) => changeExamIds(t), t.id),
            m: t.id,
            n: common_vendor.n(t.required || t.disabled || !t.passRelate ? "disabled kkitem" : "kkitem")
          });
        }),
        k: common_vendor.o(prev),
        l: common_vendor.o(submitForm),
        m: common_vendor.t(common_vendor.unref(bankInfo).name),
        n: common_vendor.t(common_vendor.unref(bankInfo).bank),
        o: common_vendor.t(common_vendor.unref(bankInfo).account),
        p: common_vendor.t(common_vendor.unref(totalAmount)),
        q: common_vendor.o(copyPlat),
        r: common_vendor.o(sure),
        s: common_vendor.sr(bankShow, "f862fc74-4", {
          "k": "bankShow"
        }),
        t: common_vendor.p({
          type: "bottom",
          ["background-color"]: "#fff"
        })
      };
    };
  }
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-f862fc74"], ["__file", "/Users/yangyang/ztx_wx_minapp/training/components/step4.vue"]]);
wx.createComponent(Component);