index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <view class="content">
  3. {{GET_REQUEST_DATA}}
  4. <view>
  5. <view class="bluetoothConnected">
  6. <view class="bluetoothList" v-for="(item,index) in GET_CONNECTBLEDATA" :key="index"
  7. @tap="confirm_bluetooth(item)">
  8. <view class="bluetoothList-name">名称:{{item.name}}</view>
  9. <view class="bluetoothList-mac">地址:{{item.mac}}</view>
  10. </view>
  11. </view>
  12. <button type="default" @click="search_bluetooth">搜索蓝牙</button>
  13. <button @click="senBleLabel">打印</button>
  14. <view class="bluetoothItem" v-if="GET_INFODATA">
  15. <view class="bluetoothList" v-for="(item,index) in GET_INFODATA" :key="index"
  16. @tap="confirm_bluetooth(item)">
  17. <view class="bluetoothList-name">名称:{{item.name}}</view>
  18. <view class="bluetoothList-mac">地址:{{item.mac}}</view>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import printConnect from "@/common/print.js"; //引入打印机模板文件
  26. let _this = null;
  27. import {
  28. mapGetters,
  29. mapActions
  30. } from 'vuex';
  31. import {
  32. GET_INFODATA,
  33. GET_CONNECTBLEDATA,
  34. GET_REQUEST_DATA
  35. } from "@/store/gettersType.js";
  36. import {
  37. SET_CONNECTBLEDATA,
  38. SET_REQUEST_DATA
  39. } from '@/store/actionsType.js';
  40. // #ifdef APP-PLUS
  41. const HanyinPlugin = uni.requireNativePlugin('Hanyin-Plugin'); //汉印
  42. // #endif
  43. let print;
  44. import store from 'store';
  45. import {
  46. DX
  47. } from '@/common/dateFormat.js';
  48. export default {
  49. data() {
  50. return {
  51. bArray: [], //用于搜索蓝牙去重用的
  52. no_match_list: [], //没有配对的蓝牙列表
  53. match_list: "", //已连接蓝牙打印机
  54. val: "",
  55. dateTimer: "",
  56. valArr: [],
  57. form:{},
  58. amountNumber:{},
  59. connectedPrint:{}
  60. // 巴枪参数
  61. // broadcase_actions: "com.android.receive_scan_action",
  62. // broadcast_flag: "data"
  63. };
  64. },
  65. computed: {
  66. ...mapGetters([GET_INFODATA, GET_CONNECTBLEDATA,GET_REQUEST_DATA])
  67. },
  68. onShow() {
  69. // console.log(this.$store.state.connectedPrint)
  70. // this.connectedPrint = this.$store.state.connectedPrint
  71. uni.hideLoading();
  72. //检查是否已连接蓝牙
  73. this.$check_bluetooth_connect();
  74. console.log('onShow');
  75. },
  76. onHide() {
  77. console.log('onHide');
  78. },
  79. onUnload() {
  80. console.log('onUnload');
  81. },
  82. onLoad(options) {
  83. _this = this;
  84. _this.form = JSON.parse(options.data)
  85. console.log(JSON.parse(options.data))
  86. _this.amountNumber = {
  87. deliveryAll: 0, //送货总数量
  88. cost: 0, //成本
  89. grossProfit: 0, //毛利
  90. delivery: 0, //送货
  91. saleAll: 0, //销售数量
  92. amount: 0
  93. }
  94. for (let item of _this.form.orderItemsList) {
  95. _this.amountNumber.saleAll += Number(item.storageInQuantity)
  96. _this.amountNumber.cost += Number(item.storageInQuantity) * Number(item.purchasePrice)
  97. _this.amountNumber.delivery += Number(item.actualQuantity)
  98. _this.amountNumber.deliveryAll += Number(item.actualQuantity)
  99. _this.amountNumber.amount += Number(item.amount)
  100. _this.amountNumber.grossProfit += Number(item.amount) - (item.purchasePrice ? Number(item.storageInQuantity) * Number(item.purchasePrice) : 0)
  101. }
  102. _this.form.purchaseAmount = this.amountNumber.amount
  103. _this.$init_bluetooth();
  104. },
  105. methods: {
  106. ...mapActions([SET_CONNECTBLEDATA]),
  107. senBleLabel() {
  108. // console.log(this.$Mock.order_data);
  109. return this.$store.dispatch(SET_REQUEST_DATA, {name:this.name,mac:this.mac});
  110. if (!print) return;
  111. this.$Mock.printTemplate.pagConfig = 0
  112. console.log(this.$Mock.printTemplate.pagConfig)
  113. let data = []
  114. let i = 0
  115. for(let item of this.form.orderItemsList){
  116. data.push({
  117. "top": Number(i*40+90),
  118. "left": "0",
  119. "textAlign": "start",
  120. "width": "270",
  121. "fontSize": 9,
  122. "text": item.cname,
  123. "type": "text",
  124. "fontWeight": "400",
  125. "height": "20"
  126. })
  127. data.push({
  128. "top": Number(i*40+110),
  129. "left": "140",
  130. "textAlign": "start",
  131. "width": "40",
  132. "fontSize": 8,
  133. "text": Number(item.storageInQuantity),
  134. "type": "text",
  135. "fontWeight": "400",
  136. "height": "20"
  137. })
  138. data.push({
  139. "top": Number(i*40+110),
  140. "left": "160",
  141. "textAlign": "start",
  142. "width": "50",
  143. "fontSize": 8,
  144. "text": item.price,
  145. "type": "text",
  146. "fontWeight": "400",
  147. "height": "20"
  148. })
  149. data.push({
  150. "top": Number(i*40+110),
  151. "left": "210",
  152. "textAlign": "start",
  153. "width": "60",
  154. "fontSize": 8,
  155. "text": item.amount,
  156. "type": "text",
  157. "fontWeight": "400",
  158. "height": "20"
  159. })
  160. i++
  161. }
  162. data.push({
  163. "top": Number(i*40+90),
  164. "left": "20",
  165. "textAlign": "start",
  166. "width": "270",
  167. "fontSize": 9,
  168. "text": "合计:",
  169. "type": "text",
  170. "fontWeight": "400",
  171. "height": "20"
  172. })
  173. data.push({
  174. "top": Number(i*40+90),
  175. "left": "140",
  176. "textAlign": "start",
  177. "width": "40",
  178. "fontSize": 8,
  179. "text": this.amountNumber.saleAll,
  180. "type": "text",
  181. "fontWeight": "400",
  182. "height": "20"
  183. })
  184. data.push({
  185. "top": Number(i*40+90),
  186. "left": "210",
  187. "textAlign": "start",
  188. "width": "60",
  189. "fontSize": 8,
  190. "text": this.form.orderAmount,
  191. "type": "text",
  192. "fontWeight": "400",
  193. "height": "20"
  194. })
  195. data.push({
  196. "top": Number(i*40+110),
  197. "left": "20",
  198. "textAlign": "start",
  199. "width": "270",
  200. "fontSize": 9,
  201. "text": "产品合计:",
  202. "type": "text",
  203. "fontWeight": "400",
  204. "height": "20"
  205. })
  206. data.push({
  207. "top": Number(i*40+110),
  208. "left": "70",
  209. "textAlign": "start",
  210. "width": "70",
  211. "fontSize": 8,
  212. "text": this.amountNumber.amount,
  213. "type": "text",
  214. "fontWeight": "400",
  215. "height": "20"
  216. })
  217. data.push({
  218. "top": Number(i*40+110),
  219. "left": "140",
  220. "textAlign": "start",
  221. "width": "60",
  222. "fontSize": 8,
  223. "text": "合计金额:",
  224. "type": "text",
  225. "fontWeight": "400",
  226. "height": "20"
  227. })
  228. data.push({
  229. "top": Number(i*40+110),
  230. "left": "190",
  231. "textAlign": "start",
  232. "width": "80",
  233. "fontSize": 8,
  234. "text": DX(this.amountNumber.amount),
  235. "type": "text",
  236. "fontWeight": "400",
  237. "height": "40"
  238. })
  239. data.push({
  240. "top": Number(i*40+130),
  241. "left": "20",
  242. "textAlign": "start",
  243. "width": "270",
  244. "fontSize": 9,
  245. "text": "订货电话:"+this.form.clientAttn,
  246. "type": "text",
  247. "fontWeight": "400",
  248. "height": "20"
  249. })
  250. data.push({
  251. "top": Number(i*40+150),
  252. "left": "20",
  253. "textAlign": "start",
  254. "width": "270",
  255. "fontSize": 9,
  256. "text": "制单人:"+this.form.client,
  257. "type": "text",
  258. "fontWeight": "400",
  259. "height": "20"
  260. })
  261. data.push({
  262. "top": Number(i*40+150),
  263. "left": "140",
  264. "textAlign": "start",
  265. "width": "80",
  266. "fontSize": 8,
  267. "text": "收货人(签字):",
  268. "type": "text",
  269. "fontWeight": "400",
  270. "height": "20"
  271. })
  272. console.log((this.form.orderItemsList.length*40)/3)
  273. print.startPrint({
  274. SALES_SLIP:this.form.sysNo,
  275. CUSTOMER_NAME:this.form.corpsName,
  276. SALES_DATE:this.form.businesDate.slice(0, 10)
  277. },{pageHeight:(this.form.orderItemsList.length*40)/3},data);
  278. },
  279. // 连接打印机
  280. confirm_bluetooth(item) {
  281. let {
  282. name,
  283. mac
  284. } = item;
  285. //判断蓝牙是否打开
  286. this.$check_bluetooth_open().then(res => {
  287. console.log(res);
  288. //进行打印机连接
  289. if (res) {
  290. print = new printConnect(item); //打印机连接
  291. }
  292. })
  293. },
  294. //搜索没匹配的蓝牙设备
  295. search_bluetooth(address) {
  296. let _this = this;
  297. //检查蓝牙是否开启
  298. this.$check_bluetooth_open().then(ores => {
  299. if (ores) {
  300. console.log(ores);
  301. //搜索蓝牙
  302. _this.$search_bluetooth().then(bres => {
  303. console.log(bres);
  304. if (bres.code) {
  305. _this.$search_pipei().then(pres => {
  306. console.log(pres);
  307. })
  308. }
  309. })
  310. }
  311. })
  312. }
  313. }
  314. }
  315. </script>
  316. <style lang="scss">
  317. .bluetoothItem {
  318. width: 100%;
  319. height: 100%;
  320. .bluetoothList {
  321. display: flex;
  322. flex-direction: column;
  323. padding: 20rpx;
  324. border-bottom: 1rpx solid #BEBEBE;
  325. font-size: 18rpx;
  326. }
  327. }
  328. </style>