<template>
  <div>
    <el-dialog title="导出站点类型" :visible.sync="isShow" @open="dialogOpen" class="site-export-dialog">
      <el-form :inline="true" :model="exportSite" class="demo-form-inline" label-width="150px">
        <el-form-item label="导出站点类型：">
          <el-checkbox-group v-model="exportSite.type">
            <span v-for="item in exportSiteTypes" :key="item.value" style="margin-left:5px;">
              <el-checkbox :label="item.value">{{item.label}}</el-checkbox>
            </span>
          </el-checkbox-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="isShow = false">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import util from '@src/common/util.js'
export default {
  data() {
    return {
      confirmLoading: false,
      exportSite: { type: [] },
      exportSiteTypes: []
    }
  },
  computed: {
    isShow: {
      get() {
        return this.show
      },
      set(val) {
        this.$emit('update:show', val)
      }
    }
  },
  methods: {
    async dialogOpen() {
      this.confirmLoading = false
      this.exportSite.type = []
      let res = await axios.get('/ui/platform/codes/ExportSiteType')
      this.exportSiteTypes = res.data.data
      res.data.data.forEach(o => {
        this.exportSite.type.push(o.codeValue)
      })
    },
    async confirm() {
      let selType = this.exportSite.type.join()
      if (!selType) {
        this.alert('请选择导出站点数据类型！', '提示', {
          type: 'info'
        })
        return
      }
      try {
        await this.$confirm('确认导出选中站点的数据吗 ？', '系统提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        let res = await axios.put(`/ui/sites/${this.siteID}/exportsite`, {
          exportSiteType: selType
        })
        util.showResponseMessage(res.data)
        if (res.data.status === 1) {
          this.isShow = false
          this.$emit('callback', res.data.taskID, res.data.path)
        }
      } catch (e) {

      }
    }
  },
  props: {
    show: {
      type: Boolean
    },
    siteID: {
      type: [String, Number]
    }
  }
}
</script>

<style>
.site-export-dialog .el-dialog {
  width: 500px;
}

@media (max-width: 480px) {
  .site-export-dialog .el-dialog {
    width: 90%;
  }
}
</style>
