<template>
  <div class="adjust">
    <ex-table
      v-loading="loading"
      :table="table"
      :data="tableData"
      :columns="level === '1' ? columns : Pcolumns"
      @screen-reset="
        parmValue.page = 1;
        pageInfo.curr = 1;
        searchList();
      "
      @screen-submit="
        parmValue.page = 1;
        pageInfo.curr = 1;
        searchList();
      "
    >
      <template #status="{ scope }">
        <el-tag
          :size="tablebtnSize"
          :type="scope.row.status == '0' ? 'warning' : ''"
          v-text="
            (statusOptions.find((item) => item.value == scope.row.status) || {}).label ||
            '--'
          "
        ></el-tag>
      </template>
      <template #level="{ scope }">
        <el-tag
          :size="tablebtnSize"
          :type="
            (levelOptions.find((item) => item.value == scope.row.level) || {}).type ||
            'success'
          "
          v-text="
            (levelOptions.find((item) => item.value == scope.row.level) || {}).label ||
            '--'
          "
        ></el-tag>
      </template>

      <template #company_type="{ scope }">
        <el-tag
          :size="tablebtnSize"
          :type="scope.row.type == '0' ? 'success' : ''"
          v-text="
            (company_type.find((item) => item.value == scope.row.company_type) || {})
              .label || '--'
          "
        ></el-tag>
      </template>
      <template #types="{ scope }">
        <el-tag
          :size="tablebtnSize"
          :type="scope.row.type == '0' ? 'warning' : ''"
          v-text="
            (typeOptions.find((item) => item.value == scope.row.type) || {}).label || '--'
          "
        ></el-tag>
      </template>

      <template #operation="{ scope }">
        <el-tooltip effect="dark" content="详情" placement="top">
          <i class="el-icon-view tb-icon" @click="getRouter('detail', scope.row.id)"></i>
        </el-tooltip>
      </template>
    </ex-table>
    <!-- 弹窗 新增/修改 -->
    <add-edit
      :show-model="showModel"
      :type="type"
      @refresh="searchList"
      @cancel="showModel = false"
    />
  </div>
</template>
<script>
import asyncRequest from "@/apis/service/purchaseAndSale/adjust";
import mixinPage from "@/mixins/elPaginationHandle";
import { mapGetters } from "vuex";
import resToken from "@/mixins/resToken";
import addEdit from "@/components/addEdit";

import {
  company_type,
  seachStatus,
  statusOptions,
  levelOptions,
  typeOptions,
  columns,
  Pcolumns,
  parmValue,
} from "@/views/pucColumns";
export default {
  name: "adjust",
  mixins: [mixinPage, resToken],
  components: {
    addEdit,
  },
  computed: {
    //组件SIZE设置
    ...mapGetters(["tablebtnSize", "searchSize", "size", "level"]),
    powers() {
      return this.$store.getters.btnList;
    },
  },
  data() {
    return {
      select: "1",
      input: "",
      type: 1,
      company_type,
      seachStatus,
      statusOptions,
      levelOptions,
      typeOptions,
      // 表格 - 列参数
      columns, //超管
      Pcolumns, //普通角色
      showModel1: false,
      loading: true,
      showModel: false,
      isDetail: false,
      modelId: 0,
      parmValue: {},

      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
    };
  },
  methods: {
    getRouter(toRouter, queryId) {
      if (toRouter && queryId) {
        let model = {
          type: "view",
          id: queryId,
        };
        let item = JSON.parse(JSON.stringify(this.parmValue));
        item.select = this.select;
        item.input = this.input;

        let routerModel = {
          options: item,
          router: this.$route.path,
        };
        model.preModel = JSON.stringify(routerModel);
        this.routeGoto(toRouter, model);
      } else {
        this.$message.warning("暂未找到相关流程！");
      }
    },
    // 新建/编辑/详情
    openModal(id, isDetail) {
      this.showModel = true;
      this.modelId = id;
      this.isDetail = isDetail;
    },
    // 时间
    // 刷新表格
    async searchList(parmValue) {
      this.loading = true
      const { code, data, message } = await asyncRequest.list(parmValue);
      if (code === 0) {
        const { list, count } = data;
        this.tableData = list;
        // this.pageInfo.total = Number(count);
        this.$emit('getTotal',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>
.adjust{
  margin-top:10px;
}
</style>
