addShop.vue 16.5 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 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 217 218 219 220 221 222 223 224 225 226 227 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 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 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 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 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 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 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
<template>
    <div>
        <el-dialog
        :title="$t('button.addArea')"
        class="manage-dialog"
        :visible.sync="addDialogVisible"
        :close-on-click-modal="false"
        @open="dialogOpen(addForm)"
        @close="addDialogClose()">
            <el-form :model="addForm" status-icon :rules="rules" ref="addForm">
                <el-form-item :label="$t('table.areaName')" prop="name">
                    <el-input v-model="addForm.name"></el-input>
                    <i class="error-tip">*</i>
                </el-form-item>
                <el-form-item :label="$t('table.type')" prop="type">
                    <el-select class="manage-sel" v-model="addForm.type" :placeholder="$t('pholder.type')" @change="typeChange(addForm.type)">
                        <el-option :label="$t('pholder.type1')" :value="1"></el-option>
                        <el-option :label="$t('pholder.type2')" :value="3"></el-option>
                        <el-option :label="$t('pholder.type3')" :value="2"></el-option>
                        <el-option :label="$t('pholder.type4')" :value="4"></el-option>
                    </el-select>
                    <i class="error-tip">*</i>
                </el-form-item>
                <el-form-item :label="$t('table.state')" prop="status">
                    <el-select class="manage-sel" v-model="addForm.status" :placeholder="$t('pholder.state')">
                        <el-option :label="$t('pholder.state1')" :value="1"></el-option>
                        <el-option :label="$t('pholder.state2')" :value="2"></el-option>
                    </el-select>
                    <i class="error-tip">*</i>
                </el-form-item>
                 <el-form-item :label="$t('table.shopNum')" prop="shopNo">
                    <el-autocomplete
                        class="unit-input"
                        v-model="addForm.shopNo"
                        :fetch-suggestions="querySearch"
                        :placeholder="$t('table.shopNum')"
                    ></el-autocomplete>
                </el-form-item>
                <el-form-item :label="$t('table.shopUnitId')" prop="locationNo">
                    <el-autocomplete
                        class="unit-input"
                        v-model="addForm.locationNo"
                        :fetch-suggestions="querySearchId"
                        :placeholder="$t('table.shopUnitId')"
                    ></el-autocomplete>
                </el-form-item> 
                <!-- <el-form-item :label="$t('table.shopNum')" prop="locationNo">
                    <el-input v-model="addForm.locationNo"></el-input>
                </el-form-item>  -->
                <el-form-item :label="$t('table.externalNum')" prop="externalId">
                    <el-input v-model="addForm.externalId"></el-input>
                </el-form-item>
                <!-- <el-form-item label="所属集团" prop="accountId">
                    <el-select class="manage-sel" v-model="addForm.accountId" filterable :placeholder="$t('pholder.select')" @change="changeAddAccount" :no-data-text="$t('pholder.nodata')">
                        <el-option v-for="item in accountList" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item> -->
                <el-form-item :label="$t('dialog.format')" prop="formatId">
                    <el-select class="manage-sel" v-model="addForm.formatId" filterable :placeholder="$t('pholder.format')" :no-data-text="$t('pholder.nodata')" @change="formatChange">
                        <el-option v-for="item in formatOpts" :key="item.id" :label="item.label" :value="item.id">
                        </el-option>
                    </el-select>
                    <!-- <i class="error-tip">*</i> -->
                </el-form-item>
                <el-form-item :label="$t('dialog.subFormat')" prop="subFormatId" v-show="addForm.formatId">
                    <el-select class="manage-sel" v-model="addForm.subFormatId" filterable :placeholder="$t('pholder.subFormat')" :no-data-text="$t('pholder.nodata')">
                        <el-option v-for="item in subFormatOpts" :key="item.id" :label="item.label" :value="item.id">
                        </el-option>
                    </el-select>
                    <!-- <i class="error-tip">*</i> -->
                </el-form-item>
                <el-form-item :label="$t('table.square')" prop="mallId">
                    <el-select class="manage-sel" v-model="addForm.mallId" filterable :placeholder="$t('pholder.select')" :no-data-text="$t('pholder.nodata')" @change="changeAddMall">
                        <el-option v-for="item in mallList" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                    <i class="error-tip">*</i>
                </el-form-item>
                <el-form-item :label="$t('table.floor')" prop="floorId">
                    <el-select class="manage-sel" v-model="addForm.floorId" filterable :placeholder="$t('pholder.select')" :no-data-text="$t('pholder.nodata')" @change="getFloorImg">
                        <el-option v-for="item in floorList" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                    <i class="error-tip">*</i>
                </el-form-item>
                <el-form-item :label="$t('dialog.coordinate')" v-if="isMl">
                    <el-col :span="7">
                        <el-form-item prop="x" class="spe-form-item">
                            <el-input v-model="addForm.x" :placeholder="$t('pholder.x')" class="gate-xy-inp"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col class="line" :span="2" style="text-align: center;">-</el-col>
                    <el-col :span="7">
                        <el-form-item prop="y" class="spe-form-item">
                            <el-input v-model="addForm.y" :placeholder="$t('pholder.y')" class="gate-xy-inp"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-button class="bdmap-btn" icon="el-icon-location" @click="getXY()">{{$t('button.getXY')}}</el-button>
                    </el-col>
                    <i class="error-tip">*</i>
                </el-form-item>
                <el-form-item :label="$t('table.describe')">
                    <el-input type="textarea" v-model="addForm.intro"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="addDialogVisible = false" class="dialog-btn">{{$t('dialog.cancel')}}</el-button>
                <el-button type="primary" @click="addSubmit('addForm')" class="dialog-btn dialog-confirm-btn">{{$t('dialog.confirm')}}</el-button>
            </div>
        </el-dialog>
        <!-- 楼层平面图 -->
        <floor-pos-dialog ref="posModel" @posXY="getPosXY"></floor-pos-dialog>
    </div>
</template>


<script>
import defaultImg from '@/assets/img/manage/defaultFloor.svg';
import floorPos from './addFloorpos';
export default {
    props: {
        unitList: {
            type: Array,
            default: () => []
        }
    },
    computed: {
        zoneUnitList() {
            return this.unitList.map(item => {
                item.value = item.UnitNo
                return item
            })
        },
        zoneIdUnitList() {
            return this.unitList.map(item => {
                item.value = item.UnitID
                return item
            })
        },
    },
    data() {
        var checkX = (rule, value, callback) => {
            if(this.isMl) {
                if (!value && value != 0) {
                    return callback(new Error('X坐标不能为空'));
                }
                var valReg = /^[0-9]+([.]{1}[0-9]+){0,1}$/;
                if (!valReg.test(value)) {
                    callback(new Error('请输入正确的格式'));
                } else {
                    callback();
                }
            } else {
                callback();
            }
		};
		var checkY = (rule, value, callback) => {
            if(this.isMl) {
                if (!value && value != 0) {
                    return callback(new Error('Y坐标不能为空'));
                }
                var valReg = /^[0-9]+([.]{1}[0-9]+){0,1}$/;
                if (!valReg.test(value)) {
                    callback(new Error('请输入正确的格式'));
                } else {
                    callback();
                }
            } else {
                callback();
            }
		};
        return {
            addDialogVisible: false,
            addForm: {
                name: '',
                type: null,
                status: null,
                locationNo: '',
                shopNo: '',
                externalId: '',
                mallId: '',
                floorId: '',
                formatId: '',
                subFormatId: '',
                x: null,
                y: null,
                intro: ''
            },
            isMl: false,
            // XyActive: true,
            mallList: [],
            floorList: [],
            zoneTypeList: [],
            floorPlanUrl: window._vionConfig.imagesUrl + "/images/",
            // rules: {},
            rules: {
				name: [
					{ required: true, message: '请输入区域名称', trigger: 'blur' },
					// { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' }
				],
				type: [
					{ required: true, message: '请选择类型', trigger: 'change' },
				],
				status: [
					{ required: true, message: '请选择状态', trigger: 'change' },
				],
                mallId: [
                    { required: true, message: '请选择广场', trigger: 'change' },
                ],
				// accountId: [
				// 	{ required: true, message: '请选择阅读空间', trigger: 'blur' },
				// ],
				floorId: [
					{ required: true, message: '请选择楼层', trigger: 'change' },
                ],
                x: [
					// { required: true, message: '请输入x坐标', trigger: 'change' },
					{ validator: checkX, trigger: 'change' }
				],
				y: [
					// { required: true, message: '请输入y坐标', trigger: 'change' },
					{ validator: checkY, trigger: 'change' }
				],
            },
            floorImg: '',
            curMallId: null,
            isMl: false,
            formatOpts: [],
            subFormatOpts: [],
            filterSubFormat: [],
            // zoneUnitList: []
        }
    },
    components: {
        'floor-pos-dialog': floorPos
    },
    created() {
        // zoneTypeList
    },
    methods: {
        dialogInit(mall_id) {
            this.curMallId = mall_id;
            this.addDialogVisible = true;
            this.sessionFormat('format').then(resovleData => {
                this.formatOpts = resovleData.format;
                this.filterSubFormat = [];
                resovleData.subFormat.forEach(item => {
                    item.children.forEach(child => {
                        this.filterSubFormat.push(child);
                    })
                });
            })
        },
        dialogOpen(formDatas) {
			formDatas.accountId = this.$cookie.get('accountId');
			this.getMallList(formDatas.accountId);
		},
        getMallList(accountId) {
            this.mallList = [];
            this.floorList = [];
            this.addForm.mallId = '';
            this.addForm.floorId = '';
			this.$api.base.mall({
                accountId: accountId,
                // status: 1,
                status_arr: '1,3'
                // _t: Date.parse(new Date()) / 1000
			},null,true)
				.then((data) => {
                    let result = data.data;
                    result.data.forEach(item => {
                        if(item.id == this.curMallId) { 
                            this.addForm.mallId = item.id;
                        }
                    })
                    this.mallList = result.data;
					if (this.mallList.length > 0) {
                        if(!this.curMallId) {
                            this.addForm.mallId = this.mallList[0].id;
                        }
						this.getFloorList(this.addForm.mallId)
					}
				})
				.catch((error) => { })
		},
        getFloorList(mallId) {
            this.floorList = [];
            this.addForm.floorId = '';
			this.$api.base.floor({
                mallId: mallId,
                status: 1,
                // _t: Date.parse(new Date()) / 1000
			})
				.then((data) => {
					let result = data.data;
					this.floorList = result.data;
					if (this.floorList.length > 0) {
                        this.addForm.floorId = this.floorList[0].id;
                        this.getFloorImg();
					}
				})
				.catch((error) => { })
		},
        changeAddMall(val) {
			this.getFloorList(val);
        },
        getFloorImg() {
			// if (this.addForm.floorId) {
			// 	this.XyActive = false;
			// } else {
			// 	this.XyActive = true;
			// }
			this.$api.base.floor({
                id: this.addForm.floorId,
                // _t: Date.parse(new Date()) / 1000
			})
				.then(res => {
					if (res.data.data[0].floorPlan) {
						this.floorImg = this.floorPlanUrl + res.data.data[0].floorPlan;
					} else {
						this.floorImg = defaultImg
						this.$message({
                            showClose: true,
							message: this.$t('message.NoFloorImg'),
							type: 'warning'
						})
					}
                })
                .catch(err => {
					// console.log('add gate err:', err.message)
				})
        },
        typeChange(val) {
            this.isMl = val == 4 ? true : false;
        },
        formatChange(val) {
            this.addForm.subFormatId = '';
            this.subFormatOpts = [];
            this.filterSubFormat.forEach(item => {
                if(item.formatId === val) {
                    this.subFormatOpts.push(item)
                }
            })
        },
        getXY() {
            this.$refs.posModel.dialogInit(this.floorImg);
        },
        getPosXY(XY) {
            this.addForm.x = XY.x;
			this.addForm.y = XY.y;
        },
        querySearch(queryString, cb) {
            var restaurants = this.zoneUnitList;
            var results = queryString ? restaurants.filter(this.createFilter(queryString, 'UnitNo')) : restaurants;
            // 调用 callback 返回建议列表的数据
            cb(results);
        },
        querySearchId(queryString, cb) {
            var restaurants = this.zoneIdUnitList;
            var results = queryString ? restaurants.filter(this.createFilter(queryString, 'UnitID')) : restaurants;
            // 调用 callback 返回建议列表的数据
            cb(results);
        },
        createFilter(queryString, key) {
            return (restaurant) => {
                return (restaurant[key].toLowerCase().indexOf(queryString.toLowerCase()) === 0);
            };
        },
        addSubmit(formName) {
			this.$refs[formName].validate((valid) => {
				if (valid) {
					this.addForm.accountId = this.$cookie.get('accountId');
					this.addForm.createUser = this.$cookie.get('userId');
                    this.addForm.modifyUser = this.$cookie.get('userId');
                    // return
                    this.$api.management.addZone(this.addForm)
						.then((data) => {
                            this.addDialogVisible = false;
                            this.sessionFormat('filterFormat',true).then()
							this.$parent.getTableData();
						})
						.catch((error) => {
                            // this.$message.error(error.message)
                        })
				} else {
					return false;
				}
			});
		},
        addDialogClose() {
			this.$refs.addForm.resetFields();
		},
    }
}
</script>

<style scoped>
    .bdmap-btn {
        margin-left: 17px;
        padding: 0 8px;
        height: 28px;
        border-radius: 2px;
        font-size: 13px;
    }
    .unit-input {
        width: 100%;
    }
    @media only screen and (max-width: 1680px) {
        .bdmap-btn {
            padding: 0 10px;
            height: 30px;
        }
    }
    @media only screen and (max-width: 1440px) {
        .bdmap-btn {
            padding: 0 10px;
            height: 20px;
        }
    }
    @media only screen and (max-width: 1366px) {
        .bdmap-btn {
            padding: 0 9px;
            height: 20px;
        }
    }
    @media only screen and (max-width: 1280px) {
        .bdmap-btn {
            padding: 0 9px;
            height: 20px;
        }
    }
</style>