forked from nsjcy/frontEnd/nsjcy

liuwh
2020-03-14 12e9a4001d693505cc044fe2df0614257c26d535
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// pages/createSub/createSub.js
const app = getApp();
const $v = app.globalData.createInfo;
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    question: {},
    confirm: true
  },
  // 去单选页面
  toRadio(e) {
    var types = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: '/pages/radio/radio?type=' + types,
    })
  },
  //去编辑页面
  edit(e) {
    var index = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: '/pages/radio/radio?index=' + index,
    })
  },
  // 提交信息
  submit() {
    if ($v.psqList.length == 0) {
      wx.showToast({
        title: '你还没有创建题目',
        icon: "none",
        duration: 800
      });
      return;
    }
    this.setData({
      confirm: false
    })
  },
  // 发布信息
  publish() {
    app.res({
      url: "psq/save",
      method: "POST",
      data: $v,
      callback: res => {
        $v.paper = {};
        $v.psqList = [];
        wx.showModal({
          title: '提示',
          content: '发布成功,跳转新建问卷',
          showCancel: false,
          success: res => {
            if (res.confirm) {
              wx.switchTab({
                url: '/pages/creat/creat',
                success: function(e) {
                  var page = getCurrentPages().pop();
                  if (page == undefined || page == null) return;
                  page.onLoad();
                }
              })
            }
          }
        })
      }
    })
  },
  returnEdit() {
    this.setData({
      confirm: true
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var _m = "question";
    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) {
    var index = e.currentTarget.dataset['index'];
    const {
      value
    } = e.detail;
    console.log('checkbox', e, '索引', index);
    const data = this.data.question.psqList[index].value || [];
    const idx = data.indexOf(value)
    const current = idx === -1 ? [...data, value] : data.filter((n) => n !== value)
    console.log('current', current);
    this.data.question.psqList[index].value = current
    this.setData({
      question: this.data.question
    })
 
  }
 
})