Blame view

pages/createQuestionnaire/createQuestionnaire.vue 5.32 KB
4dfe89e4   monkeyhouyi   初始化
1
2
  <template>
  <view class="page">
15ee21cf   monkeyhouyi   调查问卷,时间段选择
3
4
  	<u-form :model="form" ref="uForm" :label-width="120">
  		<view class="form-box">
354e3811   杨鑫   '验收'
5
  			<u-form-item label="问卷名称"><u-input v-model="form.title" /></u-form-item>
4dfe89e4   monkeyhouyi   初始化
6
  		</view>
15ee21cf   monkeyhouyi   调查问卷,时间段选择
7
  		<view class="form-box">
354e3811   杨鑫   '验收'
8
  			<u-form-item label="问卷说明" label-position="top"><u-input v-model="form.remarks" type="textarea"/></u-form-item>
4dfe89e4   monkeyhouyi   初始化
9
  		</view>
354e3811   杨鑫   '验收'
10
  		<view class="select-item" v-for="(val,index) in items" :key="index">
15ee21cf   monkeyhouyi   调查问卷,时间段选择
11
  			<view class="top">
354e3811   杨鑫   '验收'
12
13
  				<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;"/>
4dfe89e4   monkeyhouyi   初始化
14
  				</view>
354e3811   杨鑫   '验收'
15
16
17
18
19
20
  				<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>
15ee21cf   monkeyhouyi   调查问卷,时间段选择
21
  				</u-radio-group>
354e3811   杨鑫   '验收'
22
23
24
25
26
  				<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>
4dfe89e4   monkeyhouyi   初始化
27
  			</view>
15ee21cf   monkeyhouyi   调查问卷,时间段选择
28
  			<view class="bottom">
354e3811   杨鑫   '验收'
29
30
31
32
33
  				<!-- <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>
4dfe89e4   monkeyhouyi   初始化
34
35
  			</view>
  		</view>
354e3811   杨鑫   '验收'
36
  		 <view style="padding: 20px 45%;margin-bottom: 40px;color: #0FBB59;" @click="addItems"> + 添加</view>
15ee21cf   monkeyhouyi   调查问卷,时间段选择
37
38
  	</u-form>
  		<view class="page-footer">
354e3811   杨鑫   '验收'
39
40
41
  			<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>
15ee21cf   monkeyhouyi   调查问卷,时间段选择
42
  		</view>	  
354e3811   杨鑫   '验收'
43
  		<u-select v-model="typeShow" :list="questionnaireType" @confirm="typeChange"></u-select>
4dfe89e4   monkeyhouyi   初始化
44
45
46
47
48
49
50
  </view>
  </template>
  
  <script>
  	export default {
  		data() {
  			return {
15ee21cf   monkeyhouyi   调查问卷,时间段选择
51
52
  				form: {
  					name: '',
354e3811   杨鑫   '验收'
53
54
55
  					remarks:'',
  					questionId:'',
  					
15ee21cf   monkeyhouyi   调查问卷,时间段选择
56
  				},
354e3811   杨鑫   '验收'
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
  				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)
  			}
  		 
4dfe89e4   monkeyhouyi   初始化
91
92
  		},
  		methods:{
354e3811   杨鑫   '验收'
93
94
95
96
97
  			go(urls){
  				uni.navigateTo({
  					url:`${urls}`
  				})
  			},
4dfe89e4   monkeyhouyi   初始化
98
99
  			 bindTextAreaBlur: function (e) {
  			            console.log(e.detail.value)
354e3811   杨鑫   '验收'
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
  			        },
  					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)}`
  							})
  					
  						},
4dfe89e4   monkeyhouyi   初始化
172
173
174
175
176
177
178
  		}
  	}
  </script>
  
  <style  scoped lang="scss">
  	@import 'createQuestionnaire.scss';
  </style>