reshui.vue 43 KB

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