<template>
  <div class="fullheight">
    <ht-table
      @load="loadData"
      @row-dblclick="row => showDialog(row.id)"
      :data="data"
      :pageResult="pageResult"
      :selection="true"
      quick-search-props="orderCode,orderName"
      :show-export="false"
      :show-custom-column="false"
      ref="htTable"
    >
      <template v-slot:toolbar>
        <el-button
          size="small"
          @click="showDialog()"
          icon="el-icon-plus"
          type="primary"
          >添加</el-button
        >
        <ht-delete-button
          url="${cssc}/biz/model/orderInfo/v1/"
          :htTable="$refs.htTable"
          >删除</ht-delete-button
        >
      </template>
      <template>
        <ht-table-column
          prop="orderCode"
          label="指令编码"
          :sortable="true"
          :show-overflow-tooltip="true"
        >
        </ht-table-column>
        <ht-table-column
          prop="orderName"
          label="指令名称"
          :sortable="true"
          :show-overflow-tooltip="true"
        >
        </ht-table-column>
        <ht-table-column
          prop="orderType"
          label="指令类型"
          :sortable="true"
          :filters="selecteTypeTable"
        >
          <template v-slot="{row}">
            <el-tag v-if="row.orderType == 'B'">布尔型</el-tag>
            <el-tag type="success" v-if="row.orderType == 'I'">整型 </el-tag>
            <el-tag type="warning" v-if="row.orderType == 'F'">浮点型 </el-tag>
          </template>
        </ht-table-column>
      </template>
    </ht-table>
    <common-dialog
      width="800px"
      title="指令管理信息"
      :visible="dialogVisible"
      :before-close="beforeCloseDialog"
      destroy-on-close
    >
      <el-form v-form data-vv-scope="orderInfoForm">
        <ht-form-item label="指令编码" label-width="200px">
          <ht-input
            v-model="orderInfo.orderCode"
            validate="required"
            placeholder="请输入指令编码"
            style="width:75%"
          />
        </ht-form-item>
        <ht-form-item label="指令名称" label-width="200px">
          <ht-input
            v-model="orderInfo.orderName"
            validate="required"
            placeholder="请输入指令名称"
            style="width:75%"
          />
        </ht-form-item>
        <ht-form-item label="指令类型" label-width="200px">
          <ht-select
            v-model="orderInfo.orderType"
            :options="selecteTypeTable"
            :props="{key: 'value', value: 'text'}"
            validate="required"
            style="width:75%"
          />
        </ht-form-item>
      </el-form>
      <div slot="footer" style="text-align: center">
        <ht-submit-button
          url="${cssc}/biz/model/orderInfo/v1/"
          :model="orderInfo"
          :request-method="saveMethod"
          scope-name="orderInfoForm"
          @after-save-data="afterSaveData"
          >保存</ht-submit-button
        >
        <el-button @click="beforeCloseDialog">取消</el-button>
      </div>
    </common-dialog>
  </div>
</template>
<script>
export default {
  name: 'order-adim',
  data() {
    return {
      dialogVisible: false,
      data: [],
      pageResult: {
        page: 1,
        pageSize: 50,
        total: 0
      },
      orderInfo: {orderType: 'B'},
      saveMethod: 'POST',
      selecteTypeTable: [
        {value: 'B', text: '布尔型'},
        {value: 'I', text: '整型'},
        {value: 'F', text: '浮点型'}
      ]
    }
  },
  mounted() {
    this.$validator = this.$root.$validator
  },
  methods: {
    showDialog(id) {
      if (id) {
        this.saveMethod = 'PUT'
        this.$http.get('${cssc}/biz/model/orderInfo/v1/' + id).then(
          resp => {
            this.orderInfo = resp.data
            this.dialogVisible = true
          },
          error => {
            reject(error)
          }
        )
      } else {
        this.saveMethod = 'POST'
        this.dialogVisible = true
      }
    },
    beforeCloseDialog() {
      this.orderInfo = {orderType: 'B'}
      this.dialogVisible = false
    },
    loadData(param, cb) {
      this.$http
        .post('${cssc}/biz/model/orderInfo/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>
/deep/ .el-radio-group[data-v-4f57f050] {
  line-height: initial;
}
</style>
