<!-- 风场线路 -->
<template>
  <div class="fullheight">
    <ht-table
      @load="loadData"
      @row-dblclick="handleDbClick"
      :data="data"
      :pageResult="pageResult"
      :selection="true"
      quick-search-props="lineName,lineCode"
      :show-export="false"
      :show-custom-column="false"
      ref="htTable"
    >
      <template v-slot:toolbar>
        <el-button
          size="small"
          type="primary"
          @click="showDialog()"
          icon="el-icon-plus"
          >添加</el-button
        >
        <ht-delete-button
          url="${cssc}/biz/base/wfLine/v1/"
          :htTable="$refs.htTable"
          >删除</ht-delete-button
        >
      </template>
      <template>
        <ht-table-column
          prop="lineName"
          label="线路名称"
          :sortable="true"
          :show-overflow-tooltip="true"
        >
        </ht-table-column>
        <ht-table-column
          prop="lineCode"
          label="线路编号"
          :sortable="true"
          :show-overflow-tooltip="true"
        >
        </ht-table-column>
      </template>
    </ht-table>
    <common-dialog
      width="800px"
      title="风场线路信息"
      class="sp-manager__dialog"
      :visible="dialogVisible"
      :before-close="beforeCloseDialog"
      destroy-on-close
    >
      <el-form v-form data-vv-scope="BizWfLineForm" class="form-single-row">
        <ht-form-item label="线路名称">
          <ht-input v-model="BizWfLine.lineName" validate="required" />
        </ht-form-item>
        <ht-form-item label="线路编号">
          <ht-input v-model="BizWfLine.lineCode" validate="required" />
        </ht-form-item>
      </el-form>
      <div slot="footer" style="text-align: center">
        <ht-submit-button
          url="${cssc}/biz/base/wfLine/v1/"
          :model="BizWfLine"
          :request-method="saveMethod"
          scope-name="BizWfLineForm"
          @after-save-data="afterSaveData"
          >保存</ht-submit-button
        >
        <el-button @click="beforeCloseDialog">取消</el-button>
      </div>
    </common-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      dialogVisible: false,
      data: [],
      pageResult: {
        page: 1,
        pageSize: 50,
        total: 0
      },
      BizWfLine: {},
      saveMethod: 'POST'
    }
  },
  mounted() {
    this.$validator = this.$root.$validator
  },
  methods: {
    handleDbClick(row) {
      this.showDialog(row.id)
    },
    showDialog(id) {
      console.log(id)
      if (id) {
        this.saveMethod = 'PUT'
        this.$http.get('${cssc}/biz/base/wfLine/v1/' + id).then(
          resp => {
            this.BizWfLine = resp.data
            this.dialogVisible = true
          },
          error => {
            reject(error)
          }
        )
      } else {
        this.saveMethod = 'POST'
        this.dialogVisible = true
      }
    },
    beforeCloseDialog() {
      this.BizWfLine = {}
      this.dialogVisible = false
    },
    loadData(param, cb) {
      this.$http
        .post('${cssc}/biz/base/wfLine/v1/query', param)
        .then(
          resp => {
            let response = resp.data
            this.data = response.rows
            this.pageResult = {
              page: response.page,
              pageSize: response.pageSize,
              total: response.total
            }
          },
          error => {
            reject(error)
          }
        )
        .finally(() => cb())
    },
    afterSaveData() {
      setTimeout(() => {
        this.beforeCloseDialog()
        this.$refs.htTable.load()
      }, 500)
    }
  }
}
</script>

<style lang="scss" scoped></style>
