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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
| <template>
| <div class="quest_add">
| <v-header title="问卷调查"></v-header>
| <div class="btn">
| <button
| class="m_btn bgc_primary"
| v-for="(i,j) in btn"
| :key="j+'-btn'"
| @click="onBtnCreate(i)"
| >{{i.t}}</button>
| </div>
| <div class="main">
| <v-tool-scroll ids="quest-add-scroll">
| <div class="list">
| <p
| class="label"
| data-require
| >问卷标题:</p>
| <div class="box">
| <input
| type="text"
| maxlength="35"
| class="m_inp"
| placeholder="填写问卷标题"
| v-model="title"
| >
| </div>
| </div>
| <div class="list">
| <p
| class="label"
| data-require
| >问卷描述:</p>
| <div class="box">
| <textarea
| maxlength="120"
| cols="30"
| rows="10"
| class="m_inp"
| placeholder="请填写问卷描述"
| v-model="desc"
| ></textarea>
| </div>
| </div>
| <div class="list">
| <p
| class="label"
| data-require
| >仅调研特殊对象:</p>
| <div class="box pad">
| <el-checkbox-group v-model="checkList">
| <el-checkbox
| :label="i.t"
| v-for="(i,j) in change"
| :key="j+'-check'"
| ></el-checkbox>
| </el-checkbox-group>
| </div>
| </div>
| <p class="err">提示:默认社区所有居民可参与调研,勾选后只针对所选群体开放问卷</p>
| <ul>
| <li
| class="list"
| v-for="(i,j) in item"
| :key="j+'-li'"
| >
| <p class="label">{{j+1}}.题目:</p>
| <div class="box">
| <input
| type="text"
| class="m_inp small"
| :placeholder="'填写题目['+i.plac+']'"
| v-model="i.title"
| maxlength="100"
| >
| <div
| class="l"
| v-for="(x,y) in i.child"
| :key="y+'-li-c'"
| >
| <input
| type="text"
| class="m_inp"
| :placeholder="x.type?'其他___':'选项'"
| v-model="x.v"
| maxlength="100"
| >
| <span
| class="del"
| @click="onDelChild(i,y,j)"
| ><i class="el-icon-remove-outline"></i></span>
| </div>
| <div class="a">
| <button
| class="m_btn bgc_tran small info"
| v-if="i.more"
| @click="onAddChild(i,j)"
| >添加选项</button>
| <button
| class="m_btn bgc_tran small grey"
| v-if="i.more"
| @click="onAddChildOther(i,j)"
| >添加"其他"项</button>
| <div class="r">
| <button
| class="m_btn bgc_tran small"
| :class="j===0?'grey':'info'"
| @click="onUp(i,j)"
| >上移</button>
| <button
| class="m_btn bgc_tran small"
| :class="j===item.length-1?'grey':'info'"
| @click="onDown(i,j)"
| >下移</button>
| <button
| class="m_btn bgc_tran small info"
| @click="onDelItem(i,j)"
| >删除</button>
| </div>
| </div>
| </div>
| </li>
| </ul>
| </v-tool-scroll>
| </div>
| <div class="foot">
| <button
| class="m_btn"
| @click="$router.back()"
| >取消</button>
| <button
| class="m_btn bgc_primary"
| @click="onSubmit"
| >立即发布</button>
| </div>
| </div>
| </template>
|
| <script>
| import mock from "./a";
| export default {
| props: {},
| components: {},
| data() {
| return {
| title: "",
| desc: "",
| btn: [
| { t: "添加单选题", v: 0 },
| { t: "添加多选题", v: 1 },
| { t: "添加填空题", v: 2 },
| ],
| item: [],
| change: [
| { t: "社区党员", v: 1 },
| { t: "社区志愿者", v: 2 },
| ],
| checkList: [],
| };
| },
| computed: {},
| watch: {},
| methods: {
| // 添加新的
| onBtnCreate(v) {
| let c = [];
| let m = true;
| switch (v.v) {
| case 0:
| c = [
| { v: "", id: 1 },
| { v: "", id: 2 },
| ];
| break;
| case 1:
| c = [
| { v: "", id: 1 },
| { v: "", id: 2 },
| { v: "", id: 3 },
| ];
| break;
| default:
| m = false;
| }
| this.item.push({
| type: v.v,
| title: "",
| time: Date.now(),
| child: c,
| plac: v.t.replace("添加", ""),
| more: m,
| min: c.length,
| });
| },
| // 添加选项
| onAddChild(i, j) {
| if (i.child.length >= 10) {
| return demo.toast("选项最大添加十项");
| }
| i.child.push({ v: "", id: Date.now() });
| },
| // 添加其他项
| onAddChildOther(i, j) {
| if (i.child.length >= 10) {
| return demo.toast("选项最大添加十项");
| }
| i.child.push({ v: "", id: Date.now(), type: true });
| },
| // 删除数据
| onDelItem(i, j) {
| this.$js.model(
| "",
| "是否删除" + i.plac + (i.title ? "[" + i.title + "]" : ""),
| (res) => {
| if (res) {
| this.item.splice(j, 1);
| }
| }
| );
| },
| // 上移
| onUp(i, j) {
| if (j === 0) return 0;
| let v = demo.copy(this.item);
| v.splice(j, 1);
| v.splice(j - 1, 0, i);
| this.$nextTick(() => {
| this.item = v;
| });
| },
| // 下移
| onDown(i, j) {
| if (j === this.item.length - 1) return 0;
| let v = demo.copy(this.item);
| v.splice(j, 1);
| v.splice(j + 1, 0, i);
| this.$nextTick(() => {
| this.item = v;
| });
| },
| // 删除选项
| onDelChild(i, j, p) {
| if (i.child.length <= i.min) {
| demo.toast("选项数不能低于" + i.min + "个");
| return 0;
| }
| let v = i.child;
| if (j < 0) {
| j = v.length - 1;
| }
| this.$js.model("", "是否删除选项", (res) => {
| if (res) {
| let id = v[j].id;
| v = v.filter((r) => {
| return +r.id !== +id;
| });
| this.$nextTick(() => {
| this.item[p].child = v;
| });
| }
| });
| },
| resetVal() {
| this.item = [];
| this.title = "";
| this.desc = "";
| },
| // 发布 整合数据
| onSubmit() {
| let t = this;
| if (!t.title) return demo.toast("请输入问卷标题");
| if (!t.desc) return demo.toast("请输入问卷描述");
| if (!t.item.length) return demo.toast("请添加题目");
| let os = {
| queTitle: t.title,
| queDescribe: t.desc,
| check: t.change
| .filter((r) => {
| return t.checkList.indexOf(r.t) >= 0;
| })
| .map((r) => {
| return +r.v;
| }),
| list: t.item,
| };
| // if (os.check.length) {
| os.forVolunteer = os.check.indexOf(2) >= 0;
| os.forParty = os.check.indexOf(1) >= 0;
| os.forMasses = !os.forVolunteer && !os.forParty;
| // }
| let index = -1;
| let err = "";
| os.list.forEach((r, y) => {
| if (!r.title) {
| err = "请输入问题";
| index = y;
| } else {
| if (r.type !== 2) {
| if (!r.child.length) {
| index = y;
| err = "请添加选项";
| } else {
| r.child.forEach((q) => {
| if (q.v === "") {
| index = y;
| err = "请完整填写选项";
| }
| });
| }
| }
| }
| });
|
| if (index >= 0) {
| return demo.toast(err);
| }
| os.questnaiteSubVOS = os.list.map((r) => {
| return {
| content: r.title,
| type: r.type,
| questnaiteSubSelectionVOS: r.child.map((k, v) => {
| return { content: k.v, type: !!k.more * 1, optionName: v };
| }),
| };
| });
| delete os.check;
| delete os.list;
| this.$api.post("questnaire/add", os, (e) => {
| demo.toast("创建成功");
| this.resetVal();
| let tt = this;
| setTimeout(() => {
| tt.$router.back();
| }, 1e3);
| });
| },
| ces() {
| let t = this;
| mock.forEach((r) => {
| t.$api.post("questnaire/add", r, (e) => {
| demo.toast("创建成功");
| });
| });
| },
| },
| mounted() {
| // this.ces();
| },
| };
| </script>
| <style lang="less">
| .quest_add {
| position: relative;
| .btn,
| .foot {
| height: 50px;
| box-sizing: border-box;
| display: flex;
| .m_btn {
| margin-right: 10px;
| min-width: 100px;
| }
| }
| .foot {
| margin-top: 10px;
| }
| .main {
| height: calc(100% - 160px);
| }
| .err {
| font-size: 12px;
| color: #ccc;
| margin-bottom: 10px;
| transform: translateY(-10px);
| }
| textarea.m_inp {
| display: block;
| width: 100% !important;
| resize: none;
| max-width: 100%;
| }
| .list {
| position: relative;
| display: flex;
| margin-bottom: 12px;
| .label {
| width: 120px;
| font-size: 15px;
| line-height: 32px;
| text-align: right;
| }
| .box {
| max-width: 600px;
| width: calc(100% - 120px);
| &.pad {
| padding-top: 6px;
| }
| .m_inp {
| width: 100%;
| }
| .l {
| border-bottom: 1px solid #eee;
| position: relative;
| .m_inp {
| border: 0;
| padding-right: 40px;
| }
| .del {
| position: absolute;
| right: 10px;
| top: 0;
| bottom: 0;
| margin: auto;
| width: 30px;
| height: 30px;
| text-align: center;
| font-size: 20px;
| line-height: 30px;
| cursor: pointer;
| color: #999;
| &.dis {
| color: #eee;
| }
| }
| }
| .a {
| display: flex;
| .r {
| flex: 1;
| text-align: right;
| }
| .m_btn + .m_btn {
| margin-left: 8px;
| }
| }
| .info {
| color: #5bc0de;
| }
| .grey {
| color: #999;
| }
| }
| }
| }
| </style>
|
|