jiaofei.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. <template>
  2. <view class="container">
  3. <view class="select-item" @tap="navigateToSelect">
  4. <view class="picker-item-logol">
  5. <image class="picker-item-logo-left" src="../static/images/room.png"></image>
  6. </view>
  7. <view class="picker-item-label">已选房间</view>
  8. <view class="picker-item-content" :class="{'font-txt':add_class==1}">{{roomSelect}}</view>
  9. <view class="picker-item-logor">
  10. <image class="picker-item-logo-right" src="../static/images/right.png"></image>
  11. </view>
  12. </view>
  13. <view class="show-item">
  14. <view class="picker-item-logol">
  15. <image class="picker-item-logo-left" src="../static/images/elec.png"></image>
  16. </view>
  17. <view class="picker-item-label">账户金额</view>
  18. <view class="picker-item-content font-txt">¥ {{remainElec}}</view>
  19. </view>
  20. <view class="show-item details">
  21. <view class="xiangqing" @tap="dfxq_click">
  22. <image class="xiangqing-icon" src="../static/images/dfxq.png"></image>
  23. <view>电费详情</view>
  24. </view>
  25. <view class="xiangqing" @tap="sfxq_click">
  26. <image class="xiangqing-icon" src="../static/images/sfxq.png"></image>
  27. <view>水费详情</view>
  28. </view>
  29. </view>
  30. <view class="show-item add-money">
  31. <view class="add-money-show">
  32. <view class="picker-item-logol money-logo">
  33. <image class="picker-item-logo-left" src="../static/images/money.png"></image>
  34. </view>
  35. <view class="picker-item-label money-show">请选择充值金额</view>
  36. </view>
  37. <view class="add-money-list">
  38. <view class="add-money-button">
  39. <button class="select-submit" :data-item="10" @tap="add_money" :class="{selStyle:amount == 10}">10元</button>
  40. </view>
  41. <view class="add-money-button">
  42. <button class="select-submit" :data-item="20" @tap="add_money" :class="{selStyle:amount == 20}">20元</button>
  43. </view>
  44. <view class="add-money-button">
  45. <button class="select-submit" :data-item="30" @tap="add_money" :class="{selStyle:amount == 30}">30元</button>
  46. </view>
  47. <view class="add-money-button">
  48. <button class="select-submit" :data-item="50" @tap="add_money" :class="{selStyle:amount == 50}">50元</button>
  49. </view>
  50. <view class="add-money-button">
  51. <button class="select-submit" :data-item="100" @tap="add_money" :class="{selStyle:amount == 100}">100元</button>
  52. </view>
  53. <view class="add-money-button">
  54. <button class="select-submit" :data-item="200" @tap="add_money" :class="{selStyle:amount == 200}">200元</button>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="show-item jine">
  59. <input type="number" class="input-money" maxlength="4" placeholder="请输入金额(10-200)" placeholder-class="input-ph-color" v-model:value="amount"
  60. @input="onInput" @blur="onBlur" />
  61. </view>
  62. <view class="submit-item" v-if="true">
  63. <button class="submit" :data-rooms='room' @tap="input_money">充值</button>
  64. </view>
  65. <view class="change-show" @tap="navigateToShow">
  66. 台账管理
  67. </view>
  68. <view v-if="img_url !== ''" class="ad">
  69. <image :src="img_url" mode="aspectFill" class="ad_img" @tap="ad_redirect" @error="loadImgError"></image>
  70. </view>
  71. </view>
  72. </template>
  73. <script>
  74. export default {
  75. data() {
  76. return {
  77. roomSelect: '', //校区宿舍号
  78. remainElec: 0.00.toFixed(2), //剩余电量
  79. add_class: '', //增加class属性
  80. amount: '',
  81. sub_appid: '', //商户号
  82. xiaofei_items: '', // 消费记录
  83. dorm_number: '', //栋宿舍号
  84. stu_number: '',
  85. compus: '', //校区
  86. ceshi: 'code',
  87. test: this.$store.state.test,
  88. img_url: ''
  89. }
  90. },
  91. onLoad(options) {
  92. // console.log(options);
  93. if (typeof(options.from) != 'undefined' && options.from == 2) {
  94. wx.navigateTo({
  95. url: '../../pages/index/index?from=' + options.from
  96. });
  97. return;
  98. }
  99. // 系统正在维护...
  100. if (this.test == 'weihuzhong') {
  101. wx.redirectTo({
  102. url: '../../pages/index/index'
  103. });
  104. return;
  105. }
  106. // 测试环境
  107. if (this.test) {
  108. this.amount = 0.01;
  109. }
  110. // 获取基本信息
  111. this.get_base_info(options, 'onLoad');
  112. this.get_img();
  113. },
  114. onShow() {
  115. // 获取基本信息
  116. // this.get_base_info('options', 'onShow')
  117. // 获取电量
  118. if (this.$store.state.building.roomSelect != '') {
  119. // 如果是选择宿舍号返回
  120. this.roomSelect = this.$store.state.building.roomSelect;
  121. this.add_class = this.$store.state.building.add_class;
  122. this.dorm_number = this.$store.state.building.dorm_number;
  123. this.add_class = 1;
  124. if (this.roomSelect && typeof(this.roomSelect) != 'undefined') {
  125. this.getDianLiang();
  126. }
  127. // 初始化参数
  128. this.$store.state.building.add_class = 0;
  129. // 获取code
  130. this.getCode('options', 'onShow');
  131. }
  132. },
  133. methods: {
  134. /**
  135. * 获取广告缩略图出错
  136. */
  137. loadImgError(e) {
  138. // console.log(e);
  139. this.img_url = ''
  140. },
  141. /**
  142. * 获取广告缩略图
  143. */
  144. async get_img() {
  145. var _this = this;
  146. let res = await this.$myRequest({
  147. host: _this.ceshi,
  148. url: '/HotWaters/advertquery_h.action',
  149. method: 'POST',
  150. header: {
  151. 'content-type': 'application/x-www-form-urlencoded'
  152. },
  153. data: {
  154. 'url_name': '水电广告'
  155. }
  156. })
  157. // console.log(res.data)
  158. if (typeof res.data.data == 'undefined' || res.data.data.length == 0) {
  159. return
  160. }
  161. if (res.data.code == 200) {
  162. let tf = false;
  163. let tmpData = res.data.data;
  164. for (var i = 0; i < tmpData.length; i++) {
  165. if (tmpData[i].state == 1 && tmpData[i].remark.indexOf('缩略图') != -1) {
  166. this.img_url = tmpData[i].url;
  167. tf = true;
  168. }
  169. }
  170. if (tf == false) {
  171. uni.showToast({
  172. icon: 'none',
  173. title: '没有启用的缩略图',
  174. duration: 2000
  175. });
  176. }
  177. } else {
  178. uni.showToast({
  179. title: '加载数据异常',
  180. duration: 1500
  181. })
  182. return
  183. }
  184. },
  185. /**
  186. * 电费详情页面
  187. */
  188. dfxq_click() {
  189. if (this.haveSelectRoom()) {
  190. return;
  191. }
  192. if (this.roomSelect == '' || typeof this.roomSelect == 'undefined') {
  193. uni.showToast({
  194. title: '请再次选择宿舍',
  195. icon: 'success'
  196. })
  197. } else {
  198. uni.navigateTo({
  199. url: '../dfxq/dfxq?roomSelect=' + this.roomSelect + '&stu_number=' + this.stu_number,
  200. success: function(res) {
  201. }
  202. });
  203. }
  204. },
  205. /**
  206. * 水费详情页面
  207. */
  208. sfxq_click() {
  209. if (this.haveSelectRoom()) {
  210. return;
  211. }
  212. if (this.roomSelect == '' || typeof this.roomSelect == 'undefined') {
  213. uni.showToast({
  214. title: '请再次选择宿舍',
  215. icon: 'success'
  216. })
  217. } else {
  218. uni.navigateTo({
  219. url: '../sfxq/sfxq?roomSelect=' + this.roomSelect + '&stu_number=' + this.stu_number,
  220. success: function(res) {
  221. }
  222. });
  223. }
  224. },
  225. /**
  226. * 跳转到ad页面
  227. */
  228. ad_redirect() {
  229. uni.navigateTo({
  230. url: 'ad_dianfei'
  231. })
  232. },
  233. /**
  234. * 获取基本信息
  235. */
  236. get_base_info(options, param) {
  237. try {
  238. if (this.stu_number == '' || typeof this.stu_number == 'undefined') {
  239. // 获取学号
  240. this.stu_number = this.$store.state.userInfo.card_number
  241. }
  242. if (this.stu_number == '' || typeof this.stu_number == 'undefined') {
  243. const userinfo = uni.getStorageSync('userinfo_storage_key')
  244. if (userinfo) {
  245. this.stu_number = userinfo.card_number
  246. } else {
  247. uni.navigateTo({
  248. url: '../../pages/index/index?from=' + options.from
  249. })
  250. uni.showToast({
  251. icon: 'none',
  252. title: '学号为空,请进行授权',
  253. duration: 3000
  254. });
  255. return
  256. }
  257. }
  258. } catch (e) {
  259. console.log(e);
  260. }
  261. // 初始化参数
  262. this.$store.state.building.add_class = 0;
  263. // 获取code
  264. this.getCode(options, param)
  265. },
  266. /**
  267. * 获取code
  268. */
  269. getCode(options, param) {
  270. // console.log(options, param)
  271. var _this = this;
  272. uni.login({
  273. success: (res) => {
  274. if (res.code) {
  275. if (param == 'comfirm') {
  276. // 组合地址,发起支付
  277. _this.jsapi(res.code)
  278. } else {
  279. // 请求服务器,获得openid
  280. _this.getOpenId(options, res.code)
  281. }
  282. } else {
  283. uni.showToast({
  284. title: res.errMsg,
  285. icon: 'none'
  286. });
  287. // 跳转到首页
  288. uni.redirectTo({
  289. url: '../../pages/index/index?from=0'
  290. });
  291. }
  292. }
  293. })
  294. },
  295. /**
  296. * 请求服务器,获得openid
  297. */
  298. async getOpenId(options, param_code) {
  299. // console.log(options, param_code)
  300. var _this = this;
  301. if (param_code != '') {
  302. const res = await _this.$myRequest({
  303. host: _this.ceshi,
  304. url: '/HotWaters/wpget_stu.action',
  305. method: 'POST',
  306. header: {
  307. 'content-type': 'application/x-www-form-urlencoded'
  308. },
  309. data: {
  310. code: param_code,
  311. card_number: _this.stu_number
  312. }
  313. })
  314. // console.log('获得openid', res);
  315. if (res.data.mess == '返回成功') {
  316. if (!(_this.$store.state.building.roomSelect && typeof _this.$store.state.building.roomSelect != 'undefined')) {
  317. // 栋宿舍号
  318. _this.dorm_number = res.data.info[0].build + res.data.info[0].dom
  319. // 校区
  320. _this.compus = res.data.info[0].campus
  321. // 填充校区宿舍号
  322. if (typeof _this.dorm_number.split('栋')[1] == 'undefined') {
  323. _this.roomSelect = _this.compus + ''
  324. } else {
  325. _this.roomSelect = _this.compus + _this.dorm_number.split('栋')[1]
  326. }
  327. // 存储选择
  328. _this.$store.state.building.roomSelect = _this.roomSelect
  329. // 样式
  330. _this.add_class = 1
  331. }
  332. // 请求选定的月份消费记录
  333. _this.getDianLiang()
  334. } else if (res.data.mess == '未查询到用户信息') {
  335. // 数据库中 未查询到用户信息,就清除本地存储
  336. uni.removeStorageSync('userinfo_storage_key');
  337. uni.showToast({
  338. title: '获取用户信息失败!'
  339. })
  340. // 跳转到首页
  341. if (options && typeof(options.from) != 'undefined' && typeof(options.from) != '') {
  342. uni.navigateTo({
  343. url: '../../pages/index/index?from=' + options.from
  344. })
  345. } else {
  346. uni.redirectTo({
  347. url: '../../pages/index/index/index?from=0'
  348. });
  349. }
  350. }
  351. if (_this.roomSelect == '' || typeof _this.roomSelect == 'undefined' || !_this.roomSelect) {
  352. const userinfo = uni.getStorageSync('userinfo_storage_key')
  353. if (userinfo && typeof(userinfo) != 'undefined' && typeof(userinfo.campus) != 'undefined' &&
  354. typeof(userinfo.dorm_number) != 'undefined' && userinfo.campus != '' && userinfo
  355. .dorm_number != '') {
  356. _this.roomSelect = userinfo.campus + userinfo.dorm_number
  357. } else {
  358. _this.roomSelect = '请选择宿舍号'
  359. }
  360. }
  361. } else {
  362. // 请求选定的月份消费记录
  363. this.getDianLiang()
  364. } else if (res.data.mess == '未查询到用户信息') {
  365. // 数据库中 未查询到用户信息,就清除本地存储
  366. uni.removeStorageSync('userinfo_storage_key')
  367. uni.showToast({
  368. title: 'code为空!',
  369. icon: 'success'
  370. });
  371. }
  372. },
  373. /**
  374. * 取得电费额度
  375. */
  376. async getDianLiang() {
  377. var _this = this;
  378. if (this.roomSelect != '' && typeof(this.roomSelect) != 'undefined') {
  379. const res = await this.$myRequest({
  380. host: _this.ceshi,
  381. url: '/HotWaters/buildoverElec.action',
  382. method: 'POST',
  383. header: {
  384. 'content-type': 'application/x-www-form-urlencoded'
  385. },
  386. data: {
  387. 'roomSelect': _this.roomSelect
  388. }
  389. })
  390. // console.log('取得电费额度', res);
  391. if (res.data.mess == '0') {
  392. setTimeout(() => {
  393. _this.remainElec = res.data.amount.toFixed(2)
  394. }, 30);
  395. } else {
  396. this.remainElec = 0.00.toFixed(2)
  397. }
  398. } else {
  399. uni.showToast({
  400. title: '请先选择宿舍号,\n再查询详情 或 充值',
  401. icon: 'none',
  402. duration: 3000
  403. });
  404. }
  405. },
  406. //跳转到选择页面
  407. navigateToSelect() {
  408. uni.navigateTo({
  409. url: '../select/select',
  410. });
  411. },
  412. // 是否选择了宿舍号
  413. haveSelectRoom() {
  414. if (this.roomSelect == '请选择宿舍') {
  415. uni.showToast({
  416. title: '请选择宿舍',
  417. icon: 'success'
  418. })
  419. return true
  420. }
  421. uni.setStorageSync('roomSelect', this.roomSelect);
  422. uni.setStorageSync('stu_number', this.stu_number);
  423. return false
  424. },
  425. //跳转到台账页面
  426. navigateToShow(e) {
  427. if (this.haveSelectRoom()) {
  428. return
  429. }
  430. if (this.roomSelect == '' || typeof this.roomSelect == 'undefined') {
  431. uni.showToast({
  432. title: '请再次选择宿舍号',
  433. icon: 'success'
  434. })
  435. } else {
  436. uni.navigateTo({
  437. url: '../show/show?roomSelect=' + this.roomSelect + '&stu_number=' + this.stu_number,
  438. success: function(res) {
  439. }
  440. });
  441. }
  442. },
  443. /**
  444. * 增加固定金额
  445. */
  446. add_money(e) {
  447. this.amount = e.currentTarget.dataset.item
  448. },
  449. /**
  450. * 确认宿舍号
  451. */
  452. confirm_room(op) {
  453. // 检查房间号
  454. if (this.roomSelect == '' || this.roomSelect == '请选择宿舍号') {
  455. uni.showToast({
  456. title: '请选择宿舍号',
  457. icon: 'success'
  458. })
  459. return
  460. }
  461. // 输入金额进行充值
  462. if (op == 'input_money') {
  463. //判断输入是否为空或不是数字
  464. if (this.amount == '' || this.amount == null || this.amount == 0) {
  465. uni.showToast({
  466. title: '请输入充值金额',
  467. duration: 2000
  468. })
  469. return
  470. }
  471. if (isNaN(this.amount)) {
  472. uni.showToast({
  473. title: '请输入正确金额',
  474. duration: 2000
  475. })
  476. return
  477. }
  478. if (!this.test) { // 非测试环境
  479. if (this.amount > 200 || this.amount < 10) {
  480. uni.showToast({
  481. title: '限额10~200元',
  482. duration: 2000
  483. })
  484. return
  485. }
  486. }
  487. }
  488. // 确认充值对话框
  489. this.confirm_dialog()
  490. },
  491. /**
  492. * 确认充值对话框
  493. */
  494. confirm_dialog() {
  495. var _this = this;
  496. uni.showModal({
  497. // title: '确定充值'+this.amount+'元',
  498. title: '确定充值' + _this.amount + '元',
  499. success: (res) => {
  500. if (res.confirm) {
  501. // 获取code
  502. _this.getCode('options', 'comfirm')
  503. } else if (res.cancel) {
  504. // console.log('用户点击取消');
  505. }
  506. }
  507. })
  508. },
  509. //增加可变金额
  510. input_money(e) {
  511. // console.log(this.test);
  512. // console.log(e)
  513. this.confirm_room('input_money')
  514. },
  515. /**
  516. * 请求服务器,获取支付参数,并支付
  517. */
  518. async jsapi(param_code) {
  519. if (param_code == '' || this.amount == '' || this.roomSelect == '') {
  520. uni.showToast({
  521. title: 'code、充值金额、宿舍号或IP为空'
  522. });
  523. return
  524. }
  525. var _this = this;
  526. // console.log(_this.roomSelect);
  527. const res = await this.$myRequest({
  528. host: _this.ceshi,
  529. url: '/HotWaters/elpay_ns.action',
  530. method: 'POST',
  531. header: {
  532. 'content-type': 'application/x-www-form-urlencoded'
  533. },
  534. data: {
  535. code: param_code,
  536. num: _this.amount,
  537. stu_number: _this.stu_number,
  538. roomSelect: _this.roomSelect
  539. }
  540. })
  541. // console.log(res);
  542. if (res.data.code == 200 && res.data.sub_openid && res.data.sub_openid != '') {
  543. wx.requestPayment({
  544. appId: res.data.appId,
  545. timeStamp: res.data.timeStamp,
  546. nonceStr: res.data.nonceStr,
  547. package: res.data.package,
  548. signType: res.data.signType,
  549. paySign: res.data.paySign,
  550. success: res => {
  551. if (res.errMsg == 'requestPayment:ok') {
  552. uni.showToast({
  553. title: '支付成功',
  554. icon: 'success'
  555. });
  556. }
  557. },
  558. fail: (res) => {
  559. if (res.errMsg == 'requestPayment:fail cancel') {
  560. uni.showToast({
  561. title: '取消支付',
  562. icon: 'success',
  563. duration: 2000
  564. });
  565. }
  566. },
  567. complete: (res) => {
  568. // console.log(res);
  569. }
  570. });
  571. } else {
  572. uni.showToast({
  573. title: res.data.message,
  574. icon: 'none',
  575. duration: 3000
  576. });
  577. }
  578. },
  579. /**
  580. * 输入充值金额
  581. */
  582. onInput(e) {
  583. if (this.test) { // 测试环境
  584. return
  585. }
  586. const v = e.detail.value
  587. const zero = /^(0{1,})|[^0-9]/g
  588. let final = 0
  589. if (!v) {
  590. final = 0
  591. } else {
  592. final = v.toString().replace(zero, (v) => {
  593. return 0
  594. })
  595. if (final.split('')[0] * 1 === 0) {
  596. final = final.slice(1) - 0 || 0
  597. }
  598. if (final > 200) {
  599. final = 200
  600. }
  601. }
  602. this.$nextTick(() => {
  603. if (final.toString() == '0') {
  604. _this.amount = ''
  605. } else {
  606. _this.amount = final.toString() || '0'
  607. }
  608. })
  609. },
  610. /**
  611. * 失去焦点时
  612. */
  613. onBlur() {
  614. if (this.test) { // 测试环境
  615. return
  616. }
  617. if (this.amount < 10) {
  618. this.amount = 10
  619. }
  620. }
  621. },
  622. }
  623. </script>
  624. <style>
  625. @import url("jiaofei.css");
  626. </style>