<template>
  <div class="oo-page">
    <div class="oo-server">
      <h3 class="page-name" v-show="$customs.flag">{{title}}</h3>
      <cs-dynamic-table :prop="csTable" ref="child" :parent="this"></cs-dynamic-table>
       <Modal
        v-model="modelFlag"
        title="结果明细"
        width="50"
        :mask-closable="false"
        @on-cancel="closeModel" 
      >
        <log-result ref="logResult" @fill="fill"></log-result>
        <div slot="footer"></div>
      </Modal>
    </div>
  </div>
</template>

<script lang="ts">
import { Component,Vue } from "vue-property-decorator";
import LogResult from "./log-result.vue";
@Component({
  components: {
    LogResult
  }
})
export default class LogView extends Vue {
  private title: any = "";
  modelFlag: boolean = false;
  resultData: any="";
  log: any = "";
  private csTable: any = {
    parentVm: this,
    timeout: 3000,
    dataSrc: this.$msPrefix.automation + "/api/v1/data/list/scriptDetail",
    postMethod: true,
    dataProp: "data.content",
    pageableProp: {
      pageSize: "data.size",
      total: "data.totalElements",
      currentPage: "data.number"
    },
    showIndex: false,
    emptyModel: {
    },
    showActions:false,
    columns: [
      {
        key: "codeType",
        title: "脚本类型",
        align: "center",
        minWidth: 200,
        resizeable: true,
        ellipsis: true,
        tooltip: true,
        render: (h,params) => {
          return h('span',params.row.script ? params.row.script.codeType : '')
        }
      },
      {
        key: "syncId",
        title: "参数列表",
        align: "center",
        minWidth: 200,
        resizeable: true,
        ellipsis: true,
        tooltip: true
      },
      {
        key: "status",
        title: "执行结果",
        align: "center",
        minWidth: 200,
        ellipsis: true,
        render:(h,params) =>{
          return h('a',{
              style: {
                  color: params.row.status == 0 ? 'green': 'red',
                  textDecoration: 'underline'
              },
              on: {
                "click": (e) => {
                  this.showResult(params.row.result)
                }
              }
          },params.row.status == 0 ? '成功': '失败')
        }
      },
      {
        key: "createTime",
        title: "执行时间",
        align: "center",
        minWidth: 200,
        resizeable: true,
        ellipsis: true,
        tooltip: true
      },
      {
        key: "name",
        title: "执行人",
        align: "center",
        minWidth: 200,
        resizeable: true,
        ellipsis: true,
        tooltip: true
      }
    ]
  };
  showResult (res:any) {
    this.log.showLog(res)
  }
  fill (log:any) {
    this.log =log
  }
  mounted() {
    this.title = (this.$globalFun() as any).getMethod('title')
  }
}
</script>
