add.vue 4.86 KB
<template>
  <div>
    <el-dialog :title="isEdit=='add'?$t('dialog.addDevice'):$t('dialog.editDevice')":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.deviceName')" prop="name">
          <el-input v-model.trim="addForm.name" maxlength="10" :placeholder="$t('pholder.input')" @input='nameChange'></el-input>
          <i class="error-tip">*</i>
        </el-form-item>
        <el-form-item :label="$t('table.videoSource')" prop="platform">
          <el-select v-model="addForm.platform" :placeholder="$t('pholder.select')" :disabled="isEdit=='edit'?true:false">
            <el-option label="拾联" :value="1"></el-option>
            <el-option label="萤石云" :value="2"></el-option>
          </el-select>
          <i class="error-tip">*</i>
        </el-form-item>
        <el-form-item :label="$t('table.deviceSerial')" prop="deviceSerial">
          <el-input v-model.trim="addForm.deviceSerial" :placeholder="$t('pholder.deviceSerial')" :disabled="isEdit=='edit'?true:false"></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() {
      return {
        isEdit:'add',
        isShow: false,
        addForm: {
          accountId: this.$cookie.get('accountId'),
          name: '',
          mallId: null,
          deviceSerial: null,
          platform: null,
        },
        rules: {
          name: [{
            required: true,
            message: this.$t("pholder.input"),
            trigger: 'blur'
          }],
          platform: [{
            required: true,
            message: this.$t("pholder.select"),
            trigger: 'blur'
          }],
          deviceSerial: [{
            required: true,
            message: this.$t("pholder.input"),
            trigger: 'blur'
          }],
        },
      }
    },
    methods: {
      dialogInit(val,type,row) {
        this.isEdit = type;
        this.isShow = true;
        this.addForm.mallId = val;
        this.addForm.accountId = this.$cookie.get('accountId');
        if(row){
          this.addForm.name = row.name;
          this.addForm.deviceSerial = row.deviceSerial;
          this.addForm.platform = row.platform;
          this.addForm.id = row.id;
        }
      },
      nameChange(val){
        this.$forceUpdate()
      },
      addSubmit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if(this.isEdit=='add'){
              this.$api.videoShopTourReport.addDevice(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 = {
                      accountId: this.$cookie.get('accountId')
                    }
                    this.isShow = false
                  }else{
                    this.$message({
                      message: result.msg,
                      type: 'error'
                    });
                  }
                })
            }else{
              this.$api.videoShopTourReport.editDevice(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 = {
                      accountId: this.$cookie.get('accountId')
                    }
                    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>