<template>
  <el-dialog
    v-loading="loading"
    :title="'操作记录'"
    :center="true"
    align="left"
    top="5vh"
    width="1040px"
    :close-on-click-modal="false"
    :visible.sync="showModelThis"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
    @close="showModelThis = false"
    append-to-body
  >
    <el-card style="margin-top: -20px">
    <ex-table
      v-loading="loading"
      :table="table"
      :data="tableData"
      :columns="columns"
      :page="pageInfo"
      :size="size"
      @page-curr-change="handlePageChange"
      @page-size-change="handleSizeChange"
      @screen-reset="reloadList()"
      @screen-submit="reloadList()"
    >
      <template #action_item="{ scope }">
        <span v-if="scope.row.handle_name === '描述'">
          <el-tag size="mini" @click="openModal(scope.row)">查看详情</el-tag>
        </span>
        <span v-else>{{ scope.row.action_item }}</span>
      </template>
      <template #action_after="{ scope }">
        <span v-if="scope.row.handle_name === '描述'">
          <el-tag size="mini" @click="openModal(scope.row)">查看详情</el-tag>
        </span>
        <span v-else>{{ scope.row.action_after }}</span>
      </template>
    </ex-table>
    <contrastModel
      :show-model="showConModel"
      :sitem="sitem"
      @cancel="showConModel = false"
    />
  </el-card>
  </el-dialog>
</template>
<script>
import asyncRequest from "@/apis/service/purchaseAndSale/adjust";
import mixinPage from "@/mixins/elPaginationHandle";
import resToken from "@/mixins/resToken";
import contrastModel from "./contrastModel";
import { recordList } from "@/views/pucColumns";
export default {
  name: "record",
  mixins: [mixinPage, resToken],
  props: [ "showModel","bugNo"],
  components: {
    contrastModel,
  },
  watch: {
    showModel: function (val) {
      this.showModelThis = val;
      if (val) {
        this.reloadList();
      }
    },
    showModelThis(val) {
      if (!val) {
        this.$emit("cancel");
      }
    },
  },
  data() {
    return {
      loading: true,
      showModelThis: this.showModel,
      showConModel: false,
      parmValue: {
        page: 1, // 页码
        size: 15, // 每页显示条数
        bugNo: "",
      },
      // 状态
      statusOptions: [
        { id: 0, label: "禁用" },
        { id: 1, label: "启用" },
      ],
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        // _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns: recordList,
    };
  },
  methods: {
    async reloadList() {
      this.parmValue.page = 1;
      this.pageInfo.curr = 1;
      await this.searchList();
    },
    openModal(row) {
      this.sitem = row;
      this.showConModel = true;
    },
    // 刷新表格
    async searchList() {
      this.tableData = [];
      this.loading = true;
      this.parmValue.bugNo = this.bugNo;
      const {code,data,message} = await asyncRequest.MLogList(this.parmValue);
      if (code === 0 ) {
        const {list,count}=data
        this.tableData = list;
        this.tableData.forEach((v) => {
          v.type_name = v.type === "1" ? "新建" : "编辑";
        });
        this.pageInfo.total = Number(count);
      } else if (code >= 100 && code <= 104) {
        await this.logout();
      } else {
        this.tableData = [];
        this.pageInfo.total = 0;
      }
      this.loading = false;
    },
  },
};
</script>

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