addShop.vue 14.4 KB
Newer Older
M
maguohua 已提交
1
<template>
M
maguohua 已提交
2 3 4 5
    <div>
        <head-top></head-top>
        <el-row style="margin-top: 20px;">
  			<el-col :span="12" :offset="4">
M
maguohua 已提交
6
		        <el-form :model="formData" :rules="rules" ref="formData" label-width="110px" class="demo-formData">
M
maguohua 已提交
7
					<el-form-item label="店铺名称" prop="name">
M
maguohua 已提交
8
						<el-input v-model="formData.name"></el-input>
M
maguohua 已提交
9 10
					</el-form-item>
					<el-form-item label="详细地址" prop="address">
M
maguohua 已提交
11 12 13 14 15 16 17 18
						<el-autocomplete
						  v-model="formData.address"
						  :fetch-suggestions="querySearchAsync"
						  placeholder="请输入地址"
						  style="width: 100%;"
						  @select="addressSelect"
						></el-autocomplete>
						<span>当前城市:{{city.name}}</span>
M
maguohua 已提交
19 20
					</el-form-item>
					<el-form-item label="联系电话" prop="phone">
M
maguohua 已提交
21
						<el-input v-model.number="formData.phone" maxLength="11"></el-input>
M
maguohua 已提交
22 23
					</el-form-item>
					<el-form-item label="店铺简介" prop="description">
M
maguohua 已提交
24
						<el-input v-model="formData.description"></el-input>
M
maguohua 已提交
25 26
					</el-form-item>
					<el-form-item label="店铺标语" prop="promotion_info">
M
maguohua 已提交
27
						<el-input v-model="formData.promotion_info"></el-input>
M
maguohua 已提交
28
					</el-form-item>
M
maguohua 已提交
29 30 31 32 33 34 35
					<el-form-item label="店铺分类">
						<el-cascader
						  :options="categoryOptions"
						  v-model="selectedCategory"
						  change-on-select
						></el-cascader>
					</el-form-item>
M
maguohua 已提交
36 37
					<el-form-item label="店铺特点" style="white-space: nowrap;">
						<span>品牌保证</span>
M
maguohua 已提交
38
						<el-switch on-text="" off-text="" v-model="formData.is_premium"></el-switch>
M
maguohua 已提交
39
						<span>蜂鸟专送</span>
M
maguohua 已提交
40
						<el-switch on-text="" off-text="" v-model="formData.delivery_mode"></el-switch>
M
maguohua 已提交
41
						<span>新开店铺</span>
M
maguohua 已提交
42
						<el-switch on-text="" off-text="" v-model="formData.new"></el-switch>
M
maguohua 已提交
43 44 45
					</el-form-item>
					<el-form-item style="white-space: nowrap;">
						<span>外卖保</span>
M
maguohua 已提交
46
						<el-switch on-text="" off-text="" v-model="formData.bao"></el-switch>
M
maguohua 已提交
47
						<span>准时达</span>
M
maguohua 已提交
48
						<el-switch on-text="" off-text="" v-model="formData.zhun"></el-switch>
M
maguohua 已提交
49
						<span>开发票</span>
M
maguohua 已提交
50 51 52 53 54 55 56
						<el-switch on-text="" off-text="" v-model="formData.piao"></el-switch>
					</el-form-item>
					<el-form-item label="配送费" prop="float_delivery_fee">
						<el-input-number v-model="formData.float_delivery_fee" :min="0" :max="20"></el-input-number>
					</el-form-item>
					<el-form-item label="起送价" prop="float_minimum_order_amount">
						<el-input-number v-model="formData.float_minimum_order_amount" :min="0" :max="100"></el-input-number>
M
maguohua 已提交
57 58 59 60
					</el-form-item>
					<el-form-item label="营业时间" style="white-space: nowrap;">
						<el-time-select
							placeholder="起始时间"
M
maguohua 已提交
61
							v-model="formData.startTime"
M
maguohua 已提交
62 63 64 65 66 67 68 69
							:picker-options="{
							start: '05:30',
							step: '00:15',
							end: '23:30'
							}">
						</el-time-select>
						<el-time-select
							placeholder="结束时间"
M
maguohua 已提交
70
							v-model="formData.endTime"
M
maguohua 已提交
71 72 73 74
							:picker-options="{
							start: '05:30',
							step: '00:15',
							end: '23:30',
M
maguohua 已提交
75
							minTime: formData.startTime
M
maguohua 已提交
76 77 78
							}">
						</el-time-select>
					</el-form-item>
M
maguohua 已提交
79
					
M
maguohua 已提交
80 81 82
					<el-form-item label="上传店铺头像">
						<el-upload
						  class="avatar-uploader"
M
maguohua 已提交
83
						  :action="baseUrl + '/v1/addimg/shop'"
M
maguohua 已提交
84 85 86
						  :show-file-list="false"
						  :on-success="handleShopAvatarScucess"
						  :before-upload="beforeAvatarUpload">
M
maguohua 已提交
87
						  <img v-if="formData.image_path" :src="baseImgPath + formData.image_path" class="avatar">
M
maguohua 已提交
88 89 90 91 92 93
						  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
						</el-upload>
					</el-form-item>
					<el-form-item label="上传营业执照">
						<el-upload
						  class="avatar-uploader"
M
maguohua 已提交
94
						  :action="baseUrl + '/v1/addimg/shop'"
M
maguohua 已提交
95 96 97
						  :show-file-list="false"
						  :on-success="handleBusinessAvatarScucess"
						  :before-upload="beforeAvatarUpload">
M
maguohua 已提交
98
						  <img v-if="formData.business_license_image" :src="baseImgPath + formData.business_license_image" class="avatar">
M
maguohua 已提交
99 100 101 102 103 104
						  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
						</el-upload>
					</el-form-item>
					<el-form-item label="上传餐饮服务许可证">
						<el-upload
						  class="avatar-uploader"
M
maguohua 已提交
105
						  :action="baseUrl + '/v1/addimg/shop'"
M
maguohua 已提交
106 107 108
						  :show-file-list="false"
						  :on-success="handleServiceAvatarScucess"
						  :before-upload="beforeAvatarUpload">
M
maguohua 已提交
109
						  <img v-if="formData.catering_service_license_image" :src="baseImgPath + formData.catering_service_license_image" class="avatar">
M
maguohua 已提交
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
						  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
						</el-upload>
					</el-form-item>
					<el-form-item label="优惠活动">
						<el-select v-model="activityValue" @change="selectActivity" :placeholder="activityValue">
						    <el-option
						      	v-for="item in options"
						      	:key="item.value"
						      	:label="item.label"
						      	:value="item.value">
						    </el-option>
						</el-select>
					</el-form-item>
					<el-table
					    :data="activities"
					    style="min-width: 600px;margin-bottom: 20px;"
						align="cneter"
					    :row-class-name="tableRowClassName">
					    <el-table-column
					      prop="icon_name"
					      label="活动标题"
					      align="cneter"
					      width="120">
					    </el-table-column>
					    <el-table-column
					      prop="name"
					      label="活动名称"
					      align="cneter"
					      width="120">
					    </el-table-column>
					    <el-table-column
					      prop="description"
					      align="cneter"
					      label="活动详情">
					    </el-table-column>
					    <el-table-column 
					    	label="操作" 
					    	width="120">
					    <template scope="scope">
					        <el-button
					          size="small"
					          type="danger"
					          @click="handleDelete(scope.$index)">删除</el-button>
					    </template>
					    </el-table-column>
					</el-table>
					<el-form-item class="button_submit">
M
maguohua 已提交
157
						<el-button type="primary" @click="submitForm('formData')">立即创建</el-button>
M
maguohua 已提交
158 159 160 161
					</el-form-item>
				</el-form>
  			</el-col>
  		</el-row>
M
maguohua 已提交
162 163 164 165
    </div>
</template>

<script>
M
maguohua 已提交
166
    import headTop from '@/components/headTop'
M
maguohua 已提交
167 168
    import {cityGuess, addShop, searchplace, foodCategory} from '@/api/getData'
    import {baseUrl, baseImgPath} from '@/config/env'
M
maguohua 已提交
169
    export default {
M
maguohua 已提交
170 171
    	data(){
    		return {
M
maguohua 已提交
172 173
    			city: {},
    			formData: {
M
maguohua 已提交
174 175
					name: '', //店铺名称
					address: '', //地址
M
maguohua 已提交
176 177
					latitude: '',
					longitude: '',
M
maguohua 已提交
178 179 180
					description: '', //介绍
					phone: '',
					promotion_info: '',
M
maguohua 已提交
181 182
					float_delivery_fee: 5, //运费
					float_minimum_order_amount: 20, //起价
M
desc  
maguohua 已提交
183 184 185 186 187 188
					is_premium: true,
					delivery_mode: true,
					new: true,
					bao: true,
					zhun: true,
					piao: true,
M
maguohua 已提交
189 190 191 192 193
					startTime: '',
       	 			endTime: '',
       	 			image_path: '',
       	 			business_license_image: '',
       	 			catering_service_license_image: '',
M
maguohua 已提交
194
       	 			
M
maguohua 已提交
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
		        },
		        rules: {
					name: [
						{ required: true, message: '请输入店铺名称', trigger: 'blur' },
					],
					address: [
						{ required: true, message: '请输入详细地址', trigger: 'blur' }
					],
					phone: [
						{ required: true, message: '请输入联系电话' },
						{ type: 'number', message: '电话号码必须是数字' }
					],
				},
				options: [{
		          	value: '满减优惠',
		          	label: '满减优惠'
		        }, {
		          	value: '优惠大酬宾',
		          	label: '优惠大酬宾'
		        }, {
		          	value: '新用户立减',
		          	label: '新用户立减'
		        }, {
		          	value: '进店领券',
		          	label: '进店领券'
		        }],
       	 		activityValue: '满减优惠',
				activities: [{
		        	icon_name: '',
		        	name: '满减优惠',
		        	description: '满30减5,满60减8',
M
maguohua 已提交
226 227
			    }],
			    baseUrl,
M
maguohua 已提交
228 229 230
			    baseImgPath,
			    categoryOptions: [],
			    selectedCategory: ['快餐便当', '简餐']
M
maguohua 已提交
231 232 233 234 235
    		}
    	},
    	components: {
    		headTop,
    	},
M
maguohua 已提交
236 237 238
    	mounted(){
    		this.initData();
    	},
M
maguohua 已提交
239
    	methods: {
M
maguohua 已提交
240 241 242
    		async initData(){
    			try{
    				this.city = await cityGuess();
M
maguohua 已提交
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
    				const categories = await foodCategory();
    				categories.forEach(item => {
    					if (item.sub_categories.length) {
    						const addnew = {
    							value: item.name,
						        label: item.name,
						        children: []
    						}
    						item.sub_categories.forEach((subitem, index) => {
    							if (index == 0) {
    								return
    							}
    							addnew.children.push({
    								value: subitem.name,
						        	label: subitem.name,
    							})
    						})
    						this.categoryOptions.push(addnew)

    					}
    				})
M
maguohua 已提交
264
    			}catch(err){
M
maguohua 已提交
265
    				console.log(err);
M
maguohua 已提交
266 267 268 269 270 271 272 273 274 275 276 277 278 279
    			}
    		},
    		async querySearchAsync(queryString, cb) {
    			if (queryString) {
	    			try{
	    				const cityList = await searchplace(this.city.id, queryString);
	    				if (cityList instanceof Array) {
		    				cityList.map(item => {
		    					item.value = item.address;
		    					return item;
		    				})
		    				cb(cityList)
	    				}
	    			}catch(err){
M
maguohua 已提交
280
	    				console.log(err)
M
maguohua 已提交
281 282 283 284 285 286
	    			}
    			}
		    },
		    addressSelect(address){
		    	this.formData.latitude = address.latitude;
		    	this.formData.longitude = address.longitude;
M
maguohua 已提交
287
		    	console.log(this.formData.latitude, this.formData.longitude)
M
maguohua 已提交
288
		    },
M
maguohua 已提交
289
			handleShopAvatarScucess(res, file) {
M
maguohua 已提交
290 291 292 293 294
				if (res.status == 1) {
					this.formData.image_path = res.image_path;
				}else{
					this.$message.error('上传图片失败!');
				}
M
maguohua 已提交
295 296
			},
			handleBusinessAvatarScucess(res, file) {
M
maguohua 已提交
297 298 299 300 301
				if (res.status == 1) {
					this.formData.business_license_image = res.image_path;
				}else{
					this.$message.error('上传图片失败!');
				}
M
maguohua 已提交
302 303
			},
			handleServiceAvatarScucess(res, file) {
M
maguohua 已提交
304 305 306 307 308
				if (res.status == 1) {
					this.formData.catering_service_license_image = res.image_path;
				}else{
					this.$message.error('上传图片失败!');
				}
M
maguohua 已提交
309 310
			},
			beforeAvatarUpload(file) {
M
maguohua 已提交
311
				const isRightType = (file.type === 'image/jpeg') || (file.type === 'image/png');
M
maguohua 已提交
312 313
				const isLt2M = file.size / 1024 / 1024 < 2;

M
maguohua 已提交
314
				if (!isRightType) {
M
maguohua 已提交
315 316 317 318 319
					this.$message.error('上传头像图片只能是 JPG 格式!');
				}
				if (!isLt2M) {
					this.$message.error('上传头像图片大小不能超过 2MB!');
				}
M
maguohua 已提交
320
				return isRightType && isLt2M;
M
maguohua 已提交
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
			},
			tableRowClassName(row, index) {
		        if (index === 1) {
		        	return 'info-row';
		        } else if (index === 3) {
		        	return 'positive-row';
		        }
		        return '';
		    },
		    selectActivity(){
		    	this.$prompt('请输入活动详情', '提示', {
		          	confirmButtonText: '确定',
		          	cancelButtonText: '取消',
		        }).then(({ value }) => {
		        	if (value == null) {
		        		this.$message({
				            type: 'info',
				            message: '请输入活动详情'
				        }); 
		        		return
		        	}
		          	let newObj = {};
		          	switch(this.activityValue){
		          		case '满减优惠':
		          			newObj= {
		          				icon_name: '',
					        	name: '满减优惠',
					        	description: value,
		          			}
		          			break;
		          		case '优惠大酬宾':
		          			newObj= {
		          				icon_name: '',
					        	name: '优惠大酬宾',
					        	description: value,
		          			}
		          			break;
		          		case '新用户立减':
		          			newObj= {
M
maguohua 已提交
360
		          				icon_name: '',
M
maguohua 已提交
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
					        	name: '新用户立减',
					        	description: value,
		          			}
		          			break;
		          		case '进店领券':
		          			newObj= {
		          				icon_name: '',
					        	name: '进店领券',
					        	description: value,
		          			}
		          			break;			
		          	}
		          	this.activities.push(newObj);
		        }).catch(() => {
		          	this.$message({
		            	type: 'info',
		            	message: '取消输入'
		          	});       
		        });
		    },
		    handleDelete(index){
		    	this.activities.splice(index, 1)
M
maguohua 已提交
383 384 385 386
		    },
		    submitForm(formName) {
				this.$refs[formName].validate(async (valid) => {
					if (valid) {
M
maguohua 已提交
387 388 389
						Object.assign(this.formData, {activities: this.activities}, {
							category: this.selectedCategory.join('/')
						})
M
maguohua 已提交
390 391
						try{
							let result = await addShop(this.formData);
M
maguohua 已提交
392 393 394 395 396
							if (result.status == 1) {
								this.$message({
					            	type: 'success',
					            	message: '添加成功'
					          	});
M
maguohua 已提交
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
					          	this.formData = {
									name: '', //店铺名称
									address: '', //地址
									latitude: '',
									longitude: '',
									description: '', //介绍
									phone: '',
									promotion_info: '',
									float_delivery_fee: 5, //运费
									float_minimum_order_amount: 20, //起价
									is_premium: true,
									delivery_mode: true,
									new: true,
									bao: true,
									zhun: true,
									piao: true,
									startTime: '',
				       	 			endTime: '',
				       	 			image_path: '',
				       	 			business_license_image: '',
				       	 			catering_service_license_image: '',	
						        };
						        this.selectedCategory = ['快餐便当', '简餐'];
						        this.activities = [{
						        	icon_name: '',
						        	name: '满减优惠',
						        	description: '满30减5,满60减8',
							    }];
M
maguohua 已提交
425 426 427 428 429 430
							}else{
								this.$message({
					            	type: 'error',
					            	message: result.message
					          	});
							}
M
maguohua 已提交
431 432
							console.log(result)
						}catch(err){
M
maguohua 已提交
433
							console.log(err)
M
maguohua 已提交
434 435 436 437 438 439 440 441 442 443 444
						}
					} else {
						this.$notify.error({
							title: '错误',
							message: '请检查输入是否正确',
							offset: 100
						});
						return false;
					}
				});
			},
M
maguohua 已提交
445
		}
M
maguohua 已提交
446 447 448 449 450
    }
</script>

<style lang="less">
	@import '../style/mixin';
M
maguohua 已提交
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
	.button_submit{
		text-align: center;
	}
	.avatar-uploader .el-upload {
	    border: 1px dashed #d9d9d9;
	    border-radius: 6px;
	    cursor: pointer;
	    position: relative;
	    overflow: hidden;
	}
	.avatar-uploader .el-upload:hover {
	    border-color: #20a0ff;
	}
	.avatar-uploader-icon {
	    font-size: 28px;
	    color: #8c939d;
	    width: 120px;
	    height: 120px;
	    line-height: 120px;
	    text-align: center;
	}
	.avatar {
	    width: 120px;
	    height: 120px;
	    display: block;
	}
	.el-table .info-row {
	    background: #c9e5f5;
	}

	.el-table .positive-row {
	    background: #e2f0e4;
	}
M
maguohua 已提交
484
</style>