<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      ref="crud"
      v-model="form"
      :page.sync="page"
      :permission="permissionList"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot-scope="scope" slot="menuLeft">
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          v-if="scope.row.status == 1"
          @click="rowSelect(scope.row)"
          >入库</el-button
        >
      </template>
      <template slot-scope="scope" slot="caigoudanmingcheng">
        <el-button
          type="text"
          @click.stop="purchaseFn(scope.row)"
          v-if="scope.row.caigoudanmingcheng != ''"
          >{{ scope.row.caigoudanmingcheng }}</el-button
        >
        <span v-else>无</span>
      </template>
    </avue-crud>
    <!-- 入库 -->
    <inDialog
      v-if="inDialogVisible"
      :repairVisible="inDialogVisible"
      :inDialogTiltle="inDialogTiltle"
      :inDialogType="inDialogType"
      :inDialogData="inDialogData"
      @handleCloseDetail="handleCloseDetail"
      type="二级库"
    >
    </inDialog>

    <!-- 采购单详情 -->
    <purchaseDialog
      :showDialog="purchaseOpen"
      v-if="purchaseOpen"
      @closeDialog="closeDialog"
      :purchaseTitle="purchaseTitle"
    ></purchaseDialog>
  </basic-container>
</template>

<script>
import { mapGetters } from "vuex";
import inDialog from "./components/inDialog.vue";
import purchaseDialog from "./components/purchaseDialog.vue";
import { getList } from "@/api/secondOrder/inbound";
export default {
  components: {
    inDialog,
    purchaseDialog,
  },
  data() {
    return {
      form: {},
      selectionList: [],
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      option: {
        height: "auto",
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        selection: true,
        viewBtn: false,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        dialogClickModal: false,
        selection: false,
        printBtn: false,
        refreshBtn: false,
        gridBtn: false,
        gridBackgroundImage: false,
        gridSpan: false,
        filterBtn: false,
        columnBtn: false,
        menu: true,
        menuWidth: 100,
        menuAlign: "left",
        searchMenuPosition: "right",
        column: [
          {
            label: "需求单名称",
            prop: "demandEndInfo",
            width: 180,
            headerAlign: "center",
            align: "center",
          },
          // {
          //   label: "仓库类型",
          //   prop: "str1",
          // },
          {
            label: "入库单号",
            prop: "orderNo",
            headerAlign: "center",
            align: "center",
          },
          {
            label: "入库时间",
            prop: "inDate",
            search: true,
            type: "date",
            searchRange: true,
            startPlaceholder: "开始时间",
            endPlaceholder: "结束时间",
            format: "yyyy-MM-dd HH:mm:ss",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
            headerAlign: "center",
            align: "center",
          },
          {
            label: "入库人",
            prop: "inOperatorName",
            search: true,
            headerAlign: "center",
            align: "center",
          },
          {
            label: "部门",
            prop: "departments",
            search: true,
            headerAlign: "center",
            align: "center",
          },
          {
            label: "状态",
            prop: "status",
            type: "select",
            headerAlign: "center",
            align: "center",
            dicData: [
              {
                label: "已入库",
                value: 2,
              },
              {
                label: "未入库",
                value: 1,
              },
            ],
          },
        ],
      },
      data: [],
      inDialogVisible: false,
      inDialogTiltle: "入库",
      inDialogType: "", //弹框类型
      purchaseOpen: false,
      purchaseTitle: "",
      inDialogData: {}, //获取行信息
    };
  },
  methods: {
    // 采购单
    purchaseFn(row) {
      this.purchaseOpen = true;
      this.purchaseTitle = row.caigoudanmingcheng + "详情";
    },
    closeDialog() {
      this.purchaseOpen = false;
    },
    handleCloseDetail(table) {
      this.inDialogVisible = false;
    },
    // 入库 行点击事件
    rowSelect(row) {
      this.inDialogVisible = true;
      this.inDialogType = "inbound";
      this.inDialogTiltle = "入库";
      this.inDialogData = row;
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },

    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      const queryParams = {
        ...params,
        ...this.query,
        pageSize: page.pageSize,
        pageNum: page.currentPage,
      };
      if (queryParams.inDate && Array.isArray(queryParams.inDate)) {
        queryParams.startTime = queryParams.inDate[0];
        queryParams.endTime = queryParams.inDate[1];
        delete queryParams.inDate;
      }
      getList(page.currentPage, page.pageSize, queryParams).then((res) => {
        console.log("列表", res.data.result);
        this.data = res.data.result.list;
        this.loading = false;
        this.page.total = res.data.result.total;
      });
    },
  },
};
</script>

<style></style>
