<template>
  <el-dialog
    v-if="visible"
    width="600px"
    :title="form.id?'编辑文旅数据开放网站':'新建文旅数据开放网站'"
    :visible.sync="visible"
  >
    <el-form v-loading="isLoading" :model="form" label-width="100px" label-position="top">
      <el-form-item label="网站标题">
        <el-input v-model="form.title"/>
      </el-form-item>
      <el-form-item label="网站URL">
        <el-input v-model="form.url"/>
      </el-form-item>
      <el-form-item label="备注说明">
        <el-input v-model="form.remark"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>

import { save, updateById } from '@/api/open_website'

export default {
  components: {},
  data() {
    return {
      visible: false,
      isLoading: false,
      form: {}
    }
  },
  mounted() {
  },
  methods: {
    open(data) {
      this.visible = true
      this.isLoading = false
      this.form = Object.assign({}, data)
    },
    handleSubmit() {
      console.log(this.form)
      if (this.form.id) {
        updateById(this.form.id, this.form).then(() => {
          this.visible = false
          this.$emit('ok')
        }).finally(() => {
          this.isLoading = false
        })
      } else {
        save(this.form).then(res => {
          this.visible = false
          this.$emit('ok')
        }).finally(() => {
          this.isLoading = false
        })
      }
    }
  }
}
</script>
