el-col
<script>
import { TableColumns, SearchColumns } from "./column";
import { LIST, SHUTDOWN } from "@/api/business/purchase/task";
import {
  initPage,
  initDicts,
  initLayout,
  initParams,
  initPageSizes,
} from "@/utils/init";
export default {
  name: "PuchaseTask",
  dicts: [...initDicts(TableColumns), ...initDicts(SearchColumns)],
  components: {
    SeeDialog: () => import("./see/index.vue"),
    FirstDirectDialog: () => import("./first-direct/index.vue"),
    DocReturnDialog: () => import("./documents-return/index.vue"),
    ModifyBuyerDialog: () => import("./modify-buyer/index.vue"),
  },
  data() {
    return {
      size: "mini",
      loading: false,
      searchColumns: SearchColumns,
      params: initParams(SearchColumns),
      tableData: [],
      selectData: [],
      tableColumns: TableColumns,
      page: { pageNum: 1, pageSize: 10, total: 0 },
    };
  },
  computed: {},
  watch: {},
  created() {
    this.queryList(this.params, this.page);
  },
  methods: {
    //
    async fetchList(prop, page) {
      try {
        this.loading = true;
        const { pageNum, pageSize } = page;
        const { code, msg, rows, total } = await LIST(
          { ...prop },
          { pageNum, pageSize, isAsc: "desc", orderByColumn: "createTime" }
        );
        if (code === 200) {
          this.tableData = rows;
          this.page.total = total;
          this.$notify.success({ title: msg });
        } else {
          this.$notify.warning({ title: msg });
        }
      } catch (err) {
        //
      } finally {
        this.loading = false;
      }
    },
    // 查询操作
    queryList(prop, page) {
      const { date } = prop;
      prop.endDate = date[1];
      prop.startDate = date[0];
      this.fetchList({ ...prop, date: undefined }, page);
    },
    // 重置操作
    resetList() {
      this.page = initPage();
      this.params = initParams(SearchColumns);
      this.queryList(this.params, this.page);
    },
    // 页大小变
    sizeChange(prop) {
      this.page.pageSize = prop;
      this.queryList(this.params, this.page);
    },
    // 当前页变
    currentChange(prop) {
      this.page.pageNum = prop;
      this.queryList(this.params, this.page);
    },
    // 选择行
    selectionChange(prop) {
      this.selectData = prop;
    },
    // 行关闭
    async shutDown(prop) {
      try {
        this.loading = true;
        const { demandItemId } = prop;
        const { code, msg } = await SHUTDOWN(demandItemId);
        if (code === 200) {
          this.$notify.success({ title: msg });
          await this.queryList(this.params, this.page);
        } else {
          this.$notify.warning({ title: msg });
        }
      } catch (err) {
        //
      } finally {
        this.loading = false;
      }
    },
    // 退回需求
    async openDocumentsReturnDialog(prop) {
      const { open } = this.$refs.DocReturnDialog;
      await open(prop);
    },
    // 转派
    async openModifyBuyerDialog(prop) {
      const { id } = prop;
      const { open } = this.$refs.ModifyBuyerDialog;
      await open(id);
    },
    // 打开查看drawer
    async openSeeDialog(prop) {
      const { id } = prop;
      const { open } = this.$refs.SeeDialog;
      await open(id);
    },
    // 打开首次直采drawer
    async openFristDirectDialog(prop) {
      const { open } = this.$refs.FirstDirectDialog;
      await open(prop);
    },
    // 导出
    async useExport(prop, page) {
      const { pageNum, pageSize } = page;
      this.download(
        "pu/order/generate/export",
        { ...prop, pageNum, pageSize },
        `KONG_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>

<template>
  <el-card
    v-loading="loading"
    style="
      width: calc(100% - 20px);
      height: 100%;
      margin: 10px;
      padding: 0 20px 20px 0;
    "
    :body-style="{ padding: 0 }"
  >
    <see-dialog ref="SeeDialog"></see-dialog>
    <first-direct-dialog
      ref="FirstDirectDialog"
      @success="resetList"
    ></first-direct-dialog>
    <doc-return-dialog
      ref="DocReturnDialog"
      @success="resetList"
    ></doc-return-dialog>
    <modify-buyer-dialog
      ref="ModifyBuyerDialog"
      @success="resetList"
    ></modify-buyer-dialog>
    <el-backtop target=".el-scrollbar__wrap"></el-backtop>
    <el-form
      :size="size"
      :model="params"
      label-width="auto"
      label-position="right"
      style="padding: 20px 20px 0"
      @submit.native.prevent
    >
      <el-row :gutter="20" style="display: flex; flex-wrap: wrap">
        <el-col
          v-for="column in searchColumns"
          :key="column.title"
          :span="column.span || 6"
        >
          <el-form-item :prop="column.key" :label="column.title">
            <el-input
              v-if="column.inputType === 'Input'"
              v-model="params[column.key]"
              :disabled="column.disabled"
              :clearable="column.clearable"
              :placeholder="column.placeholder"
              style="width: 100%"
            ></el-input>
            <el-select
              v-if="column.inputType === 'Select'"
              v-model="params[column.key]"
              :disabled="column.disabled"
              :clearable="column.clearable"
              :placeholder="column.placeholder"
              style="width: 100%"
            >
              <el-option
                v-for="item in dict.type[column.referName]"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
            <el-date-picker
              v-if="column.inputType === 'DatePicker'"
              v-model="params[column.key]"
              :type="column.type"
              :placeholder="column.placeholder"
              :value-format="column.valueFormat"
              :unlink-panels="column.unlinkPanels"
              :picker-options="column.pickerOptions"
              :range-separator="column.rangeSeparator"
              :end-placeholder="column.endPlaceholder"
              :start-placeholder="column.startPlaceholder"
              style="width: 100%"
            >
            </el-date-picker>
            <dr-popover-select
              v-if="column.inputType === 'PopoverSelect'"
              v-model="params[column.key]"
              :size="size"
              :source.sync="params"
              :title="column.title"
              :type="column.referName"
              :multiple="column.multiple"
              :readonly="column.readonly"
              :value-key="column.valueKey"
              :placeholder="column.placeholder"
              :data-mapping="column.dataMapping"
              :query-params="column.queryParams(params)"
            >
            </dr-popover-select>
            <dr-popover-tree-select
              v-if="column.inputType === 'PopoverTreeSelect'"
              v-model="params[column.key]"
              :source.sync="params"
              :title="column.title"
              :type="column.referName"
              :multiple="column.multiple"
              :show-key="column.showKey"
              :value-key="column.valueKey"
              :placeholder="column.placeholder"
              :data-mapping="column.dataMapping"
              :query-params="column.queryParams(params)"
            >
            </dr-popover-tree-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label-width="0">
            <el-button
              circle
              :size="size"
              icon="el-icon-search"
              @click="queryList(params, page)"
            ></el-button>
            <el-button
              circle
              :size="size"
              icon="el-icon-refresh"
              @click="resetList"
            ></el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row :gutter="24" style="padding: 0 20px">
      <el-col :span="24">
        <el-button :size="size" @click="useExport(params, page)">
          导 出
        </el-button>
        <el-button
          :size="size"
          :disabled="selectData.length !== 1"
          @click="openModifyBuyerDialog(selectData[0])"
        >
          转 派
        </el-button>
        <el-button
          :size="size"
          :disabled="!selectData.length"
          @click="openDocumentsReturnDialog(selectData)"
        >
          退回需求
        </el-button>
        <!-- <el-button
          :size="size"
          :disabled="selectData.length !== 1"
          @click="shutDown(selectData[0])"
        >
          行关闭
        </el-button> -->
        <el-button
          :size="size"
          :disabled="!selectData.length"
          @click="openFristDirectDialog(selectData)"
        >
          协议直采
        </el-button>
      </el-col>
    </el-row>
    <el-table
      :data="tableData"
      size="mini"
      style="width: 100%; margin: 20px 0 0 0"
      @row-dblclick="openSeeDialog"
      @selection-change="selectionChange"
    >
      <el-table-column fixed width="55" align="center" type="selection">
      </el-table-column>
      <el-table-column
        v-for="(column, index) in tableColumns"
        :key="index"
        :prop="column.key"
        :label="column.title"
        :width="column.width || 180"
        :show-overflow-tooltip="column.showOverflowTooltip || true"
      >
        <template slot-scope="scope">
          <dict-tag
            v-if="column.referName"
            :size="size"
            :value="scope.row[column.key]"
            :options="dict.type[column.referName]"
          />
          <span v-else>{{ scope.row[column.key] }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total="page.total"
      :page.sync="page.pageNum"
      :limit.sync="page.pageSize"
      @pagination="queryList(params, page)"
    />
  </el-card>
</template>
