reshui.vue 43 KB

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