import { request } from '../../src';

const res = 'MovePlan';

export default {
    submit(movePlan, movePlanItems) {
        return request({
            url: `api/${res}/submit`,
            method: 'post',
            data: {
                movePlan,
                movePlanItems
            }
        });
    },
    getPrint(id) {
        return request({
            url: `api/${res}/print`,
            method: 'get',
            params: { id: JSON.stringify(id) }
        });
    },
    async print(id, isAuto) {
        let model = await this.getPrint(id);
        console.log(model);
        try {
            var LODOP = getLodop();
        } catch (e) {
            alert('请检查打印驱动！' + e.message);
            return;
        }
        //这个语句设置网络共享打印机连接不通时是否提示一下
        LODOP.SET_PRINT_MODE('TRYLINKPRINTER_NOALERT', true);

        for (let index = 0; index < model.length; index++) {
            const item = model[index];
            if (!index == 0) {
                LODOP.NewPageA();
            }

            LODOP.ADD_PRINT_HTM(item.top, item.left, item.width, item.height, item.content);
            if (item.pageWidth != null && item.pageHeight != null) {
                LODOP.SET_PRINT_PAGESIZE(2, item.pageWidth, item.pageHeight, item.pageName);
                // LODOP.SET_PRINT_PAGESIZE(model.orient, model.pageWidth, model.pageHeight, model.pageName);
                LODOP.SET_SHOW_MODE('LANDSCAPE_DEFROTATED', 1);
            }
        }

        LODOP.SET_PRINT_STYLEA(0, 'TableHeightScope', 1);
        LODOP.PREVIEW();

        // if (isAuto) {
        //     //这里指定第-1号打印机打印
        //     if (LODOP.SET_PRINTER_INDEX(-1)) {
        //         LODOP.PRINT();
        //     }
        // } else if (model.IsPreview) {
        //     //这里指定第-1号打印机打印
        //     if (LODOP.SET_PRINTER_INDEX(-1)) {
        //         LODOP.PREVIEW();
        //     }
        // } else {
        //     //这里指定第-1号打印机打印
        //     if (LODOP.SET_PRINTER_INDEX(-1)) {
        //         LODOP.PRINT();
        //     }
        // }
    }
};
