From 8d68b6a1dcdf5008fba6bdac5858d1085a0e63e7 Mon Sep 17 00:00:00 2001
From: liuwh <hugeinfo123>
Date: Mon, 30 Mar 2020 23:14:04 +0800
Subject: [PATCH] 提交

---
 SunshineLnsMinApp/pages/createSub/createSub.js |   77 +++++++++++++++++++++++++++++++++-----
 1 files changed, 67 insertions(+), 10 deletions(-)

diff --git a/SunshineLnsMinApp/pages/createSub/createSub.js b/SunshineLnsMinApp/pages/createSub/createSub.js
index 9f59096..5e4635e 100644
--- a/SunshineLnsMinApp/pages/createSub/createSub.js
+++ b/SunshineLnsMinApp/pages/createSub/createSub.js
@@ -9,7 +9,9 @@
   data: {
     question: {},
     confirm: true,
-    value1:''
+    value1: '',
+    answer: [],
+    id: ''
   },
   // 去单选页面
   toRadio(e) {
@@ -27,6 +29,48 @@
   },
   // 提交信息
   submit() {
+    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: '../yshjqyfw/yshjqyfw',
+            })
+          }, 2000)
+        } else {
+          wx.showModal({
+            title: '提示',
+            content: "提交失败!"
+          })
+        }
+      }
+    })
     // if ($v.psqList.length == 0) {
     //   wx.showToast({
     //     title: '你还没有创建题目',
@@ -35,14 +79,14 @@
     //   });
     //   return;
     // }
-    wx.showToast({
-      title: '提交成功!',
-      icon: 'success',
-      duration: 2000
-    }, wx.reLaunch({
-      url: '../yshjqyfw/yshjqyfw',
-    }))
-    
+    // wx.showToast({
+    //   title: '提交成功!',
+    //   icon: 'success',
+    //   duration: 2000
+    // }, wx.reLaunch({
+    //   url: '../yshjqyfw/yshjqyfw',
+    // }))
+
   },
   // 发布信息
   publish() {
@@ -93,6 +137,7 @@
         if (res.data.code == 0) {
           console.log(res)
           that.setData({
+            id: res.data.data.id,
             [_m]: {
               "paper": {
                 "title": res.data.data.title,
@@ -155,16 +200,23 @@
 
   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
@@ -173,6 +225,8 @@
 
   onChange: function(e) {
     var index = e.currentTarget.dataset['index'];
+    var userinfo = wx.getStorageSync("user");
+    var questionId = e.currentTarget.dataset['questionId'];
     const {
       value
     } = e.detail;
@@ -182,6 +236,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