<template>
    <div>
        <div class="divborder newSearchDiv">
            <div class="filter">
                <label>类型：</label>
                <Select v-model="storetype" class="searchSelect">
                    <Option
                        v-for="item in typeList"
                        :value="item.dkey"
                        :key="item.dkey"
                        >{{ item.dval }}</Option
                    >
                </Select>
            </div>
            <div class="filter">
                <label>仓库名称：</label>
                <Select v-model="name" class="searchSelect">
                    <Option
                        v-for="item in storeList"
                        :value="item.id"
                        :key="item.id"
                        >{{ item.name }}</Option
                    >
                </Select>
            </div>
            <div class="filter">
                <label>状态：</label>
                <Select v-model="state" class="searchSelect">
                    <Option
                        v-for="item in stateList"
                        :value="item.k"
                        :key="item.k"
                        >{{ item.v }}</Option
                    >
                </Select>
            </div>
            <div class="filter">
                <label>单号：</label>
                <Input type="text" class="searchInput" v-model="orderNum" />
            </div>
            <!-- 次级搜索条件--隐藏 -->
            <div v-show="!morecondition">
                <div class="filter">
                    <label>原始单号：</label>
                    <Select v-model="originalOrder" class="searchSelect">
                        <Option
                            v-for="item in originalOrderList"
                            :value="item.origin_order_number"
                            :key="item.id"
                            >{{ item.origin_order_number }}</Option
                        >
                    </Select>
                </div>
                <div class="filter">
                    <label>{{ $t("900908") }}：</label>
                    <DatePicker
                        type="datetimerange"
                        format="yyyy-MM-dd HH:mm:ss"
                        :clearable="false"
                        v-model="index_time"
                        class="searchInput MaxWidth"
                    ></DatePicker>
                </div>
            </div>
            <div class="searchBtn">
                <Button
                    type="primary"
                    class="twoWord"
                    icon="ios-search"
                    @click="search(1, 10)"
                    >{{ $t("1001") }}</Button
                >
                <Button
                    type="success"
                    class="twoWord"
                    icon="md-add-circle"
                    @click="add()"
                    >{{ $t("1002") }}</Button
                >
                <Button
                    type="warning"
                    class="twoWord"
                    icon="ios-create-outline"
                    @click="edit()"
                    >{{ $t("1003") }}</Button
                >
                <Button
                    type="error"
                    class="twoWord"
                    icon="md-close-circle"
                    @click="del()"
                    >删除</Button
                >
                <Button
                    type="primary"
                    class="twoWord"
                    icon="ios-cloud-download"
                    @click="checkShow()"
                    >审核</Button
                >
                <Button
                    type="primary"
                    class="twoWord"
                    icon="ios-cloud-download"
                    @click="backShow()"
                    >反审</Button
                >
                <Button
                    type="primary"
                    class="twoWord"
                    icon="ios-cloud-download"
                    @click="printShow()"
                    >打印</Button
                >
            </div>
            <!-- 更多条件 按钮组件 -->
            <MoreConbtn
                @getCon="morecondition = !morecondition"
                :morecondition="morecondition"
            ></MoreConbtn>
        </div>
        <div class="divborder newTableDiv">
            <Table
                class="tableClass"
                @on-current-change="handleRowChange"
                highlight-row
                :data="tableData1"
                :columns="tableColumns1"
            ></Table>
            <div class="pageDiv">
                <div class="pageDirection">
                    <Page
                        :total="total"
                        :current="page"
                        @on-change="changePage"
                        show-elevator
                        show-sizer
                        show-total
                        @on-page-size-change="handlePageSize"
                        :page-size-opts="[10, 20, 30, 40, 100]"
                    ></Page>
                </div>
            </div>
        </div>
        <div class="divborder newTableDiv" v-show="show">
            <!-- @on-current-change="handleRowChange" -->
            <Table
                class="tableClass"
                highlight-row
                :data="tableData3"
                :columns="tableColumns3"
            ></Table>
            <div class="pageDiv">
                <div class="pageDirection">
                    <Page
                        :total="total3"
                        :current="page3"
                        @on-change="changePage"
                        show-elevator
                        show-sizer
                        show-total
                        @on-page-size-change="handlePageSize"
                        :page-size-opts="[10, 20, 30, 40, 100]"
                    ></Page>
                </div>
            </div>
        </div>
        <Modal
            class="newModalClass"
            v-model="addmodal"
            title="添加"
            :styles="{ width: '1100px' }"
        >
            <div style="padding-right: 30px">
                <div class="row">
                    <div class="filter">
                        <label> <i>*</i> 类型： </label>
                        <Select
                            v-model="addType"
                            label-in-value
                            clearable
                            class="searchSelect"
                            @on-change="getSupplier()"
                            :disabled="type == 2"
                        >
                            <Option
                                v-for="item in typeList"
                                :value="item.dkey"
                                :key="item.dkey"
                                >{{ item.dval }}</Option
                            >
                        </Select>
                    </div>
                    <div class="filter" v-show="addType == 2">
                        <label> <i>*</i>部门： </label>
                        <Select
                            v-model="depart"
                            clearable
                            class="searchSelect"
                            label-in-value
                            @on-change="getMaterialPn"
                            :disabled="type == 2"
                        >
                            <Option
                                v-for="(item, index) in departList"
                                :value="item.id"
                                :key="item.id"
                                >{{ item.title }}</Option
                            >
                        </Select>
                    </div>
                    <div class="filter">
                        <label> <i>*</i>仓库名称： </label>
                        <Select
                            v-model="name1"
                            class="searchSelect"
                            :disabled="type == 2"
                        >
                            <Option
                                v-for="item in storeList"
                                :value="item.id"
                                :key="item.id"
                                >{{ item.name }}</Option
                            >
                        </Select>
                    </div>
                    <div class="filter">
                        <label>原始单号：</label>
                        <Input
                            type="text"
                            class="searchInput"
                            v-model="originalOrder1"
                            :disabled="type == 2"
                        />
                    </div>
                </div>

                <div class="row">
                    <div class="filter" v-show="addType != 2">
                        <label> <i>*</i>供应商： </label>
                        <Select
                            v-model="supplier"
                            clearable
                            class="searchSelect"
                            label-in-value
                            @on-change="getMaterialPn"
                        >
                            <Option
                                v-for="(item, index) in suppliers"
                                :value="item.id"
                                :key="item.id"
                                >{{ item.name }}</Option
                            >
                        </Select>
                    </div>
                    <div class="filter">
                        <label> <i>*</i> 料号： </label>
                        <Select
                            v-model="pn"
                            clearable
                            class="searchSelect"
                            filterable
                            remote
                            :remote-method="remoteMethod1"
                            label-in-value
                            @on-change="getMt"
                        >
                            <!-- <Option value v-show="supplier==''" style="color:red">数据过多请继续输入搜索内容</Option> -->

                            <Option
                                v-for="(item, index) in pnList"
                                :value="item.id"
                                :key="item.id"
                                :label="item.name"
                            >
                                <span>{{ item.name }}</span>
                            </Option>
                        </Select>
                    </div>
                    <div class="filter">
                        <label> <i>*</i>数量： </label>
                        <InputNumber
                            :min="0"
                            class="searchInput"
                            v-model="count"
                        />
                    </div>
                    <div>
                        <Button
                            type="primary"
                            class="fourWord"
                            size="small"
                            @click="addMt()"
                            >新增物料</Button
                        >
                    </div>
                </div>

                <div class="divborder newTableDiv">
                    <Table
                        class="tableClass"
                        :data="tableData2"
                        :columns="tableColumns2"
                    ></Table>
                </div>
            </div>
            <div slot="footer">
                <Button
                    type="text"
                    class="twoWord"
                    size="large"
                    @click="closeadd()"
                    >{{ $t("1033") }}</Button
                >
                <Button
                    type="primary"
                    class="twoWord"
                    size="large"
                    @click="addPost()"
                    >确定</Button
                >
            </div>
        </Modal>
        <!-- 审核 -->
        <Modal class="newModalClass" v-model="checkModal" title="审核">
            <div class="modal_body" style="height: 120px">
                <div class="filter">
                    <label></label>
                    <RadioGroup v-model="checkState">
                        <Radio label="1">通过</Radio>
                        <Radio label="2">不通过</Radio>
                    </RadioGroup>
                </div>
                <div class="filter">
                    <label>{{ $t("1030") }}：</label>
                    <Input
                        type="textarea"
                        v-model="checkremark"
                        class="searchInput MaxWidth"
                        :autosize="{ minRows: 2, maxRows: 2 }"
                    />
                </div>
            </div>
            <div slot="footer">
                <Button type="text" size="large" @click="closeadd()">{{
                    $t("1033")
                }}</Button>
                <Button type="primary" size="large" @click="checkpost()"
                    >确定</Button
                >
            </div>
        </Modal>
        <!-- 反审 -->
        <Modal class="newModalClass" title="反审" v-model="checkback">
            <div class="filter" style="height: 80px">
                <label>{{ $t("1030") }}：</label>
                <Input
                    type="textarea"
                    v-model="backremark"
                    class="searchInput MaxWidth"
                    :autosize="{ minRows: 2, maxRows: 2 }"
                />
            </div>
            <div slot="footer">
                <Button type="text" size="large" @click="closeadd()">{{
                    $t("1033")
                }}</Button>
                <Button type="primary" size="large" @click="backpost()"
                    >确定</Button
                >
            </div>
        </Modal>
        <!-- 打印单 -->
        <Modal
            class="newModalClass"
            title="打印"
            v-model="printModal"
            :styles="{ width: '830px' }"
        >
            <div class="modal_body" style="margin-right: 40px">
                <div id="printTest">
                    <p class="enterTitle">入库单</p>
                    <div class="printDetail">
                        <p>
                            {{ printobj.category }}：{{ printobj.businessname }}
                        </p>
                        <p>联系人：{{ printobj.businessContractUser }}</p>
                        <p>电话：{{ printobj.phone }}</p>
                        <p>入库仓库：{{ printobj.storagename }}</p>
                        <p>单号：{{ printobj.order_number }}</p>
                        <p>原始单号：{{ printobj.origin_order_number }}</p>
                        <p>状态：{{ printobj.stateName }}</p>
                        <p>创建人：{{ printobj.createName }}</p>
                        <p>创建时间:{{ printobj.create_time }}</p>
                        <p>审核人：{{ printobj.checkName }}</p>
                        <p>审核时间：{{ printobj.audit_time }}</p>
                    </div>
                    <div style="border: 1px solid #e9e9e9; margin-top: 10px">
                        <Table :data="printData" :columns="printTable"></Table>
                    </div>
                </div>
            </div>
            <div slot="footer">
                <Button type="text" size="large" @click="closeadd()">{{
                    $t("1033")
                }}</Button>
                <Button
                    type="primary"
                    size="large"
                    v-print="'#printTest'"
                    v-text="$t('100077')"
                    >打印</Button
                >
            </div>
        </Modal>
    </div>
</template>

<script>
import moment from "moment";

export default {
    data() {
        return {
            morecondition: false, // 条件
            name1: "",
            name: "",
            storetype: "",
            typeList: [],
            storeList: [],
            state: "",
            stateList: [],
            orderNum: "",
            originalOrder: "",
            originalOrderList: [],
            index_time: [], // 时间范围
            tableData1: [],
            total: 0,
            page: 1,
            pagesize: 10,
            tableColumns1: [
                {
                    type: "index2",
                    title: this.$t("1008"),
                    key: "xuhao",
                    render: (h, params) => {
                        return h(
                            "span",
                            params.index + (this.page - 1) * this.pagesize + 1
                        );
                    },
                },
                {
                    title: "类型",
                    key: "category",
                },
                {
                    title: "仓库名称",
                    key: "wavehouseName",
                },
                {
                    title: "单号",
                    key: "order_number",
                },
                {
                    title: "来源方",
                    key: "address",
                },
                {
                    title: "创建人",
                    key: "createrName",
                },
                {
                    title: "创建时间",
                    key: "createTime",
                },
                {
                    title: "审核人",
                    key: "checkUser",
                },
                {
                    title: "审核时间",
                    key: "checkTime",
                },
                {
                    title: "审核备注",
                    key: "auditdesc",
                },
                {
                    title: "状态",
                    key: "state",
                },
            ],
            detailobj: {},
            addmodal: false,
            addType: "",
            originalOrder1: "",
            suppliers: [],
            supplierName: "",
            supplier: "",
            pn: "",
            pnList: "",
            count: 0,
            oddBill: "",
            tableData2: [],
            tableColumns2: [
                {
                    title: "单号",
                    key: "order",
                    align: "center",
                },
                {
                    title: "供应商",
                    key: "supplier",
                    align: "center",
                },
                {
                    title: "料号",
                    key: "inventoryid",
                    align: "center",
                },
                {
                    title: "名称",
                    key: "material_name",
                    align: "center",
                },

                {
                    title: "规格",
                    key: "spec",
                    align: "center",
                },

                {
                    title: "数量",
                    key: "quantity",
                    align: "center",
                    render: (h, params) => {
                        return h("InputNumber", {
                            props: {
                                min: 0,
                                value: params.row.quantity,
                            },
                            on: {
                                "on-change": (e) => {
                                    this.tableData2[params.index][
                                        params.column.key
                                    ] = e;

                                    // this.updateData(id, val);
                                },
                            },
                        });
                    },
                },
                {
                    title: "编辑",
                    key: "com",
                    align: "center",
                    render: (h, params) => {
                        return h("div", [
                            h(
                                "p",
                                {
                                    style: {
                                        color: "#2D8CF0",
                                        cursor: "pointer",
                                    },
                                    on: {
                                        click: (row) => {
                                            var arr = [];
                                            for (
                                                let i = 0;
                                                i < this.tableData2.length;
                                                i++
                                            ) {
                                                if (i != params.index) {
                                                    arr.push(
                                                        this.tableData2[i]
                                                    );
                                                }
                                            }
                                            this.tableData2 = arr;
                                            // this.tableData2.push(params.row);
                                        },
                                    },
                                },
                                "删除"
                            ),
                        ]);
                    },
                },
            ],
            mtInfo: {},
            tableData3: [],
            total3: 0,
            page3: 1,
            pagesize3: 10,
            tableColumns3: [
                {
                    type: "index2",
                    title: this.$t("1008"),
                    key: "xuhao",
                    render: (h, params) => {
                        return h(
                            "span",
                            params.index + (this.page3 - 1) * this.pagesize3 + 1
                        );
                    },
                },
                {
                    title: "单号",
                    key: "billCode",
                },
                {
                    title: "供应商",
                    key: "businessName",
                },
                {
                    title: "料号",
                    key: "material_pn",
                },
                {
                    title: "管理模式",
                    key: "manage_modeName",
                },
                {
                    title: "名称",
                    key: "material_name",
                },
                {
                    title: "规格",
                    key: "material_spec",
                },
                {
                    title: "总数量",
                    key: "quantity",
                },
                {
                    title: "入库数量",
                    key: "access_quantity",
                },
            ],
            show: false,
            depart: "",
            departList: [],
            type: 1,
            checkModal: false,
            checkback: false,
            checkState: "",
            checkremark: "",
            backremark: "",
            printModal: false,
            printData: [],
            printTable: [
                {
                    type: "index2",
                    title: this.$t("1008"),
                    key: "xuhao",
                    render: (h, params) => {
                        return h(
                            "span",
                            params.index + (this.page - 1) * this.pagesize + 1
                        );
                    },
                    width: 70,
                },
                {
                    title: "供应商",
                    key: "businessName",
                },
                {
                    title: "料号",
                    key: "material_pn",
                },
                {
                    title: "品名",
                    key: "material_name",
                },
                {
                    title: "规格",
                    key: "material_spec",
                },
                {
                    title: "数量",
                    key: "quantity",
                },
                {
                    title: "单位",
                    key: "unit",
                },
            ],
            printobj: {},
        };
    },
    created() {
        this.tableColumns1 = this.$time.initTableTitle(this.tableColumns1);
        this.tableColumns2 = this.$time.initTableTitle(this.tableColumns2);
        this.tableColumns3 = this.$time.initTableTitle(this.tableColumns3);

        this.index_time = [
            moment(new Date().getTime() - 3600 * 1000 * 24 * 7).format(
                "YYYY-MM-DD "
            ) + "00:00:00",
            moment(new Date().getTime()).format("YYYY-MM-DD ") + "23:59:59",
        ];
        this.initData();
        this.search(1, 10);
    },
    methods: {
        initData() {
            this.getStoreList();
            this.getType();
            this.getState();
            this.getOrderList();
            this.getSupplier();
            // this.getMaterialPn();
            // this.getBill();
        },
        search(page, pagesize) {
            let starttime = this.index_time[0];
            let endtime = this.index_time[1];

            this.page = page;
            this.pagesize = pagesize;
            let data = {
                bill: 1, // 1入库2出库
                waveHouseType: this.storetype,
                waveHouseID: this.name,
                state: this.state,
                billCode: this.orderNum,
                originBillCode: this.originalOrder,
                start: starttime,
                end: endtime,
                page: page,
                pageSize: pagesize,
            };

            this.request("/wms/WaveHousing/GetList", data, "get").then(
                (res) => {
                    if (res.data.ret == 1) {
                        this.total = res.data.total;
                        this.renderTable(res.data.data);
                    }
                }
            );
        },
        renderTable(arr = []) {
            let data = [];
            arr.forEach((item) => {
                data.push({
                    id: item.id,
                    category: item.category, // 类型
                    category_id: item.category_id,
                    wavehouseName: item.wavehouseName,
                    storageID: item.storageID,
                    businessID: item.businessID,
                    businessName: item.businessName,
                    order_number: item.order_number,
                    createrName: item.createrName,
                    createTime: item.createTime,
                    checkUser: item.checkUser,
                    checkTime: item.checkTime,
                    quantity: item.quantity,
                    state: item.state,
                    stateid: item.stateid,
                    auditdesc: item.auditdesc, // 审核备注
                });
            });
            this.tableData1 = data;
        },
        del() {
            if (this.detailobj.id == "" || this.detailobj.id == undefined) {
                this.$Message.error("请先选择入库单");
                return false;
            }
            if (this.detailobj.stateid != 1) {
                this.$Message.error("只有待审核入库单才能删除");
                return false;
            }

            this.$Modal.confirm({
                title: this.$t("1018"),
                content: "",
                width: "290px",
                closable: true,
                okText: this.$t("1004"),
                onOk: () => {
                    let data = {
                        id: this.detailobj.id,
                    };
                    this.request(
                        "/wms/WaveHousing/DeleteBill",
                        data,
                        "post"
                    ).then((res) => {
                        if (res.data.ret == 1) {
                            this.$Message.success(this.$t("1058"));
                            this.tableData1 = this.search(1, this.pagesize);
                            this.show = false;
                            this.detailobj = {};
                            this.search(this.page, this.pagesize);
                        } else {
                            this.$Message.error(this.$t(res.data.msg));
                        }
                    });
                },
            });
        },
        closeadd() {
            this.addmodal = false;
            this.checkModal = false;
            this.checkback = false;
            this.printModal = false;
        },
        add() {
            this.addType = "";
            this.name1 = "";
            this.originalOrder1 = "";
            this.depart = "";
            this.supplier = "";
            this.pn = "";
            this.count = 0;
            this.tableData2 = [];
            this.type = 1;
            this.getBill();
            this.addmodal = true;
        },
        addPost() {
            let arr = [];

            if (this.addType == "" || this.name1 == "") {
                this.$Message.error("请输入必填选项");
                return false;
            }
            if (this.addType == 2) {
                if (this.depart == "") {
                    this.$Message.error("请输入必填选项");
                    return false;
                }
            } else {
                if (this.supplier == "" && this.type != 2) {
                    this.$Message.error("请输入必填选项");
                    return false;
                }
            }
            if (this.tableData2.length == 0) {
                // this.$Message.error("请添加物料");
                this.$Message.error("请添加要新增的物料");
                return false;
            }
            // this.supplier = "";
            // this.pn = "";
            // this.count = "";
            let businessid;
            if (this.addType != 2) {
                businessid = 0;
            } else {
                businessid = this.depart;
            }
            var bool = false;
            this.tableData2.forEach((ele) => {
                var item = {};
                item.InventoryID = ele.pn;
                item.Count = ele.quantity;
                item.businessID = ele.businessID; // 供应商id
                if (ele.quantity < 1) {
                    bool = true;
                }
                arr.push(item);
            });
            if (bool) {
                this.$Message.error("新增的物料数量不能小于1");
                return false;
            }
            // var
            // return;
            let url = "",
                msg = "",
                data = {};
            if (this.type == 1) {
                url = "/wms/WaveHousing/AddBill";
                data = {
                    wavehousingtype: parseInt(this.addType), // 1:原材入库2:生产入库3:其他入库4:生产领料5:销售出货6:其他出库
                    billType: 1, // 1入库2出库
                    rowBillID:
                        this.originalOrder1 == ""
                            ? this.oddBill
                            : this.originalOrder1,
                    billID: this.oddBill,
                    businessid: businessid,
                    waveHouseID: this.name1,
                    inventories: arr,
                };
                msg = "添加成功";
            } else {
                url = "/wms/WaveHousing/UpdateBill";
                data = {
                    billID: this.detailobj.id,
                    inventories: arr,
                };
                msg = "编辑成功";
            }
            // console.log(data);

            this.request(url, data, "post").then((res) => {
                console.log(res.data);
                if (res.data.ret == 1) {
                    this.$Message.success(msg);
                    // this.tableData1 = this.search(this.page, this.pagesize);
                    this.addmodal = false;
                    this.show = false;
                    this.search(1, 10);

                    // this.typeList = res.data.data;
                } else {
                    this.$Message.error(this.$t(res.data.msg));
                }
            });
        },
        edit() {
            if (this.detailobj.id) {
                if (this.detailobj.stateid != "1") {
                    alert("只有待审核入库单才能修改");
                    return false;
                }
                this.addType = "" + this.detailobj.category_id;
                this.name1 = this.detailobj.storageID;
                this.getSupplier();

                this.originalOrder1 = this.detailobj.order_number;
                if (this.addType == 2) {
                    this.depart = this.detailobj.businessID;
                } else {
                    this.supplier = "";
                }

                this.pn = "";
                this.count = 0;
                this.tableData2 = [];
                let data = [];
                this.tableData3.forEach((ele) => {
                    data.push({
                        order: ele.billCode,
                        supplier: ele.businessName,
                        pn: ele.material_id, // 料号id
                        inventoryid: ele.material_pn, // 料号
                        material_name: ele.material_name,
                        spec: ele.material_spec,
                        quantity: ele.quantity,
                        businessID: ele.businessid,
                        id: ele.id,
                    });
                });
                this.tableData2 = data;
                this.type = 2;
                this.addmodal = true;
            } else {
                this.$Message.error("请选择数据");
            }
        },
        // 新增物料
        addMt() {
            // this.tableData2.push(obj);
            if (this.addType == "" || this.name1 == "") {
                this.$Message.error("请输入必填选项");
                return false;
            }
            if (this.addType == 2) {
                if (this.depart == "") {
                    this.$Message.error("请输入必填选项");
                    return false;
                }
            } else {
                if (this.supplier == "" && this.type != 2) {
                    this.$Message.error("请输入必填选项");
                    return false;
                }
            }
            let obj = {
                order:
                    this.originalOrder1 == ""
                        ? this.oddBill
                        : this.originalOrder1,
                supplier: this.addType == 2 ? "" : this.supplierName,
                pn: this.pn,
                inventoryid: this.mtInfo.inventoryid, // 料号
                material_name: this.mtInfo.name,
                spec: this.mtInfo.spec,
                quantity: this.count,
                businessID: this.addType == 2 ? 0 : this.supplier,
            };

            let arr = [];
            console.log(this.pn);
            if (this.tableData2.length > 0) {
                // arr.push(obj);
                for (let i = 0; i < this.tableData2.length; i++) {
                    if (this.addType == 2) {
                        if (this.tableData2[i].pn != this.pn) {
                            arr.push(this.tableData2[i]);
                        }
                    } else {
                        if (
                            this.tableData2[i].pn != this.pn ||
                            this.tableData2[i].supplier != this.supplierName
                        ) {
                            arr.push(this.tableData2[i]);
                        }
                    }
                }
                arr.push(obj);

                this.tableData2 = arr;
            } else {
                console.log(11111111);
                arr.push(obj);
                this.tableData2 = arr;
                // this.tableData2.push(obj);
            }
        },
        getDetail() {
            let data = {
                type: 1, // 入库1 出库2
                billCode: this.detailobj.order_number, // 单号
                dataFilter: 0, // 0获取所有数据，1获取审核数据
                page: this.page3,
                pageSize: this.pagesize3,
            };
            this.request("/wms/Stock/GetBillList", data, "get").then((res) => {
                // console.log(res.data.data);
                if (res.data.ret == 1) {
                    // this.typeList = res.data.data;
                    this.total3 = res.data.total;
                    this.page3 = res.data.page;
                    this.pagesize3 = res.data.pagesize;
                    let arr = res.data.data;
                    let list = [];
                    arr.forEach((item) => {
                        list.push({
                            id: item.id,
                            billCode: item.billCode,
                            material_id: item.material_id,
                            material_name: item.material_name,
                            material_pn: item.material_pn,
                            material_spec: item.material_spec,
                            businessName: item.businessName,
                            businessid: item.businessid,
                            manage_modeName: item.manage_modeName,
                            manage_mode: item.manage_mode,
                            quantity: item.quantity,
                            access_quantity: item.access_quantity,
                            stateid: item.stateid,
                            auditdesc: item.auditdesc, // 审核备注
                        });
                    });
                    this.tableData3 = list;
                }
            });
        },
        handleRowChange(currentRow, oldCurrentRow) {
            this.detailobj = currentRow;
            this.getDetail();
            this.show = true;
            // console.log(this.detailobj);
        },
        handlePageSize(value) {
            this.pagesize = value;
            this.tableData1 = this.search(this.page, this.pagesize);
            this.show = false;
        },
        changePage(value) {
            this.page = value;
            this.tableData1 = this.search(this.page, this.pagesize);
            this.show = false;
        },
        checkShow() {
            if (this.detailobj.id) {
                if (this.detailobj.stateid != 1) {
                    this.$Message.error("只有待审核状态入库单才能审核");
                } else {
                    this.checkState = "1";
                    this.checkremark = "";
                    this.checkModal = true;
                }
            } else {
                this.$Message.error("请先选择入库单");
            }
        },
        checkpost() {
            let data = {
                id: this.detailobj.id,
                pass: this.checkState == "1" ? 1 : 0,
                des: this.checkremark,
            };
            this.request(
                "/wms/wavehousing/CheckWaveHousing",
                data,
                "post"
            ).then((res) => {
                if (res.data.ret == 1) {
                    this.checkModal = false;
                    this.show = false;
                    this.search(1, 10);
                } else {
                    this.$Message.error(this.$t(res.data.msg));
                }
            });
        },
        backShow() {
            if (this.detailobj.id) {
                if (
                    this.detailobj.stateid != 2 &&
                    this.detailobj.stateid != 3
                ) {
                    this.$Message.error("只有已审核入库单才能反审");
                } else {
                    this.backremark = "";
                    this.checkback = true;
                }
            } else {
                this.$Message.error("请先选择入库单");
            }
        },
        backpost() {
            if (this.backremark == "") {
                this.$Message.error("请填写反审备注");
                return false;
            }
            let data = {
                id: this.detailobj.id,
                des: this.backremark,
            };
            this.request(
                "/wms/wavehousing/UnCheckWaveHousing",
                data,
                "post"
            ).then((res) => {
                if (res.data.ret == 1) {
                    this.checkback = false;
                    this.show = false;
                    this.$Message.success(this.$t("1"));
                    this.search(1, 10);
                } else {
                    this.$Message.error(this.$t(res.data.msg));
                }
            });
        },
        printShow() {
            if (this.detailobj.id) {
                if (
                    this.detailobj.stateid != 2 &&
                    this.detailobj.stateid != 4
                ) {
                    this.$Message.error("只有审核通过及入库中的入库单可以打印");
                } else {
                    this.printobj = {};
                    this.GetPrintHtml();
                    this.printModal = true;
                }
            } else {
                this.$Message.error("请先选择入库单");
            }
        },
        GetPrintHtml() {
            let data = {
                billCode: this.detailobj.order_number,
            };
            this.request("/wms/Print/GetBillInfo", data, "get").then((res) => {
                console.log(res.data);
                if (res.data.ret == 1) {
                    // this.checkback = false;
                    // this.show = false;
                    // this.search(1, 10);
                    this.printData = res.data.data.detail;
                    let obj = res.data.data;
                    this.printobj = res.data.data;
                    this.printobj.phone = obj.phone == null ? "" : obj.phone;
                    this.printobj.businessContractUser =
                        obj.businessContractUser == null
                            ? ""
                            : obj.businessContractUser;
                    this.printobj.category =
                        obj.category == "生产入库" ? "部门" : "供应商";
                    // this.renderPrint(res.data.data);
                } else {
                    this.$Message.error(this.$t(res.data.msg));
                }
            });
        },
        // 类型
        getType() {
            let data = {
                cat: "warehousing_type",
                // cat: ""
            };
            this.request("/config/Dict/GetDictByCat", data, "get").then(
                (res) => {
                    // console.log(res.data);
                    if (res.data.ret == 1) {
                        this.typeList = res.data.data;
                    }
                }
            );
        },
        // 仓库名称
        getStoreList() {
            this.request("/wms/WaveHouse/GetWaveHouseNameList", "", "get").then(
                (res) => {
                    if (res.data.ret == 1) {
                        this.storeList = res.data.data;
                    }
                }
            );
        },
        // 状态
        getState() {
            this.request(
                "/wms/WaveHousing/GetWavehousingState",
                "",
                "get"
            ).then((res) => {
                if (res.data.ret == 1) {
                    this.stateList = res.data.data;
                }
            });
        },
        // 原始单号
        getOrderList() {
            this.request(
                "/wms/WaveHousing/GetOriginOrderNumbers?type=1",
                "",
                "get"
            ).then((res) => {
                // console.log(res.data);
                if (res.data.ret == 1) {
                    this.originalOrderList = res.data.data;
                }
            });
        },
        getBill() {
            this.request("/wms/System/GetBillID?data=0", "", "get").then(
                (res) => {
                    // console.log(res.data);
                    if (res.data.ret == 1) {
                        this.oddBill = res.data.data;
                    }
                }
            );
        },
        // 供应商
        getSupplier() {
            let supply = [],
                depart = [];

            if (this.addType == 2) {
                this.getMaterialPn();
                this.request(
                    "/wms/WaveHousing/GetDepartmentList",
                    "",
                    "get"
                ).then((res) => {
                    // console.log(res.data);
                    if (res.data.ret == 1) {
                        this.departList = res.data.data;
                    }
                });
            } else {
                this.request(
                    "/wms/Business/GetSupplierNameList?type=1",
                    "",
                    "get"
                ).then((res) => {
                    if (res.data.ret == 1) {
                        this.suppliers = res.data.data;
                    }
                });
            }
            console.log(this.suppliers);
        },
        // 料号
        getMaterialPn(value) {
            if (value) {
                this.supplier = value.value;
                this.supplierName = value.label;
            }
            console.log(value);
            let businessID;
            businessID = this.supplier;

            if (this.addType == 2) {
                businessID = 0;
            }

            let data = {
                businessID: businessID,
                pn: "",
                count: 50,
            };
            this.request(
                "/wms/Inventory/GetInventoryListByName",
                data,
                "get"
            ).then((res) => {
                if (res.data.ret == 1) {
                    this.pnList = res.data.data;
                }
            });
        },
        remoteMethod1(query) {
            if (query !== "") {
                // this.loading1 = true;
                setTimeout(() => {
                    let data = {
                        businessID: this.supplier,
                        pn: query,
                        count: 50,
                    };
                    this.request(
                        "/wms/Inventory/GetInventoryListByName",
                        data,
                        "get"
                    ).then((res) => {
                        if (res.data.ret == 1) {
                            this.pnList = res.data.data;
                        }
                    });
                }, 200);
            } else {
                this.pnList = [];
            }
        },
        getMt(value) {
            // console.log(value);
            let pn;
            if (value) {
                pn = value.label;
            }

            let type_value;
            if (this.addType == 2) {
                type_value = 0;
            } else {
                type_value = this.supplier;
            }
            var data = {
                pn: pn,
                storage: "", // 入库不考虑仓库信息
                businessid: type_value,
            };
            this.request("/wms/WaveHousing/GetInventoryInfo", data, "get").then(
                (res) => {
                    console.log(res.data);
                    if (res.data.ret == 1) {
                        this.mtInfo = res.data.data;
                    }
                }
            );
        },
        request(url, data, type) {
            if (type == "get") {
                return this.axios
                    .request({
                        url: url,
                        params: data,
                        method: type,
                    })
                    .then((res) => {
                        return res;
                    })
                    .catch((error) => error);
            } else {
                return this.axios
                    .request({
                        url: url,
                        data,
                        method: type,
                    })
                    .then((res) => {
                        return res;
                    })
                    .catch((error) => error);
            }
        },
    },
};
</script>

<style scoped>
.row {
    display: flex;

    align-items: center;
}
.row .filter {
    line-height: 40px;
}
.row .filter label {
    width: 80px;
}
.printDetail {
    /* width: 880px; */
    display: flex;
    flex-wrap: wrap;
    /* justify-content: space-between; */
}
.printDetail p {
    width: 33.3%;
    height: 30px;
    line-height: 30px;
}
.enterTitle {
    font-size: 25px;
    text-align: center;
}
#printTest {
    border: 1px solid #e9e9e9;
    padding: 10px;
}
</style>
