From 4e44bc1fd7806a6c1611302120882b91d96640b5 Mon Sep 17 00:00:00 2001
From: liuwh <hugeinfo123>
Date: Mon, 27 Apr 2020 17:50:19 +0800
Subject: [PATCH] bug修复

---
 SunshineLnsMinApp/pages/createSub/createSub.js |  193 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 128 insertions(+), 65 deletions(-)

diff --git a/SunshineLnsMinApp/pages/createSub/createSub.js b/SunshineLnsMinApp/pages/createSub/createSub.js
index 0323bca..5df15cc 100644
--- a/SunshineLnsMinApp/pages/createSub/createSub.js
+++ b/SunshineLnsMinApp/pages/createSub/createSub.js
@@ -8,7 +8,11 @@
    */
   data: {
     question: {},
-    confirm: true
+    confirm: true,
+    value1: '',
+    answer: [],
+    id: '',
+    disabled: false
   },
   // 去单选页面
   toRadio(e) {
@@ -26,17 +30,64 @@
   },
   // 提交信息
   submit() {
-    if ($v.psqList.length == 0) {
-      wx.showToast({
-        title: '你还没有创建题目',
-        icon: "none",
-        duration: 800
-      });
-      return;
-    }
-    this.setData({
-      confirm: false
+    console.log(this.data.question)
+    var list = this.data.question.psqList.map(({
+      questionId,
+      questionItemId,
+      objectId,
+      questionnaireId
+    }) => ({
+      questionId,
+      questionItemId,
+      objectId,
+      questionnaireId
+    }))
+    console.log(list)
+
+    var that = this;
+    wx.request({
+      url: app.globalData.url + '/api/question/submitResult',
+      data: list,
+      method: 'POST',
+      header: {
+        "Content-Type": "application/json"
+      },
+      success: function(res) {
+        if (res.data.code == 0) {
+          wx.showToast({
+            title: '提交成功!',
+            icon: 'success',
+            duration: 2000
+          })
+          setTimeout(function() {
+            wx.reLaunch({
+              url: '../index/index',
+            })
+          }, 2000)
+        } else {
+          wx.showModal({
+            title: '提示',
+            content: "提交失败!"
+          })
+        }
+      }
     })
+    // if ($v.psqList.length == 0) {
+    //   wx.showToast({
+    //     title: '你还没有创建题目',
+    //     icon: "none",
+    //     duration: 800
+    //   });
+    //   return;
+    // }
+    // wx.showToast({
+    //   title: '提交成功!',
+    //   icon: 'success',
+    //   duration: 2000
+    // }, wx.reLaunch({
+    //   url: '../yshjqyfw/yshjqyfw',
+    // }))
+
   },
   // 发布信息
   publish() {
@@ -55,7 +106,7 @@
             if (res.confirm) {
               wx.switchTab({
                 url: '/pages/creat/creat',
-                success: function (e) {
+                success: function(e) {
                   var page = getCurrentPages().pop();
                   if (page == undefined || page == null) return;
                   page.onLoad();
@@ -75,15 +126,44 @@
   /**
    * 生命周期函数--监听页面加载
    */
-  onLoad: function (options) {
+  onLoad: function(options) {
     var _m = "question";
-
+    var id = options.id
+    console.log(options)
     var that = this;
     wx.request({
-      url: app.globalData.url + '/api/activity/finds',
-      success: function (res) {
+      url: app.globalData.url + '/api/question/find/' + id,
+      data: {
+        userId: wx.getStorageSync("user").id
+      },
+      success: function(res) {
+        console.log(res)
         if (res.data.code == 0) {
           console.log(res)
+          that.setData({
+            id: res.data.data.id,
+            [_m]: {
+              "paper": {
+                "title": res.data.data.title,
+                "des": res.data.data.content || ''
+              },
+              "psqList": res.data.data.questionDtos
+            }
+
+          });
+        } else if (res.data.code == 3) {
+          that.setData({
+            id: res.data.data.id,
+            [_m]: {
+              "paper": {
+                "title": res.data.data.title,
+                "des": res.data.data.content || ''
+              },
+              "psqList": res.data.data.questionDtos
+            },
+            disabled: true
+
+          });
         } else {
           wx.showModal({
             title: '提示',
@@ -92,58 +172,38 @@
         }
       }
     })
-    this.setData({
-      [_m]: {
-        "paper": {
-          "title": "11",
-          "des": "111"
-        },
-        "psqList": [{
-          "isMust": 1,
-          "type": 1,
-          "question": "111",
-          "answerslist": [{
-            "answer": "11"
-          }, {
-            "answer": "111"
-          }, {
-            "answer": "11"
-          }, {
-            "answer": "111"
-          }],
-          'value': []
-        }, {
-          "isMust": 1,
-          "type": 1,
-          "question": "11111",
-          "answerslist": [{
-            "answer": "111"
-          }, {
-            "answer": "111"
-          }],
-          value: []
-        }, {
-          "isMust": 1,
-          "type": 0,
-          "question": "11111"
-        }, {
-          "isMust": 0,
-          "type": 1,
-          "question": "wqwqw",
-          "answerslist": [{
-            "answer": "qw"
-          }, {
-            "answer": "wqw"
-          }, {
-            "answer": "wqw"
-          }]
-        }]
-      }
-    });
+
   },
 
-  onChange: function (e) {
+  onChange1(e) {
     var index = e.currentTarget.dataset['index'];
+    var userinfo = wx.getStorageSync("user");
+    var questionId = e.currentTarget.dataset['questionId'];
+    const {
+      value
+    } = e.detail;
+
+    console.log('checkbox', e, '索引', index);
+    console.log('value', value);
+    console.log('questionId', questionId);
+    console.log('this.data.question', this.data.question);
+    const data = this.data.question.psqList[index].value || [];
+    console.log(data)
+    this.data.question.psqList[index].value = value
+    this.data.question.psqList[index].questionItemId = this.data.question.psqList[index].optionsId[this.data.question.psqList[index].options.indexOf(value)]
+    this.data.question.psqList[index].objectId = userinfo.id
+    this.data.question.psqList[index].questionnaireId = this.data.id
+
+    console.log('this.data.question', this.data.question)
+    this.setData({
+      question: this.data.question
+    })
+  },
+
+  onChange: function(e) {
+    var index = e.currentTarget.dataset['index'];
+    var userinfo = wx.getStorageSync("user");
+    var questionId = e.currentTarget.dataset['questionId'];
     const {
       value
     } = e.detail;
@@ -153,6 +213,9 @@
     const current = idx === -1 ? [...data, value] : data.filter((n) => n !== value)
     console.log('current', current);
     this.data.question.psqList[index].value = current
+    this.data.question.psqList[index].questionItemId = this.data.question.psqList[index].optionsId[this.data.question.psqList[index].options.indexOf(value)]
+    this.data.question.psqList[index].objectId = userinfo.id
+    this.data.question.psqList[index].questionnaireId = this.data.id
     this.setData({
       question: this.data.question
     })

--
Gitblit v1.8.0