createQuestionnaire.vue
5.32 KB
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
<template>
<view class="page">
<u-form :model="form" ref="uForm" :label-width="120">
<view class="form-box">
<u-form-item label="问卷名称"><u-input v-model="form.title" /></u-form-item>
</view>
<view class="form-box">
<u-form-item label="问卷说明" label-position="top"><u-input v-model="form.remarks" type="textarea"/></u-form-item>
</view>
<view class="select-item" v-for="(val,index) in items" :key="index">
<view class="top">
<view class="title" style="display: flex;align-items: center;">
{{index + 1}}.<u-input v-model="val.tikuTitle" type="text" :border="false" style="margin-left: 10px;"/>
</view>
<u-form-item label="题型" borderBottom>
<u-input v-model="val.questionType" type="select" @click="tixin(index)"
placeholder='请选择题型' />
</u-form-item>
<u-radio-group class="radio-box" v-if="val.questionType=='单选'">
<u-radio shape="circle" v-for="(item,val) in val.optionSettings"><u-input v-model="item.ules" type="text" :border="false" style="margin-left: 10px;" /></u-radio>
</u-radio-group>
<u-checkbox-group v-if="val.questionType=='多选'">
<u-checkbox
v-for="(item,val) in val.optionSettings"
><u-input v-model="item.ules" type="text" :border="false" style="margin-left: 10px;" /></u-checkbox>
</u-checkbox-group>
</view>
<view class="bottom">
<!-- <u-button type="primary" size="mini">编辑</u-button> -->
<u-button type="success" size="mini" @click="addxuan(index)" v-if="val.questionType!=''">添加选项</u-button>
<u-button type="success" size="mini" @click="moveUp(index)">上移</u-button>
<u-button type="success" size="mini" @click="moveDown(index)">下移</u-button>
<u-button type="error" size="mini" @click="del(index)">删除</u-button>
</view>
</view>
<view style="padding: 20px 45%;margin-bottom: 40px;color: #0FBB59;" @click="addItems"> + 添加</view>
</u-form>
<view class="page-footer">
<u-button type="info" @click="go('/pages/setPage/setPage')"><u-icon name="setting" ></u-icon>设置</u-button>
<u-button type="info" @click="goDetail()"><u-icon name="eye"></u-icon>预览</u-button>
<u-button type="success" @click="tijiao"><u-icon name="checkmark-circle"></u-icon>提交</u-button>
</view>
<u-select v-model="typeShow" :list="questionnaireType" @confirm="typeChange"></u-select>
</view>
</template>
<script>
export default {
data() {
return {
form: {
name: '',
remarks:'',
questionId:'',
},
items: [{
tikuTitle: '',
questionBank:'用户端题库',
questionType: '',
optionSettings: [{
ules:''
}],
}],
xuanSet:[{
ules:''
}],
value:0,
typeShow:false,
questionnaireType: [{
value: 1,
label: '单选'
},
{
value: 2,
label: '多选'
}
],
tixinIndex:0,
formS:{
}
}
},
onLoad(option) {
if(option.data){
this.form = {...this.form,...JSON.parse(option.data)}
this.formS = JSON.parse(option.data)
}
},
methods:{
go(urls){
uni.navigateTo({
url:`${urls}`
})
},
bindTextAreaBlur: function (e) {
console.log(e.detail.value)
},
addItems() {
this.items.push({
tikuTitle: '',
questionBank:'用户端题库',
questionType: '',
optionSettings: [{
ules:''
}],
})
},
addxuan(index){
this.items[index].optionSettings.push({
ules:'',
})
},
del(index){
this.items.splice(index, 1)
},
moveUp(index) {
if (index > 0) {
// 使用数组的 splice 方法交换元素位置
this.items.splice(index - 1, 0, this.items.splice(index, 1)[0]);
}
},
moveDown(index) {
if (index < this.items.length - 1) {
// 使用数组的 splice 方法交换元素位置
this.items.splice(index + 1, 0, this.items.splice(index, 1)[0]);
}
},
tijiao(){
let Ids = [];
let promises = this.items.map(tem => {
tem.optionSettings = tem.optionSettings.map(item => `"ules":"${item.ules}"`).join(',')
tem.user = uni.getStorageSync('shopId');
return this.$http.sendRequest('/cereQuestionManagement/add', 'POST', tem, 1).then(res => {
Ids.push(res.data.data.id)
})
})
Promise.all(promises).then(() => {
this.form.questionId = Ids.join(',');
let obj = { ...this.form, ...this.formS }
this.$http.sendRequest('/cereQuestionnaireTable/add', 'POST', obj, 1).then(res => {
uni.redirectTo({
url: '/pages/questionnaire/questionnaire'
})
})
}).catch(error => {
console.error('Error:', error);
})
},
tixin(index){
this.typeShow = true
this.tixinIndex = index
},
typeChange(e) {
this.items[this.tixinIndex].questionType = e[0].label
},
goDetail(){
let obj ={
msg :this.items
}
obj = JSON.stringify(obj)
uni.navigateTo({
url: `/pages/questionnaire/questDetail/questDetail?detail=${JSON.stringify(obj)}`
})
},
}
}
</script>
<style scoped lang="scss">
@import 'createQuestionnaire.scss';
</style>