

<script>
import test from "@/components/form-test/index.vue";
import query from "@/components/query/index.vue";

import byTable from "@/components/by-table/index.js";
import addInbound from "./addInbound.vue";

import * as API from "@/api/inbound-outbound/inbound/index.js";
import { warehouseSelectList } from "@/api/product-material/warehouse/index.js";

export default {
  components: {
    test,
    byTable,
    query,
    addInbound,
  },
  data() {
    return {
      warehouseTypeList: [],
      warehouseSelectList: [],
      btnForm: {
        otherButton: {
          list: [
            {
              name: "采购入库",
              methodsText: "add",
              type: "primary",
              add: () => {
                this.handleAdd(10);
              },
            },
            {
              name: "手动入库",
              methodsText: "add",
              type: "defualt",
              add: () => {
                this.handleAdd(20);
              },
            },
            {
              name: "入库质检",
              methodsText: "add",
              type: "defualt",
              add: () => {
                this.handleAdd();
              },
            },
          ],
        },
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: "",
        warehouseId: "",
        status: "",
        code: "",
        goodsCode: "",
        goodsName: "",
        applyUserId: "",
        startTime: "",
        endTime: "",
      },
      selectConfig: [
        {
          label: "收获仓库",
          prop: "type",
          data: [],
        },
        {
          label: "入库状态",
          prop: "type",
          data: [],
        },
      ],
      tableList: [],
      loading: false,
      inboundType: null, // 入库类型  10 采购入库  20 手动入库
      titleText: "",
      open: false,
      form: {
        id: "",
        changeDetailsList: [],
      },
    };
  },
  created() {
    const businessDictData = JSON.parse(
      window.localStorage.getItem("businessDict")
    );
    this.warehouseTypeList = businessDictData.find(
      (item) => item.code === "warehouseType"
    ).children;
    this.selectConfig[0].data = this.warehouseTypeList.map((item) => ({
      label: item.dictValue,
      value: item.dictKey,
    }));
    warehouseSelectList().then((res) => {
      this.warehouseSelectList = res.data.data;
    });
    // this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      API.outboundList(this.queryParams).then(
        (res) => {
          console.log(res, "qq");
          this.tableList = res.data.data.records;
          this.total = res.data.data.total;
          this.loading = false;
        },
        (err) => {
          console.log("outboundList: " + err);
          this.loading = false;
        }
      );
    },
    handleQuery() {
      this.getList();
    },
    handleAdd(type) {
      this.form = {
        id: "",
        changeDetailsList: [],
      };
      if (type === 10) {
        this.titleText = "add";
      } else {
        this.titleText = "manual";
      }
      this.inboundType = type;
      this.open = true;
    },
    handleCancel() {
      this.form = {
        id: "",

        changeDetailsList: [],
      };
      this.open = false;
    },
    handleEdit(row) {
      this.titleText = "edit";
      this.form = row;
      this.open = true;
      if (this.form.fileInfoList === "") {
        this.form.fileInfoList = [];
      }
      this.$nextTick(() => {
        this.$refs.addInbound.loading = true;
        this.$refs.addInbound.countryChange(this.form.countryId);
        this.$refs.addInbound.provinceChange(this.form.provinceId);
        this.$refs.addInbound.loading = false;
      });
    },
    handleSubmit() {
      if (this.inboundType === 10) {
        API.purchaseAdd(this.form).then(
          () => {
            this.msgSuccess(this.$t("addSuccess"));
            this.$refs.addInbound.loading = false;
            this.open = false;
            this.getList();
          },
          (err) => {
            console.log("purchaseAdd: " + err);
            this.$refs.addInbound.loading = false;
          }
        );
      } else {
        API.manualAdd(this.form).then(
          () => {
            this.msgSuccess(this.$t("addSuccess"));
            this.open = false;
            this.$refs.addInbound.loading = false;
            this.getList();
          },
          (err) => {
            console.log("manualAdd: " + err);
            this.$refs.addInbound.loading = false;
          }
        );
      }
    },

    handleDelete(row) {
      this.$confirm(this.$t("askDeleteData"), {
        confirmButtonText: this.$t("submitText"),
        cancelButtonText: this.$t("cancelText"),
        type: "warning",
      }).then(() => {
        API.outboundDel({ id: row.id }).then(() => {
          this.msgSuccess(this.$t("deleteSuccess"));
          this.getList();
        });
      });
    },
    showAddress(row) {
      return (
        <div>
          {row.countryName} , {row.provinceName} , {row.cityName}
        </div>
      );
    },
  },
};
</script>


<template>
  <div class="box-card">
    <el-card class="header">
      <test :form-config="btnForm"></test>
    </el-card>
    <el-card class="body-main">
      <query
        :selectConfig="selectConfig"
        :req="queryParams"
        :isShowMore="true"
        @handleQuery="handleQuery"
        @handleMore="
          () => {
            queryDialog = true;
          }
        "
      ></query>
      <el-table :data="tableList" v-loading="loading">
        <el-table-column
          :label="$t('inbound_outbound.outbound.outboundOddNumbers')"
          align="center"
          prop="code"
        />
        <el-table-column
          :label="$t('inbound_outbound.outbound.salesOddNumbers')"
          align="center"
          prop="name"
        />
        <el-table-column
          :label="$t('inbound_outbound.outbound.customerType')"
          align="center"
          :formatter="showAddress"
        />
        <el-table-column
          :label="$t('inbound_outbound.outbound.customerCode')"
          align="center"
          prop="contacts"
        />
        <el-table-column
          :label="$t('inbound_outbound.outbound.customerNmae')"
          align="center"
          prop="phone"
        />
        <el-table-column
          :label="$t('inbound_outbound.outbound.outboundQuantity')"
          align="center"
          prop="phone"
        />
        <el-table-column
          :label="$t('inbound_outbound.outbound.createTime')"
          align="center"
          prop="phone"
        />

        <el-table-column
          :label="$t('inbound_outbound.outbound.remarks')"
          align="center"
          prop="phone"
        />

        <el-table-column :label="$t('operation')" align="center" width="120">
          <template slot-scope="scope">
            <el-button type="text" @click="handleEdit(scope.row)"
              >{{ $t("edit") }}
            </el-button>
            <el-button type="text" @click="handleDelete(scope.row)"
              >{{ $t("delete") }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <el-dialog
      :title="titleText === 'manual' ? '手动入库' : '采购入库'"
      :visible.sync="open"
      v-if="open"
      width="80%"
      top="60px"
    >
      <add-inbound
        :form="form"
        :warehouseSelectList="warehouseSelectList"
        :warehouseTypeList="warehouseTypeList"
        :inboundType="inboundType"
        @submit="handleSubmit"
        @cancel="handleCancel"
        ref="addInbound"
      ></add-inbound>
    </el-dialog>
  </div>
</template>


<style lang="scss" scoped>
.box-card {
  height: calc(100vh - 110px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  .header {
    // height: 100px;
    margin-bottom: 10px;
    box-sizing: border-box;
  }
  .body-main {
    flex: 1;
  }
}
</style>