"use strict"; const common_vendor = require("../../common/vendor.js"); const api_index = require("../../api/index.js"); const _sfc_main = { data() { return { isChecked: true, isShake: false, scaleDetail: {}, questionList: [], currentQuestion: {}, currentAnswerList: [], currentIndex: 0, userAnswerList: [], resultId: "", isLoading: false, isDisbale: false, maxLength: 0, userInfo: {} }; }, computed: { percentage() { return this.currentIndex / this.maxLength * 652 + "rpx"; } }, created() { this.loadData(); this.userInfo = JSON.parse(sessionStorage.getItem("user")); }, methods: { loadData() { this.$request.get({ url: `scaleInfo/20210820143117`, loadingTip: "加载中...", data: {} }).then((res) => { this.questionList = JSON.parse(JSON.stringify(res.data)); this.maxLength = this.questionList.length; this.currentQuestion = this.questionList[this.currentIndex]; this.currentAnswerList = this.getAnswerItem(this.currentQuestion.checkItems); }); }, nextHandle(str) { if (this.isDisbale) { return; } this.isDisbale = true; this.userAnswerList[this.currentIndex] = JSON.parse(JSON.stringify(this.currentQuestion)); this.userAnswerList[this.currentIndex].checkItems = str; if (this.currentIndex >= this.questionList.length - 1) { this.isDisbale = false; } else { setTimeout(() => { this.currentIndex++; this.currentQuestion = this.questionList[this.currentIndex]; this.currentAnswerList = this.getAnswerItem(this.currentQuestion.checkItems); this.isDisbale = false; }, 150); } }, prevHandle() { setTimeout(() => { this.currentIndex--; this.currentQuestion = this.questionList[this.currentIndex]; this.currentAnswerList = this.getAnswerItem(this.currentQuestion.checkItems); }, 300); }, submitResult() { let _this = this; if (_this.isLoading) { return; } _this.isLoading = true; let params = { testPlanId: "", scale_result: _this.userAnswerList, userId: JSON.parse(sessionStorage.getItem("user")).id }; common_vendor.index.showLoading({ title: "测试结果生成中" }); _this.$request.post({ url: `${api_index.getResult}/20210820143117`, loadingTip: "加载中...", data: params }).then((res) => { _this.resultId = res.data; common_vendor.index.hideLoading(); _this.getQueryPromotionBySubjectId(); _this.isLoading = false; }).catch(() => { common_vendor.index.showToast({ icon: "none", title: "提交失败" }); common_vendor.index.hideLoading(); _this.isLoading = false; }); }, // 获取支付金额 async getQueryPromotionBySubjectId() { let _this = this; let urls = api_index.queryPromotionBySubjectId + "/20210820143117"; await _this.$request.get({ url: urls, loadingTip: "加载中...", data: {} }).then((res) => { var _a; console.log("量表支付信息", res.data); let data = res.data; if (data.price == 0) { common_vendor.index.navigateTo({ url: `/newScale/EQtest/testResult?resultId=${_this.resultId}&messageShare=1` }); } else { let params = { productId: "20210820143117", userId: (_a = _this.userInfo) == null ? void 0 : _a.id, resultId: _this.resultId, description: data.name, total: data.price, sceneType: common_vendor.index.getSystemInfoSync().platform == "android" ? "Android" : "iOS" }; sessionStorage.setItem("orderInfo", JSON.stringify(params)); common_vendor.index.navigateTo({ url: "/newScale/EQtest/paymentPage" }); } }); }, checkActive(item) { return this.userAnswerList[this.currentIndex] && this.userAnswerList[this.currentIndex].checkItems == item ? "active" : ""; }, getAnswerItem(arr) { return arr.split(";"); } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return { a: $options.percentage, b: common_vendor.t($data.currentIndex + 1), c: common_vendor.t($data.maxLength), d: common_vendor.t($data.currentQuestion.answer), e: common_vendor.f($data.currentAnswerList, (item, index, i0) => { return { a: common_vendor.t(item), b: common_vendor.n(`answer${index + 1}`), c: common_vendor.n($options.checkActive(item)), d: common_vendor.o(($event) => $options.nextHandle(item)) }; }), f: $data.currentIndex > 0, g: common_vendor.o((...args) => $options.prevHandle && $options.prevHandle(...args)), h: $data.currentIndex >= $data.maxLength - 1, i: common_vendor.o((...args) => $options.submitResult && $options.submitResult(...args)) }; } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-a0c71dc4"], ["__file", "E:/psy_web_share/newScale/EQtest/testPage.vue"]]); tt.createPage(MiniProgramPage);