reshui.vue 43 KB

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