addGate.vue 15.3 KB
<template>
    <div>
        <el-dialog
        :title="$t('button.addSite')"
        class="manage-dialog"
        :visible.sync="addDialogVisible"
        :close-on-click-modal="false"
        @open="dialogOpenAdd(addForm)"
        @close="addDialogClose()">
            <el-form :model="addForm" status-icon :rules="rules" ref="addForm">
                <el-form-item :label="$t('dialog.name')" 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')">
                        <el-tooltip class="item" popper-class="tooltipClass"  effect="light" placement="top-start" offset="-200">
                                <div slot="content">
                                    传统客流智能机或者CBOX统计基础客流量。
                                </div>
                                <el-option :label="$t('dictionary.tradCount')" :value="1"></el-option>
                        </el-tooltip>
                        <el-tooltip class="item" popper-class="tooltipClass"  effect="light" placement="top-start" offset="-200">
                                <div slot="content">
                                    通过人脸抓拍识别统计<span class="red-font">客流量</span><span class="red-font">人脸属性</span>分析。
                                </div>
                                <el-option :label="$t('dictionary.faceFlow')" :value="3"></el-option>
                        </el-tooltip>
                        <el-tooltip class="item" popper-class="tooltipClass"  effect="light" placement="top-start" offset="-200">
                                <div slot="content">
                                    通过人脸抓拍识别仅分析人脸属性。<span class="red-font">无客流量</span>
                                </div>
                               <el-option :label="$t('dictionary.faceCapture')" :value="5"></el-option>
                         </el-tooltip>
                        <el-tooltip class="item" popper-class="tooltipClass"  effect="light" placement="top-start" offset="-200">
                                <div slot="content">
                                    通过店外设备统计门前路过的客流量。
                                </div>
                               <el-option :label="$t('dictionary.inStoreRate')" :value="2"></el-option>
                        </el-tooltip>
                        <el-tooltip class="item" popper-class="tooltipClass"  effect="light" placement="top-start" offset="-200">
                                <div slot="content">
                                    通过鱼眼相机采集人员位置信息,并做热力呈现。
                                </div>
                               <el-option :label="$t('dictionary.heatmap')" :value="4"></el-option> 
                         </el-tooltip>                                      
                        <!-- <el-option label="出入口" value="1"></el-option>
                            <el-option label="柜台" value="2"></el-option> -->
                        <!-- <el-option label="收银台" value="3"></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('table.stateA')" :value="1"></el-option>
                        <el-option :label="$t('table.stateB')" :value="2"></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.InstallationFloor')" 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>
                </el-form-item>
                <el-form-item :label="$t('dialog.coordinate')">
                    <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()" :disabled="XyActive">{{$t('button.getXY')}}</el-button>
                    </el-col>
                    <i class="error-tip">*</i>
                </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="安装坐标(X)" prop="x">
                        <el-input v-model.number="addForm.x"></el-input>
                        <i class="error-tip">*</i>
                    </el-form-item>
                    <el-form-item label="安装坐标(Y)" prop="y">
                        <el-input v-model.number="addForm.y"></el-input>
                        <i class="error-tip">*</i>
                    </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('table.SquareEntrance')" prop="isMallGate">
                    <el-select class="manage-sel" v-model="addForm.isMallGate" :placeholder="$t('pholder.select')">
                        <el-option label="否" :value="0"></el-option>
                        <el-option label="是" :value="1"></el-option>
                    </el-select>
                    <i class="error-tip">*</i>
                </el-form-item>
                <el-form-item :label="$t('table.faceCamera')" prop="isHasFace">
                    <el-select class="manage-sel" v-model="addForm.isHasFace" :placeholder="$t('pholder.select')">
                        <el-option label="否" :value="0"></el-option>
                        <el-option label="是" :value="1"></el-option>
                    </el-select>
                    <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" :disabled="btnDisabled">{{$t('dialog.confirm')}}</el-button>
            </div>
        </el-dialog>
        <!-- 楼层平面图 -->
        <floor-pos-dialog ref="posModel" @posXY="getPosXY"></floor-pos-dialog>
    </div>
</template>

<script>
import floorPos from './addFloorpos'
import defaultImg from '@/assets/img/manage/defaultFloor.svg'
export default {
    data() {
        var checkX = (rule, value, callback) => {
			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();
			}
		};
		var checkY = (rule, value, callback) => {
			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();
			}
		};
        return {
            addDialogVisible: false,
            addForm: {
                name: '',
                externalId: '',
                type: null,
                status: null,
                mallId: null,
                floorId: null,
                x: null,
                y: null,
                isMallGate: null,
                isHasFace: null,
                intro: ''
            },
            mallList: [],
            floorList: [],
            XyActive: true,
            floorPlanUrl: window._vionConfig.imagesUrl + "/images/",
            floorImg: '',
            btnDisabled: false,
            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' },
				],
				x: [
					// { required: true, message: '请输入x坐标', trigger: 'change' },
					{ validator: checkX, trigger: 'change' }
				],
				y: [
					// { required: true, message: '请输入y坐标', trigger: 'change' },
					{ validator: checkY, trigger: 'change' }
				],
				mallId: [
					{ required: true, message: '请选择书店', trigger: 'change' },
				],
				// accountId: [
				// 	{ required: true, message: '请选择集团', trigger: 'blur' }
				// ],
				// floorId: [
				// 	{ required: true, message: '请选择楼层', trigger: 'blur' }
				// ],
				isMallGate: [
					{ required: true, message: '请选择是否为入口', trigger: 'change' },
				],
				isHasFace: [
					{ required: true, message: '请选择是否为人脸', trigger: 'change' },
				]
            },
            curMallId: null,
        }
    },
    components: {
        'floor-pos-dialog': floorPos
    },
    methods: {
        dialogInit(mall_id) {
            this.curMallId = mall_id;
            this.addDialogVisible = true;
        },
        dialogOpenAdd(formDatas) {
			formDatas['accountId'] = this.$cookie.get('accountId');
			this.getMallList(formDatas.accountId);
        },
        getMallList(accountId) {
			this.addForm.mallId = '';
			this.addForm.floorId = '';
			this.floorList = [];
			this.mallList = [];
			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) => { })
		},
        changeAddMall(val) {
			this.getFloorList(val)
        },
        getFloorList(mallId) {
			this.addForm.floorId = '';
			this.floorList = [];
			this.$api.base.floor({
                mallId: mallId,
                status: 1,
                // _t: Date.parse(new Date()) / 1000
			})
				.then((data) => {
					var result = data.data;
					if (result.data.length > 0) {
						this.floorList = result.data;
						this.addForm.floorId = this.floorList[0].id;
					}
					this.floorList = result.data;
				})
				.catch((error) => { })
		},
        //获取新增楼层照片
		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 => {
                    this.$throw(err)
				})
        },
        getXY() {
            this.$refs.posModel.dialogInit(this.floorImg);
        },
        getPosXY(XY) {
            this.addForm.x = XY.x;
			this.addForm.y = XY.y;
        },
        addSubmit(formName) {
			this.$refs[formName].validate((valid) => {
				if (valid) {
                    this.btnDisabled = true;
                    setTimeout(() => {
                        this.btnDisabled = false;
                    }, 2000)
					this.addForm.accountId = this.$cookie.get('accountId');
					this.addForm.createUser = this.$cookie.get('userId');
					this.addForm.modifyUser = this.$cookie.get('userId');
                    this.$api.management.addGate(this.addForm)
						.then((data) => {
							this.addDialogVisible = false;
							this.$parent.getTableData();
						})
						.catch((error) => { })
				} else {
					return false;
				}
			});
			// this.$refs.addUpload.submit();
		},
        addDialogClose() {
			this.$refs.addForm.resetFields();
			this.XyActive = true;
		},
    }
}
</script>

<style scoped>
    .bdmap-btn {
        margin-left: 17px;
        padding: 0 8px;
        height: 28px;
        border-radius: 2px;
        font-size: 13px;
    }
    
    @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>