<template>
  <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog" :title="isAdd ? '新增' : '编辑'" width="720px">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="150px">
      <el-form-item label="名称" prop="proname">
        <el-input v-model="form.proname" style="width: 470px;"/>
      </el-form-item>
      <!--<el-form-item label="信息1" >
        <el-input v-model="form.msg1" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="信息2" >
        <el-input v-model="form.msg2" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="信息3" >
        <el-input v-model="form.msg3" style="width: 370px;"/>
      </el-form-item>-->
      <!--<el-form-item label="信息4" >
        <el-input v-model="form.msg4" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="信息5" >
        <el-input v-model="form.msg5" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="信息6" >
        <el-input v-model="form.msg6" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="信息7" >
        <el-input v-model="form.msg7" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="信息8" >
        <el-input v-model="form.msg8" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="信息9" >
        <el-input v-model="form.msg9" style="width: 370px;"/>
      </el-form-item>-->
      <el-form-item label="视频监控链接" >
        <el-input v-model="form.videoadr" :rows="2" type="textarea" style="width: 470px;"/>
      </el-form-item>
      <!--<el-form-item label="创建时间" >
        <el-input v-model="form.createTime" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="更新时间" >
        <el-input v-model="form.updateTime" style="width: 370px;"/>
      </el-form-item>-->
      <el-form-item label="app视频监控链接" >
        <el-input v-model="form.nt" :rows="3" type="textarea" style="width: 470px;"/>
      </el-form-item>
      <el-form-item label="地址">
        <el-input v-model="form.msg9" style="width: 470px;"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { add, edit } from '@/api/sProject'
export default {
  props: {
    isAdd: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      loading: false, dialog: false,
      form: {
        id: '',
        proname: '',
        msg1: '',
        msg2: '',
        msg3: '',
        msg4: '',
        msg5: '',
        msg6: '',
        msg7: '',
        msg8: '',
        msg9: '',
        videoadr: '',
        createTime: '',
        updateTime: '',
        nt: ''
      },
      rules: {
        proname: [
          { required: true, message: '请输入名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    doSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.loading = true
          if (this.isAdd) {
            this.doAdd()
          } else this.doEdit()
        }
      })
    },
    doAdd() {
      add(this.form).then(res => {
        this.resetForm()
        this.$notify({
          title: '添加成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.init()
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    },
    doEdit() {
      edit(this.form).then(res => {
        this.resetForm()
        this.$notify({
          title: '修改成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.init()
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
      this.form = {
        id: '',
        proname: '',
        msg1: '',
        msg2: '',
        msg3: '',
        msg4: '',
        msg5: '',
        msg6: '',
        msg7: '',
        msg8: '',
        msg9: '',
        videoadr: '',
        createTime: '',
        updateTime: '',
        nt: ''
      }
    }
  }
}
</script>

<style scoped>

</style>
