Newer
Older
XiaoGanWXMini / unpackage / dist / dev / mp-weixin / pages / quesNaire / index.js
@zhangdeliang zhangdeliang on 29 Jul 6 KB 迁移
"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
const utils_homeApi = require("../../utils/homeApi.js");
if (!Array) {
  const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput");
  const _easycom_uni_forms_item2 = common_vendor.resolveComponent("uni-forms-item");
  const _easycom_uni_data_checkbox2 = common_vendor.resolveComponent("uni-data-checkbox");
  const _easycom_uni_forms2 = common_vendor.resolveComponent("uni-forms");
  (_easycom_uni_easyinput2 + _easycom_uni_forms_item2 + _easycom_uni_data_checkbox2 + _easycom_uni_forms2)();
}
const _easycom_uni_easyinput = () => "../../uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.js";
const _easycom_uni_forms_item = () => "../../uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.js";
const _easycom_uni_data_checkbox = () => "../../uni_modules/uni-data-checkbox/components/uni-data-checkbox/uni-data-checkbox.js";
const _easycom_uni_forms = () => "../../uni_modules/uni-forms/components/uni-forms/uni-forms.js";
if (!Math) {
  (_easycom_uni_easyinput + _easycom_uni_forms_item + _easycom_uni_data_checkbox + _easycom_uni_forms)();
}
const _sfc_main = {
  __name: "index",
  setup(__props) {
    const quesList = common_vendor.ref({ topicName: "", introduce: "", problemConfigList: [] });
    const formData = common_vendor.ref({
      name: null,
      telephone: null,
      questionnaireId: "",
      programOpenId: "1623498094314524674",
      //小程序openId
      problemResultList: []
    });
    const dataResult = common_vendor.ref(true);
    function getResult() {
      let params = {
        programOpenId: formData.value.programOpenId
      };
      utils_homeApi.questionNaireResult(params).then((res) => {
        dataResult.value = res.data;
        if (!res.data) {
          getQuesList();
        }
      });
    }
    function submitData() {
      console.log(formData.value);
      let pattrens = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
      if (!pattrens.test(formData.value.telephone)) {
        common_vendor.index.showToast({
          icon: "none",
          title: "手机号格式不正确"
        });
        return false;
      }
      let params = JSON.parse(JSON.stringify(formData.value));
      params.problemResultList.map((item) => {
        if (item.problemType == "checkbox") {
          item.answersResult = item.answersResult.join(",");
        }
      });
      utils_homeApi.questionNaireAdd(params).then((res) => {
        if (res.code == 200) {
          common_vendor.index.showToast({
            icon: "none",
            title: "提交成功"
          });
          getResult();
        }
      });
    }
    function getQuesList() {
      formData.value.problemResultList = [];
      utils_homeApi.questionNaireList().then((res) => {
        let datas = res.data;
        quesList.value = datas;
        formData.value.questionnaireId = datas.id;
        datas.problemConfigList.map((item) => {
          formData.value.problemResultList.push({
            answersResult: item.problemType == "checkbox" ? [] : "",
            problemType: item.problemType,
            problemId: item.id
          });
        });
      });
    }
    common_vendor.onMounted(() => {
      formData.value.programOpenId = common_vendor.index.getStorageSync("openidXGWXMN");
      getResult();
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: !dataResult.value
      }, !dataResult.value ? {
        b: common_assets._imports_0$1,
        c: common_vendor.t(quesList.value.topicName || ""),
        d: common_vendor.t(quesList.value.introduce || ""),
        e: common_vendor.o(($event) => formData.value.name = $event),
        f: common_vendor.p({
          type: "text",
          placeholder: "请输入您的姓名",
          modelValue: formData.value.name
        }),
        g: common_vendor.p({
          label: "您的姓名",
          required: true,
          name: "name"
        }),
        h: common_vendor.o(($event) => formData.value.telephone = $event),
        i: common_vendor.p({
          type: "text",
          placeholder: "请输入您的手机号",
          maxlength: "11",
          modelValue: formData.value.telephone
        }),
        j: common_vendor.p({
          label: "您的手机号",
          required: true,
          name: "telephone"
        }),
        k: common_vendor.f(quesList.value.problemConfigList, (item, index, i0) => {
          return common_vendor.e({
            a: item.problemType == "radio"
          }, item.problemType == "radio" ? {
            b: "24ee7560-6-" + i0 + "," + ("24ee7560-5-" + i0),
            c: common_vendor.o(($event) => formData.value.problemResultList[index].answersResult = $event, item),
            d: common_vendor.p({
              localdata: item.problemOptionList,
              map: {
                text: "optionName",
                value: "id"
              },
              modelValue: formData.value.problemResultList[index].answersResult
            })
          } : {}, {
            e: item.problemType == "checkbox"
          }, item.problemType == "checkbox" ? {
            f: "24ee7560-7-" + i0 + "," + ("24ee7560-5-" + i0),
            g: common_vendor.o(($event) => formData.value.problemResultList[index].answersResult = $event, item),
            h: common_vendor.p({
              multiple: true,
              localdata: item.problemOptionList,
              map: {
                text: "optionName",
                value: "id"
              },
              modelValue: formData.value.problemResultList[index].answersResult
            })
          } : {}, {
            i: item.problemType == "answers"
          }, item.problemType == "answers" ? {
            j: "24ee7560-8-" + i0 + "," + ("24ee7560-5-" + i0),
            k: common_vendor.o(($event) => formData.value.problemResultList[index].answersResult = $event, item),
            l: common_vendor.p({
              type: "textarea",
              placeholder: "请输入",
              modelValue: formData.value.problemResultList[index].answersResult
            })
          } : {}, {
            m: item,
            n: "24ee7560-5-" + i0 + ",24ee7560-0",
            o: common_vendor.p({
              label: `${index + 1},` + item.problemName
            })
          });
        }),
        l: common_vendor.o(submitData),
        m: common_vendor.p({
          modelValue: formData.value,
          ["label-width"]: "100%"
        })
      } : {}, {
        n: dataResult.value
      }, dataResult.value ? {
        o: common_assets._imports_0
      } : {});
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "E:/项目/孝感海绵城市/XiaoGanWXMini/pages/quesNaire/index.vue"]]);
wx.createPage(MiniProgramPage);