<template>
  <el-dialog
    v-model="dialogFormVisible"
    :title="title"
    width="500px"
    @close="close"
  >
    <div class="manage-container">
      <el-form
        ref="form"
        :model="form"
        label-width="100px"
        label-position="left"
      >
        <el-form-item :label="$t('dataEnquiry.zdmc')">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item :label="$t('device.zdbh')">
          <el-input v-model="form.code"></el-input>
        </el-form-item>
        <el-form-item :label="$t('dataEnquiry.xlh')">
          <el-input v-model="form.serial"></el-input>
        </el-form-item>
        <vab-query-form>
          <el-button type="primary" @click="save">
            {{ $t('defalult.tjtn') }}
          </el-button>
        </vab-query-form>
      </el-form>
    </div>
  </el-dialog>
</template>

<script>
import { copy } from '@/api/device';
export default {
  data() {
    return {
      form: {
        name: '',
        code: '',
        serial: '',
        deviceId: '',
      },
      dialogFormVisible: false,
      title: '',
    };
  },
  methods: {
    showCopy(row) {
      this.form.deviceId = row.id;
      this.dialogFormVisible = true;
      this.title = '复制站点';
    },
    close() {
      this.$refs['form'].resetFields();
      this.form = this.$options.data().form;
      this.dialogFormVisible = false;
      this.$emit('fetch-data');
    },
    save() {
      this.$refs['form'].validate(async valid => {
        if (valid) {
          const { msg } = await copy(this.form);
          this.$notify({
            title: msg,
            type: 'success',
          });
          this.$refs['form'].resetFields();
          this.dialogFormVisible = false;
          this.$parent.fetchData();
        } else {
          return false;
        }
      });
    },
  },
};
</script>
