add.vue 6.05 KB
<template>
  <div>
    <el-dialog :title="isEdit=='add'?$t('button.groupAdd'):$t('button.groupEdit')" :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">
        <el-form-item :label="$t('table.monitorSiteName')" prop="name">
          <el-input v-model.trim="addForm.name" @input="nameChange" maxlength="10"></el-input>
          <i class="error-tip">*</i>
        </el-form-item>
        <el-form-item :label="$t('navData.devices')" prop="device">
          <el-select v-model="addForm.device" :placeholder="$t('pholder.select')"  @change="deviceChange">
            <el-option v-for="item in deviceList" :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.aisle')" prop="channelId">
          <el-select v-model="addForm.channelId" :placeholder="$t('pholder.select')" @change="channelChange">
            <el-option v-for="item in channelList" :key="item.id" :label="item.channelName" :value="item.id"></el-option>
          </el-select>
          <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() {
      return {
        isEdit:'add',
        isShow: false,
        deviceList:[],
        channelList:[],
        addForm: {
          accountId: this.$cookie.get('accountId'),
          name: '',
          mallId: null,
          channelId: null
        },
        rules: {
          name: [{
            required: true,
            message: this.$t('pholder.Site'),
            trigger: 'blur'
          }],
          device: [{
            required: true,
            message: this.$t('pholder.select'),
            trigger: 'blur'
          }],
          channelId: [{
            required: true,
            message: this.$t('pholder.select'),
            trigger: 'blur'
          }],
        },
      }
    },
    methods: {
      getDeciveList(mallId){
        let parmas = {
          accountId: this.$cookie.get('accountId'),
          mallId:mallId
        }
        this.$api.videoShopTourReport.getDeviceList(parmas, null, true)
          .then(data => {
            this.tableData = [];
            var result = data.data;
            result.data.list.forEach((item, index) => {
              item.newName = item.name+(item.deviceName?'('+item.deviceName+')':'');
            });
            this.deviceList = result.data.list;
          })
      },
      nameChange(val){
        this.$forceUpdate()
      },
      channelChange(val){
        this.$forceUpdate()
      },
      deviceChange(val){
        this.$forceUpdate()
        this.addForm.channelId = null
        this.$api.videoShopTourReport.getPatrolDeviceChannelList({ deviceId:val,pageSize: 999999,page:1})
          .then(data => {
            this.tableData = [];
            var result = data.data;
            result.data.list.forEach((item, index) => {
              item.newName = (item.name?'('+item.name+')':'')+item.channelName;
            });
            this.channelList = result.data.list;
          })
      },
      dialogInit(val,type,row) {
        let currObj = Object.assign({},row)
        this.isEdit = type;
        this.isShow = true;
        this.addForm = {
          accountId: this.$cookie.get('accountId'),
          mallId: val,
        };
        this.getDeciveList(val)
        if(row){
          this.addForm.name = currObj.name;
          this.addForm.device = currObj.patrolDevice.id;
          this.deviceChange(currObj.patrolDevice.id)
          this.addForm.channelId = currObj.patrolDeviceChannel.id;
          this.addForm.id = currObj.id;
          this.addForm.mallId = currObj.mallId;
        }
      },
      addSubmit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if(this.isEdit=='add'){
              this.$api.videoShopTourReport.addPatrolGate(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.addForm = {}
                    this.isShow = false
                  }else{
                    this.$message({
                      message: result.msg,
                      type: 'error'
                    });
                  }
                })
            }else{
              this.$api.videoShopTourReport.editPatrolGate(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.addForm = {}
                    this.isShow = false
                  }else{
                    this.$message({
                      message: result.msg,
                      type: 'error'
                    });
                  }
                })
            }

          } else {
            return false;
          }
        });
      },
      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%;
    }
  }
</style>