Blame view

lvdao-miniapp/pages/createQuestionnaire/createQuestionnaire.vue 6.51 KB
3f535f30   杨鑫   '初始'
1
2
  <template>
  <view class="page">
e5b57447   杨鑫   '分包问卷'
3
4
5
  	<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>
3f535f30   杨鑫   '初始'
6
  		</view>
e5b57447   杨鑫   '分包问卷'
7
8
  		<view class="form-box">
  			<u-form-item label="问卷说明" label-position="top"><u-input v-model="form.remarks" type="textarea"/></u-form-item>
3f535f30   杨鑫   '初始'
9
  		</view>
e5b57447   杨鑫   '分包问卷'
10
11
12
13
  		<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;"/>
3f535f30   杨鑫   '初始'
14
  				</view>
e5b57447   杨鑫   '分包问卷'
15
16
17
18
19
20
21
22
23
24
25
26
  				<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>
3f535f30   杨鑫   '初始'
27
  			</view>
e5b57447   杨鑫   '分包问卷'
28
29
30
31
32
33
  			<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>
3f535f30   杨鑫   '初始'
34
35
  			</view>
  		</view>
e5b57447   杨鑫   '分包问卷'
36
37
38
39
40
41
42
43
  		 <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>
3f535f30   杨鑫   '初始'
44
45
46
47
48
49
50
  </view>
  </template>
  
  <script>
  	export default {
  		data() {
  			return {
e5b57447   杨鑫   '分包问卷'
51
  				form: {
8550d958   杨鑫   '最新'
52
  					title:'',
e5b57447   杨鑫   '分包问卷'
53
54
55
56
57
58
59
60
61
  					remarks:'',
  					questionId:'',
  					
  				},
  				items: [{
  					tikuTitle: '',
  					questionBank:'用户端题库',
  					questionType: '',
  					optionSettings: [{
8550d958   杨鑫   '最新'
62
  					1:''
e5b57447   杨鑫   '分包问卷'
63
64
65
  						}],
  				}],
  				xuanSet:[{
8550d958   杨鑫   '最新'
66
  					1:''
e5b57447   杨鑫   '分包问卷'
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  				}],
  				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)
  			}
  		 
3f535f30   杨鑫   '初始'
91
92
  		},
  		methods:{
e5b57447   杨鑫   '分包问卷'
93
94
95
96
97
  			go(urls){
  				uni.navigateTo({
  					url:`${urls}`
  				})
  			},
3f535f30   杨鑫   '初始'
98
99
  			 bindTextAreaBlur: function (e) {
  			            console.log(e.detail.value)
e5b57447   杨鑫   '分包问卷'
100
101
102
103
104
105
106
  			        },
  					addItems() {
  						this.items.push({
  					tikuTitle: '',
  					questionBank:'用户端题库',
  					questionType: '',
  					optionSettings: [{
8550d958   杨鑫   '最新'
107
  					1:''
e5b57447   杨鑫   '分包问卷'
108
109
110
111
112
  						}],
  				})
  					},
  					addxuan(index){
  						this.items[index].optionSettings.push({
8550d958   杨鑫   '最新'
113
  							index:'',
e5b57447   杨鑫   '分包问卷'
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  						})
  					},
  					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(){
8550d958   杨鑫   '最新'
133
  					
e5b57447   杨鑫   '分包问卷'
134
135
  						  let Ids = [];
  						  let promises = this.items.map(tem => {
8550d958   杨鑫   '最新'
136
137
138
139
140
141
142
143
  						 //    tem.optionSettings =  {}
  							// tem.optionSettings =  tem.optionSettings.map((item,index) => `"${index + 1 }":"${item.ules}"`).join(',')
  							let strSettings = tem.optionSettings.map((item, index) => `"${index + 1}":"${item.ules}"`).join(',');
  							
  							// 将字符串转换为对象
  							let objSettings = JSON.parse('{' + strSettings + '}');
  							tem.optionSettings =  JSON.stringify(objSettings)
  					         
e5b57447   杨鑫   '分包问卷'
144
145
146
147
148
  						    tem.user = uni.getStorageSync('shopId');
  						    return this.$http.sendRequest('/cereQuestionManagement/add', 'POST', tem, 1).then(res => {
  						      Ids.push(res.data.data.id)
  						    })
  						  })
8550d958   杨鑫   '最新'
149
  							this.form.createTime = this.currentTime()
e5b57447   杨鑫   '分包问卷'
150
151
  						  Promise.all(promises).then(() => {
  						    this.form.questionId = Ids.join(',');
8550d958   杨鑫   '最新'
152
153
154
  						    // let obj = { ...this.form, ...this.formS }
  						
  						    this.$http.sendRequest('/cereQuestionnaireTable/add', 'POST', this.form, 1).then(res => {
e5b57447   杨鑫   '分包问卷'
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
  						      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)}`
  							})
  					
  						},
8550d958   杨鑫   '最新'
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
  						// 获取时间
  						currentTime() {
  						  let date = new Date();
  						  let year = date.getFullYear();
  						  let month = date.getMonth() + 1; // 月份从0~11,所以加一
  						  let day = date.getDate();
  						  let hours = date.getHours();
  						  let minutes = date.getMinutes();
  						  let seconds = date.getSeconds();
  						
  						  // 为月、日、小时、分钟和秒添加前导零(如果需要)
  						  month = month < 10 ? '0' + month : month;
  						  day = day < 10 ? '0' + day : day;
  						  hours = hours < 10 ? '0' + hours : hours;
  						  minutes = minutes < 10 ? '0' + minutes : minutes;
  						  seconds = seconds < 10 ? '0' + seconds : seconds;
  						
  						  // 返回格式化的日期和时间字符串
  						  return `${year}-${month}-${day} ${hours}:${minutes}`;
  						},
3f535f30   杨鑫   '初始'
201
202
203
204
205
206
207
  		}
  	}
  </script>
  
  <style  scoped lang="scss">
  	@import 'createQuestionnaire.scss';
  </style>