reshui.vue 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737
  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. setTimeout(() => {
  499. this.isChecked = false
  500. }, 200)
  501. uni.showToast({
  502. icon: 'none',
  503. title: '先【扫码连接】,后【开启设备】',
  504. duration: 1500
  505. })
  506. }
  507. } else {
  508. if (!(this.deviceId && this.serviceId)) {
  509. uni.showToast({
  510. icon: 'none',
  511. title: '与设备连接中断!请在设备上手动停止即可!',
  512. duration: 3000
  513. })
  514. setTimeout(() => {
  515. this.setInit()
  516. }, 300)
  517. return
  518. }
  519. uni.showModal({
  520. title: '提示',
  521. content: '确定要关闭设备?',
  522. success: (res) => {
  523. if (res.confirm) {
  524. if (this.deviceId && this.serviceId) {
  525. this.isChecked = false
  526. this.send('stop')
  527. } else {
  528. uni.showToast({
  529. icon: 'none',
  530. title: '与设备连接中断!请在设备上手动停止即可!',
  531. duration: 3000
  532. })
  533. setTimeout(() => {
  534. // this.isChecked = true;
  535. this.setInit()
  536. }, 300)
  537. }
  538. } else if (res.cancel) {
  539. setTimeout(() => {
  540. this.isChecked = true
  541. }, 300)
  542. }
  543. }
  544. })
  545. }
  546. },
  547. /**
  548. * 跳转到充值页面
  549. */
  550. chongzhi_yemian() {
  551. //在起始页面跳转到recharge.vue页面并传递参数
  552. uni.navigateTo({
  553. url: '../recharge/recharge'
  554. });
  555. },
  556. /**
  557. * 判断余额是否充足
  558. */
  559. judgeBalance(param) {
  560. var limit_amount = parseFloat(this.$store.state.amount)
  561. var amount = parseFloat(this.amount);
  562. // 启动最低金额限制
  563. if (amount < limit_amount) {
  564. uni.showModal({
  565. title: '提示',
  566. content: '当前余额不足¥' + limit_amount + '元',
  567. cancelText: '我知道了',
  568. confirmText: '我要充值',
  569. success: (res) => {
  570. if (res.confirm) {
  571. // 跳转充值页面
  572. this.chongzhi_yemian()
  573. // return false
  574. // } else if (res.cancel) {
  575. // return false
  576. }
  577. }
  578. })
  579. return false
  580. }
  581. // 已经启动扫描连接设备中
  582. if (this.isScan) {
  583. uni.showToast({
  584. icon: 'none',
  585. title: '正在扫描,请耐心等待',
  586. })
  587. return false
  588. }
  589. // 已经启动设备,不启动扫描
  590. if (this.isChecked) {
  591. let info_str = ''
  592. if (param == 'scan') {
  593. info_str = '设备已启动,无需重新扫码'
  594. } else {
  595. info_str = '设备已启动,无需重新启动'
  596. }
  597. uni.showToast({
  598. icon: 'none',
  599. title: info_str,
  600. })
  601. return false
  602. }
  603. // console.log(this.deviceId);
  604. // 设备已连接
  605. if (this.deviceId) {
  606. uni.showModal({
  607. title: '提示',
  608. content: '设备已经连接,需要重新连接吗?',
  609. success: res => {
  610. if (res.confirm) {
  611. // 关闭连接
  612. this.closeBLEConnection()
  613. if (param == 'scan') {
  614. // 扫描
  615. this.scan_qr()
  616. } else {
  617. // cancel
  618. }
  619. }
  620. }
  621. })
  622. return false
  623. }
  624. },
  625. /**
  626. * 111111111111111111111111111111
  627. * 扫码连接设备
  628. */
  629. scan() {
  630. if (this.judgeBalance('scan') == false) {
  631. return
  632. }
  633. this.scan_qr()
  634. },
  635. /**
  636. * 启动摄像头,扫描二维码
  637. */
  638. scan_qr() {
  639. this.get_Bluetooth_Bevice = true
  640. uni.scanCode({
  641. onlyFromCamera: true,
  642. success: (res) => {
  643. this.isScan = true
  644. // console.log(res)
  645. // charSet: "utf-8"
  646. // codeVersion: 3
  647. // errMsg: "scanCode:ok"
  648. // rawData: "aHR0cDovL3Rvb2xzLjlrYnMuY29tLz93eG1pbmljb2RlPUtCNTgwMDAyNjUy"
  649. // result: "http://tools.9kbs.com/?wxminicode=KB580002652"
  650. // scanType: "QR_CODE"
  651. this.device_code = res.result.split('=')[1]
  652. if (this.device_code === '') {
  653. uni.showToast({
  654. icon: 'success',
  655. title: '获取设备码失败',
  656. duration: 3000
  657. })
  658. this.isScan = false
  659. } else {
  660. // 初始化蓝牙
  661. this.openBluetoothAdapter()
  662. }
  663. }
  664. })
  665. },
  666. /**
  667. * 22222222222222222222222222222
  668. * 初始化蓝牙
  669. */
  670. openBluetoothAdapter() {
  671. let _this = this;
  672. uni.openBluetoothAdapter({
  673. success: (res) => { // 已打开
  674. uni.getBluetoothAdapterState({ // 蓝牙的匹配状态
  675. success: (res1) => {
  676. // console.log(res1, '“本机设备的蓝牙已打开”');
  677. // 本机设备的蓝牙已打开
  678. // 开始搜索蓝牙设备
  679. if (this.deviceId == '' && this.serviceId == '')
  680. this.startBluetoothDeviceDiscovery()
  681. },
  682. fail: (error) => {
  683. // console.log(error)
  684. uni.showModal({
  685. content: '请开启手机蓝牙!',
  686. showCancel: false,
  687. success() {
  688. // _this.myOpenBluetoothAdapter();
  689. }
  690. });
  691. this.isScan = false
  692. }
  693. });
  694. },
  695. fail: (err) => { // 未打开
  696. // console.log(err)
  697. this.isScan = false;
  698. if (err.errCode == 10001) {
  699. uni.showModal({
  700. content: '请授权手机蓝牙!',
  701. showCancel: false,
  702. success() {
  703. // _this.myOpenBluetoothAdapter();
  704. }
  705. });
  706. } else {
  707. uni.showToast({
  708. icon: 'none',
  709. title: err.errMsg,
  710. duration: 2000
  711. })
  712. }
  713. }
  714. });
  715. },
  716. /**
  717. * 让用户去手动授权
  718. */
  719. myOpenBluetoothAdapter() {
  720. // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.bluetooth" 这个 scope
  721. uni.getSetting({
  722. success(res) {
  723. // console.log(res.authSetting)
  724. //判断是否有'scope.bluetooth'属性
  725. if (res.authSetting.hasOwnProperty('scope.bluetooth')) {
  726. //'scope.bluetooth'属性存在,且为false
  727. if (!res.authSetting['scope.bluetooth']) {
  728. //弹窗授权
  729. uni.openSetting({
  730. success(res) {
  731. console.log(res.authSetting)
  732. }
  733. })
  734. }
  735. } else
  736. //'scope.bluetooth'属性不存在,需要授权
  737. uni.authorize({
  738. scope: 'scope.bluetooth',
  739. success() {
  740. // 用户已经同意小程序使用手机蓝牙功能,后续调用 蓝牙 接口不会弹窗询问
  741. console.log(res.authSetting)
  742. }
  743. })
  744. }
  745. });
  746. },
  747. /**
  748. * 333333333333333333333333333
  749. * 开始搜索蓝牙设备
  750. */
  751. startBluetoothDeviceDiscovery() {
  752. uni.startBluetoothDevicesDiscovery({ // 开始搜寻附近的蓝牙外围设备
  753. // services: ['FEE7'], // 要搜索但蓝牙设备主 service 的 uuid 列表
  754. allowDuplicatesKey: true,
  755. success: (res) => {
  756. if (this.get_Bluetooth_Bevice == true)
  757. this.process_control(0)
  758. this.onBluetoothDeviceFound() // 监听搜索到新设备 同时进行
  759. setTimeout(() => {
  760. if (this.isScan) {
  761. uni.showModal({
  762. title: '温馨提示',
  763. content: '请确认已开启【蓝牙授权】或【定位授权】!',
  764. confirmText: '我已开启',
  765. cancelText: '取消',
  766. success: (res) => {
  767. // console.log(res);
  768. if (res.confirm) {
  769. } else if (res.cancel) {
  770. switch (uni.getSystemInfoSync().platform) {
  771. case 'android':
  772. // 打开设置
  773. break;
  774. case 'ios':
  775. // 打开设置
  776. break;
  777. default:
  778. // console.log('运行在开发者工具上')
  779. break;
  780. }
  781. }
  782. }
  783. })
  784. }
  785. }, 6000)
  786. },
  787. fail: err => {
  788. // console.log(err, '错误信息');
  789. uni.showToast({
  790. icon: 'none',
  791. title: err.errMsg,
  792. duration: 2000
  793. })
  794. this.isScan = false
  795. }
  796. })
  797. },
  798. stopBluetoothDevicesDiscovery() { //停止搜索
  799. uni.stopBluetoothDevicesDiscovery({
  800. success: (res) => {
  801. // console.log(res, '停止蓝牙搜索')
  802. // uni.showToast({
  803. // title: '停止蓝牙搜索',
  804. // duration: 2000
  805. // })
  806. if (this.get_Bluetooth_Bevice == true || this.device_code) {
  807. this.createBLEConnection()
  808. } else {
  809. this.get_room()
  810. setTimeout(() => {
  811. this.get_Bluetooth_Bevice = true
  812. }, 2000)
  813. }
  814. },
  815. fail: err => {
  816. // console.log('停止搜索蓝牙设备失败,错误码:' + err.errCode);
  817. this.isScan = false
  818. uni.showToast({
  819. title: err.errCode,
  820. duration: 2000
  821. })
  822. }
  823. })
  824. },
  825. /**
  826. * 444444444444444444444444444444444
  827. * 发现外围设备
  828. */
  829. onBluetoothDeviceFound() {
  830. uni.onBluetoothDeviceFound((res) => {
  831. let dname = ''
  832. res.devices.forEach(device => { // 筛选找到的蓝牙中对名称匹配
  833. try {
  834. // 过滤掉没有名字的设备
  835. if (!device.name && !device.localName) {
  836. return
  837. }
  838. // 把搜索到的设备存储起来,如有需要可以在页面上展示
  839. dname = device.name.substr(1)
  840. let d = {
  841. did: device.deviceId,
  842. dname: dname
  843. }
  844. if (dname.length == 10 && JSON.stringify(this.devices).indexOf(JSON.stringify(
  845. d)) === -1) {
  846. this.devices.push(d)
  847. }
  848. if (device.name == this.device_code) {
  849. this.process_control(0);
  850. //data里面建立一个deviceId、device_code,存储起来
  851. // this.device_code = device.name;
  852. this.deviceId = device.deviceId
  853. // 放此位置,苹果手机兼容
  854. this.stopBluetoothDevicesDiscovery()
  855. return
  856. }
  857. setTimeout(() => {
  858. this.stopBluetoothDevicesDiscovery()
  859. }, 2000)
  860. } catch (e) {
  861. // console.log('发现外围设备:' + e.message);
  862. }
  863. })
  864. });
  865. },
  866. // 获取水表对应的宿舍号
  867. async get_room() {
  868. try {
  869. if (this.devices.length > 0) {
  870. let devices_str = []
  871. for (var i = 0, len = this.devices.length; i < len; i++) {
  872. devices_str.push(this.devices[i].dname)
  873. }
  874. const res = await this.$myRequest({
  875. host: this.ceshi,
  876. url: '/HotWaters/waterqueryDom.action',
  877. method: 'POST',
  878. header: {
  879. 'content-type': 'application/x-www-form-urlencoded'
  880. },
  881. data: {
  882. user_id: devices_str.join(',')
  883. }
  884. });
  885. if (res.data.msg == '获取成功') {
  886. // 消费记录
  887. let items = res.data.data
  888. if (typeof items === 'undefined') {
  889. uni.showToast({
  890. title: '获取宿舍号为空',
  891. duration: 2000
  892. })
  893. return
  894. }
  895. for (var i = 0; i < items.length; i++) {
  896. let item = {
  897. id: items[i].user_id,
  898. room: items[i].dom
  899. }
  900. if (JSON.stringify(this.rooms).indexOf(JSON.stringify(item)) === -1) {
  901. this.rooms.push(item); // 进行动态的操作
  902. }
  903. }
  904. } else {
  905. if (this.changeDate) {
  906. uni.showToast({
  907. icon: 'success',
  908. title: res.data.mess,
  909. success: () => {
  910. this.changeDate = false
  911. }
  912. })
  913. if (res.data.mess == '本月无消费记录') {
  914. this.xiaofei_items = []
  915. }
  916. }
  917. }
  918. }
  919. } catch (e) {
  920. console.log('获取水表对应的宿舍号:' + e.message);
  921. }
  922. },
  923. /**
  924. * 555555555555555555555555555555555
  925. * 连接蓝牙设备
  926. */
  927. createBLEConnection() {
  928. //连接蓝牙
  929. uni.createBLEConnection({
  930. deviceId: this.deviceId,
  931. timeout: 6000,
  932. success: (res) => {
  933. // console.log(res)
  934. this.connect_BLE()
  935. },
  936. fail: (err) => {
  937. // console.log(err)
  938. this.isScan = false
  939. if (err.errMsg.indexOf('already connect') != -1) {
  940. this.connect_BLE()
  941. } else {
  942. uni.showToast({
  943. title: '错误:' + err.errMsg,
  944. icon: 'none',
  945. duration: 3000,
  946. success: (res1) => {
  947. this.setInit()
  948. }
  949. })
  950. }
  951. }
  952. })
  953. },
  954. connect_BLE() {
  955. if (this.isConnected === false) {
  956. this.isConnected = true
  957. // 获取蓝牙设备所有服务(service)
  958. this.getBLEDeviceServices()
  959. }
  960. },
  961. /**
  962. * 6666666666666666666666666666666666
  963. * 获取蓝牙的所有服务
  964. */
  965. getBLEDeviceServices() {
  966. uni.getBLEDeviceServices({
  967. deviceId: this.deviceId,
  968. success: (res) => {
  969. // console.log(res)
  970. // res1.services.forEach((item) => {
  971. // this.getBLEDeviceCharacteristics()
  972. // })
  973. this.serviceId = res.services[1].uuid
  974. this.process_control(1);
  975. this.getBLEDeviceCharacteristics()
  976. },
  977. fail: (err) => {
  978. // console.log(err)
  979. this.isScan = false
  980. uni.showToast({
  981. title: '获取服务失败',
  982. icon: 'none',
  983. duration: 3000
  984. })
  985. return
  986. }
  987. });
  988. },
  989. /**
  990. * 777777777777777777777777777777777
  991. * 获取蓝牙特征
  992. */
  993. getBLEDeviceCharacteristics() {
  994. // 获取蓝牙设备某个服务中所有特征值(characteristic)
  995. uni.getBLEDeviceCharacteristics({
  996. deviceId: this.deviceId,
  997. // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
  998. serviceId: this.serviceId,
  999. success: (res) => {
  1000. // console.log(res)
  1001. this.characteristicIdForWrite = res.characteristics[0].uuid
  1002. this.characteristicIdForNotity = res.characteristics[1].uuid
  1003. this.deviceIsWrite = res.characteristics[0].properties.write
  1004. this.deviceIsNotify = res.characteristics[1].properties.notify
  1005. // console.log(this.characteristicIdForWrite, this.characteristicIdForNotity)
  1006. // 确保对应服务id下的特征值id具备监听数据变化的特性
  1007. if (res.characteristics[1].properties.notify) {
  1008. this.notifyBLECharacteristicValueChange()
  1009. }
  1010. },
  1011. fail: (err) => {
  1012. this.isScan = false
  1013. // console.error('获取蓝牙设备特征值失败(getBLEDeviceCharacteristics)', err)
  1014. }
  1015. });
  1016. },
  1017. /**
  1018. * 888888888888888888888888888888888888
  1019. * 启用 notify 功能
  1020. */
  1021. notifyBLECharacteristicValueChange() {
  1022. uni.notifyBLECharacteristicValueChange({
  1023. state: true, // 启用 notify 功能
  1024. deviceId: this.deviceId,
  1025. // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
  1026. serviceId: this.serviceId,
  1027. // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
  1028. characteristicId: this.characteristicIdForNotity,
  1029. success: (res) => {
  1030. this.process_control(2)
  1031. uni.showToast({
  1032. icon: 'none',
  1033. title: '要启动水表,请手动点击【开启设备】右侧开关!',
  1034. duration: 5000
  1035. })
  1036. // uni.showModal({
  1037. // title: '提示',
  1038. // content: '要启动水表,请手动点击【开启设备】右侧开关!',
  1039. // showCancel: false,
  1040. // confirmText: '好,知道'
  1041. // })
  1042. this.isScan = false
  1043. // console.log('通知启用(notifyBLECharacteristicValueChange)',res);
  1044. this.onBLECharacteristicValueChange()
  1045. setTimeout(() => {
  1046. // 发送 AAABAC,采集数据(会返回 35字节 的数据)
  1047. this.send('')
  1048. }, 800)
  1049. // // 请求设备信息
  1050. // this.request_device_info()
  1051. // // 显示设备启动授权金额
  1052. // this.display_device_startup_amount()
  1053. },
  1054. fail: (err) => {
  1055. // console.log(err)
  1056. this.isScan = false
  1057. uni.showModal({
  1058. content: err.errMsg,
  1059. showCancel: false
  1060. })
  1061. // 初始化
  1062. this.setInit()
  1063. }
  1064. })
  1065. },
  1066. /**
  1067. * 999999999999999999999999999999999
  1068. * 监听低功耗蓝牙设备的特征值变化
  1069. */
  1070. onBLECharacteristicValueChange() {
  1071. uni.onBLECharacteristicValueChange((characteristic) => {
  1072. let condition = this.ab2hex(characteristic.value)
  1073. // console.log(condition)
  1074. if (condition.length > 2) {
  1075. this.byte35_tmp += condition
  1076. if (this.byte35_tmp.length > 40) {
  1077. this.byte35 = this.byte35_tmp
  1078. this.byte35_tmp = ''
  1079. if (this.byte35.startsWith('ad')) {
  1080. // console.log(this.byte35, '结束用水成功')
  1081. // 关闭蓝牙连接
  1082. this.closeBLEConnection()
  1083. // 请求结算
  1084. this.request_pay()
  1085. } else {
  1086. // 发送 AAABAC,采集数据(会返回 35字节 的数据)
  1087. // b58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0103bc
  1088. // uni.showToast({
  1089. // icon: 'success',
  1090. // title: '采集数据成功!',
  1091. // duration: 2000
  1092. // })
  1093. // console.log(this.byte35, '采集上一条消费数据')
  1094. }
  1095. }
  1096. }
  1097. switch (condition) {
  1098. case 'bb':
  1099. // uni.showToast({
  1100. // title: '设备启动成功',
  1101. // duration: 3000,
  1102. // icon: 'none'
  1103. // })
  1104. this.isChecked = true
  1105. break
  1106. case 'bc':
  1107. uni.showToast({
  1108. title: '启动失败,设备检验启动代码不通过',
  1109. duration: 3000,
  1110. icon: 'none'
  1111. })
  1112. break
  1113. case 'aa':
  1114. uni.showToast({
  1115. title: '设备正在使用',
  1116. duration: 3000,
  1117. icon: 'none'
  1118. })
  1119. break
  1120. case 'ab':
  1121. uni.showToast({
  1122. title: '结束失败,设备对结束代码检验失败',
  1123. duration: 3000,
  1124. icon: 'none'
  1125. })
  1126. break
  1127. default:
  1128. break
  1129. }
  1130. })
  1131. },
  1132. /**
  1133. * 关闭连接
  1134. */
  1135. closeBLEConnection() {
  1136. uni.closeBLEConnection({
  1137. deviceId: this.deviceId,
  1138. success: () => {
  1139. // 关闭蓝牙模块
  1140. this.closeBluetoothAdapter()
  1141. },
  1142. fail: () => {
  1143. this.setInit()
  1144. // uni.showToast({
  1145. // icon: 'none',
  1146. // title: '蓝牙连接断开失败',
  1147. // duration: 3000,
  1148. // success: (res1) => {
  1149. // this.setInit()
  1150. // }
  1151. // })
  1152. }
  1153. })
  1154. },
  1155. closeBluetoothAdapter() {
  1156. // 关闭蓝牙模块
  1157. uni.closeBluetoothAdapter({
  1158. success: () => {
  1159. this.setInit()
  1160. if (this.isUserClose == false) { // 设备端结束用水
  1161. if (this.isChecked) {
  1162. // console.log('设备端已结束用水,蓝牙断开成功')
  1163. uni.showToast({
  1164. icon: 'none',
  1165. title: '设备端已结束用水,蓝牙断开成功',
  1166. duration: 3000
  1167. })
  1168. } else {
  1169. // console.log('用户重启扫描,蓝牙断开成功')
  1170. uni.showToast({
  1171. icon: 'none',
  1172. title: '用户重启扫描,蓝牙断开成功',
  1173. duration: 3000
  1174. })
  1175. }
  1176. } else { // 手机移动端结束用水
  1177. // console.log('APP端已结束用水,蓝牙断开成功')
  1178. uni.showToast({
  1179. icon: 'none',
  1180. title: 'APP端已结束用水,蓝牙断开成功',
  1181. duration: 3000
  1182. })
  1183. }
  1184. }
  1185. })
  1186. },
  1187. setInit() {
  1188. setTimeout(() => {
  1189. this.isUserClose = false
  1190. this.isChecked = false
  1191. this.isConnected = false
  1192. this.isScan = false
  1193. this.active = -1
  1194. this.device_code = '' // 设备编号
  1195. this.devices = [] // 保存设备, 加了【空中连接】,不需要置为空。
  1196. this.deviceId = '' // 加了【空中连接】,不需要置为空。
  1197. this.serviceId = ''
  1198. this.characteristicIdForWrite = ''
  1199. this.characteristicIdForNotity = ''
  1200. this.deviceIsNotify = false
  1201. this.deviceIsWrite = false
  1202. this.byte35 = '' // 70 个字符
  1203. this.byte35_tmp = '' // 70 个字符 临时变量
  1204. this.get_Bluetooth_Bevice = false
  1205. this.rooms = [] // 宿舍号,蓝牙连接具有时效性,断开连接后清空
  1206. this.start_code = ''
  1207. }, 200)
  1208. },
  1209. /**
  1210. * 10===========10==================10
  1211. * 发送数据到设备
  1212. */
  1213. send(val) {
  1214. let buffer
  1215. let dataView
  1216. let newArr
  1217. if (val == 'start') { // 启动设备
  1218. this.isUserClose = false
  1219. // 发送 17字节 启动代码(会返回 35字节 的数据)
  1220. // b58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0103bc
  1221. newArr = this.str2StrArray(this.start_code)
  1222. } else if (val == 'stop') { // 结束当前使用,设备成功返回:AD+35字节 消费结算代码
  1223. this.isUserClose = true
  1224. // 发送 AAABAD+17字节 启动代码(会返回 ad+35字节 的数据)
  1225. // adb58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0104bc
  1226. newArr = ['AA', 'AB', 'AD'].concat(this.str2StrArray(this.start_code))
  1227. } else {
  1228. // 发送 AAABAC 采集数据(会返回 35字节 的数据)
  1229. // b58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0103bc
  1230. newArr = ['AA', 'AB', 'AC']
  1231. }
  1232. buffer = new ArrayBuffer(newArr.length)
  1233. dataView = new DataView(buffer)
  1234. newArr.forEach((item, i) => {
  1235. dataView.setUint8(i, this.sixteen_to_ten(item))
  1236. })
  1237. // 写特征值数据到设备
  1238. if (this.deviceIsWrite) {
  1239. // 写数据到设备
  1240. this.writeBLECharacteristicValue(val, buffer)
  1241. } else {
  1242. uni.showToast({
  1243. title: '设备不可写',
  1244. duration: 3000
  1245. })
  1246. }
  1247. },
  1248. /**
  1249. * 11====================11=====================11
  1250. * 写数据到设备
  1251. */
  1252. writeBLECharacteristicValue(val, buffer) {
  1253. uni.writeBLECharacteristicValue({
  1254. deviceId: this.deviceId,
  1255. // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
  1256. serviceId: this.serviceId,
  1257. // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
  1258. characteristicId: this.characteristicIdForWrite,
  1259. // 这里的value是ArrayBuffer类型
  1260. value: buffer,
  1261. success: (res) => {
  1262. // console.log(res)
  1263. if (val == 'start') {
  1264. setTimeout(() => {
  1265. this.isChecked = true;
  1266. this.isConnected = true;
  1267. this.byte35 = '';
  1268. }, 300)
  1269. this.process_control(3)
  1270. } else if (val == 'stop') {
  1271. setTimeout(() => {
  1272. this.isChecked = false;
  1273. }, 300)
  1274. }
  1275. },
  1276. fail: (err) => {
  1277. // console.log(err)
  1278. if (err.errCode !== 0) {
  1279. setTimeout(() => {
  1280. this.setInit()
  1281. }, 300)
  1282. if (this.isConnected) {
  1283. uni.showToast({
  1284. title: '设备连接已断开!请在水表上手动停止!',
  1285. icon: 'none',
  1286. duration: 5000
  1287. })
  1288. } else {
  1289. uni.showToast({
  1290. title: '设备连接失败!请重试扫描连接!',
  1291. icon: 'none',
  1292. duration: 5000
  1293. })
  1294. }
  1295. }
  1296. }
  1297. })
  1298. },
  1299. /**
  1300. * 请求获取设备启动码
  1301. */
  1302. async request_device_start_code() {
  1303. if (this.byte35 != '' && this.stu_number != '') {
  1304. const res = await this.$myRequest({
  1305. host: this.ceshi,
  1306. url: '/HotWaters/wpstart.action',
  1307. data: {
  1308. collect_code: this.byte35,
  1309. stu_number: this.stu_number
  1310. }
  1311. })
  1312. // console.log(res)
  1313. let sc = res.data.start_code
  1314. if (typeof(sc) != 'undefined' && sc != '') {
  1315. this.start_code = sc
  1316. setTimeout(() => {
  1317. this.send('start')
  1318. }, 100)
  1319. // 刷新选定的月份消费记录
  1320. this.request_consumption_records()
  1321. } else {
  1322. this.isChecked = false
  1323. uni.showToast({
  1324. icon: 'none',
  1325. title: res.data.mess,
  1326. duration: 3000,
  1327. })
  1328. }
  1329. } else {
  1330. uni.showToast({
  1331. icon: 'none',
  1332. title: '字节码或学号为空!'
  1333. });
  1334. // 初始化
  1335. this.setInit()
  1336. }
  1337. },
  1338. /**
  1339. * 请求结算
  1340. */
  1341. async request_pay() {
  1342. if (this.byte35 != '') {
  1343. const res = await this.$myRequest({
  1344. host: this.ceshi,
  1345. url: '/HotWaters/wpconsume.action',
  1346. data: {
  1347. stu_number: this.stu_number,
  1348. user_name: this.user_name,
  1349. collect_code: this.byte35.substring(2)
  1350. }
  1351. })
  1352. // console.log(res)
  1353. if (res.data.mess == "支付成功") {
  1354. uni.showToast({
  1355. icon: 'success',
  1356. title: '结算成功!',
  1357. success: (res1) => {
  1358. this.use_amount = res.data.use_amount.toFixed(2)
  1359. this.amount = (this.amount - this.use_amount).toFixed(2)
  1360. this.$store.state.reshui_amount = this.amount
  1361. setTimeout(() => {
  1362. // 刷新选定的月份消费记录
  1363. this.request_consumption_records()
  1364. }, 1000)
  1365. }
  1366. })
  1367. } else {
  1368. uni.showToast({
  1369. icon: 'none',
  1370. title: res.data.mess,
  1371. duration: 3000
  1372. })
  1373. }
  1374. } else {
  1375. uni.showToast({
  1376. icon: 'success',
  1377. title: '字节码为空!'
  1378. });
  1379. // 初始化
  1380. this.setInit()
  1381. }
  1382. },
  1383. /**
  1384. * 返回字符处理
  1385. */
  1386. str2StrArray(start_code) {
  1387. if (typeof(start_code) == 'undefined' || start_code == '') {
  1388. uni.showToast({
  1389. icon: 'none',
  1390. title: '设备码获取失败'
  1391. })
  1392. this.setInit()
  1393. return
  1394. }
  1395. if (start_code.length != 34) {
  1396. // console.log('启动码长度错误')
  1397. throw new Error("启动码长度错误");
  1398. return
  1399. }
  1400. var resultArray = new Array()
  1401. for (var i = 0; i < start_code.length; i += 2) {
  1402. resultArray.push(start_code.substr(i, 2));
  1403. }
  1404. return resultArray;
  1405. },
  1406. /**
  1407. * ArrayBuffer转16进度字符串
  1408. */
  1409. ab2hex(buffer) {
  1410. const hexArr = Array.prototype.map.call(
  1411. new Uint8Array(buffer),
  1412. function(bit) {
  1413. // console.log('====================' + bit + '==========================')
  1414. return ('00' + bit.toString(16)).slice(-2)
  1415. }
  1416. )
  1417. return hexArr.join('');
  1418. },
  1419. /**
  1420. * 16进制转10进制
  1421. */
  1422. sixteen_to_ten(str) {
  1423. return parseInt(str, 16);
  1424. }
  1425. }
  1426. }
  1427. </script>
  1428. <style scoped lang="scss">
  1429. .content {
  1430. width: 100%;
  1431. height: 100%;
  1432. .container {
  1433. width: 100%;
  1434. padding: 20rpx 40rpx;
  1435. box-sizing: border-box;
  1436. .header {
  1437. display: flex;
  1438. justify-content: center;
  1439. position: relative;
  1440. height: 200rpx;
  1441. .scan {
  1442. display: flex;
  1443. flex-direction: column;
  1444. justify-content: center;
  1445. align-items: center;
  1446. height: 200rpx;
  1447. width: 30%;
  1448. .iconfont {
  1449. margin-bottom: 10rpx;
  1450. font-size: 100rpx;
  1451. color: $my-color-primary;
  1452. }
  1453. }
  1454. .scan_hover {
  1455. border-radius: 15rpx;
  1456. background-color: $my-color-btn-background;
  1457. }
  1458. .qinshihao {
  1459. display: flex;
  1460. align-items: center;
  1461. position: fixed;
  1462. top: 20rpx;
  1463. right: 30rpx;
  1464. font-size: 28rpx;
  1465. .icon-zhuye {
  1466. margin-right: 10rpx;
  1467. font-family: Microsoft YaHei-3970(82674968);
  1468. color: $my-color-primary;
  1469. }
  1470. .compustxt {
  1471. font-size: 18rpx;
  1472. }
  1473. }
  1474. }
  1475. .start_text {
  1476. .start_top,
  1477. .start_mid {
  1478. display: flex;
  1479. justify-content: space-between;
  1480. height: 100rpx;
  1481. align-items: center;
  1482. border-bottom: 2rpx #ccc solid;
  1483. .item_left {
  1484. display: flex;
  1485. align-items: center;
  1486. }
  1487. .start_mid_txt {
  1488. padding: 16rpx;
  1489. border-radius: 10rpx;
  1490. font-size: 36rpx;
  1491. font-weight: bold;
  1492. color: #333;
  1493. }
  1494. .iconfont {
  1495. font-size: 50rpx;
  1496. color: $my-color-primary;
  1497. margin-right: 20rpx;
  1498. }
  1499. .start_payamount {
  1500. display: flex;
  1501. justify-content: flex-end;
  1502. align-items: center;
  1503. font-size: 38rpx;
  1504. padding: 10rpx;
  1505. font-family: Microsoft YaHei-3970(82674968);
  1506. color: #B2B2B2;
  1507. border-radius: 10rpx;
  1508. .icon-dayuhao {
  1509. margin: 0 0 0 20rpx;
  1510. font-size: 38rpx;
  1511. color: #B2B2B2;
  1512. }
  1513. }
  1514. }
  1515. .start_bot {
  1516. display: flex;
  1517. justify-content: space-between;
  1518. height: 100rpx;
  1519. align-items: center;
  1520. .kongzhonglianjie {
  1521. margin: 0;
  1522. height: 60rpx;
  1523. line-height: 60rpx;
  1524. font-size: 28rpx;
  1525. background-color: #1296DB;
  1526. color: #FFFFFF;
  1527. }
  1528. .start_bot_txt {
  1529. margin-left: 20rpx;
  1530. color: #333;
  1531. font-size: 28rpx;
  1532. }
  1533. }
  1534. }
  1535. .btn_room {
  1536. font-size: 28rpx;
  1537. background-color: #41c560;
  1538. margin: 10rpx auto;
  1539. }
  1540. .start_up_process {
  1541. padding: 20rpx 0;
  1542. color: #007AFF;
  1543. }
  1544. .ad {
  1545. margin: 0 -40rpx;
  1546. padding: 10rpx;
  1547. width: 730rpx;
  1548. height: 424rpx;
  1549. .ad_img {
  1550. height: 100%;
  1551. width: 100%;
  1552. }
  1553. }
  1554. .title {
  1555. height: 100rpx;
  1556. margin: 0 -40rpx;
  1557. padding: 0 40rpx;
  1558. line-height: 100rpx;
  1559. color: #808080;
  1560. font-size: 32rpx;
  1561. background: #f2f2f2;
  1562. }
  1563. .record-item {
  1564. width: 100%;
  1565. .uni-list-cell-db {
  1566. height: 100rpx;
  1567. line-height: 100rpx;
  1568. font-weight: bold;
  1569. .uni-input {
  1570. display: flex;
  1571. align-items: center;
  1572. text:nth-child(1) {
  1573. margin-right: 10rpx;
  1574. }
  1575. }
  1576. }
  1577. .item-list {
  1578. height: 80rpx;
  1579. display: flex;
  1580. align-items: center;
  1581. justify-content: space-between;
  1582. border-top: 2rpx #ccc solid;
  1583. .icon-shijian {
  1584. margin-right: 8rpx;
  1585. }
  1586. .icon-shuidi {
  1587. margin-right: 3rpx;
  1588. }
  1589. .item-list-txt {
  1590. font-size: 28rpx;
  1591. &:nth-of-type(2) {
  1592. color: #515151;
  1593. }
  1594. &:nth-of-type(3) {
  1595. color: #f76200;
  1596. font-size: 32rpx;
  1597. }
  1598. }
  1599. }
  1600. }
  1601. }
  1602. }
  1603. </style>