<template>
    <div>
        <div class="divborder">
            <div
                style="
                    display: flex;
                    align-items: center;
                    height: 40px;
                    line-height: 40px;
                    padding-left: 20px;
                "
            >
                <label style="width: 120px">批次单补印--批次：</label>
                <Input
                    type="text"
                    placeholder="请输入批次号"
                    style="width: 200px"
                    v-model="batch"
                />
                <div style="margin: 0 10px">
                    <Button
                        type="primary"
                        class="twoWord"
                        icon="ios-cloud-download"
                        @click="getPrintData(batch, 1)"
                        >补印</Button
                    >
                </div>
            </div>
        </div>
        <div class="divborder">
            <div
                style="
                    display: flex;
                    align-items: center;
                    height: 40px;
                    line-height: 40px;
                    padding-left: 20px;
                "
            >
                <label style="width: 120px">序号补印--序号：</label>
                <Input
                    type="text"
                    placeholder="请输入序号"
                    style="width: 200px"
                    v-model="sn"
                />
                <div style="margin: 0 10px">
                    <Button
                        type="primary"
                        class="twoWord"
                        icon="ios-cloud-download"
                        @click="getPrintData(sn, 2)"
                        >补印</Button
                    >
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            batch: "",
            sn: "",
        };
    },
    created() {},
    methods: {
        getPrintData(code, type) {
            if(!code){
                let msg = type==1?'请输入批次号':'请输入序号'
                this.$Message.error(msg);
                return false
            }
            let params = {
                value: code,
                type: type,
            };
            this.axios
                .request({
                    url: "/wms/Stock/GetQRInfo",
                    params,
                    method: "get",
                })
                .then((res) => {
                    console.log(res.data);
                    if (res.data.ret == 1) {
                        this.printData(res.data.data,code,type)
                    }else{
                        this.$Message.error(this.$t(res.data.msg))
                    }
                });
        },
        printData(res, material_num, num) {
            var data = [];
            $.each(res, function (i, ele) {
                var arr = {};
                var arr1 = [];
                // if(num==1)
                // {
                //     arr1.push("批次："+ele.code);
                // }
                // else
                // {
                //     arr1.push("序号："+ele.code);
                // }

                arr1.push(ele.material_name);
                arr1.push(material_num);
                arr1.push(ele.time);

                arr.serinum = ele.code;
                arr.columns = arr1;
                data.push(arr);
            });
            var dataArray = {
                type: num,
                data: data,
            };
            // console.log(dataArray);
            this.LaunchApp(JSON.stringify(dataArray),true);
        },
        //打印
        LaunchApp(data,ret) {
            try {
                // var ret = confirm("调用打印机？");
                if (ret == true) {
                    // console.log(11111111);
                    // console.log("myapp://" + data);
                    // console.log(data);
                    window.location = "myapp://" + data;
                    this.preview = false;
                }
            } catch (ex) {
                // console.log(ex);
                let errMsg = '';
                errMsg = "启动 myapp 报错.\n\n";
                this.$Message.error(errMsg);
            }
            return;
        },
    },
};
</script>

<style>
</style>