<template>
    <uni-popup v-model="printerList!.visible">
        {{printerList}}
        <uni-popup-dialog ref="inputClose" mode="input" title="输入内容" value="对话框预置提示内容!" placeholder="请输入内容" @confirm="dialogInputConfirm">
            <!-- <template #default>
                <text class="title">
                    {{ printerList.title }}
                    <text class="ml-2">{{ printerList?.postData?.order_no }}</text>
                </text>
            </template> -->
            <!-- <view v-if="printerList">
                <uni-data-checkbox multiple v-model="downloadFile" :disabled="true" :localdata=" [{
                    text: '下载文件',
                    value: 1
                }]">></uni-data-checkbox>

                <view><el-checkbox label="下载文件" v-model="downloadFile" :disabled="true"></el-checkbox></view>
                <view class="ml-4">
                            <view>
                        <el-checkbox label="发送到标签打印机打印" v-model="sendToPeinter" @change="sendToPeinterFun"></el-checkbox>
                    </view>
                    <el-radio-group v-model="printer_code">
                        <el-radio v-for="(item, i) in printerList.printers as any" :key="i" :label="item.value">{{ item.name }}</el-radio>
                    </el-radio-group>
                </view>
            </view> -->
        </uni-popup-dialog>

        <!-- <template #footer>
            <div>
                <el-button @click="printerList.visible = false">{{ t('Cancel') }}</el-button>
                <el-button :loading="submitLoading" @click="toPrint()" type="primary" v-blur>
                    {{ '打印' }}
                </el-button>
            </div>
        </template> -->
    </uni-popup>
</template>
<script setup lang="ts">
import { inject, ref } from 'vue';
import { printWaybillLabelURL } from '../../../utils/api';
const printerList = inject('printerList') as any;
const printer_code = ref('');
const submitLoading = ref(false);
const downloadFile = ref(true);
const sendToPeinter = ref(true);
const sendToPeinterFun = () => {
    if (!sendToPeinter.value) {
        printer_code.value = '';
    } else {
        printer_code.value = Object.keys(printerList.value.printers)[0];
    }
};
const dialogInputConfirm = () => {
    printerList.value && (printer_code.value = Object.keys(printerList.value.printers)[0]);
};
const openPrinterSelect = () => {
    printerList.value && (printer_code.value = Object.keys(printerList.value.printers)[0]);
};
const toPrint = async () => {
    const { batoken, postData, resetForm } = printerList.value;
    /*
    const loading = ElLoading.service({
        lock: true,
        text: 'Loading',
        background: 'rgba(0, 0, 0, 0.7)',
    })
    */
    submitLoading.value = true;
    uni.request({
        url: printWaybillLabelURL,
        method: 'POST',
        header: {
            batoken: batoken
        },
        data: {
            ...postData,
            printer_code: printer_code.value
        },
        success: (res) => {
            console.log(res);
        }
    });
    /*
    await postPrint({
        ...postData,
        printer_code: printer_code.value
    })
        .then((res: any) => {
            //loading.close()
            const list = res.data?.label_path || res.data?.labels || (res.data?.express_label ? [res.data?.express_label] : []);
            if (list.length === 0) {
                // ElMessage.error('没有可打印的文件');
                return;
            }

            list.map((url: string) => {
                let path = fullUrl(url);
                window.open(path, '_blank');
            });
            submitLoading.value = false;
            printerList.value.visible = false;
            resetForm();
        })
        .catch((error: any) => {
            console.log('error--', error);
            //loading.close()
            submitLoading.value = false;
        });
        */
};
</script>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
    name: 'printer-list-scan',
})
</script>
<style scoped lang="scss"></style>
