<template>
  <div class="hum-page-container">
    <div class="hum-page-title">断面管理</div>
    <div class="hum-page-section">
      <div class="hum-page-search">
        <el-form :model="queryParams" size="large" ref="queryForm" label-position="top">
          <el-row :gutter="30">
            <el-col :span="6">
              <el-form-item label="选择站点">
                <SiteSelector @change="siteIdHandler" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item class="hum-page-search-action">
                <el-button type="primary" @click="handleQuery">查询</el-button>
                <el-button @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="hum-page-action">
        <el-button type="primary" @click="handleAdd">新增断面</el-button>
      </div>
      <el-table v-loading="loading" :data="list" border>
        <el-table-column label="站码" prop="id" />
        <el-table-column label="断面名称" prop="berthingName" />
        <el-table-column label="创建日期">
          <template slot-scope="scope">
            <span>{{ formatDateTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">编辑</el-button>
            <el-button size="mini" type="text" icon="el-icon-download" @click="download(scope.row)">导出</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="hum-page-title" style="margin-top: 30px">断面图</div>
    <div class="hum-page-section">
      <SectionChart :sections="sections" />
    </div>
  </div>
</template>

<script>
import { getSiteSection } from "@/api/site/berthing";
import SiteSelector from '@/components/SiteSelector';
import SectionChart from './chart';

export default {
  components: {
    SiteSelector,
    SectionChart,
  },
  data() {
    return {
      siteId: '',
      queryParams: {
        page: 1,
        size: 1000,
      },
      loading: true,
      list: [],
      sections: [],
      sectionChartVisible: false,
    }
  },
  created() {
    this.init();
  },
  methods: {
    siteIdHandler(v) {
      this.siteId = v;
      this.handleQuery();
    },
    handleQuery() {
      this.getList()
    },
    resetQuery() {},
    getList() {
      this.loading = true;
      getSiteSection(this.siteId).then(response => {
        if (response.data) {
          this.list = [response.data];
          this.sections = JSON.parse(response.data.positions);
          this.loading = false;
        }
      });
    },
    handleAdd() {
      this.$router.push(`/site/section/add?siteId=${this.siteId}`)
    },
    handleUpdate(section) {
      this.$router.push(`/site/section/edit/${section.berthingId}?siteId=${this.siteId}`)
    },
    download(section) {
      window.open(`${process.env.VUE_APP_BASE_API}/berthing/downFile/${section.berthingId}`, '_blank')
    },
  }
}
</script>

<style scoped>

</style>
