<template>
  <div class="fullheight">
    <ht-table
      @load="loadData"
      :data="data"
      :selection="true"
      :page-result="pageResult"
      quick-search-props="procDefName"
      :default-sorter="[{direction: 'DESC', property: 'callTime'}]"
      :show-export="false"
      :show-custom-column="false"
      ref="htTable"
      @selection-change="handleSelectionChange"
    >
      <template v-slot:toolbar>
        <el-button-group>
          <ht-delete-button
            url="${portal}/portal/portalServiceLog/v1/"
            :htTable="$refs.htTable"
            :disabled="isDisabled"
            >删除</ht-delete-button
          >
        </el-button-group>
      </template>
      <template>
        <ht-table-column type="index" width="50" align="center" label="序号" />
        <ht-table-column
          prop="procDefName"
          label="名称"
          :sortable="true"
          :show-overflow-tooltip="true"
        >
          <template v-slot="{row}">
            <span>{{ row.procDefName }}({{ row.procDefKey }})</span>
          </template>
        </ht-table-column>
        <ht-table-column
          prop="callTime"
          label="调用时间"
          :sortable="true"
          :show-overflow-tooltip="true"
        >
        </ht-table-column>
        <ht-table-column
          prop="userName"
          label="用户"
          :sortable="true"
          :show-overflow-tooltip="true"
        >
          <template v-slot="{row}">
            <span>{{ row.userName }}[{{ row.userAccount }}]</span>
          </template>
        </ht-table-column>
        <ht-table-column
          prop="isSuccess"
          label="是否异常"
          :filters="[
            {text: '否', value: '1'},
            {text: '是', value: '0'}
          ]"
        >
          <template v-slot="{row}">
            <el-tag type="success" v-if="row.isSuccess == '1'">否</el-tag>
            <el-tag type="danger" v-if="row.isSuccess == '0'">是</el-tag>
          </template>
        </ht-table-column>
      </template>
    </ht-table>
  </div>
</template>

<script>
import req from '@/request.js'

export default {
  props: ['type', 'alias'],
  data() {
    return {
      dialogVisible: false,
      formData: {},
      saveMethod: 'POST',
      data: [],
      pageResult: {
        page: 1,
        pageSize: 20,
        total: 0
      },
      selectedList: [],
      isDisabled: true
    }
  },
  watch: {
    selectedList: {
      handler(val) {
        this.isDisabled = val.length < 1 ? true : false
      },
      deep: true
    }
  },
  mounted() {
    this.$validator = this.$root.$validator
  },
  methods: {
    loadData(param, cb) {
      req
        .post(
          window.context.portal +
            '/portal/portalServiceLog/v1/querList?type=' +
            this.type +
            '&alias=' +
            this.alias,
          param
        )
        .then(resp => {
          let response = resp.data
          this.data = response.rows
          this.pageResult = {
            page: response.page,
            pageSize: response.pageSize,
            total: response.total
          }
        })
        .finally(() => cb && cb())
    },
    handleSelectionChange(selection) {
      this.selectedList = selection
    }
  }
}
</script>
