<template>
	<view>
		<radio-group @change="radioChange">
			<label class="uni-list-cell uni-list-cell-pd">
				<label class="radio">
					<radio value="rbBT2" checked="true" />BT2.0
				</label>
				<uni-data-select v-model="udsBT2Value" :localdata="udsBT2Range"></uni-data-select>
			</label>
			<label class="uni-list-cell uni-list-cell-pd">
				<label class="radio">
					<radio value="rbNET" />NET
				</label>
				<uni-data-select v-model="udsNETValue" :localdata="udsNETRange"></uni-data-select>
			</label>
			<label class="uni-list-cell uni-list-cell-pd">
				<label class="radio">
					<radio value="rbUSB" />USB
				</label>
				<uni-data-select v-model="udsUSBValue" :localdata="udsUSBRange"></uni-data-select>
			</label>
			<label class="uni-list-cell uni-list-cell-pd">
				<label class="radio">
					<radio value="rbCOM" />COM
				</label>
				<uni-data-select v-model="udsCOMValue" :localdata="udsCOMRange"></uni-data-select>
				<uni-data-select v-model="udsCOMBaudrateValue" :localdata="udsCOMBaudrateRange"></uni-data-select>
				<uni-data-select v-model="udsCOMFlowControlValue" :localdata="udsCOMFlowControlRange"></uni-data-select>
			</label>
		</radio-group>

		<view class="uni-flex uni-row">
			<button type="default" @click="enumPort">Enum Port</button>
			<button type="default" @click="openPort" :disabled="btnOpenPortDisabled">Open Port</button>
			<button type="default" @click="closePort" :disabled="btnClosePortDisabled">Close Port</button>
		</view>

		<view>
			<button type="primary" @click="Test_Label_SampleTicket_58MM_1">Test_Label_SampleTicket_58MM_1</button>
			<button type="primary" @click="Test_Label_SampleTicket_80MM_1">Test_Label_SampleTicket_80MM_1</button>

			<button type="primary" @click="GetPrinterResolutionInfo">GetPrinterResolutionInfo</button>
			<button type="primary" @click="GetPrinterFirmwareVersion">GetPrinterFirmwareVersion</button>
			<button type="primary" @click="GetPrinterStatusInfo">GetPrinterStatusInfo</button>

			<button type="primary" @click="CP_Pos_KickOutDrawer">CP_Pos_KickOutDrawer</button>
			<button type="primary" @click="CP_Pos_Beep">CP_Pos_Beep</button>
			<button type="primary" @click="CP_Pos_PrintSelfTestPage">CP_Pos_PrintSelfTestPage</button>
			<button type="primary" @click="CP_Pos_ResetPrinter">CP_Pos_ResetPrinter</button>
			<button type="primary" @click="CP_Pos_SetPrintSpeed_100">CP_Pos_SetPrintSpeed_100</button>
			<button type="primary" @click="CP_Pos_SetPrintSpeed_150">CP_Pos_SetPrintSpeed_150</button>
			<button type="primary" @click="CP_Pos_SetPrintDensity_7">CP_Pos_SetPrintDensity_7</button>
			<button type="primary" @click="CP_Pos_SetPrintDensity_15">CP_Pos_SetPrintDensity_15</button>

			<button type="primary" @click="CP_Label_EnableLabelMode">CP_Label_EnableLabelMode</button>
			<button type="primary" @click="CP_Label_DisableLabelMode">CP_Label_DisableLabelMode</button>
			<button type="primary" @click="CP_Label_CalibrateLabel">CP_Label_CalibrateLabel</button>
			<button type="primary" @click="CP_Label_FeedLabel">CP_Label_FeedLabel</button>
			<button type="primary" @click="CP_Label_PageBegin">CP_Label_PageBegin</button>
			<button type="primary" @click="CP_Label_PagePrint">CP_Label_PagePrint</button>
			<button type="primary" @click="CP_Label_DrawText">CP_Label_DrawText</button>
			<button type="primary" @click="CP_Label_DrawTextInUTF8">CP_Label_DrawTextInUTF8</button>
			<button type="primary" @click="CP_Label_DrawTextInGBK">CP_Label_DrawTextInGBK</button>
			<button type="primary" @click="CP_Label_DrawBarcode">CP_Label_DrawBarcode</button>
			<button type="primary" @click="CP_Label_DrawQRCode">CP_Label_DrawQRCode</button>
			<button type="primary" @click="CP_Label_DrawPDF417Code">CP_Label_DrawPDF417Code</button>
			<button type="primary" @click="CP_Label_DrawImageFromFile">CP_Label_DrawImageFromFile</button>
			<button type="primary" @click="CP_Label_DrawImageFromPixels">CP_Label_DrawImageFromPixels</button>
			<button type="primary" @click="CP_Label_DrawLine">CP_Label_DrawLine</button>
			<button type="primary" @click="CP_Label_DrawRect">CP_Label_DrawRect</button>
			<button type="primary" @click="CP_Label_DrawBox">CP_Label_DrawBox</button>
		</view>

	</view>

</template>


<script>
	const modal = uni.requireNativePlugin('modal');

	var AutoReplyPrintUniModule = uni.requireNativePlugin("AutoReplyPrintUniModule");
	var hPrinter = 0;
	var isEnumeratingBT2 = false;
	var isEnumeratingNET = false;
	var selectedPortType = 'rbBT2';

	export default {
		data() {
			return {
				udsBT2Value: 0,
				udsBT2Range: [],

				udsNETValue: 0,
				udsNETRange: [],

				udsUSBValue: 0,
				udsUSBRange: [],

				udsCOMValue: 0,
				udsCOMRange: [],
				udsCOMBaudrateValue: 9600,
				udsCOMBaudrateRange: [{
						text: '9600',
						value: 9600
					},
					{
						text: '19200',
						value: 19200
					},
					{
						text: '38400',
						value: 38400
					},
					{
						text: '57600',
						value: 57600
					},
					{
						text: '115200',
						value: 115200
					},
					{
						text: '230400',
						value: 230400
					},
					{
						text: '256000',
						value: 256000
					},
					{
						text: '500000',
						value: 500000
					},
				],
				udsCOMFlowControlValue: 0,
				udsCOMFlowControlRange: [{
						text: 'NoFlowControl',
						value: 0
					},
					{
						text: 'Hardware',
						value: 2
					},
				],

				btnOpenPortDisabled: false,
				btnClosePortDisabled: true,
			}
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: 'SampleLabel ' + AutoReplyPrintUniModule.CP_Library_Version()
			});
		},
		onReady() {
			//要做到第一次进入界面的时候，自动搜索一次。这样用不行。
			//enumPort();
		},
		methods: {
			radioChange: function(evt) {
				selectedPortType = evt.detail.value;
			},
			enumPort() {
				var newComRange = new Array();
				var comNameList = AutoReplyPrintUniModule.CP_Port_EnumCom();
				if (comNameList != null) {
					for (var i = 0; i < comNameList.length; i++) {
						var tmp = {
							text: comNameList[i],
							value: i
						};
						console.log(tmp);
						newComRange.push(tmp);
					}
				}
				this.udsCOMRange = newComRange;

				var newUsbRange = new Array();
				var usbNameList = AutoReplyPrintUniModule.CP_Port_EnumUsb();
				if (usbNameList != null) {
					for (var i = 0; i < usbNameList.length; i++) {
						var tmp = {
							text: usbNameList[i],
							value: i
						};
						console.log(tmp);
						newUsbRange.push(tmp);
					}
				}
				this.udsUSBRange = newUsbRange;

				if (!isEnumeratingBT2) {
					isEnumeratingBT2 = true;
					console.log('isEnumeratingBT2');
					AutoReplyPrintUniModule.CP_Port_EnumBtDevice(
						12000,
						(ret) => {
							//console.log(ret);
							var text = ret.device_address + '(' + ret.device_name + ')';
							for (var i = 0; i < this.udsBT2Range.length; i++) {
								if (this.udsBT2Range[i].text == text) {
									return;
								}
							}
							var tmp = {
								text: text,
								value: this.udsBT2Range.length
							};
							console.log(tmp);
							this.udsBT2Range.push(tmp);
						},
						(ret) => {
							isEnumeratingBT2 = false;
							console.log('finishedEnumeratingBT2');
						}
					);
				}

				if (!isEnumeratingNET) {
					isEnumeratingNET = true;
					console.log('isEnumeratingNET');
					AutoReplyPrintUniModule.CP_Port_EnumNetPrinter(
						12000,
						(ret) => {
							//console.log(ret);
							var text = ret.discovered_ip + '(' + ret.discovered_name + ')';
							for (var i = 0; i < this.udsNETRange.length; i++) {
								if (this.udsNETRange[i].text == text) {
									return;
								}
							}
							var tmp = {
								text: text,
								value: this.udsNETRange.length
							};
							console.log(tmp);
							this.udsNETRange.push(tmp);
						},
						(ret) => {
							isEnumeratingNET = false;
							console.log('finishedEnumeratingNET');
						}
					);
				}

			},
			openPort() {
				if (hPrinter == 0) {
					if (selectedPortType == 'rbBT2') {
						var text = this.udsBT2Range[this.udsBT2Value].text;
						var btAddress = text.substring(0, text.indexOf('('));
						modal.toast({
							message: 'Connecting: ' + btAddress + ' ......',
							duration: 1.5
						});
						console.log('Connecting: ' + btAddress + ' ......');
						hPrinter = AutoReplyPrintUniModule.CP_Port_OpenBtSpp(btAddress, 1);
						console.log('hPrinter: ' + hPrinter);
					} else if (selectedPortType == 'rbNET') {
						var text = this.udsNETRange[this.udsNETValue].text;
						var ipAddress = text.substring(0, text.indexOf('('));
						modal.toast({
							message: 'Connecting: ' + ipAddress + ' ......',
							duration: 1.5
						});
						console.log('Connecting: ' + ipAddress + ' ......');
						hPrinter = AutoReplyPrintUniModule.CP_Port_OpenTcp(null, ipAddress, 9100, 5000, 1);
						console.log('hPrinter: ' + hPrinter);
					} else if (selectedPortType == 'rbUSB') {
						var usbName = this.udsUSBRange[this.udsUSBValue].text;
						modal.toast({
							message: 'Connecting: ' + usbName + ' ......',
							duration: 1.5
						});
						console.log('Connecting: ' + usbName + ' ......');
						hPrinter = AutoReplyPrintUniModule.CP_Port_OpenUsb(usbName, 1);
						console.log('hPrinter: ' + hPrinter);
					} else if (selectedPortType == 'rbCOM') {
						var comName = this.udsCOMRange[this.udsCOMValue].text;
						var comBaudrate = this.udsCOMBaudrateValue;
						var comFlowControl = this.udsCOMFlowControlValue;
						modal.toast({
							message: 'Connecting: ' + comName + ',' + comBaudrate + ',' + comFlowControl +
								' ......',
							duration: 1.5
						});
						console.log('Connecting: ' + comName + ',' + comBaudrate + ',' + comFlowControl + '......');
						hPrinter = AutoReplyPrintUniModule.CP_Port_OpenCom(comName, comBaudrate, 8, 0, 0, comFlowControl,
							1);
						console.log('hPrinter: ' + hPrinter);
					}
					modal.toast({
						message: (hPrinter != 0) ? 'Connected' : 'Failed',
						duration: 1.5
					});
				}
				this.btnOpenPortDisabled = (hPrinter != 0);
				this.btnClosePortDisabled = (hPrinter == 0);
			},
			closePort() {
				if (hPrinter != 0) {
					AutoReplyPrintUniModule.CP_Port_Close(hPrinter);
					hPrinter = 0;
				}
				this.btnOpenPortDisabled = (hPrinter != 0);
				this.btnClosePortDisabled = (hPrinter == 0);
			},

			Test_Label_SampleTicket_58MM_1() {
				AutoReplyPrintUniModule.CP_Pos_SetMultiByteMode(hPrinter);
				AutoReplyPrintUniModule.CP_Pos_SetMultiByteEncoding(hPrinter, 1);

				AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 240, 0);
				AutoReplyPrintUniModule.CP_Label_DrawText(hPrinter, 10, 10, 24, 0, "型号：P58A+");
				AutoReplyPrintUniModule.CP_Label_DrawText(hPrinter, 10, 40, 24, 0, "MFG ：00");
				AutoReplyPrintUniModule.CP_Label_DrawBarcode(hPrinter, 10, 70, 8, 2, 60, 2, 0, "No.123456");
				AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
				//AutoReplyPrintUniModule.CP_Pos_HalfCutPaper(hPrinter);
				//AutoReplyPrintUniModule.CP_Pos_FullCutPaper(hPrinter);

				var printResult = AutoReplyPrintUniModule.CP_Pos_QueryPrintResult(hPrinter, 10000);
				modal.toast({
					message: printResult ? 'Print Success' : 'Print Failed',
					duration: 1.5
				});
			},
			Test_Label_SampleTicket_80MM_1() {
				AutoReplyPrintUniModule.CP_Pos_SetMultiByteMode(hPrinter);
				AutoReplyPrintUniModule.CP_Pos_SetMultiByteEncoding(hPrinter, 1);

				AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 576, 240, 0);
				AutoReplyPrintUniModule.CP_Label_DrawText(hPrinter, 10, 10, 24, 0, "型号：P80A+");
				AutoReplyPrintUniModule.CP_Label_DrawText(hPrinter, 10, 40, 24, 0, "MFG ：00");
				AutoReplyPrintUniModule.CP_Label_DrawBarcode(hPrinter, 10, 70, 8, 2, 60, 4, 0, "No.123456");
				AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
				//AutoReplyPrintUniModule.CP_Pos_HalfCutPaper(hPrinter);
				//AutoReplyPrintUniModule.CP_Pos_FullCutPaper(hPrinter);

				var printResult = AutoReplyPrintUniModule.CP_Pos_QueryPrintResult(hPrinter, 10000);
				modal.toast({
					message: printResult ? 'Print Success' : 'Print Failed',
					duration: 1.5
				});
			},

			GetPrinterResolutionInfo() {
				var ret = AutoReplyPrintUniModule.CP_Printer_GetPrinterResolutionInfo(hPrinter);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			GetPrinterFirmwareVersion() {
				var ret = AutoReplyPrintUniModule.CP_Printer_GetPrinterFirmwareVersion(hPrinter);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			GetPrinterStatusInfo() {
				var ret = AutoReplyPrintUniModule.CP_Printer_GetPrinterStatusInfo(hPrinter);
				var status_time = new Date(ret.timestamp_ms);
				var printer_error_status = ret.printer_error_status;

				var status_str = '';
				if (printer_error_status != 0) {
					status_str += 'ERROR_OCCURED\n'; //错误状态非零表示出错了

					if ((printer_error_status & 0x01) != 0) {
						status_str += 'ERROR_CUTTER\n'; //（切刀出错）
					}
					if ((printer_error_status & 0x02) != 0) {
						status_str += 'ERROR_FLASH\n'; //（FLASH 异常）
					}
					if ((printer_error_status & 0x04) != 0) {
						status_str += 'ERROR_NOPAPER\n'; //（缺纸）
					}
					if ((printer_error_status & 0x08) != 0) {
						status_str += 'ERROR_VOLTAGE\n'; //（电压异常）
					}
					if ((printer_error_status & 0x10) != 0) {
						status_str += 'ERROR_MARKER\n'; //（缝标或黑标定位异常）
					}
					if ((printer_error_status & 0x20) != 0) {
						status_str += 'ERROR_ENGINE\n'; //（机芯异常）
					}
					if ((printer_error_status & 0x40) != 0) {
						status_str += 'ERROR_OVERHEAT\n'; //（过热）
					}
					if ((printer_error_status & 0x80) != 0) {
						status_str += 'ERROR_COVERUP\n'; //（纸仓盖被打开了）
					}
					if ((printer_error_status & 0x100) != 0) {
						status_str += 'ERROR_MOTOR\n'; //（马达异常）
					}
				} else {
					status_str += 'Status OK\n';
				}

				modal.toast({
					message: '' + status_time + '\n' + status_str,
					duration: 1.5
				});
			},

			CP_Pos_KickOutDrawer() {
				var ret = AutoReplyPrintUniModule.CP_Pos_KickOutDrawer(hPrinter, 0, 100, 100);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Pos_Beep() {
				var ret = AutoReplyPrintUniModule.CP_Pos_Beep(hPrinter, 3, 500);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Pos_PrintSelfTestPage() {
				var ret = AutoReplyPrintUniModule.CP_Pos_PrintSelfTestPage(hPrinter);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Pos_ResetPrinter() {
				var ret = AutoReplyPrintUniModule.CP_Pos_ResetPrinter(hPrinter);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Pos_SetPrintSpeed_100() {
				var ret = AutoReplyPrintUniModule.CP_Pos_SetPrintSpeed(hPrinter, 100);
				AutoReplyPrintUniModule.CP_Pos_PrintSelfTestPage(hPrinter);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Pos_SetPrintSpeed_150() {
				var ret = AutoReplyPrintUniModule.CP_Pos_SetPrintSpeed(hPrinter, 150);
				AutoReplyPrintUniModule.CP_Pos_PrintSelfTestPage(hPrinter);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Pos_SetPrintDensity_7() {
				var ret = AutoReplyPrintUniModule.CP_Pos_SetPrintDensity(hPrinter, 7);
				AutoReplyPrintUniModule.CP_Pos_PrintSelfTestPage(hPrinter);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Pos_SetPrintDensity_15() {
				var ret = AutoReplyPrintUniModule.CP_Pos_SetPrintDensity(hPrinter, 15);
				AutoReplyPrintUniModule.CP_Pos_PrintSelfTestPage(hPrinter);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},

			CP_Label_EnableLabelMode() {
				var ret = AutoReplyPrintUniModule.CP_Label_EnableLabelMode(hPrinter);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Label_DisableLabelMode() {
				var ret = AutoReplyPrintUniModule.CP_Label_DisableLabelMode(hPrinter);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Label_CalibrateLabel() {
				var ret = AutoReplyPrintUniModule.CP_Label_CalibrateLabel(hPrinter);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Label_FeedLabel() {
				var ret = AutoReplyPrintUniModule.CP_Label_FeedLabel(hPrinter);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Label_PageBegin() {
				var ret = AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
				AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
				AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Label_PagePrint() {
				AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
				AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
				var ret = AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Label_DrawText() {
				var str = "$$$123哈哈哈";
				AutoReplyPrintUniModule.CP_Pos_SetMultiByteMode(hPrinter);
				AutoReplyPrintUniModule.CP_Pos_SetMultiByteEncoding(hPrinter, 1);

				AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
				AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
				var ret = AutoReplyPrintUniModule.CP_Label_DrawText(hPrinter, 10, 10, 24, 0, str);
				AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Label_DrawTextInUTF8() {
				var str = "$$$123哈哈哈";
				AutoReplyPrintUniModule.CP_Pos_SetMultiByteMode(hPrinter);
				AutoReplyPrintUniModule.CP_Pos_SetMultiByteEncoding(hPrinter, 1);

				AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
				AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
				var ret = AutoReplyPrintUniModule.CP_Label_DrawTextInUTF8(hPrinter, 10, 10, 24, 0, str);
				AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Label_DrawTextInGBK() {
				var str = "$$$123哈哈哈";
				AutoReplyPrintUniModule.CP_Pos_SetMultiByteMode(hPrinter);
				AutoReplyPrintUniModule.CP_Pos_SetMultiByteEncoding(hPrinter, 0);

				AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
				AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
				var ret = AutoReplyPrintUniModule.CP_Label_DrawTextInGBK(hPrinter, 10, 10, 24, 0, str);
				AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Label_DrawBarcode() {
				var str = "01234567890";

				AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
				AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);

				var ret = AutoReplyPrintUniModule.CP_Label_DrawBarcode(hPrinter, 10, 10, 0, 2, 60, 2, 0, str);

				AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Label_DrawQRCode() {
				var str = "Hello 你好";

				AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
				AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);

				var ret = AutoReplyPrintUniModule.CP_Label_DrawQRCode(hPrinter, 10, 10, 0, 1, 8, 0, str);

				AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Label_DrawPDF417Code() {
				var str = "Hello 你好";

				AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
				AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);

				var ret = AutoReplyPrintUniModule.CP_Label_DrawPDF417Code(hPrinter, 10, 10, 3, 3, 0, 3, 0, str);

				AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Label_DrawImageFromFile() {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
						AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
						var ret = AutoReplyPrintUniModule.CP_Label_DrawImageFromFile(hPrinter, 0, 0, 384, 0,
							res.tempFilePaths[0], 2, 0);
						AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
						modal.toast({
							message: ret,
							duration: 1.5
						});
					}
				});
			},
			CP_Label_DrawImageFromPixels() {
				var image_width = 100;
				var image_height = 100;
				var image_pixels_array = new Uint8Array(image_width * image_height * 4);
				for (let y = 0; y < image_height; ++y) {
					for (let x = 0; x < image_width; ++x) {
						var offset = y * image_width * 4 + x * 4;
						if (x == y) {
							image_pixels_array[offset] = 0x00;
							image_pixels_array[offset + 1] = 0x00;
							image_pixels_array[offset + 2] = 0x00;
							image_pixels_array[offset + 3] = 0xff;
						} else {
							image_pixels_array[offset] = 0xff;
							image_pixels_array[offset + 1] = 0xff;
							image_pixels_array[offset + 2] = 0xff;
							image_pixels_array[offset + 3] = 0xff;
						}
					}
				}
				var image_pixels_base64 = uni.arrayBufferToBase64(image_pixels_array);

				AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
				AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
				var ret = AutoReplyPrintUniModule.CP_Label_DrawImageFromPixels(hPrinter, 0, 0, image_pixels_base64,
					image_width, image_height, image_width * 4, 7, 2, 0);
				AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);

				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Label_DrawLine() {
				AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
				AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
				var ret = AutoReplyPrintUniModule.CP_Label_DrawLine(hPrinter, 20, 20, 100, 300, 1, 1);
				AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Label_DrawRect() {
				AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
				AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
				var ret = AutoReplyPrintUniModule.CP_Label_DrawRect(hPrinter, 20, 20, 200, 10, 1);
				AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			CP_Label_DrawBox() {
				AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
				AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
				var ret = AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 30, 30, 300, 200, 1, 1);
				AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
		}
	}
</script>


<style>

</style>