<template>
  <div>
    <!-- 操作日志 -->
    <p-card title="操作日志">
      <span slot="extra">
        <!-- <p-button type="primary" style="margin-right:10px" @click="showmodel()">添加</p-button> -->
      </span>
      <p-grid-form :label-col="{ span: 8 }" :span="8" :items="config.items" @submit="hanlderSubmit" />
      <p-table
        ref="table"
        row-key="id"
        bordered
        :columns="config.columns"
        :remoteUrl="config.remoteUrl"
        :remoteParams="remoteParams"
        :rowSelectType="false"
        :data-source="data"
      >
      </p-table>
    </p-card>
  </div>
</template>

<script>
import config from './config.js'

import { add, deletes, update } from './api'
const data = [
  { name: '111', id: 111 },
  { name: '111', id: 1121 },
  { name: '111', id: 1131 },
  { name: '111', id: 1151 },
  { name: '111', id: 1141 }
]
export default {
  data() {
    return {
      config,
      data,
      type: true,
      remoteParams: {
        createTime: '',
        data: '',
        endtime: '',
        id: '',
        ip: '',
        method: '',
        returnValue: '',
        starttime: '',
        type: '',
        url: '',
        userid: ''
      },
      visible: false,
      confirmLoading: false
    }
  },
  mounted() {
    // this.getinfo()
  },
  methods: {
    hanlderSubmit(e, form) {
      e.preventDefault()
      form.validateFields((error, values) => {
        console.log(error, values, 'valuesvaluesvaluesvaluesvalues')
        // this.queryName = values.name
        // this.queryType = values.type
        // this.getlistCompanyByAuthId()
        if (!error) {
          this.remoteParams = { ...this.remoteParams, ...values }
        }
      })
    },
    handleOk(e) {
      this.$refs.model.form.validateFields(async (err, value) => {
        if (!err) {
          console.log(value)
          this.confirmLoading = true
          if (this.type) {
            let res = await update(value)
            console.log(res)
            if (res.success) {
              this.visible = false
              this.remoteParams = { ...this.remoteParams }
            } else {
              this.$exception(res)
            }
          } else {
            let res = await add(value)
            console.log(res)
            if (res.success) {
              this.visible = false
              this.remoteParams = { ...this.remoteParams }
            } else {
              this.$exception(res)
            }
          }

          this.confirmLoading = false
          //
        }
      })
    },
    handleCancel(e) {
      console.log('Clicked cancel button')
      this.visible = false
    },
    //点击弹出
    showmodel(data) {
      console.log(data)
      this.visible = true

      if (data) {
        this.$nextTick(() => {
          this.$refs.model.form.setFieldsValue(data)
          this.$refs.model.form.setFieldsValue(data)
        })
        this.type = true
      } else {
        this.$nextTick(() => {
          this.$refs.model.form.resetFields()
        })
        this.type = false
      }
    },
    del(text) {
      let that = this
      console.log(text)
      this.$confirm({
        title: '确定是否要删除?',
        content: '',
        async onOk() {
          let res = await deletes({ id: text.id })
          if (res.success) {
            that.$message.success('删除成功')
            that.remoteParams = { ...that.remoteParams }
          } else {
            that.$exception(res)
          }
        },
        onCancel() {}
      })
    }
  }
}
</script>

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