index.vue 9.8 KB

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