diff --git a/pages/components/bluetooth/bluetooth.axml b/pages/components/bluetooth/bluetooth.axml
index 80b4837..e0d2491 100644
--- a/pages/components/bluetooth/bluetooth.axml
+++ b/pages/components/bluetooth/bluetooth.axml
@@ -7,8 +7,8 @@
{{selectedDevice.name}}
- {{discovering}}
- {{available}}
+
@@ -40,6 +40,7 @@
+
diff --git a/pages/components/bluetooth/bluetooth.js b/pages/components/bluetooth/bluetooth.js
index e589c58..a61a83c 100644
--- a/pages/components/bluetooth/bluetooth.js
+++ b/pages/components/bluetooth/bluetooth.js
@@ -2,7 +2,8 @@ Component({
mixins: [],
data: {
printdata: {},
- array: ['TSPL', 'ZPL', 'CPCL', 'ESC/POS'],
+ percent: '0',
+ array: ['TSPL', 'ZPL 待开发', 'CPCL 待开发', 'ESC/POS 待开发'],
index: 0,
// 初始化蓝牙的开关状态,false 表示关闭,true 表示打开
switchswitchopenBluetoothAdapter: false,
@@ -81,6 +82,197 @@ Component({
}
},
methods: {
+ onSubmit() {
+ const selectedDevice = this.data.selectedDevice;
+ console.log('selectedDevice', selectedDevice);
+ const isConnected = this.data.isConnected;
+ // 检查蓝牙设备是否已连接
+ if (!selectedDevice || !isConnected) {
+ console.log('请先连接蓝牙设备');
+ const title = '请先连接蓝牙设备';
+ if (title) {
+ dd.showToast({
+ title,
+ icon: 'none'
+ });
+ }
+ return;
+ }
+
+ // 从可写特征值列表中获取第一个可写特征值(这里假设只有一个可写特征值,你可以根据实际情况调整)
+ const writableCharacteristic = this.data.writableCharacteristics[0];
+ console.log('writableCharacteristics', this.data.writableCharacteristics);
+ if (!writableCharacteristic) {
+ console.log('未找到可写特征值');
+ const title = '未找到可写特征值';
+ if (title) {
+ dd.showToast({
+ title,
+ icon: 'none'
+ });
+ }
+ return;
+ }
+
+ const serviceId = writableCharacteristic.serviceId;
+ const characteristicId = writableCharacteristic.characteristicId;
+ const deviceId = selectedDevice.deviceId;
+
+ // 检查参数完整性
+ if (!deviceId || !serviceId || !characteristicId) {
+ console.error('缺少必要参数:', {
+ deviceId,
+ serviceId,
+ characteristicId
+ });
+ const title = '缺少必要参数,请检查连接';
+ if (title) {
+ dd.showToast({
+ title,
+ icon: 'none'
+ });
+ }
+ return;
+ }
+ //打印数据处理
+ const selectedSaleOrderLines = dd.getStorageSync({
+ key: 'selectedSaleOrderLines'
+ }).data;
+ const printdata = selectedSaleOrderLines || {};
+ this.setData({
+ printdata
+ });
+
+ const allValuesToPrint = [];
+ // 检查打印数据是否存在,并且 selectedItems 是一个数组
+ if (printdata && printdata.selectedItems && Array.isArray(printdata.selectedItems)) {
+ // 遍历 selectedItems 数组
+ printdata.selectedItems.forEach((item) => {
+ // 输出当前遍历的 item
+ console.log('每个订单行数据item:', item);
+ // 检查 item 的 fineCode3Names 是否存在,并且是一个数组
+ if (item.fineCode3Names && Array.isArray(item.fineCode3Names)) {
+ // 遍历 fineCode3Names 数组
+ item.fineCode3Names.forEach((value) => {
+ // 拼接要打印的内容
+ value = `name ${item.name[1]}.color ${item.color_id_2[1]}.code ${value}`;
+ // 去除中文和[]符号
+ value = value.replace(/[\u4e00-\u9fa5\[\]]/g, '');
+ allValuesToPrint.push(value);
+ });
+ }
+ });
+ }
+
+
+ const totalCodes = allValuesToPrint.length;
+ let sentCodes = 0;
+ let totalChunks = 0;
+ let sentChunks = 0;
+
+ // 计算总的数据块数量
+ allValuesToPrint.forEach((code) => {
+ const command = `
+ SIZE 7,5
+ GAP 2,0
+ CLS
+ QRCODE 20,150,H,5,A,0,"${code}"
+ TEXT 20,350,"2",0,1,1,"${code}"
+ PRINT 1,1
+ `;
+ const encoder = new TextEncoder('utf-8');
+ const commandBuffer = encoder.encode(command);
+ const hexValue = Array.from(commandBuffer)
+ .map(byte => byte.toString(16).padStart(2, '0'))
+ .join('');
+ const chunkSize = 40;
+ const chunks = [];
+ for (let i = 0; i < hexValue.length; i += chunkSize) {
+ chunks.push(hexValue.slice(i, i + chunkSize));
+ }
+ totalChunks += chunks.length;
+ });
+
+ const sendPrintCode = (index) => {
+ if (index >= allValuesToPrint.length) {
+ console.log('所有 printcode 数据发送完成');
+ this.setData({
+ percent: '100',
+ });
+ return;
+ }
+
+ const currentCode = allValuesToPrint[index];
+ const command = `
+ SIZE 7,5
+ GAP 2,0
+ CLS
+ QRCODE 20,150,H,5,A,0,"${currentCode}"
+ TEXT 20,350,"2",0,1,1,"${currentCode}"
+ PRINT 1,1
+ `;
+ const encoder = new TextEncoder('utf-8');
+ const commandBuffer = encoder.encode(command);
+
+ // 将二进制数据转换为 hex 编码
+ const hexValue = Array.from(commandBuffer)
+ .map(byte => byte.toString(16).padStart(2, '0'))
+ .join('');
+
+ // 分段发送数据
+ const chunkSize = 40; // 每个分段的长度,20 字节 = 40 个十六进制字符
+ const chunks = [];
+ for (let i = 0; i < hexValue.length; i += chunkSize) {
+ chunks.push(hexValue.slice(i, i + chunkSize));
+ }
+
+ const sendNextChunk = (chunkIndex) => {
+ if (chunkIndex >= chunks.length) {
+ console.log(`printcode ${currentCode} 的所有数据分段发送完成`);
+ sentCodes++;
+ sendPrintCode(index + 1);
+ return;
+ }
+
+ const currentChunk = chunks[chunkIndex];
+ console.log(`准备发送 printcode ${currentCode} 的第 ${chunkIndex + 1} 个数据分段,长度: ${currentChunk.length}`, currentChunk);
+ dd.writeBLECharacteristicValue({
+ deviceId,
+ serviceId,
+ characteristicId,
+ value: currentChunk,
+ success: (res) => {
+ console.log(`printcode ${currentCode} 的第 ${chunkIndex + 1} 个数据分段发送成功`, res);
+ sentChunks++;
+ const percent = ((sentChunks / totalChunks) * 100).toFixed(0);
+ this.setData({
+ percent: percent,
+ });
+ sendNextChunk(chunkIndex + 1);
+ },
+ fail: (res) => {
+ console.error(`printcode ${currentCode} 的第 ${chunkIndex + 1} 个数据分段发送失败,错误码:`, res.errorCode);
+ const title = `printcode ${currentCode} 的第 ${chunkIndex + 1} 个数据分段发送失败,错误码: ${res.errorCode}`;
+ if (title) {
+ dd.showToast({
+ title: title,
+ icon: 'none'
+ });
+ }
+ },
+ complete: (res) => {
+ console.log(`printcode ${currentCode} 的第 ${chunkIndex + 1} 个数据分段发送调用结束`, res);
+ }
+ });
+ };
+
+ sendNextChunk(0);
+ };
+
+ sendPrintCode(0);
+ },
+
+
getBluetoothAdapterState() {
// 调用 dd.getBluetoothAdapterState 方法获取本机蓝牙模块的状态
dd.getBluetoothAdapterState({
@@ -639,138 +831,7 @@ Component({
});
this.reconnectBluetoothDevice();
}
- },
- onSubmit() {
- const selectedDevice = this.data.selectedDevice;
- console.log('selectedDevice', selectedDevice);
- const isConnected = this.data.isConnected;
- // 检查蓝牙设备是否已连接
- if (!selectedDevice || !isConnected) {
- console.log('请先连接蓝牙设备');
- const title = '请先连接蓝牙设备';
- if (title) {
- dd.showToast({
- title,
- icon: 'none'
- });
- }
- return;
- }
-
- // 从可写特征值列表中获取第一个可写特征值(这里假设只有一个可写特征值,你可以根据实际情况调整)
- const writableCharacteristic = this.data.writableCharacteristics[0];
- console.log('writableCharacteristics', this.data.writableCharacteristics);
- if (!writableCharacteristic) {
- console.log('未找到可写特征值');
- const title = '未找到可写特征值';
- if (title) {
- dd.showToast({
- title,
- icon: 'none'
- });
- }
- return;
- }
-
- const serviceId = writableCharacteristic.serviceId;
- const characteristicId = writableCharacteristic.characteristicId;
- const deviceId = selectedDevice.deviceId;
-
- // 检查参数完整性
- if (!deviceId || !serviceId || !characteristicId) {
- console.error('缺少必要参数:', {
- deviceId,
- serviceId,
- characteristicId
- });
- const title = '缺少必要参数,请检查连接';
- if (title) {
- dd.showToast({
- // title,
- icon: 'none'
- });
- }
- return;
- }
-
- // 假设 printcode 是一个变量,需要在代码里定义
- const printcode = [1, 2, 3, 4];
-
- const sendPrintCode = (index) => {
- if (index >= printcode.length) {
- console.log('所有 printcode 数据发送完成');
- // const title = '所有 printcode 数据发送完成';
- // if (title) {
- // dd.showToast({
- // // title,
- // icon: 'success'
- // });
- // }
- return;
- }
-
- const currentCode = printcode[index];
- const command = `
- SIZE 7,5
- GAP 2,0
- CLS
- QRCODE 20,150,H,5,A,0,"${currentCode}"
- TEXT 20,350,"2",0,1,1,"${currentCode}"
- PRINT 1,1
- `;
- const encoder = new TextEncoder('utf-8');
- const commandBuffer = encoder.encode(command);
-
- // 将二进制数据转换为 hex 编码
- const hexValue = Array.from(commandBuffer)
- .map(byte => byte.toString(16).padStart(2, '0'))
- .join('');
-
- // 分段发送数据
- const chunkSize = 40; // 每个分段的长度,20 字节 = 40 个十六进制字符
- const chunks = [];
- for (let i = 0; i < hexValue.length; i += chunkSize) {
- chunks.push(hexValue.slice(i, i + chunkSize));
- }
-
- const sendNextChunk = (chunkIndex) => {
- if (chunkIndex >= chunks.length) {
- console.log(`printcode ${currentCode} 的所有数据分段发送完成`);
- sendPrintCode(index + 1);
- return;
- }
-
- const currentChunk = chunks[chunkIndex];
- console.log(`准备发送 printcode ${currentCode} 的第 ${chunkIndex + 1} 个数据分段,长度: ${currentChunk.length}`, currentChunk);
- dd.writeBLECharacteristicValue({
- deviceId,
- serviceId,
- characteristicId,
- value: currentChunk,
- success: (res) => {
- console.log(`printcode ${currentCode} 的第 ${chunkIndex + 1} 个数据分段发送成功`, res);
- sendNextChunk(chunkIndex + 1);
- },
- fail: (res) => {
- console.error(`printcode ${currentCode} 的第 ${chunkIndex + 1} 个数据分段发送失败,错误码:`, res.errorCode);
- const title = `printcode ${currentCode} 的第 ${chunkIndex + 1} 个数据分段发送失败,错误码: ${res.errorCode}`;
- // if (title) {
- // dd.showToast({
- // title: title,
- // icon: 'none'
- // });
- // }
- },
- complete: (res) => {
- console.log(`printcode ${currentCode} 的第 ${chunkIndex + 1} 个数据分段发送调用结束`, res);
- }
- });
- };
-
- sendNextChunk(0);
- };
-
- sendPrintCode(0);
}
+
},
});
\ No newline at end of file
diff --git a/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.acss b/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.acss
index e69de29..0c1ab2a 100644
--- a/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.acss
+++ b/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.acss
@@ -0,0 +1,88 @@
+
+.list-header {
+ font-size: 18px;
+ font-weight: bold;
+ padding: 10px;
+ background-color: #f0f0f0;
+}
+
+.order-item {
+ /* 卡片边框颜色 */
+ border: 1px solid #161515;
+ padding: 10px;
+ margin: 10px;
+ cursor: pointer;
+ border-radius: 5px;
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
+ background-color: #ffffff;
+}
+
+.order-title {
+ font-size: 16px;
+ font-weight: bold;
+ color: #dbe45a;
+}
+
+.order-brief {
+ font-size: 14px;
+ color: #666;
+}
+
+.order-extra {
+ font-size: 14px;
+ color: #666;
+ float: right;
+}
+
+.order-details {
+ font-size: 14px;
+ margin-top: 5px;
+ color: #444444;
+}
+
+.order-line-item {
+ border: 1px solid #eee;
+ padding: 5px;
+ margin-top: 5px;
+ border-radius: 3px;
+ /* 销售订单行背景色 */
+ background-color: #f9f9f9;
+}
+
+.pagination {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ margin-top: 20px;
+}
+
+.pagination-button {
+ padding: 8px 16px;
+ margin: 0 10px;
+ border: none;
+ border-radius: 5px;
+ background-color: #007aff;
+ color: #ffffff;
+ cursor: pointer;
+ transition: background-color 0.3s ease;
+}
+
+.pagination-button:hover {
+ background-color: #0056b3;
+}
+
+.disabled-button {
+ background-color: #cccccc;
+ cursor: not-allowed;
+}
+
+.pagination-text {
+ font-size: 14px;
+ color: #333333;
+ margin: 0 10px;
+}
+
+.image {
+ width: 50px;
+ height: 50px;
+}
\ No newline at end of file
diff --git a/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.axml b/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.axml
index b971fab..dd8e47b 100644
--- a/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.axml
+++ b/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.axml
@@ -1,3 +1,9 @@
-
+
+
+
+
+ name:{{item.name || '无货号'}}. color: {{item.color_id_2 || '无色号'}} . code: {{item.fineCode || '无细码'}}
+
+
\ No newline at end of file
diff --git a/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.js b/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.js
index a0f1c41..96966c4 100644
--- a/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.js
+++ b/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.js
@@ -1,22 +1,35 @@
Page({
data: {
- printdata: {},
- // printFormat: 'TSPL',
- // maxAllowedLength: 1024,
- // delayTime: 5000, // 默认延迟 5 秒,单位:毫秒
- // paperSize: {
- // width: 80, // 默认宽度 80mm
- // height: 60 // 默认高度 60mm
- // },
- // index: 0 //指令集默认选择
+ printdata: {},
+ selectedItems: [],
+ fineCode3Names: []
},
onLoad() {
- const selectedSaleOrderLines = dd.getStorageSync({
- key: 'selectedSaleOrderLines'
- }).data;
- const printdata = selectedSaleOrderLines || {};
- this.setData({
- printdata
- });
- },
-});
\ No newline at end of file
+ const selectedSaleOrderLines = dd.getStorageSync({
+ key: 'selectedSaleOrderLines'
+ }).data;
+ const printdata = selectedSaleOrderLines || {};
+ const selectedItems = printdata.selectedItems || [];
+ const fineCode3Names = [];
+
+ selectedItems.forEach(item => {
+ if (item.fineCode3Names) {
+ item.fineCode3Names.forEach(fineCode => {
+ fineCode3Names.push({
+ name: item.name || '无货号',
+ color_id_2: item.color_id_2[1] || '无色号',
+ fineCode
+ });
+ });
+ }
+ });
+
+ this.setData({
+ printdata,
+ selectedItems,
+ fineCode3Names
+ });
+ console.log('selectedItems', selectedItems);
+ console.log('fineCode3Names', fineCode3Names);
+ }
+});
\ No newline at end of file
diff --git a/pages/static/images/胜佳纺织.png b/pages/static/images/胜佳纺织.png
new file mode 100644
index 0000000..4fbc581
Binary files /dev/null and b/pages/static/images/胜佳纺织.png differ