reshui.vue 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720
  1. <template>
  2. <view class="content">
  3. <view class="container">
  4. <view class="header">
  5. <view class="scan" @tap="scan()" hover-class="scan_hover">
  6. <text class="iconfont icon-saoma"></text>
  7. <text>扫码连接</text>
  8. </view>
  9. <view class="qinshihao">
  10. <text class="iconfont icon-zhuye"></text>
  11. <text class="dormtxt">{{dorm_number || '宿舍未知'}}</text>
  12. </view>
  13. </view>
  14. <view class="start_text">
  15. <view class="start_top">
  16. <view class="item_left">
  17. <text class="iconfont icon-shuibiao"></text>
  18. <text>开启设备</text>
  19. </view>
  20. <view>
  21. <switch :color="colorPrimary" :checked="isChecked" @change="switchChange" />
  22. </view>
  23. </view>
  24. <view class="start_mid">
  25. <view class="item_left">
  26. <text class="iconfont icon-qian"></text>
  27. <!-- <navigator url="/pagesWater/reshuiDetails/reshuiDetails" open-type="navigate"
  28. class="start_mid_txt">¥{{amount}}</navigator> -->
  29. <navigator url="" open-type="navigate" class="start_mid_txt">¥{{amount}}</navigator>
  30. </view>
  31. <view class="start_payamount" @tap="chongzhi_yemian()" hover-class="scan_hover">
  32. <text>点击充值</text>
  33. <text class="iconfont icon-dayuhao"></text>
  34. </view>
  35. </view>
  36. <view class="start_bot">
  37. <button class="kongzhonglianjie" @click="open">空中连接</button>
  38. <text class="start_bot_txt">当前结算消费:¥{{use_amount}}</text>
  39. </view>
  40. </view>
  41. <view v-if="showRoom" style="width: 100%; height: 100%; ">
  42. <view style="display: flex; flex-wrap: wrap;">
  43. <button v-for="item in rooms" :key="item.id" @tap="clickRoom(item.id)"
  44. class="btn_room">{{item.room}}</button>
  45. </view>
  46. </view>
  47. <view class="start_up_process">
  48. <uni-steps :options="list1" :active-color="colorPrimary" :active="active" />
  49. </view>
  50. <view class="ad">
  51. <image src="../../static/images/ad_reshui.jpg" mode="aspectFill" class="ad_img" @tap="ad_redirect">
  52. </image>
  53. </view>
  54. <view class="title">
  55. 消费记录
  56. </view>
  57. <view class="record-item">
  58. <view class="uni-list-cell-db">
  59. <picker mode="date" :value="date" fields="month" :start="startDate" :end="endDate"
  60. @change="bindDateChange">
  61. <view class="uni-input">
  62. <text>{{date}}</text>
  63. <text class="iconfont icon-arrow-down"></text>
  64. </view>
  65. </picker>
  66. </view>
  67. <view class="item-list" v-for="(item, i) in xiaofei_items" :key="i">
  68. <text class="item-list-txt"><text class="iconfont icon-shijian"></text>{{item.begin_time}}</text>
  69. <text class="item-list-txt"><text
  70. class="iconfont icon-shuidi"></text>{{numFilter(item.use_size)}}t</text>
  71. <text class="item-list-txt">{{numFilter(item.use_amount)}}</text>
  72. </view>
  73. </view>
  74. </view>
  75. <instructions v-if="flag" @parent_cancel="cancel" @parent_noshow='noshow'></instructions>
  76. </view>
  77. </template>
  78. <script>
  79. import instructions from '../../components/instructions.vue'
  80. export default {
  81. /**
  82. * 声明组件
  83. */
  84. components: {
  85. instructions
  86. },
  87. data() {
  88. return {
  89. colorPrimary: getApp().globalData.primaryColor,
  90. date: this.$getDate({
  91. format: true
  92. }),
  93. startDate: this.$getDate('start_date'),
  94. endDate: this.$getDate('end_date'),
  95. flag: false, // 控制说明弹窗
  96. showRoom: false,
  97. isUserClose: false, // 是否是用户自己关闭
  98. isChecked: false,
  99. isConnected: false, // 是否连接上
  100. isScan: false,
  101. active: -1,
  102. list1: [{
  103. title: '连接设备'
  104. }, {
  105. title: '连设备服务'
  106. }, {
  107. title: '数据通讯'
  108. }, {
  109. title: '启动'
  110. }],
  111. devices: [], // 保存设备
  112. rooms: [], // 保存水表id及对应的宿舍号
  113. device_code: '', // 设备编号
  114. deviceId: '',
  115. serviceId: '',
  116. characteristicIdForWrite: '',
  117. characteristicIdForNotity: '',
  118. deviceIsNotify: false,
  119. deviceIsWrite: false,
  120. byte35: '', // 70 个字符
  121. byte35_tmp: '', // 70 个字符 临时变量
  122. start_code: '',
  123. // start_code: '3459A8C660F1C284E41003E80000120000',
  124. xiaofei_items: [], // 消费记录
  125. use_amount: 0.0.toFixed(2), // 结算金额
  126. amount: 0.0.toFixed(2), // 余额
  127. dorm_number: '', // 宿舍号
  128. stu_number: '', // 学号
  129. user_name: '',
  130. // compus: '', // 校区
  131. ceshi: 'code',
  132. changeDate: false, // 是否是手动选择日期
  133. get_Bluetooth_Bevice: false // 自动获取蓝牙设备,并列表
  134. }
  135. },
  136. onLoad(options) {
  137. // console.log(options);
  138. // 向用户发起授权请求
  139. uni.authorize({
  140. scope: 'scope.userLocation',
  141. success(res) {
  142. uni.getLocation({
  143. success: (loc) => {
  144. // console.log(loc);
  145. // uni.showToast({
  146. // icon: 'none',
  147. // title: '纬度:' + loc.latitude + '\n' + '经度:' + loc
  148. // .longitude,
  149. // duration: 2000
  150. // })
  151. uni.showToast({
  152. icon: 'success',
  153. title: '已获定位信息'
  154. })
  155. },
  156. fail: (err) => {
  157. uni.showToast({
  158. icon: 'none',
  159. title: '获取定位失败,请手动开启定位!'
  160. })
  161. }
  162. })
  163. },
  164. fail: (err) => {
  165. // console.log(err);
  166. uni.showToast({
  167. icon: 'none',
  168. title: '请手动设置定位授权!'
  169. })
  170. }
  171. })
  172. if (typeof(options) != 'undefined' && typeof(options) != '' && JSON.stringify(options) == '{}') {
  173. // 获取基本信息
  174. this.get_base_info(options, 'onLoad')
  175. } else if (typeof(options.from) != 'undefined' && options.from != 0) {
  176. // 获取基本信息
  177. this.get_base_info(options, 'onLoad')
  178. // 获取设备码
  179. this.device_code = decodeURIComponent(options.q).split('=')[1]
  180. }
  181. const value = uni.getStorageSync('instruction_noshow');
  182. if (!(value == true)) {
  183. this.flag = true
  184. }
  185. },
  186. onShow() {
  187. // 充值后更新金额
  188. this.amount = this.$store.state.reshui_amount
  189. if (this.stu_number && typeof(this.stu_number) != 'undefined') {
  190. // 获取基本信息
  191. this.get_base_info('options', 'onShow')
  192. }
  193. },
  194. methods: {
  195. /**
  196. * 单击连接热水表
  197. */
  198. clickRoom(e) {
  199. try {
  200. if (this.judgeBalance('clickRoom') === false) {
  201. return
  202. } else {
  203. this.device_code = 'K' + e
  204. for (var i = 0, len = this.devices.length; i < len; i++) {
  205. if (this.devices[i].dname == e) {
  206. this.deviceId = this.devices[i].did
  207. break
  208. }
  209. }
  210. // 开始连接匹配的蓝牙设备
  211. this.createBLEConnection();
  212. }
  213. } catch (e) {
  214. console.log('单击连接热水表:' + e.message);
  215. }
  216. },
  217. /**
  218. * 空中连接热水表
  219. */
  220. open() {
  221. if (this.judgeBalance('clickRoom') === false) {
  222. return
  223. } else {
  224. this.setInit()
  225. uni.showLoading({
  226. title: '水表搜索中…',
  227. mask: true,
  228. success: (res) => {
  229. // 获取蓝牙设备,并列表
  230. this.openBluetoothAdapter();
  231. this.showRoom = true
  232. }
  233. })
  234. setTimeout(function() {
  235. uni.hideLoading();
  236. }, 3000);
  237. }
  238. },
  239. /**
  240. * 跳转到广告ad页
  241. */
  242. ad_redirect() {
  243. // uni.navigateTo({
  244. // url: 'ad_reshui'
  245. // })
  246. },
  247. /**
  248. * 保留小数点数值后两位,尾数四舍五入
  249. * @param {Object} value
  250. */
  251. numFilter(value) {
  252. // 截取当前数据到小数点后两位
  253. let realVal = parseFloat(value).toFixed(2)
  254. return realVal
  255. },
  256. /**
  257. * 获取基本信息
  258. */
  259. get_base_info(options, param) {
  260. // console.log(options);
  261. try {
  262. // 获取学号
  263. this.stu_number = this.$store.state.userInfo.card_number
  264. if (this.stu_number == '' || typeof(this.stu_number) == 'undefined') {
  265. const userinfo = uni.getStorageSync('userinfo_storage_key')
  266. if (userinfo) {
  267. this.stu_number = userinfo.card_number
  268. } else {
  269. uni.navigateTo({
  270. url: '../index/index?from=' + options.from
  271. })
  272. uni.showToast({
  273. icon: 'none',
  274. title: '学号为空,请进行授权',
  275. duration: 3000
  276. });
  277. return
  278. }
  279. }
  280. } catch (e) {
  281. console.log('获取基本信息:' + e.message);
  282. }
  283. if (param == 'onShow') {
  284. if (this.$store.state.payInfo.from == 'reshui_pay') {
  285. uni.showToast({
  286. title: this.$store.state.payInfo.resultMsg,
  287. icon: 'success',
  288. success: () => {
  289. this.$store.state.payInfo.resultMsg = ''
  290. this.$store.state.payInfo.from = ''
  291. }
  292. })
  293. }
  294. }
  295. // 获取code
  296. this.getCode(options, param)
  297. },
  298. /**
  299. * 获得code
  300. */
  301. getCode(options, param) {
  302. uni.login({
  303. success: (res) => {
  304. // console.log('getCode', res);
  305. if (res.code) {
  306. // 请求服务器,获得openid
  307. this.getOpenId(options, res.code, param)
  308. } else {
  309. uni.showToast({
  310. title: res.errMsg,
  311. icon: 'none'
  312. });
  313. }
  314. }
  315. })
  316. },
  317. /**
  318. * 请求服务器,获得openid
  319. */
  320. async getOpenId(options, param_code, param) {
  321. const res = await this.$myRequest({
  322. host: this.ceshi,
  323. url: '/HotWaters/wpget_stu.action',
  324. method: 'POST',
  325. header: {
  326. 'content-type': 'application/x-www-form-urlencoded'
  327. },
  328. data: {
  329. code: param_code
  330. }
  331. })
  332. // console.log(res);
  333. if (res.data.mess == '返回成功') {
  334. // stu_number是否存在
  335. let cardNumber = res.data.info[0].card_number
  336. if (typeof(cardNumber) != 'undefined' && cardNumber != '' && JSON.stringify(cardNumber) != '{}') {
  337. // 学号 和 姓名
  338. this.stu_number = res.data.info[0].stu_number
  339. this.user_name = res.data.info[0].user_name
  340. // 剩余金额
  341. this.amount = res.data.info[0].balance.toFixed(2)
  342. // if (this.amount > 0)
  343. this.$store.state.reshui_amount = this.amount
  344. // 组合楼栋宿舍号
  345. this.dorm_number = res.data.info[0].build + res.data.info[0].dom
  346. // 校区
  347. // this.compus = res.data.info[0].campus
  348. if (param == 'onLoad' && typeof(options.from) != 'undefined' && options.from != 0) {
  349. // 初始化蓝牙
  350. this.openBluetoothAdapter()
  351. }
  352. // 请求选定的月份消费记录
  353. this.request_consumption_records()
  354. } else {
  355. uni.showToast({
  356. title: '未获取到学号!',
  357. icon: 'success'
  358. });
  359. uni.navigateTo({
  360. url: '../index/index?from=' + options.from
  361. })
  362. }
  363. } else if (res.data.mess == '未查询到用户信息') {
  364. // 数据库中 未查询到用户信息,就清除本地存储
  365. uni.removeStorageSync('userinfo_storage_key');
  366. uni.showToast({
  367. title: '获取用户信息失败!'
  368. })
  369. if (options && typeof(options.from) != 'undefined' && typeof(options.from) != '') {
  370. uni.navigateTo({
  371. url: '../index/index?from=' + options.from
  372. })
  373. } else {
  374. uni.redirectTo({
  375. url: '../index/index?from=0'
  376. });
  377. }
  378. }
  379. },
  380. /**
  381. * 选择消费年月
  382. */
  383. bindDateChange(e) {
  384. this.date = e.detail.value
  385. this.changeDate = true
  386. // 请求选定的月份消费记录
  387. this.request_consumption_records()
  388. },
  389. /**
  390. * 使用说明组件取消
  391. */
  392. cancel(param) {
  393. this.flag = param
  394. },
  395. /**
  396. * 使用说明组件不再出现
  397. */
  398. noshow(param) {
  399. try {
  400. if (param) {
  401. uni.setStorageSync("instruction_noshow", true)
  402. } else {
  403. uni.removeStorageSync("instruction_noshow")
  404. }
  405. } catch (e) {
  406. console.log('使用说明组件不再出现:' + e.message);
  407. }
  408. },
  409. /**
  410. * 请求选定的月份消费记录
  411. */
  412. async request_consumption_records() {
  413. try {
  414. if (this.stu_number != '' && typeof(this.stu_number) != 'undefined') {
  415. const res = await this.$myRequest({
  416. host: this.ceshi,
  417. url: '/HotWaters/wpqueryConsume.action',
  418. method: 'POST',
  419. header: {
  420. 'content-type': 'application/x-www-form-urlencoded'
  421. },
  422. data: {
  423. stu_number: this.stu_number,
  424. begin_time: this.date
  425. }
  426. });
  427. // console.log(res);
  428. if (res.data.mess == '返回成功') {
  429. this.xiaofei_items = []
  430. // 消费记录
  431. let items = res.data.data
  432. for (var i = 0; i < items.length; i++) {
  433. this.xiaofei_items.push(items[i])
  434. }
  435. } else {
  436. if (this.changeDate) {
  437. uni.showToast({
  438. icon: 'success',
  439. title: res.data.mess,
  440. success: () => {
  441. this.changeDate = false
  442. }
  443. })
  444. if (res.data.mess == '本月无消费记录') {
  445. this.xiaofei_items = []
  446. }
  447. }
  448. }
  449. } else {
  450. uni.showToast({
  451. icon: 'success',
  452. title: '未获得学号'
  453. })
  454. }
  455. } catch (e) {
  456. console.log('请求选定的月份消费记录:' + e.message);
  457. }
  458. },
  459. /**
  460. * 控制进度条显示
  461. * @param {Object} active_value
  462. */
  463. process_control(active_value) {
  464. try {
  465. if (active_value <= this.list1.length - 1) {
  466. this.active = active_value
  467. }
  468. } catch (e) {
  469. console.log('控制进度条显示:' + e.message);
  470. }
  471. },
  472. /**
  473. * 开始或停止用水
  474. */
  475. switchChange(e) {
  476. this.isChecked = e.target.value
  477. if (this.isChecked) {
  478. if (this.deviceId && this.serviceId && this.devices.length != 0) {
  479. uni.showModal({
  480. title: '提示',
  481. content: '确定要启动设备?',
  482. success: (res) => {
  483. if (res.confirm) {
  484. this.isChecked = true
  485. // 开始连接匹配的蓝牙设备
  486. setTimeout(async () => {
  487. // 请求获取设备启动码
  488. this.request_device_start_code()
  489. }, 300)
  490. } else if (res.cancel) {
  491. setTimeout(() => {
  492. this.isChecked = false
  493. }, 300)
  494. }
  495. }
  496. })
  497. } else {
  498. uni.showToast({
  499. icon: 'none',
  500. title: '先【扫码连接】,后【开启设备】',
  501. duration: 1500
  502. })
  503. setTimeout(() => {
  504. this.isChecked = false
  505. }, 300)
  506. }
  507. } else {
  508. uni.showModal({
  509. title: '提示',
  510. content: '确定要关闭设备?',
  511. success: (res) => {
  512. if (res.confirm) {
  513. this.isChecked = false
  514. if (this.deviceId && this.serviceId) {
  515. this.send('stop')
  516. } else {
  517. uni.showToast({
  518. icon: 'none',
  519. title: '与设备连接中断!请在设备上手动停止即可!',
  520. duration: 5000
  521. })
  522. setTimeout(() => {
  523. this.isChecked = true
  524. }, 300)
  525. }
  526. } else if (res.cancel) {
  527. setTimeout(() => {
  528. this.isChecked = true
  529. }, 300)
  530. }
  531. }
  532. })
  533. }
  534. },
  535. /**
  536. * 跳转到充值页面
  537. */
  538. chongzhi_yemian() {
  539. //在起始页面跳转到recharge.vue页面并传递参数
  540. uni.navigateTo({
  541. url: '../recharge/recharge'
  542. });
  543. },
  544. /**
  545. * 判断余额是否充足
  546. */
  547. judgeBalance(param) {
  548. var limit_amount = parseFloat(this.$store.state.amount)
  549. var amount = parseFloat(this.amount);
  550. // 启动最低金额限制
  551. if (amount < limit_amount) {
  552. uni.showModal({
  553. title: '提示',
  554. content: '当前余额不足¥' + limit_amount + '元',
  555. cancelText: '我知道了',
  556. confirmText: '我要充值',
  557. success: (res) => {
  558. if (res.confirm) {
  559. // 跳转充值页面
  560. this.chongzhi_yemian()
  561. // return false
  562. // } else if (res.cancel) {
  563. // return false
  564. }
  565. }
  566. })
  567. return false
  568. }
  569. // 已经启动扫描连接设备中
  570. if (this.isScan) {
  571. uni.showToast({
  572. icon: 'none',
  573. title: '正在扫描,请耐心等待',
  574. })
  575. return false
  576. }
  577. // 已经启动设备,不启动扫描
  578. if (this.isChecked) {
  579. let info_str = ''
  580. if (param == 'scan') {
  581. info_str = '设备已启动,无需重新扫码'
  582. } else {
  583. info_str = '设备已启动,无需重新启动'
  584. }
  585. uni.showToast({
  586. icon: 'none',
  587. title: info_str,
  588. })
  589. return false
  590. }
  591. // console.log(this.deviceId);
  592. // 设备已连接
  593. if (this.deviceId) {
  594. uni.showModal({
  595. title: '提示',
  596. content: '设备已经连接,需要重新连接吗?',
  597. success: res => {
  598. if (res.confirm) {
  599. // 关闭连接
  600. this.closeBLEConnection()
  601. if (param == 'scan') {
  602. // 扫描
  603. this.scan_qr()
  604. } else {
  605. // cancel
  606. }
  607. }
  608. }
  609. })
  610. return false
  611. }
  612. },
  613. /**
  614. * 111111111111111111111111111111
  615. * 扫码连接设备
  616. */
  617. scan() {
  618. if (this.judgeBalance('scan') == false) {
  619. return
  620. }
  621. this.scan_qr()
  622. },
  623. /**
  624. * 启动摄像头,扫描二维码
  625. */
  626. scan_qr() {
  627. this.get_Bluetooth_Bevice = true
  628. uni.scanCode({
  629. onlyFromCamera: true,
  630. success: (res) => {
  631. this.isScan = true
  632. // console.log(res)
  633. // charSet: "utf-8"
  634. // codeVersion: 3
  635. // errMsg: "scanCode:ok"
  636. // rawData: "aHR0cDovL3Rvb2xzLjlrYnMuY29tLz93eG1pbmljb2RlPUtCNTgwMDAyNjUy"
  637. // result: "http://tools.9kbs.com/?wxminicode=KB580002652"
  638. // scanType: "QR_CODE"
  639. this.device_code = res.result.split('=')[1]
  640. if (this.device_code === '') {
  641. uni.showToast({
  642. icon: 'success',
  643. title: '获取设备码失败',
  644. duration: 3000
  645. })
  646. this.isScan = false
  647. } else {
  648. // 初始化蓝牙
  649. this.openBluetoothAdapter()
  650. }
  651. }
  652. })
  653. },
  654. /**
  655. * 22222222222222222222222222222
  656. * 初始化蓝牙
  657. */
  658. openBluetoothAdapter() {
  659. let _this = this;
  660. uni.openBluetoothAdapter({
  661. success: (res) => { // 已打开
  662. uni.getBluetoothAdapterState({ // 蓝牙的匹配状态
  663. success: (res1) => {
  664. // console.log(res1, '“本机设备的蓝牙已打开”');
  665. // 本机设备的蓝牙已打开
  666. // 开始搜索蓝牙设备
  667. if (this.deviceId == '' && this.serviceId == '')
  668. this.startBluetoothDeviceDiscovery()
  669. },
  670. fail: (error) => {
  671. // console.log(error)
  672. uni.showModal({
  673. content: '请开启手机蓝牙!',
  674. showCancel: false,
  675. success() {
  676. // _this.myOpenBluetoothAdapter();
  677. }
  678. });
  679. this.isScan = false
  680. }
  681. });
  682. },
  683. fail: (err) => { // 未打开
  684. // console.log(err)
  685. this.isScan = false;
  686. if (err.errCode == 10001) {
  687. uni.showModal({
  688. content: '请授权手机蓝牙!',
  689. showCancel: false,
  690. success() {
  691. // _this.myOpenBluetoothAdapter();
  692. }
  693. });
  694. } else {
  695. uni.showToast({
  696. icon: 'none',
  697. title: err.errMsg,
  698. duration: 2000
  699. })
  700. }
  701. }
  702. });
  703. },
  704. /**
  705. * 让用户去手动授权
  706. */
  707. myOpenBluetoothAdapter() {
  708. // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.bluetooth" 这个 scope
  709. uni.getSetting({
  710. success(res) {
  711. // console.log(res.authSetting)
  712. //判断是否有'scope.bluetooth'属性
  713. if (res.authSetting.hasOwnProperty('scope.bluetooth')) {
  714. //'scope.bluetooth'属性存在,且为false
  715. if (!res.authSetting['scope.bluetooth']) {
  716. //弹窗授权
  717. uni.openSetting({
  718. success(res) {
  719. console.log(res.authSetting)
  720. }
  721. })
  722. }
  723. } else
  724. //'scope.bluetooth'属性不存在,需要授权
  725. uni.authorize({
  726. scope: 'scope.bluetooth',
  727. success() {
  728. // 用户已经同意小程序使用手机蓝牙功能,后续调用 蓝牙 接口不会弹窗询问
  729. console.log(res.authSetting)
  730. }
  731. })
  732. }
  733. });
  734. },
  735. /**
  736. * 333333333333333333333333333
  737. * 开始搜索蓝牙设备
  738. */
  739. startBluetoothDeviceDiscovery() {
  740. uni.startBluetoothDevicesDiscovery({ // 开始搜寻附近的蓝牙外围设备
  741. // services: ['FEE7'], // 要搜索但蓝牙设备主 service 的 uuid 列表
  742. allowDuplicatesKey: true,
  743. success: (res) => {
  744. if (this.get_Bluetooth_Bevice == true)
  745. this.process_control(0)
  746. this.onBluetoothDeviceFound() // 监听搜索到新设备 同时进行
  747. setTimeout(() => {
  748. if (this.isScan) {
  749. uni.showModal({
  750. title: '温馨提示',
  751. content: '请确认已开启【蓝牙授权】或【定位授权】!',
  752. confirmText: '我已开启',
  753. cancelText: '取消',
  754. success: (res) => {
  755. // console.log(res);
  756. if (res.confirm) {
  757. } else if (res.cancel) {
  758. switch (uni.getSystemInfoSync().platform) {
  759. case 'android':
  760. // 打开设置
  761. break;
  762. case 'ios':
  763. // 打开设置
  764. break;
  765. default:
  766. // console.log('运行在开发者工具上')
  767. break;
  768. }
  769. }
  770. }
  771. })
  772. }
  773. }, 6000)
  774. },
  775. fail: err => {
  776. // console.log(err, '错误信息');
  777. uni.showToast({
  778. icon: 'none',
  779. title: err.errMsg,
  780. duration: 2000
  781. })
  782. this.isScan = false
  783. }
  784. })
  785. },
  786. stopBluetoothDevicesDiscovery() { //停止搜索
  787. uni.stopBluetoothDevicesDiscovery({
  788. success: (res) => {
  789. // console.log(res, '停止蓝牙搜索')
  790. // uni.showToast({
  791. // title: '停止蓝牙搜索',
  792. // duration: 2000
  793. // })
  794. if (this.get_Bluetooth_Bevice == true || this.device_code) {
  795. this.createBLEConnection()
  796. } else {
  797. this.get_room()
  798. setTimeout(() => {
  799. this.get_Bluetooth_Bevice = true
  800. }, 2000)
  801. }
  802. },
  803. fail: err => {
  804. // console.log('停止搜索蓝牙设备失败,错误码:' + err.errCode);
  805. this.isScan = false
  806. uni.showToast({
  807. title: err.errCode,
  808. duration: 2000
  809. })
  810. }
  811. })
  812. },
  813. /**
  814. * 444444444444444444444444444444444
  815. * 发现外围设备
  816. */
  817. onBluetoothDeviceFound() {
  818. uni.onBluetoothDeviceFound((res) => {
  819. let dname = ''
  820. res.devices.forEach(device => { // 筛选找到的蓝牙中对名称匹配
  821. try {
  822. // 过滤掉没有名字的设备
  823. if (!device.name && !device.localName) {
  824. return
  825. }
  826. // 把搜索到的设备存储起来,如有需要可以在页面上展示
  827. dname = device.name.substr(1)
  828. let d = {
  829. did: device.deviceId,
  830. dname: dname
  831. }
  832. if (dname.length == 10 && JSON.stringify(this.devices).indexOf(JSON.stringify(
  833. d)) === -1) {
  834. this.devices.push(d)
  835. }
  836. if (device.name == this.device_code) {
  837. this.process_control(0);
  838. //data里面建立一个deviceId、device_code,存储起来
  839. // this.device_code = device.name;
  840. this.deviceId = device.deviceId
  841. // 放此位置,苹果手机兼容
  842. this.stopBluetoothDevicesDiscovery()
  843. return
  844. }
  845. setTimeout(() => {
  846. this.stopBluetoothDevicesDiscovery()
  847. }, 2000)
  848. } catch (e) {
  849. // console.log('发现外围设备:' + e.message);
  850. }
  851. })
  852. });
  853. },
  854. // 获取水表对应的宿舍号
  855. async get_room() {
  856. try {
  857. if (this.devices.length > 0) {
  858. let devices_str = []
  859. for (var i = 0, len = this.devices.length; i < len; i++) {
  860. devices_str.push(this.devices[i].dname)
  861. }
  862. const res = await this.$myRequest({
  863. host: this.ceshi,
  864. url: '/HotWaters/waterqueryDom.action',
  865. method: 'POST',
  866. header: {
  867. 'content-type': 'application/x-www-form-urlencoded'
  868. },
  869. data: {
  870. user_id: devices_str.join(',')
  871. }
  872. });
  873. if (res.data.msg == '获取成功') {
  874. // 消费记录
  875. let items = res.data.data
  876. if (typeof items === 'undefined') {
  877. uni.showToast({
  878. title: '获取宿舍号为空',
  879. duration: 2000
  880. })
  881. return
  882. }
  883. for (var i = 0; i < items.length; i++) {
  884. let item = {
  885. id: items[i].user_id,
  886. room: items[i].dom
  887. }
  888. if (JSON.stringify(this.rooms).indexOf(JSON.stringify(item)) === -1) {
  889. this.rooms.push(item); // 进行动态的操作
  890. }
  891. }
  892. } else {
  893. if (this.changeDate) {
  894. uni.showToast({
  895. icon: 'success',
  896. title: res.data.mess,
  897. success: () => {
  898. this.changeDate = false
  899. }
  900. })
  901. if (res.data.mess == '本月无消费记录') {
  902. this.xiaofei_items = []
  903. }
  904. }
  905. }
  906. }
  907. } catch (e) {
  908. console.log('获取水表对应的宿舍号:' + e.message);
  909. }
  910. },
  911. /**
  912. * 555555555555555555555555555555555
  913. * 连接蓝牙设备
  914. */
  915. createBLEConnection() {
  916. //连接蓝牙
  917. uni.createBLEConnection({
  918. deviceId: this.deviceId,
  919. timeout: 6000,
  920. success: (res) => {
  921. // console.log(res)
  922. this.connect_BLE()
  923. },
  924. fail: (err) => {
  925. // console.log(err)
  926. this.isScan = false
  927. if (err.errMsg.indexOf('already connect') != -1) {
  928. this.connect_BLE()
  929. } else {
  930. uni.showToast({
  931. title: '错误:' + err.errMsg,
  932. icon: 'none',
  933. duration: 3000,
  934. success: (res1) => {
  935. this.setInit()
  936. }
  937. })
  938. }
  939. }
  940. })
  941. },
  942. connect_BLE() {
  943. if (this.isConnected === false) {
  944. this.isConnected = true
  945. // 获取蓝牙设备所有服务(service)
  946. this.getBLEDeviceServices()
  947. }
  948. },
  949. /**
  950. * 6666666666666666666666666666666666
  951. * 获取蓝牙的所有服务
  952. */
  953. getBLEDeviceServices() {
  954. uni.getBLEDeviceServices({
  955. deviceId: this.deviceId,
  956. success: (res) => {
  957. // console.log(res)
  958. // res1.services.forEach((item) => {
  959. // this.getBLEDeviceCharacteristics()
  960. // })
  961. this.serviceId = res.services[1].uuid
  962. this.process_control(1);
  963. this.getBLEDeviceCharacteristics()
  964. },
  965. fail: (err) => {
  966. // console.log(err)
  967. this.isScan = false
  968. uni.showToast({
  969. title: '获取服务失败',
  970. icon: 'none',
  971. duration: 3000
  972. })
  973. return
  974. }
  975. });
  976. },
  977. /**
  978. * 777777777777777777777777777777777
  979. * 获取蓝牙特征
  980. */
  981. getBLEDeviceCharacteristics() {
  982. // 获取蓝牙设备某个服务中所有特征值(characteristic)
  983. uni.getBLEDeviceCharacteristics({
  984. deviceId: this.deviceId,
  985. // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
  986. serviceId: this.serviceId,
  987. success: (res) => {
  988. // console.log(res)
  989. this.characteristicIdForWrite = res.characteristics[0].uuid
  990. this.characteristicIdForNotity = res.characteristics[1].uuid
  991. this.deviceIsWrite = res.characteristics[0].properties.write
  992. this.deviceIsNotify = res.characteristics[1].properties.notify
  993. // console.log(this.characteristicIdForWrite, this.characteristicIdForNotity)
  994. // 确保对应服务id下的特征值id具备监听数据变化的特性
  995. if (res.characteristics[1].properties.notify) {
  996. this.notifyBLECharacteristicValueChange()
  997. }
  998. },
  999. fail: (err) => {
  1000. this.isScan = false
  1001. // console.error('获取蓝牙设备特征值失败(getBLEDeviceCharacteristics)', err)
  1002. }
  1003. });
  1004. },
  1005. /**
  1006. * 888888888888888888888888888888888888
  1007. * 启用 notify 功能
  1008. */
  1009. notifyBLECharacteristicValueChange() {
  1010. uni.notifyBLECharacteristicValueChange({
  1011. state: true, // 启用 notify 功能
  1012. deviceId: this.deviceId,
  1013. // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
  1014. serviceId: this.serviceId,
  1015. // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
  1016. characteristicId: this.characteristicIdForNotity,
  1017. success: (res) => {
  1018. this.process_control(2)
  1019. uni.showToast({
  1020. icon: 'none',
  1021. title: '要启动水表,请手动点击【开启设备】右侧开关!',
  1022. duration: 5000
  1023. })
  1024. // uni.showModal({
  1025. // title: '提示',
  1026. // content: '要启动水表,请手动点击【开启设备】右侧开关!',
  1027. // showCancel: false,
  1028. // confirmText: '好,知道'
  1029. // })
  1030. this.isScan = false
  1031. // console.log('通知启用(notifyBLECharacteristicValueChange)',res);
  1032. this.onBLECharacteristicValueChange()
  1033. setTimeout(() => {
  1034. // 发送 AAABAC,采集数据(会返回 35字节 的数据)
  1035. this.send('')
  1036. }, 800)
  1037. // // 请求设备信息
  1038. // this.request_device_info()
  1039. // // 显示设备启动授权金额
  1040. // this.display_device_startup_amount()
  1041. },
  1042. fail: (err) => {
  1043. // console.log(err)
  1044. this.isScan = false
  1045. uni.showModal({
  1046. content: err.errMsg,
  1047. showCancel: false
  1048. })
  1049. // 初始化
  1050. this.setInit()
  1051. }
  1052. })
  1053. },
  1054. /**
  1055. * 999999999999999999999999999999999
  1056. * 监听低功耗蓝牙设备的特征值变化
  1057. */
  1058. onBLECharacteristicValueChange() {
  1059. uni.onBLECharacteristicValueChange((characteristic) => {
  1060. let condition = this.ab2hex(characteristic.value)
  1061. // console.log(condition)
  1062. if (condition.length > 2) {
  1063. this.byte35_tmp += condition
  1064. if (this.byte35_tmp.length > 40) {
  1065. this.byte35 = this.byte35_tmp
  1066. this.byte35_tmp = ''
  1067. if (this.byte35.startsWith('ad')) {
  1068. // console.log(this.byte35, '结束用水成功')
  1069. // 关闭蓝牙连接
  1070. this.closeBLEConnection()
  1071. // 请求结算
  1072. this.request_pay()
  1073. } else {
  1074. // 发送 AAABAC,采集数据(会返回 35字节 的数据)
  1075. // b58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0103bc
  1076. // uni.showToast({
  1077. // icon: 'success',
  1078. // title: '采集数据成功!',
  1079. // duration: 2000
  1080. // })
  1081. // console.log(this.byte35, '采集上一条消费数据')
  1082. }
  1083. }
  1084. }
  1085. switch (condition) {
  1086. case 'bb':
  1087. // uni.showToast({
  1088. // title: '设备启动成功',
  1089. // duration: 3000,
  1090. // icon: 'none'
  1091. // })
  1092. this.isChecked = true
  1093. break
  1094. case 'bc':
  1095. uni.showToast({
  1096. title: '启动失败,设备检验启动代码不通过',
  1097. duration: 3000,
  1098. icon: 'none'
  1099. })
  1100. break
  1101. case 'aa':
  1102. uni.showToast({
  1103. title: '设备正在使用',
  1104. duration: 3000,
  1105. icon: 'none'
  1106. })
  1107. break
  1108. case 'ab':
  1109. uni.showToast({
  1110. title: '结束失败,设备对结束代码检验失败',
  1111. duration: 3000,
  1112. icon: 'none'
  1113. })
  1114. break
  1115. default:
  1116. break
  1117. }
  1118. })
  1119. },
  1120. /**
  1121. * 关闭连接
  1122. */
  1123. closeBLEConnection() {
  1124. uni.closeBLEConnection({
  1125. deviceId: this.deviceId,
  1126. success: () => {
  1127. // 关闭蓝牙模块
  1128. this.closeBluetoothAdapter()
  1129. },
  1130. fail: () => {
  1131. this.setInit()
  1132. // uni.showToast({
  1133. // icon: 'none',
  1134. // title: '蓝牙连接断开失败',
  1135. // duration: 3000,
  1136. // success: (res1) => {
  1137. // this.setInit()
  1138. // }
  1139. // })
  1140. }
  1141. })
  1142. },
  1143. closeBluetoothAdapter() {
  1144. // 关闭蓝牙模块
  1145. uni.closeBluetoothAdapter({
  1146. success: () => {
  1147. this.setInit()
  1148. if (this.isUserClose == false) { // 设备端结束用水
  1149. if (this.isChecked) {
  1150. // console.log('设备端已结束用水,蓝牙断开成功')
  1151. uni.showToast({
  1152. icon: 'none',
  1153. title: '设备端已结束用水,蓝牙断开成功',
  1154. duration: 3000
  1155. })
  1156. } else {
  1157. // console.log('用户重启扫描,蓝牙断开成功')
  1158. uni.showToast({
  1159. icon: 'none',
  1160. title: '用户重启扫描,蓝牙断开成功',
  1161. duration: 3000
  1162. })
  1163. }
  1164. } else { // 手机移动端结束用水
  1165. // console.log('APP端已结束用水,蓝牙断开成功')
  1166. uni.showToast({
  1167. icon: 'none',
  1168. title: 'APP端已结束用水,蓝牙断开成功',
  1169. duration: 3000
  1170. })
  1171. }
  1172. }
  1173. })
  1174. },
  1175. setInit() {
  1176. setTimeout(() => {
  1177. this.isUserClose = false
  1178. this.isChecked = false
  1179. this.isConnected = false
  1180. this.isScan = false
  1181. this.active = -1
  1182. this.device_code = '' // 设备编号
  1183. this.devices = [] // 保存设备, 加了【空中连接】,不需要置为空。
  1184. this.deviceId = '' // 加了【空中连接】,不需要置为空。
  1185. this.serviceId = ''
  1186. this.characteristicIdForWrite = ''
  1187. this.characteristicIdForNotity = ''
  1188. this.deviceIsNotify = false
  1189. this.deviceIsWrite = false
  1190. this.byte35 = '' // 70 个字符
  1191. this.byte35_tmp = '' // 70 个字符 临时变量
  1192. this.get_Bluetooth_Bevice = false
  1193. this.rooms = [] // 宿舍号,蓝牙连接具有时效性,断开连接后清空
  1194. // this.start_code = ''
  1195. })
  1196. },
  1197. /**
  1198. * 10===========10==================10
  1199. * 发送数据到设备
  1200. */
  1201. send(val) {
  1202. let buffer
  1203. let dataView
  1204. let newArr
  1205. if (val == 'start') { // 启动设备
  1206. this.isUserClose = false
  1207. // 发送 17字节 启动代码(会返回 35字节 的数据)
  1208. // b58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0103bc
  1209. newArr = this.str2StrArray(this.start_code)
  1210. } else if (val == 'stop') { // 结束当前使用,设备成功返回:AD+35字节 消费结算代码
  1211. this.isUserClose = true
  1212. // 发送 AAABAD+17字节 启动代码(会返回 ad+35字节 的数据)
  1213. // adb58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0104bc
  1214. newArr = ['AA', 'AB', 'AD'].concat(this.str2StrArray(this.start_code))
  1215. } else {
  1216. // 发送 AAABAC 采集数据(会返回 35字节 的数据)
  1217. // b58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0103bc
  1218. newArr = ['AA', 'AB', 'AC']
  1219. }
  1220. buffer = new ArrayBuffer(newArr.length)
  1221. dataView = new DataView(buffer)
  1222. newArr.forEach((item, i) => {
  1223. dataView.setUint8(i, this.sixteen_to_ten(item))
  1224. })
  1225. // 写特征值数据到设备
  1226. if (this.deviceIsWrite) {
  1227. // 写数据到设备
  1228. this.writeBLECharacteristicValue(val, buffer)
  1229. } else {
  1230. uni.showToast({
  1231. title: '设备不可写',
  1232. duration: 3000
  1233. })
  1234. }
  1235. },
  1236. /**
  1237. * 11====================11=====================11
  1238. * 写数据到设备
  1239. */
  1240. writeBLECharacteristicValue(val, buffer) {
  1241. uni.writeBLECharacteristicValue({
  1242. deviceId: this.deviceId,
  1243. // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
  1244. serviceId: this.serviceId,
  1245. // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
  1246. characteristicId: this.characteristicIdForWrite,
  1247. // 这里的value是ArrayBuffer类型
  1248. value: buffer,
  1249. success: (res) => {
  1250. // console.log(res)
  1251. if (val == 'start') {
  1252. setTimeout(() => {
  1253. this.isChecked = true
  1254. this.isConnected = true
  1255. }, 300)
  1256. this.process_control(3)
  1257. } else if (val == 'stop') {
  1258. setTimeout(() => {
  1259. this.isChecked = false
  1260. }, 300)
  1261. }
  1262. },
  1263. fail: (err) => {
  1264. // console.log(err)
  1265. if (err.errCode == 10006) {
  1266. setTimeout(() => {
  1267. this.setInit()
  1268. }, 300)
  1269. if (this.isConnected) {
  1270. uni.showToast({
  1271. title: '设备连接已断开!请在水表上手动停止!',
  1272. icon: 'none'
  1273. })
  1274. } else {
  1275. uni.showToast({
  1276. title: '设备连接失败!请重试扫描连接!',
  1277. icon: 'none'
  1278. })
  1279. }
  1280. }
  1281. }
  1282. })
  1283. },
  1284. /**
  1285. * 请求获取设备启动码
  1286. */
  1287. async request_device_start_code() {
  1288. if (this.byte35 != '' && this.stu_number != '') {
  1289. const res = await this.$myRequest({
  1290. host: this.ceshi,
  1291. url: '/HotWaters/wpstart.action',
  1292. data: {
  1293. collect_code: this.byte35,
  1294. stu_number: this.stu_number
  1295. }
  1296. })
  1297. // console.log(res)
  1298. let sc = res.data.start_code
  1299. if (typeof(sc) != 'undefined' && sc != '') {
  1300. this.start_code = sc
  1301. setTimeout(() => {
  1302. this.send('start')
  1303. }, 100)
  1304. // 刷新选定的月份消费记录
  1305. this.request_consumption_records()
  1306. } else {
  1307. this.isChecked = false
  1308. uni.showToast({
  1309. icon: 'none',
  1310. title: res.data.mess,
  1311. duration: 3000,
  1312. })
  1313. }
  1314. } else {
  1315. uni.showToast({
  1316. icon: 'none',
  1317. title: '字节码或学号为空!'
  1318. });
  1319. // 初始化
  1320. this.setInit()
  1321. }
  1322. },
  1323. /**
  1324. * 请求结算
  1325. */
  1326. async request_pay() {
  1327. if (this.byte35 != '') {
  1328. const res = await this.$myRequest({
  1329. host: this.ceshi,
  1330. url: '/HotWaters/wpconsume.action',
  1331. data: {
  1332. stu_number: this.stu_number,
  1333. user_name: this.user_name,
  1334. collect_code: this.byte35.substring(2)
  1335. }
  1336. })
  1337. // console.log(res)
  1338. if (res.data.mess == "支付成功") {
  1339. uni.showToast({
  1340. icon: 'success',
  1341. title: '结算成功!',
  1342. success: (res1) => {
  1343. this.use_amount = res.data.use_amount.toFixed(2)
  1344. this.amount = (this.amount - this.use_amount).toFixed(2)
  1345. this.$store.state.reshui_amount = this.amount
  1346. setTimeout(() => {
  1347. // 刷新选定的月份消费记录
  1348. this.request_consumption_records()
  1349. }, 1000)
  1350. }
  1351. })
  1352. } else {
  1353. uni.showToast({
  1354. icon: 'none',
  1355. title: res.data.mess,
  1356. duration: 3000
  1357. })
  1358. }
  1359. } else {
  1360. uni.showToast({
  1361. icon: 'success',
  1362. title: '字节码为空!'
  1363. });
  1364. // 初始化
  1365. this.setInit()
  1366. }
  1367. },
  1368. /**
  1369. * 返回字符处理
  1370. */
  1371. str2StrArray(start_code) {
  1372. if (typeof(start_code) == 'undefined' || start_code == '') {
  1373. uni.showToast({
  1374. icon: 'none',
  1375. title: '设备码获取失败'
  1376. })
  1377. this.setInit()
  1378. return
  1379. }
  1380. if (start_code.length != 34) {
  1381. // console.log('启动码长度错误')
  1382. throw new Error("启动码长度错误");
  1383. return
  1384. }
  1385. var resultArray = new Array()
  1386. for (var i = 0; i < start_code.length; i += 2) {
  1387. resultArray.push(start_code.substr(i, 2));
  1388. }
  1389. return resultArray;
  1390. },
  1391. /**
  1392. * ArrayBuffer转16进度字符串
  1393. */
  1394. ab2hex(buffer) {
  1395. const hexArr = Array.prototype.map.call(
  1396. new Uint8Array(buffer),
  1397. function(bit) {
  1398. // console.log('====================' + bit + '==========================')
  1399. return ('00' + bit.toString(16)).slice(-2)
  1400. }
  1401. )
  1402. return hexArr.join('');
  1403. },
  1404. /**
  1405. * 16进制转10进制
  1406. */
  1407. sixteen_to_ten(str) {
  1408. return parseInt(str, 16);
  1409. }
  1410. }
  1411. }
  1412. </script>
  1413. <style scoped lang="scss">
  1414. .content {
  1415. width: 100%;
  1416. height: 100%;
  1417. .container {
  1418. width: 100%;
  1419. padding: 20rpx 40rpx;
  1420. box-sizing: border-box;
  1421. .header {
  1422. display: flex;
  1423. justify-content: center;
  1424. position: relative;
  1425. height: 200rpx;
  1426. .scan {
  1427. display: flex;
  1428. flex-direction: column;
  1429. justify-content: center;
  1430. align-items: center;
  1431. height: 200rpx;
  1432. width: 30%;
  1433. .iconfont {
  1434. margin-bottom: 10rpx;
  1435. font-size: 100rpx;
  1436. color: $my-color-primary;
  1437. }
  1438. }
  1439. .scan_hover {
  1440. border-radius: 15rpx;
  1441. background-color: $my-color-btn-background;
  1442. }
  1443. .qinshihao {
  1444. display: flex;
  1445. align-items: center;
  1446. position: fixed;
  1447. top: 20rpx;
  1448. right: 30rpx;
  1449. font-size: 28rpx;
  1450. .icon-zhuye {
  1451. margin-right: 10rpx;
  1452. font-family: Microsoft YaHei-3970(82674968);
  1453. color: $my-color-primary;
  1454. }
  1455. .compustxt {
  1456. font-size: 18rpx;
  1457. }
  1458. }
  1459. }
  1460. .start_text {
  1461. .start_top,
  1462. .start_mid {
  1463. display: flex;
  1464. justify-content: space-between;
  1465. height: 100rpx;
  1466. align-items: center;
  1467. border-bottom: 2rpx #ccc solid;
  1468. .item_left {
  1469. display: flex;
  1470. align-items: center;
  1471. }
  1472. .start_mid_txt {
  1473. padding: 16rpx;
  1474. border-radius: 10rpx;
  1475. font-size: 36rpx;
  1476. font-weight: bold;
  1477. color: #333;
  1478. }
  1479. .iconfont {
  1480. font-size: 50rpx;
  1481. color: $my-color-primary;
  1482. margin-right: 20rpx;
  1483. }
  1484. .start_payamount {
  1485. display: flex;
  1486. justify-content: flex-end;
  1487. align-items: center;
  1488. font-size: 38rpx;
  1489. padding: 10rpx;
  1490. font-family: Microsoft YaHei-3970(82674968);
  1491. color: #B2B2B2;
  1492. border-radius: 10rpx;
  1493. .icon-dayuhao {
  1494. margin: 0 0 0 20rpx;
  1495. font-size: 38rpx;
  1496. color: #B2B2B2;
  1497. }
  1498. }
  1499. }
  1500. .start_bot {
  1501. display: flex;
  1502. justify-content: space-between;
  1503. height: 100rpx;
  1504. align-items: center;
  1505. .kongzhonglianjie {
  1506. margin: 0;
  1507. height: 60rpx;
  1508. line-height: 60rpx;
  1509. font-size: 28rpx;
  1510. background-color: #1296DB;
  1511. color: #FFFFFF;
  1512. }
  1513. .start_bot_txt {
  1514. margin-left: 20rpx;
  1515. color: #333;
  1516. font-size: 28rpx;
  1517. }
  1518. }
  1519. }
  1520. .btn_room {
  1521. font-size: 28rpx;
  1522. background-color: #41c560;
  1523. margin: 10rpx auto;
  1524. }
  1525. .start_up_process {
  1526. padding: 20rpx 0;
  1527. color: #007AFF;
  1528. }
  1529. .ad {
  1530. margin: 0 -40rpx;
  1531. padding: 10rpx;
  1532. width: 730rpx;
  1533. height: 424rpx;
  1534. .ad_img {
  1535. height: 100%;
  1536. width: 100%;
  1537. }
  1538. }
  1539. .title {
  1540. height: 100rpx;
  1541. margin: 0 -40rpx;
  1542. padding: 0 40rpx;
  1543. line-height: 100rpx;
  1544. color: #808080;
  1545. font-size: 32rpx;
  1546. background: #f2f2f2;
  1547. }
  1548. .record-item {
  1549. width: 100%;
  1550. .uni-list-cell-db {
  1551. height: 100rpx;
  1552. line-height: 100rpx;
  1553. font-weight: bold;
  1554. .uni-input {
  1555. display: flex;
  1556. align-items: center;
  1557. text:nth-child(1) {
  1558. margin-right: 10rpx;
  1559. }
  1560. }
  1561. }
  1562. .item-list {
  1563. height: 80rpx;
  1564. display: flex;
  1565. align-items: center;
  1566. justify-content: space-between;
  1567. border-top: 2rpx #ccc solid;
  1568. .icon-shijian {
  1569. margin-right: 8rpx;
  1570. }
  1571. .icon-shuidi {
  1572. margin-right: 3rpx;
  1573. }
  1574. .item-list-txt {
  1575. font-size: 28rpx;
  1576. &:nth-of-type(2) {
  1577. color: #515151;
  1578. }
  1579. &:nth-of-type(3) {
  1580. color: #f76200;
  1581. font-size: 32rpx;
  1582. }
  1583. }
  1584. }
  1585. }
  1586. }
  1587. }
  1588. </style>