<template>
  <div>
    <!-- 算法 -->
    <!-- <a-divider /> -->
    <p-card title="系统参数配置" :bordered="false" style="width: 100%">
      <div slot="extra"><p-button type="primary" @click="AddStrategy()">添加</p-button></div>
      <p-grid-form :span="8" :label-col="{ span: 9 }" :items="tablecolumns.grid.items" @submit="hanlderSubmit" />
      <p-table
        :remote-url="tablecolumns.MainTable.RemoteUrl"
        bordered
        :ref="tablecolumns.MainTable.ref"
        :row-key="tablecolumns.MainTable.rowkey"
        :columns="tablecolumns.MainTable.columns"
        :data-source.sync="data"
        :remoteBefore="tablecolumns.MainTable.remoteBefore"
        :rowSelectType="false"
        :remoteData="remoteData"
        :doneBefore="tablecolumns.MainTable.doneBefore"
        @submit="hanlderSubmit"
      >
        <span slot="operation" slot-scope="text, record">
          <a @click.stop="AddStrategy(text)">编辑</a>
          <a-divider type="vertical" />
          <a @click.stop="details(text)">详情</a>
          <a-divider type="vertical" />
          <a @click.stop="del(text)">删除</a>
        </span>
      </p-table>
    </p-card>
    <edit-model ref="model" :visible="visible" @hidemodel="hidemodel" :items="items"></edit-model>
    <a-modal title="系统参数配置" width="80%" :visible="visibles" @ok="visibles = false" @cancel="visibles = false">
      <a-descriptions bordered>
        <!-- v-for="item of columns.filter(t => !t.hidden && t.key != 'operation' && t.dataIndex != '_row_count')"
          :key="item.key"
          :label="item.title" -->
        <a-descriptions-item
          v-for="item of tablecolumns.MainTable.detail.filter(
            t => !t.hidden && t.key != 'operation' && t.dataIndex != '_row_count'
          )"
          :key="item.key"
          :label="item.title"
        >
          {{ detailsdata[item.key] }}
        </a-descriptions-item>
      </a-descriptions>
    </a-modal>
  </div>
</template>
<script>
import tablecolumns from './config/tableconfjg'
import model from './config/model'
import { delItem } from './api'
import EditModel from './model.vue'
export default {
  data() {
    return {
      remoteData: {},
      detailsdata: {},
      visibles: false,
      tablecolumns,
      model,
      data: [],
      //   items: [],
      visible: false,
      hide: true
    }
  },
  components: {
    EditModel
  },
  computed: {
    items() {
      return this.model.strategy.items
    }
  },
  mounted() {
    // console.log(this.$refs.table)
  },
  methods: {
    hanlderSubmit(e, form) {
      e.preventDefault()
      console.log('查询')
      let value = form.getFieldsValue()
      this.remoteData = {
        search: value.search
      }
    },
    details(text) {
      //   this.$nextTick(() => {
      this.detailsdata = text
      this.visibles = true
      //   })
    },
    hidemodel(data) {
      this.visible = false
      if (!data) {
        this.reload()
      }
    },

    reload() {
      this.$refs[this.tablecolumns.MainTable.ref].reload()
    },
    SetModel(data) {
      this.$refs.model.setvalue(data)
    },
    AddStrategy(text) {
      console.log(text)
      if (text && text.remark == null) {
        text.remark = ''
      }
      this.visible = true
      //   console.log(this.model.strategy.items)
      if (text && text.language == 'java') {
        //   this.model.strategy.items
        this.$refs.model.sss()
      } else {
        this.$refs.model.sass()
      }

      if (text) {
        this.SetModel(text)
        console.log('111')
      } else {
        this.$refs.model.types(text)
      }
    },
    back(value) {
      this.hide = value
    },
    del(data) {
      console.log(data)
      let that = this
      this.$confirm({
        title: '是否删除?',
        okText: '确认',
        cancelText: '取消',
        async onOk() {
          let res = await delItem({ uniqueid: data.regId })
          if (res.success) {
            that.$message.success(`删除成功！${res.message}`)
            that.reload()
          } else {
            that.$exception(res)
          }
        }
      })
    }
  }
}
</script>
