<script>
import useColumns from "./columns";
import { dicts } from "./dicts";
import { LIST } from "@/api/business/purchase/task";

export default {
  name: "PuchaseTask",
  dicts: dicts,
  components: {
    DcButton: () => import("./dao-chu/index.vue"),
    SeeButton: () => import("./see/index.vue"),
    ZpButton: () => import("./zhuan-pai/index.vue"),
    ThxqButton: () => import("./tui-hui-xu-qiu/index.vue"),
    XyzcButton: () => import("./xie-yi-zhi-cai/index.vue"),
    lcButton: () => import("./line-close/index.vue"),
    ZpjlButton: () => import("./zhuan-pai/record.vue"),
    ElSuperTable: () => import("@/components/super-table/index.vue"),
    ElSuperUxTable: () => import("@/components/super-ux-table/index.vue"),
    ElSuperSearch: () => import("@/components/super-search/index.vue"),
    PgButton: () => import("./pi-gai/index.vue"),
  },
  data() {
    const { TableColumns, SearchColumns } = useColumns();
    const page = this.$init.page();
    const params = this.$init.params(SearchColumns);
    return {
      size: "mini",
      loading: false,
      page: page,
      params: params,
      tableData: [],
      selectData: [],
      TableColumns: TableColumns,
      SearchColumns: SearchColumns,
    };
  },
  computed: {},
  watch: {},
  created() {
    this.params = {
      ...this.params,
      statusList: ["0", "2", "3"],
    };
    this.useQuery(this.params, this.page);
  },
  methods: {
    //
    setSelectable(row) {
      const { status } = row;
      if (status === "1") {
        // 已执行协议直采
        return false;
      } else {
        return true;
      }
    },
    //
    async fetchList(prop, page) {
      try {
        this.loading = true;
        this.tableData = [];
        const { code, rows, total } = await LIST(prop, page);
        if (code === 200) {
          this.tableData = rows;
          this.page.total = total;
        }
      } catch (err) {
        // catch
      } finally {
        // finally
        this.loading = false;
      }
    },
    // 查 询
    async useQuery(prop, page) {
      const { pageNum, pageSize } = page;
      const { date, documentsCodes: dCode, materialCodes: mCode } = prop;
      const [startDate, endDate] = date || [];
      const documentsCodes = dCode
        ? dCode.replace(/\s*/g, "").replaceAll("，", ",")
        : undefined;
      const materialCodes = Array.isArray(mCode)
        ? mCode
        : mCode
        ? mCode.replace(/\s*/g, "").replaceAll("，", ",").split(",")
        : undefined;
      await this.fetchList(
        {
          ...prop,
          endDate,
          startDate,
          materialCodes,
          documentsCodes,
          date: undefined,
        },
        { pageNum, pageSize, isAsc: "desc", orderByColumn: "updateTime" }
      );
    },
    // 重 置
    useReset() {
      this.page = this.$init.page();
      this.params = this.$init.params(this.SearchColumns);
      this.useQuery(this.params, this.page);
    },
    // 选 择
    useSelect(prop, value) {
      this.selectData = prop;
    },
  },
};
</script>

<template>
  <el-card
    v-loading="loading"
    :body-style="{
      height: '100%',
      padding: 0,
      display: 'flex',
      'flex-direction': 'column',
    }"
  >
    <el-super-search
      v-model="params"
      :size="size"
      :dict="dict"
      :columns="SearchColumns"
      @reset="useReset"
      @submit="useQuery(params, page)"
      @aaa="useQuery(params, page)"
    ></el-super-search>
    <div class="my-4" style="text-align: right">
      <el-button-group>
        <see-button
          :size="size"
          :dict="dict"
          :select-data="selectData"
          @success="useQuery(params, page)"
        ></see-button>
      </el-button-group>
      <el-button-group>
        <thxq-button
          :size="size"
          :select-data="selectData"
          @success="useQuery(params, page)"
        ></thxq-button>
        <xyzc-button
          :size="size"
          :dict="dict"
          :select-data="selectData"
          @success="useQuery(params, page)"
        ></xyzc-button>
      </el-button-group>
      <el-button-group>
        <zp-button
          :size="size"
          :select-data="selectData"
          @success="useQuery(params, page)"
        >
        </zp-button>
        <zpjl-button :size="size" :select-data="selectData"> </zpjl-button>

        <lc-button
          :size="size"
          :select-data="selectData"
          @success="useQuery(params, page)"
        >
        </lc-button>
      </el-button-group>
      <el-button-group>
        <pg-button
          :size="size"
          :select-data="selectData"
          @success="useQuery(params, page)"
        ></pg-button>
        <!-- <dc-button
          :size="size"
          :page="page"
          :data="params"
          @success="useQuery(params, page)"
        ></dc-button> -->
      </el-button-group>
    </div>
    <el-super-ux-table
      v-model="tableData"
      index
      checkbox
      pagination
      showSummary
      :size="size"
      :dict="dict"
      :page="page"
      convenitentOperation
      :columns="TableColumns"
      storage-key="PuchaseTaskSuperTable"
      @row-select="useSelect"
      @pagination="useQuery(params, page)"
    >
    </el-super-ux-table>
  </el-card>
</template>
<style scoped lang="scss">
.el-card {
  width: calc(100% - 32px);
  height: calc(100vh - 32px);
  margin: 16px;
  padding: 16px;
  border-radius: 8px;
}
.el-button-group + .el-button-group {
  margin: 0 0 0 8px;
}
</style>
