add.vue 9.31 KB
<template>
    <div>
        <el-dialog :title="$t('dialog.shopInspection')" :visible.sync="isShow" v-if="isShow" :close-on-click-modal='false' class="manage-dialog dialog_lj" :before-close="closeDialog">
            <el-form :model="addForm" :rules="rules" ref="addForm">
                <p class="infoTitle">基本信息</p>
                <el-form-item :label="$t('table.squareName')" prop="mallId">
                    <el-select v-model="addForm.mallId" filterable :placeholder="$t('pholder.select')">
                        <el-option v-for="item in mallListForTerm" :key="item.id" :label="item.name" :value="item.id" />
                    </el-select>
                    <i class="error-tip">*</i>
                </el-form-item>
                <el-form-item :label="$t('table.patroMode')" prop="patrolMethod">
                    <el-select v-model="addForm.patrolMethod" filterable :placeholder="$t('pholder.select')">
                        <el-option v-for="item in patrolMethodList" :key="item.id" :label="item.value" :value="item.key" />
                    </el-select>
                    <i class="error-tip">*</i>
                </el-form-item>
                <el-form-item :label="$t('table.customerContact')" prop="customerContact">
                    <el-input v-model="addForm.customerContact" maxlength="20" :placeholder="$t('pholder.input')"></el-input>
                    <i class="error-tip">*</i>
                </el-form-item>
                <el-form-item :label="$t('table.contactInformation')" prop="customerPhone">
                    <el-input v-model="addForm.customerPhone" :placeholder="$t('pholder.input')"></el-input>
                    <i class="error-tip">*</i>
                </el-form-item>
                <p  class="infoTitle">设备状态</p>
                <el-form-item :label="$t('table.poeStatus')" prop="poeStatus">
                    <el-input v-model="addForm.poeStatus" :placeholder="$t('pholder.input')"></el-input>
                    <i class="error-tip">*</i>
                </el-form-item>
                <el-form-item :label="$t('table.machineStatus')" prop="cameraStatus">
                    <el-input v-model="addForm.cameraStatus" :placeholder="$t('pholder.input')"></el-input>
                    <i class="error-tip">*</i>
                </el-form-item>
                <el-form-item :label="$t('dialog.note')" prop="note">
                    <el-input v-model="addForm.remark" type="textarea" :placeholder="$t('pholder.input')"></el-input>
                    <i class="error-tip">*</i>
                </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="closeDialog" 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>
    </div>
</template>

<script>
    
    export default {
        data() {
            var validatorTel = (rule, value, callback) => {
              var tel = value;
              var ph = /^(0|86|17951)?(13[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|14[57])[0-9]{8}$/;
              var mb = /^(0[0-9]{2,3}\-)([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/;
              if (!ph.test(tel) && !mb.test(tel)) {
                return callback(new Error(this.$t('rules.mobileRules')));
              } else {
                callback();
              }
            };
            return {
                isEdit: 'add',
                isShow: false,
                mallListForTerm: [],
                patrolMethodList: [],
                addForm: {
                    mallId: null,
                    patrolMethod: null,
                    customerContact: null,
                    customerPhone: null,
                    poeStatus: null,
                    cameraStatus: null,
                    remark: null,
                },
                rules: {
                    customerContact: [{
                        required: true,
                        message: this.$t("pholder.input"),
                        trigger: 'blur'
                    }],
                    patrolMethod: [{
                        required: true,
                        message: this.$t("pholder.select"),
                        trigger: 'blur'
                    }],
                    customerPhone: [{
                        required: true,
                        message: this.$t("pholder.input"),
                        trigger: 'blur'
                    },{ validator: validatorTel, trigger: 'blur' }],
                    poeStatus: [{
                        required: true,
                        message: this.$t("pholder.input"),
                        trigger: 'blur'
                    }],
                    cameraStatus: [{
                        required: true,
                        message: this.$t("pholder.input"),
                        trigger: 'blur'
                    }]
                },
            }
        },
        methods: {
            getMallListForTerm() {
                this.mallListForTerm = [];
                this.$api.base.mall({
                    accountId: this.$cookie.get('accountId')
                }).then(data => {
                    let result = data.data;
                    if (result.data.length) {
                        this.mallListForTerm = result.data;
                    }
                })
            },
            getPatroMode() {
                this.$api.base.dataDic({
                    type: 'patrolMethod'
                }).then(res => {
                    this.patrolMethodList = res.data.data.map(item => {
                        if (localStorage.getItem('lang') == 'en_US') {
                            item.value = item.valueEn;
                        }
                        return item;
                    });
                })
            },
            dialogInit(val, type, row) {
                this.isEdit = type;
                this.isShow = true;
                this.addForm.mallId = val;
                this.addForm.accountId = this.$cookie.get('accountId')
                this.getMallListForTerm()
                this.getPatroMode()
                if (row) {
                    this.addForm.patrolMethod = row.patrolMethod;
                    this.addForm.customerContact = row.customerContact;
                    this.addForm.customerPhone = row.customerPhone;
                    this.addForm.id = row.id;
                    this.addForm.poeStatus = row.poeStatus;
                    this.addForm.cameraStatus = row.cameraStatus;
                    this.addForm.remark = row.remark;
                }
            },
            addSubmit(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        if (this.isEdit == 'add') {
                            this.$api.management.addPatrol(this.addForm).then((res) => {
                                let result = res.data;
                                if (result.code == 200) {   
                                    this.$message({
                                        message: result.msg,
                                        type: 'success'
                                    });
                                    this.$parent.getTableData();
                                    this.$refs.addForm.resetFields();
                                    this.isShow = false
                                } else {
                                    this.$message({
                                        message: result.msg,
                                        type: 'error'
                                    });
                                }
                            })
                        } else {
                            this.$api.management.updatePatrol(this.addForm).then((res) => {
                                let result = res.data;
                                if (result.code == 200) {
                                    this.$message({
                                        message: result.msg,
                                        type: 'success'
                                    });
                                    this.$parent.getTableData();
                                    this.$refs.addForm.resetFields();
                                    this.isShow = false
                                } else {
                                    this.$message({
                                        message: result.msg,
                                        type: 'error'
                                    });
                                }
                            })
                        }
                    }
                })
            },
            closeDialog() {
                this.$refs.addForm.resetFields();
                this.addForm = {}
                this.isShow = false;
            }
        }
    }
</script>
<style lang="less" scoped="scoped">
    .dialog_lj {
        /deep/.el-form-item__label {
            width: 80px;
        }

        /deep/.el-select {
            width: 100%;
        }
        .infoTitle{
            height: 36px;
            line-height: 36px;
            font-weight: 900;
            color: #000;
            font-size: 18px;
        }
    }
</style>