<template>
  <el-dialog
    v-model="dialogFormVisible"
    :title="title"
    width="500px"
    @close="close"
  >
    <div class="manage-container">
      <el-form
        ref="form"
        :model="form"
        label-width="80px"
        label-position="left"
      >
        <el-form-item label="站点名称">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="站点序列号">
          <el-input v-model="form.code"></el-input>
        </el-form-item>
        <vab-query-form>
          <el-button type="primary" @click="save">提交</el-button>
        </vab-query-form>
      </el-form>
    </div>
  </el-dialog>
</template>

<script>
import { copy } from '@/api/device';
export default {
  data() {
    return {
      form: {
        name: '',
        code: '',
        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>
