reshui.vue 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794
  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: 'none',
  160. // title: '纬度:' + loc.latitude + '\n' + '经度:' + loc
  161. // .longitude,
  162. // duration: 2000
  163. // })
  164. uni.showToast({
  165. icon: 'success',
  166. title: '已获定位信息'
  167. })
  168. },
  169. fail: (err) => {
  170. uni.showToast({
  171. icon: 'none',
  172. title: '获取定位失败,请手动开启定位!'
  173. })
  174. }
  175. })
  176. },
  177. fail: (err) => {
  178. // console.log(err);
  179. uni.showToast({
  180. icon: 'none',
  181. title: '请手动设置定位授权!'
  182. })
  183. }
  184. })
  185. if (typeof(options) != 'undefined' && typeof(options) != '' && JSON.stringify(options) == '{}') {
  186. // 获取基本信息
  187. this.get_base_info(options, 'onLoad')
  188. } else if (typeof(options.from) != 'undefined' && options.from != 0) {
  189. // 获取基本信息
  190. this.get_base_info(options, 'onLoad')
  191. // 获取设备码
  192. this.device_code = decodeURIComponent(options.q).split('=')[1]
  193. }
  194. const value = uni.getStorageSync('instruction_noshow');
  195. if (!(value == true)) {
  196. this.flag = true
  197. }
  198. },
  199. onShow() {
  200. let _this = this;
  201. // 充值后更新金额
  202. this.amount = this.$store.state.reshui_amount
  203. // 刷新充值后的金额
  204. uni.$once('update_reshui_amount', (data) => {
  205. this.get_base_info('options', 'onShow');
  206. });
  207. if (this.timer > -1) {
  208. clearInterval(this.timer)
  209. }
  210. this.timer = setInterval(() => {
  211. uni.openBluetoothAdapter({
  212. success: (res) => { // 已打开
  213. uni.getBluetoothAdapterState({ // 蓝牙的匹配状态
  214. success: (res1) => {
  215. // console.log(res1);
  216. },
  217. fail: (error) => {
  218. // console.log(error)
  219. uni.showToast({
  220. title: '请开启手机蓝牙!',
  221. icon: 'none',
  222. duration: 2000
  223. });
  224. }
  225. });
  226. },
  227. fail: (err) => { // 未打开
  228. // console.log(err)
  229. if (err.errCode == 10001) {
  230. uni.showToast({
  231. title: '请开启手机蓝牙 或 授权蓝牙权限!',
  232. icon: 'none',
  233. duration: 2000
  234. });
  235. setTimeout(() => {
  236. _this.myInit();
  237. }, 100);
  238. } else {
  239. uni.showToast({
  240. icon: 'none',
  241. title: err.errMsg,
  242. duration: 2000
  243. });
  244. }
  245. }
  246. });
  247. }, 3000);
  248. },
  249. onHide() {
  250. clearInterval(this.timer)
  251. },
  252. onUnload() {
  253. clearInterval(this.timer)
  254. },
  255. methods: {
  256. /**
  257. * 单击连接热水表
  258. */
  259. clickRoom(e) {
  260. try {
  261. if (this.judgeBalance('clickRoom') === false) {
  262. return
  263. } else {
  264. this.device_code = 'K' + e
  265. for (var i = 0, len = this.devices.length; i < len; i++) {
  266. if (this.devices[i].dname == e) {
  267. this.deviceId = this.devices[i].did
  268. break
  269. }
  270. }
  271. // 开始连接匹配的蓝牙设备
  272. this.createBLEConnection();
  273. }
  274. } catch (e) {
  275. console.log('单击连接热水表:' + e.message);
  276. }
  277. },
  278. /**
  279. * 空中连接热水表
  280. */
  281. open() {
  282. if (this.judgeBalance('clickRoom') === false) {
  283. return
  284. } else {
  285. this.setInit()
  286. uni.showLoading({
  287. title: '水表搜索中…',
  288. mask: true,
  289. success: (res) => {
  290. // 获取蓝牙设备,并列表
  291. this.openBluetoothAdapter();
  292. this.showRoom = true
  293. }
  294. })
  295. setTimeout(function() {
  296. uni.hideLoading();
  297. }, 3000);
  298. }
  299. },
  300. /**
  301. * 跳转到广告ad页
  302. */
  303. ad_redirect() {
  304. // uni.navigateTo({
  305. // url: 'ad_reshui'
  306. // })
  307. },
  308. /**
  309. * 保留小数点数值后两位,尾数四舍五入
  310. * @param {Object} value
  311. */
  312. numFilter(value, param) {
  313. var v = parseFloat(value);
  314. if (param == 'l')
  315. return v.toFixed(2);
  316. else
  317. // 截取当前数据到小数点后两位
  318. return v.toFixed(2);
  319. },
  320. /**
  321. * 获取基本信息
  322. */
  323. get_base_info(options, param) {
  324. // console.log(options);
  325. try {
  326. // 获取学号
  327. this.stu_number = this.$store.state.userInfo.card_number
  328. if (this.stu_number == '' || typeof(this.stu_number) == 'undefined') {
  329. const userinfo = uni.getStorageSync('userinfo_storage_key')
  330. if (userinfo) {
  331. this.stu_number = userinfo.card_number
  332. } else {
  333. uni.navigateTo({
  334. url: '/pages/index/index?from=' + options.from
  335. })
  336. uni.showToast({
  337. icon: 'none',
  338. title: '学号为空,请进行授权',
  339. duration: 3000
  340. });
  341. return;
  342. }
  343. }
  344. } catch (e) {
  345. console.log('获取基本信息:' + e.message);
  346. }
  347. if (param == 'onShow') {
  348. if (this.$store.state.payInfo.from == 'reshui_pay') {
  349. uni.showToast({
  350. title: this.$store.state.payInfo.resultMsg,
  351. icon: 'success',
  352. success: () => {
  353. this.$store.state.payInfo.resultMsg = ''
  354. this.$store.state.payInfo.from = ''
  355. }
  356. })
  357. }
  358. }
  359. // 获取code
  360. this.getCode(options, param);
  361. },
  362. /**
  363. * 获得code
  364. */
  365. getCode(options, param) {
  366. uni.login({
  367. success: (res) => {
  368. // console.log('getCode', res);
  369. if (res.code) {
  370. // 请求服务器,获得openid
  371. this.getOpenId(options, res.code, param)
  372. } else {
  373. uni.showToast({
  374. title: res.errMsg,
  375. icon: 'none'
  376. });
  377. }
  378. }
  379. })
  380. },
  381. /**
  382. * 请求服务器,获得openid
  383. */
  384. async getOpenId(options, param_code, param) {
  385. const res = await this.$myRequest({
  386. host: this.ceshi,
  387. url: '/HotWaters/wpget_stu.action',
  388. method: 'POST',
  389. header: {
  390. 'content-type': 'application/x-www-form-urlencoded'
  391. },
  392. data: {
  393. code: param_code
  394. }
  395. })
  396. // console.log(res);
  397. if (res.data.mess == '返回成功') {
  398. // stu_number是否存在
  399. let cardNumber = res.data.info[0].card_number
  400. if (typeof(cardNumber) != 'undefined' && cardNumber != '' && JSON.stringify(cardNumber) != '{}') {
  401. // 学号 和 姓名
  402. this.stu_number = res.data.info[0].stu_number
  403. this.user_name = res.data.info[0].user_name
  404. // 剩余金额
  405. this.amount = res.data.info[0].balance.toFixed(2)
  406. // if (this.amount > 0)
  407. this.$store.state.reshui_amount = this.amount
  408. // 组合楼栋宿舍号
  409. this.dorm_number = res.data.info[0].build + res.data.info[0].dom
  410. // 校区
  411. // this.compus = res.data.info[0].campus
  412. if (param == 'onLoad' && typeof(options.from) != 'undefined' && options.from != 0) {
  413. // 初始化蓝牙
  414. this.openBluetoothAdapter()
  415. }
  416. // 请求选定的月份消费记录
  417. this.request_consumption_records()
  418. } else {
  419. uni.showToast({
  420. title: '未获取到学号!',
  421. icon: 'success'
  422. });
  423. uni.navigateTo({
  424. url: '/pages/index/index?from=' + options.from
  425. })
  426. }
  427. } else if (res.data.mess == '未查询到用户信息') {
  428. // 数据库中 未查询到用户信息,就清除本地存储
  429. uni.removeStorageSync('userinfo_storage_key');
  430. uni.showToast({
  431. title: '获取用户信息失败!'
  432. })
  433. if (options && typeof(options.from) != 'undefined' && typeof(options.from) != '') {
  434. uni.navigateTo({
  435. url: '/pages/index/index?from=' + options.from
  436. })
  437. } else {
  438. uni.redirectTo({
  439. url: '/pages/index/index?from=0'
  440. });
  441. }
  442. }
  443. },
  444. /**
  445. * 选择消费年月
  446. */
  447. bindDateChange(e) {
  448. this.date = e.detail.value
  449. this.changeDate = true
  450. // 请求选定的月份消费记录
  451. this.request_consumption_records()
  452. },
  453. /**
  454. * 使用说明组件取消
  455. */
  456. cancel(param) {
  457. this.flag = param
  458. },
  459. /**
  460. * 使用说明组件不再出现
  461. */
  462. noshow(param) {
  463. try {
  464. if (param) {
  465. uni.setStorageSync("instruction_noshow", true)
  466. } else {
  467. uni.removeStorageSync("instruction_noshow")
  468. }
  469. } catch (e) {
  470. console.log('使用说明组件不再出现:' + e.message);
  471. }
  472. },
  473. /**
  474. * 请求选定的月份消费记录
  475. */
  476. async request_consumption_records() {
  477. try {
  478. if (this.stu_number != '' && typeof(this.stu_number) != 'undefined') {
  479. const res = await this.$myRequest({
  480. host: this.ceshi,
  481. url: '/HotWaters/wpqueryConsume.action',
  482. method: 'POST',
  483. header: {
  484. 'content-type': 'application/x-www-form-urlencoded'
  485. },
  486. data: {
  487. stu_number: this.stu_number,
  488. begin_time: this.date
  489. }
  490. });
  491. // console.log(res);
  492. if (res.data.mess == '返回成功') {
  493. this.xiaofei_items = []
  494. console.log(res.data.data);
  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: '水表蓝牙连接被占用!',
  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. this.setInit();
  1015. return;
  1016. }
  1017. });
  1018. },
  1019. /**
  1020. * 777777777777777777777777777777777
  1021. * 获取蓝牙特征
  1022. */
  1023. getBLEDeviceCharacteristics() {
  1024. // 获取蓝牙设备某个服务中所有特征值(characteristic)
  1025. uni.getBLEDeviceCharacteristics({
  1026. deviceId: this.deviceId,
  1027. // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
  1028. serviceId: this.serviceId,
  1029. success: (res) => {
  1030. // console.log(res)
  1031. this.characteristicIdForWrite = res.characteristics[0].uuid
  1032. this.characteristicIdForNotity = res.characteristics[1].uuid
  1033. this.deviceIsWrite = res.characteristics[0].properties.write
  1034. this.deviceIsNotify = res.characteristics[1].properties.notify
  1035. // console.log(this.characteristicIdForWrite, this.characteristicIdForNotity)
  1036. // 确保对应服务id下的特征值id具备监听数据变化的特性
  1037. if (res.characteristics[1].properties.notify) {
  1038. this.notifyBLECharacteristicValueChange()
  1039. }
  1040. },
  1041. fail: (err) => {
  1042. this.isScan = false
  1043. // console.error('获取蓝牙设备特征值失败(getBLEDeviceCharacteristics)', err)
  1044. }
  1045. });
  1046. },
  1047. /**
  1048. * 888888888888888888888888888888888888
  1049. * 启用 notify 功能
  1050. */
  1051. notifyBLECharacteristicValueChange() {
  1052. uni.notifyBLECharacteristicValueChange({
  1053. state: true, // 启用 notify 功能
  1054. deviceId: this.deviceId,
  1055. // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
  1056. serviceId: this.serviceId,
  1057. // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
  1058. characteristicId: this.characteristicIdForNotity,
  1059. success: (res) => {
  1060. this.process_control(2)
  1061. uni.showToast({
  1062. icon: 'none',
  1063. title: '要启动水表,请手动点击【开启设备】右侧开关!',
  1064. duration: 5000
  1065. })
  1066. // uni.showModal({
  1067. // title: '提示',
  1068. // content: '要启动水表,请手动点击【开启设备】右侧开关!',
  1069. // showCancel: false,
  1070. // confirmText: '好,知道'
  1071. // })
  1072. this.isScan = false
  1073. // console.log('通知启用(notifyBLECharacteristicValueChange)',res);
  1074. this.onBLECharacteristicValueChange()
  1075. setTimeout(() => {
  1076. // 发送 AAABAC,采集数据(会返回 35字节 的数据)
  1077. this.send('')
  1078. }, 800)
  1079. // // 请求设备信息
  1080. // this.request_device_info()
  1081. // // 显示设备启动授权金额
  1082. // this.display_device_startup_amount()
  1083. },
  1084. fail: (err) => {
  1085. // console.log(err)
  1086. this.isScan = false
  1087. uni.showModal({
  1088. content: err.errMsg,
  1089. showCancel: false
  1090. })
  1091. // 初始化
  1092. this.setInit()
  1093. }
  1094. })
  1095. },
  1096. /**
  1097. * 999999999999999999999999999999999
  1098. * 监听低功耗蓝牙设备的特征值变化
  1099. */
  1100. onBLECharacteristicValueChange() {
  1101. uni.onBLECharacteristicValueChange((characteristic) => {
  1102. let condition = this.ab2hex(characteristic.value)
  1103. // console.log(condition)
  1104. if (condition.length > 2) {
  1105. this.byte35_tmp += condition
  1106. if (this.byte35_tmp.length > 40) {
  1107. this.byte35 = this.byte35_tmp
  1108. this.byte35_tmp = ''
  1109. if (this.byte35.startsWith('ad')) {
  1110. // console.log(this.byte35, '结束用水成功')
  1111. // 关闭蓝牙连接
  1112. this.closeBLEConnection()
  1113. // 请求结算
  1114. this.request_pay()
  1115. } else {
  1116. // 发送 AAABAC,采集数据(会返回 35字节 的数据)
  1117. // b58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0103bc
  1118. // uni.showToast({
  1119. // icon: 'success',
  1120. // title: '采集数据成功!',
  1121. // duration: 2000
  1122. // })
  1123. // console.log(this.byte35, '采集上一条消费数据')
  1124. }
  1125. }
  1126. }
  1127. switch (condition) {
  1128. case 'bb':
  1129. // uni.showToast({
  1130. // title: '设备启动成功',
  1131. // duration: 3000,
  1132. // icon: 'none'
  1133. // })
  1134. this.isChecked = true
  1135. break
  1136. case 'bc':
  1137. uni.showToast({
  1138. title: '启动失败,设备检验启动代码不通过',
  1139. duration: 3000,
  1140. icon: 'none'
  1141. })
  1142. break
  1143. case 'aa':
  1144. uni.showToast({
  1145. title: '设备正在使用',
  1146. duration: 3000,
  1147. icon: 'none'
  1148. })
  1149. break
  1150. case 'ab':
  1151. uni.showToast({
  1152. title: '结束失败,设备对结束代码检验失败',
  1153. duration: 3000,
  1154. icon: 'none'
  1155. })
  1156. break
  1157. default:
  1158. break
  1159. }
  1160. })
  1161. },
  1162. /**
  1163. * 关闭连接
  1164. */
  1165. closeBLEConnection() {
  1166. if (this.deviceId) {
  1167. uni.closeBLEConnection({
  1168. deviceId: this.deviceId,
  1169. success: () => {
  1170. // 关闭蓝牙模块
  1171. this.closeBluetoothAdapter()
  1172. },
  1173. fail: (err) => {
  1174. // this.setInit()
  1175. // uni.showToast({
  1176. // icon: 'none',
  1177. // title: err.errMsg,
  1178. // duration: 3000,
  1179. // success: (res1) => {
  1180. // this.setInit()
  1181. // }
  1182. // })
  1183. }
  1184. });
  1185. } else {
  1186. // 关闭蓝牙模块
  1187. this.closeBluetoothAdapter()
  1188. }
  1189. },
  1190. closeBluetoothAdapter() {
  1191. // 关闭蓝牙模块
  1192. uni.closeBluetoothAdapter({
  1193. success: () => {
  1194. this.myInit();
  1195. if (this.isUserClose == false) { // 设备端结束用水
  1196. if (this.isChecked) {
  1197. // console.log('设备端已结束用水,蓝牙断开成功')
  1198. uni.showToast({
  1199. icon: 'none',
  1200. title: '设备端已结束用水,蓝牙断开成功',
  1201. duration: 3000
  1202. });
  1203. } else {
  1204. // console.log('用户重启扫描,蓝牙断开成功')
  1205. uni.showToast({
  1206. icon: 'none',
  1207. title: '用户重启扫描,蓝牙断开成功',
  1208. duration: 3000
  1209. });
  1210. }
  1211. } else { // 手机移动端结束用水
  1212. // console.log('APP端已结束用水,蓝牙断开成功')
  1213. uni.showToast({
  1214. icon: 'none',
  1215. title: 'APP端已结束用水,蓝牙断开成功',
  1216. duration: 3000
  1217. });
  1218. }
  1219. }
  1220. })
  1221. },
  1222. setInit() {
  1223. this.closeBLEConnection();
  1224. this.myInit();
  1225. },
  1226. myInit() {
  1227. setTimeout(() => {
  1228. this.isUserClose = false;
  1229. this.isChecked = false;
  1230. this.isConnected = false;
  1231. this.isScan = false;
  1232. this.active = -1;
  1233. this.device_code = ''; // 设备编号
  1234. this.devices = []; // 保存设备, 加了【空中连接】,不需要置为空。
  1235. this.deviceId = ''; // 加了【空中连接】,不需要置为空。
  1236. this.serviceId = '';
  1237. this.characteristicIdForWrite = '';
  1238. this.characteristicIdForNotity = '';
  1239. this.deviceIsNotify = false;
  1240. this.deviceIsWrite = false;
  1241. this.byte35 = ''; // 70 个字符
  1242. this.byte35_tmp = ''; // 70 个字符 临时变量
  1243. this.get_Bluetooth_Bevice = false;
  1244. this.rooms = []; // 宿舍号,蓝牙连接具有时效性,断开连接后清空
  1245. this.start_code = '';
  1246. }, 300);
  1247. },
  1248. /**
  1249. * 10===========10==================10
  1250. * 发送数据到设备
  1251. */
  1252. send(val) {
  1253. let buffer
  1254. let dataView
  1255. let newArr
  1256. if (val == 'start') { // 启动设备
  1257. this.isUserClose = false
  1258. // 发送 17字节 启动代码(会返回 35字节 的数据)
  1259. // b58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0103bc
  1260. newArr = this.str2StrArray(this.start_code)
  1261. } else if (val == 'stop') { // 结束当前使用,设备成功返回:AD+35字节 消费结算代码
  1262. this.isUserClose = true
  1263. // 发送 AAABAD+17字节 启动代码(会返回 ad+35字节 的数据)
  1264. // adb58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0104bc
  1265. newArr = ['AA', 'AB', 'AD'].concat(this.str2StrArray(this.start_code))
  1266. } else {
  1267. // 发送 AAABAC 采集数据(会返回 35字节 的数据)
  1268. // b58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0103bc
  1269. newArr = ['AA', 'AB', 'AC']
  1270. }
  1271. buffer = new ArrayBuffer(newArr.length)
  1272. dataView = new DataView(buffer)
  1273. newArr.forEach((item, i) => {
  1274. dataView.setUint8(i, this.sixteen_to_ten(item))
  1275. })
  1276. // 写特征值数据到设备
  1277. if (this.deviceIsWrite) {
  1278. // 写数据到设备
  1279. this.writeBLECharacteristicValue(val, buffer)
  1280. } else {
  1281. uni.showToast({
  1282. title: '设备不可写',
  1283. duration: 3000
  1284. })
  1285. }
  1286. },
  1287. /**
  1288. * 11====================11=====================11
  1289. * 写数据到设备
  1290. */
  1291. writeBLECharacteristicValue(val, buffer) {
  1292. uni.writeBLECharacteristicValue({
  1293. deviceId: this.deviceId,
  1294. // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
  1295. serviceId: this.serviceId,
  1296. // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
  1297. characteristicId: this.characteristicIdForWrite,
  1298. // 这里的value是ArrayBuffer类型
  1299. value: buffer,
  1300. success: (res) => {
  1301. // console.log(res)
  1302. if (val == 'start') {
  1303. setTimeout(() => {
  1304. this.isChecked = true;
  1305. this.isConnected = true;
  1306. this.byte35 = '';
  1307. }, 300)
  1308. this.process_control(3)
  1309. } else if (val == 'stop') {
  1310. setTimeout(() => {
  1311. this.isChecked = false;
  1312. }, 300)
  1313. }
  1314. },
  1315. fail: (err) => {
  1316. // console.log(err)
  1317. if (err.errCode !== 0) {
  1318. setTimeout(() => {
  1319. this.setInit()
  1320. }, 300)
  1321. if (this.isConnected) {
  1322. uni.showToast({
  1323. title: '设备连接已断开!请在水表上手动停止!',
  1324. icon: 'none',
  1325. duration: 5000
  1326. })
  1327. } else {
  1328. uni.showToast({
  1329. title: '设备连接失败!请重试扫描连接!',
  1330. icon: 'none',
  1331. duration: 5000
  1332. })
  1333. }
  1334. }
  1335. }
  1336. })
  1337. },
  1338. /**
  1339. * 请求获取设备启动码
  1340. */
  1341. async request_device_start_code() {
  1342. if (this.byte35 != '' && this.stu_number != '') {
  1343. const res = await this.$myRequest({
  1344. host: this.ceshi,
  1345. url: '/HotWaters/wpstart.action',
  1346. data: {
  1347. collect_code: this.byte35,
  1348. stu_number: this.stu_number
  1349. }
  1350. })
  1351. // console.log(res)
  1352. let sc = res.data.start_code
  1353. if (typeof(sc) != 'undefined' && sc != '') {
  1354. this.start_code = sc
  1355. setTimeout(() => {
  1356. this.send('start')
  1357. }, 100)
  1358. // 刷新选定的月份消费记录
  1359. this.request_consumption_records()
  1360. } else {
  1361. this.isChecked = false
  1362. uni.showToast({
  1363. icon: 'none',
  1364. title: res.data.mess,
  1365. duration: 3000,
  1366. })
  1367. }
  1368. } else {
  1369. if (typeof this.byte35 == 'undefined' || this.byte35 == '') {
  1370. uni.showToast({
  1371. icon: 'none',
  1372. title: '获取字节码空!'
  1373. });
  1374. }
  1375. if (typeof this.stu_number == 'undefined' || this.stu_number == '') {
  1376. uni.showToast({
  1377. icon: 'none',
  1378. title: '学号为空!'
  1379. });
  1380. }
  1381. // 初始化
  1382. this.setInit()
  1383. }
  1384. },
  1385. /**
  1386. * 请求结算
  1387. */
  1388. async request_pay() {
  1389. if (this.byte35 != '') {
  1390. const res = await this.$myRequest({
  1391. host: this.ceshi,
  1392. url: '/HotWaters/wpconsume.action',
  1393. data: {
  1394. stu_number: this.stu_number,
  1395. user_name: this.user_name,
  1396. collect_code: this.byte35.substring(2)
  1397. }
  1398. })
  1399. // console.log(res)
  1400. if (res.data.mess == "支付成功") {
  1401. uni.showToast({
  1402. icon: 'success',
  1403. title: '结算成功!',
  1404. success: (res1) => {
  1405. this.use_amount = res.data.use_amount.toFixed(2)
  1406. this.amount = (this.amount - this.use_amount).toFixed(2)
  1407. this.$store.state.reshui_amount = this.amount
  1408. setTimeout(() => {
  1409. // 刷新选定的月份消费记录
  1410. this.request_consumption_records()
  1411. }, 1000)
  1412. }
  1413. })
  1414. } else {
  1415. uni.showToast({
  1416. icon: 'none',
  1417. title: res.data.mess,
  1418. duration: 3000
  1419. })
  1420. }
  1421. } else {
  1422. uni.showToast({
  1423. icon: 'success',
  1424. title: '结算字节码空!'
  1425. });
  1426. // 初始化
  1427. this.setInit()
  1428. }
  1429. },
  1430. /**
  1431. * 返回字符处理
  1432. */
  1433. str2StrArray(start_code) {
  1434. if (typeof(start_code) == 'undefined' || start_code == '') {
  1435. uni.showToast({
  1436. icon: 'none',
  1437. title: '设备码获取失败'
  1438. })
  1439. this.setInit()
  1440. return
  1441. }
  1442. if (start_code.length != 34) {
  1443. // console.log('启动码长度错误')
  1444. throw new Error("启动码长度错误");
  1445. return
  1446. }
  1447. var resultArray = new Array()
  1448. for (var i = 0; i < start_code.length; i += 2) {
  1449. resultArray.push(start_code.substr(i, 2));
  1450. }
  1451. return resultArray;
  1452. },
  1453. /**
  1454. * ArrayBuffer转16进度字符串
  1455. */
  1456. ab2hex(buffer) {
  1457. const hexArr = Array.prototype.map.call(
  1458. new Uint8Array(buffer),
  1459. function(bit) {
  1460. // console.log('====================' + bit + '==========================')
  1461. return ('00' + bit.toString(16)).slice(-2)
  1462. }
  1463. )
  1464. return hexArr.join('');
  1465. },
  1466. /**
  1467. * 16进制转10进制
  1468. */
  1469. sixteen_to_ten(str) {
  1470. return parseInt(str, 16);
  1471. }
  1472. }
  1473. }
  1474. </script>
  1475. <style scoped lang="scss">
  1476. .content {
  1477. width: 100%;
  1478. height: 100%;
  1479. .container {
  1480. width: 100%;
  1481. padding: 20rpx 40rpx;
  1482. box-sizing: border-box;
  1483. .header {
  1484. display: flex;
  1485. justify-content: center;
  1486. position: relative;
  1487. height: 200rpx;
  1488. .scan {
  1489. display: flex;
  1490. flex-direction: column;
  1491. justify-content: center;
  1492. align-items: center;
  1493. height: 200rpx;
  1494. width: 30%;
  1495. .iconfont {
  1496. margin-bottom: 10rpx;
  1497. font-size: 100rpx;
  1498. color: $my-color-primary;
  1499. }
  1500. }
  1501. .scan_hover {
  1502. border-radius: 15rpx;
  1503. background-color: $my-color-btn-background;
  1504. }
  1505. .qinshihao {
  1506. display: flex;
  1507. align-items: center;
  1508. position: fixed;
  1509. top: 20rpx;
  1510. right: 30rpx;
  1511. font-size: 28rpx;
  1512. height: 38rpx;
  1513. .icon-zhuye {
  1514. margin-right: 10rpx;
  1515. font-family: Microsoft YaHei-3970(82674968);
  1516. color: $my-color-primary;
  1517. }
  1518. .compustxt {
  1519. font-size: 18rpx;
  1520. }
  1521. }
  1522. }
  1523. .start_text {
  1524. .start_top,
  1525. .start_mid {
  1526. display: flex;
  1527. justify-content: space-between;
  1528. height: 100rpx;
  1529. align-items: center;
  1530. border-bottom: 2rpx #ccc solid;
  1531. .item_left {
  1532. display: flex;
  1533. align-items: center;
  1534. }
  1535. .start_mid_txt {
  1536. padding: 16rpx;
  1537. border-radius: 10rpx;
  1538. font-size: 36rpx;
  1539. font-weight: bold;
  1540. color: #333;
  1541. }
  1542. .iconfont {
  1543. font-size: 50rpx;
  1544. color: $my-color-primary;
  1545. margin-right: 20rpx;
  1546. }
  1547. .start_payamount {
  1548. display: flex;
  1549. justify-content: flex-end;
  1550. align-items: center;
  1551. font-size: 38rpx;
  1552. padding: 10rpx;
  1553. font-family: Microsoft YaHei-3970(82674968);
  1554. color: #B2B2B2;
  1555. border-radius: 10rpx;
  1556. .icon-dayuhao {
  1557. margin: 0 0 0 20rpx;
  1558. font-size: 38rpx;
  1559. color: #B2B2B2;
  1560. }
  1561. }
  1562. }
  1563. .start_bot {
  1564. display: flex;
  1565. justify-content: space-between;
  1566. height: 100rpx;
  1567. align-items: center;
  1568. .kongzhonglianjie {
  1569. margin: 0;
  1570. height: 60rpx;
  1571. line-height: 60rpx;
  1572. font-size: 28rpx;
  1573. background-color: #1296DB;
  1574. color: #FFFFFF;
  1575. }
  1576. .start_bot_txt {
  1577. margin-left: 20rpx;
  1578. color: #333;
  1579. font-size: 28rpx;
  1580. }
  1581. }
  1582. }
  1583. .btn_room {
  1584. font-size: 28rpx;
  1585. background-color: #41c560;
  1586. margin: 10rpx auto;
  1587. }
  1588. .start_up_process {
  1589. padding: 20rpx 0;
  1590. color: #007AFF;
  1591. }
  1592. .ad {
  1593. margin: 0 -40rpx;
  1594. padding: 10rpx;
  1595. width: 730rpx;
  1596. height: 424rpx;
  1597. .ad_img {
  1598. height: 100%;
  1599. width: 100%;
  1600. }
  1601. }
  1602. .title {
  1603. height: 100rpx;
  1604. margin: 0 -40rpx;
  1605. padding: 0 40rpx;
  1606. line-height: 100rpx;
  1607. color: #808080;
  1608. font-size: 32rpx;
  1609. background: #f2f2f2;
  1610. }
  1611. .record-item {
  1612. width: 100%;
  1613. .uni-list-cell-db {
  1614. height: 100rpx;
  1615. line-height: 100rpx;
  1616. font-weight: bold;
  1617. .uni-input {
  1618. display: flex;
  1619. align-items: center;
  1620. height: 58rpx;
  1621. text:nth-child(1) {
  1622. margin-right: 10rpx;
  1623. }
  1624. }
  1625. }
  1626. .item-list {
  1627. height: 80rpx;
  1628. display: flex;
  1629. align-items: center;
  1630. justify-content: space-between;
  1631. border-top: 2rpx #ccc solid;
  1632. .icon-shijian {
  1633. margin-right: 8rpx;
  1634. }
  1635. .icon-shuidi {
  1636. margin-right: 3rpx;
  1637. }
  1638. .item-list-txt {
  1639. font-size: 28rpx;
  1640. &:nth-of-type(2) {
  1641. color: #515151;
  1642. }
  1643. &:nth-of-type(3) {
  1644. color: #f76200;
  1645. font-size: 32rpx;
  1646. }
  1647. }
  1648. }
  1649. }
  1650. }
  1651. }
  1652. </style>