addShop.vue 12.2 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 29 30
					</el-form-item>
					<el-form-item label="店铺特点" style="white-space: nowrap;">
						<span>品牌保证</span>
M
maguohua 已提交
31
						<el-switch on-text="" off-text="" v-model="formData.is_premium"></el-switch>
M
maguohua 已提交
32
						<span>蜂鸟专送</span>
M
maguohua 已提交
33
						<el-switch on-text="" off-text="" v-model="formData.delivery_mode"></el-switch>
M
maguohua 已提交
34
						<span>新开店铺</span>
M
maguohua 已提交
35
						<el-switch on-text="" off-text="" v-model="formData.new"></el-switch>
M
maguohua 已提交
36 37 38
					</el-form-item>
					<el-form-item style="white-space: nowrap;">
						<span>外卖保</span>
M
maguohua 已提交
39
						<el-switch on-text="" off-text="" v-model="formData.bao"></el-switch>
M
maguohua 已提交
40
						<span>准时达</span>
M
maguohua 已提交
41
						<el-switch on-text="" off-text="" v-model="formData.zhun"></el-switch>
M
maguohua 已提交
42
						<span>开发票</span>
M
maguohua 已提交
43 44 45 46 47 48 49
						<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 已提交
50 51 52 53
					</el-form-item>
					<el-form-item label="营业时间" style="white-space: nowrap;">
						<el-time-select
							placeholder="起始时间"
M
maguohua 已提交
54
							v-model="formData.startTime"
M
maguohua 已提交
55 56 57 58 59 60 61 62
							:picker-options="{
							start: '05:30',
							step: '00:15',
							end: '23:30'
							}">
						</el-time-select>
						<el-time-select
							placeholder="结束时间"
M
maguohua 已提交
63
							v-model="formData.endTime"
M
maguohua 已提交
64 65 66 67
							:picker-options="{
							start: '05:30',
							step: '00:15',
							end: '23:30',
M
maguohua 已提交
68
							minTime: formData.startTime
M
maguohua 已提交
69 70 71 72 73 74
							}">
						</el-time-select>
					</el-form-item>
					<el-form-item label="上传店铺头像">
						<el-upload
						  class="avatar-uploader"
M
maguohua 已提交
75
						  :action="baseUrl + '/shopping/addimg'"
M
maguohua 已提交
76 77 78
						  :show-file-list="false"
						  :on-success="handleShopAvatarScucess"
						  :before-upload="beforeAvatarUpload">
M
maguohua 已提交
79
						  <img v-if="formData.image_path" :src="baseUrl + formData.image_path" class="avatar">
M
maguohua 已提交
80 81 82 83 84 85
						  <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 已提交
86
						  :action="baseUrl + '/shopping/addimg'"
M
maguohua 已提交
87 88 89
						  :show-file-list="false"
						  :on-success="handleBusinessAvatarScucess"
						  :before-upload="beforeAvatarUpload">
M
maguohua 已提交
90
						  <img v-if="formData.business_license_image" :src="baseUrl + formData.business_license_image" class="avatar">
M
maguohua 已提交
91 92 93 94 95 96
						  <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 已提交
97
						  :action="baseUrl + '/shopping/addimg'"
M
maguohua 已提交
98 99 100
						  :show-file-list="false"
						  :on-success="handleServiceAvatarScucess"
						  :before-upload="beforeAvatarUpload">
M
maguohua 已提交
101
						  <img v-if="formData.catering_service_license_image" :src="baseUrl + formData.catering_service_license_image" class="avatar">
M
maguohua 已提交
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
						  <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 已提交
149
						<el-button type="primary" @click="submitForm('formData')">立即创建</el-button>
M
maguohua 已提交
150 151 152 153
					</el-form-item>
				</el-form>
  			</el-col>
  		</el-row>
M
maguohua 已提交
154 155 156 157
    </div>
</template>

<script>
M
maguohua 已提交
158 159
    import headTop from '@/components/headTop'
    import {cityGuess, addShop, searchplace} from '@/api/getData'
M
maguohua 已提交
160
    import {baseUrl} from '@/config/env'
M
maguohua 已提交
161
    export default {
M
maguohua 已提交
162 163
    	data(){
    		return {
M
maguohua 已提交
164 165
    			city: {},
    			formData: {
M
maguohua 已提交
166 167
					name: '', //店铺名称
					address: '', //地址
M
maguohua 已提交
168 169
					latitude: '',
					longitude: '',
M
maguohua 已提交
170 171 172
					description: '', //介绍
					phone: '',
					promotion_info: '',
M
maguohua 已提交
173 174
					float_delivery_fee: 5, //运费
					float_minimum_order_amount: 20, //起价
M
maguohua 已提交
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
					is_premium: false,
					delivery_mode: false,
					new: false,
					bao: false,
					zhun: false,
					piao: false,
					startTime: '',
       	 			endTime: '',
       	 			image_path: '',
       	 			business_license_image: '',
       	 			catering_service_license_image: '',
		        },
		        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 已提交
217 218
			    }],
			    baseUrl,
M
maguohua 已提交
219 220 221 222 223
    		}
    	},
    	components: {
    		headTop,
    	},
M
maguohua 已提交
224 225 226
    	mounted(){
    		this.initData();
    	},
M
maguohua 已提交
227
    	methods: {
M
maguohua 已提交
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
    		async initData(){
    			try{
    				this.city = await cityGuess();
    			}catch(err){
    				console.error(err);
    			}
    		},
    		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){
	    				console.error(err)
	    			}
    			}
		    },
		    addressSelect(address){
		    	this.formData.latitude = address.latitude;
		    	this.formData.longitude = address.longitude;
		    	console.log(address)
		    },
M
maguohua 已提交
256
			handleShopAvatarScucess(res, file) {
M
maguohua 已提交
257 258 259 260 261
				if (res.status == 1) {
					this.formData.image_path = res.image_path;
				}else{
					this.$message.error('上传图片失败!');
				}
M
maguohua 已提交
262 263
			},
			handleBusinessAvatarScucess(res, file) {
M
maguohua 已提交
264 265 266 267 268
				if (res.status == 1) {
					this.formData.business_license_image = res.image_path;
				}else{
					this.$message.error('上传图片失败!');
				}
M
maguohua 已提交
269 270
			},
			handleServiceAvatarScucess(res, file) {
M
maguohua 已提交
271 272 273 274 275
				if (res.status == 1) {
					this.formData.catering_service_license_image = res.image_path;
				}else{
					this.$message.error('上传图片失败!');
				}
M
maguohua 已提交
276 277
			},
			beforeAvatarUpload(file) {
M
maguohua 已提交
278
				const isRightType = (file.type === 'image/jpeg') || (file.type === 'image/png');
M
maguohua 已提交
279 280
				const isLt2M = file.size / 1024 / 1024 < 2;

M
maguohua 已提交
281
				if (!isRightType) {
M
maguohua 已提交
282 283 284 285 286
					this.$message.error('上传头像图片只能是 JPG 格式!');
				}
				if (!isLt2M) {
					this.$message.error('上传头像图片大小不能超过 2MB!');
				}
M
maguohua 已提交
287
				return isRightType && isLt2M;
M
maguohua 已提交
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
			},
			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 已提交
327
		          				icon_name: '',
M
maguohua 已提交
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
					        	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 已提交
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
		    },
		    submitForm(formName) {
				this.$refs[formName].validate(async (valid) => {
					if (valid) {
						Object.assign(this.formData, {activities: this.activities})
						try{
							let result = await addShop(this.formData);
							console.log(result)
						}catch(err){
							console.error(err)
						}
					} else {
						this.$notify.error({
							title: '错误',
							message: '请检查输入是否正确',
							offset: 100
						});
						return false;
					}
				});
			},
M
maguohua 已提交
371
		}
M
maguohua 已提交
372 373 374 375 376
    }
</script>

<style lang="less">
	@import '../style/mixin';
M
maguohua 已提交
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
	.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 已提交
410
</style>