jiaofei.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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. uni.navigateTo({
  95. url: '../../pages/index/index?from=' + options.from
  96. });
  97. return;
  98. }
  99. // 系统正在维护...
  100. if (this.test == 'weihuzhong') {
  101. uni.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?rooSelect=' + this.roomSelect + '&card_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?rooSelect=' + this.roomSelect + '&card_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. }
  312. })
  313. // console.log('获得openid', res);
  314. if (res.data.mess == '返回成功') {
  315. if (!(this.$store.state.building.roomSelect && typeof(this.$store.state.building.roomSelect) !=
  316. '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. uni.showToast({
  363. title: 'code为空!',
  364. icon: 'success'
  365. });
  366. }
  367. },
  368. /**
  369. * 取得电费额度
  370. */
  371. async getDianLiang() {
  372. var _this = this;
  373. if (this.roomSelect != '' && typeof(this.roomSelect) != 'undefined') {
  374. const res = await this.$myRequest({
  375. host: _this.ceshi,
  376. url: '/HotWaters/buildoverElec.action',
  377. method: 'POST',
  378. header: {
  379. 'content-type': 'application/x-www-form-urlencoded'
  380. },
  381. data: {
  382. 'roomSelect': _this.roomSelect
  383. }
  384. })
  385. // console.log('取得电费额度', res);
  386. if (res.data.mess == '0') {
  387. setTimeout(() => {
  388. _this.remainElec = res.data.amount.toFixed(2)
  389. }, 30);
  390. } else {
  391. this.remainElec = 0.00.toFixed(2)
  392. }
  393. } else {
  394. uni.showToast({
  395. title: '请先选择宿舍号,\n再查询详情 或 充值',
  396. icon: 'none',
  397. duration: 3000
  398. });
  399. }
  400. },
  401. //跳转到选择页面
  402. navigateToSelect() {
  403. uni.navigateTo({
  404. url: '../select/select',
  405. });
  406. },
  407. // 是否选择了宿舍号
  408. haveSelectRoom() {
  409. if (this.roomSelect == '请选择宿舍号') {
  410. uni.showToast({
  411. title: '请选择宿舍号',
  412. icon: 'success'
  413. })
  414. return true
  415. }
  416. return false
  417. },
  418. //跳转到台账页面
  419. navigateToShow(e) {
  420. if (this.haveSelectRoom()) {
  421. return
  422. }
  423. if (this.roomSelect == '' || typeof this.roomSelect == 'undefined') {
  424. uni.showToast({
  425. title: '请再次选择宿舍号',
  426. icon: 'success'
  427. })
  428. } else {
  429. uni.navigateTo({
  430. url: '../show/show?rooSelect=' + this.roomSelect + '&card_number=' + this.stu_number,
  431. success: function(res) {
  432. }
  433. });
  434. }
  435. },
  436. /**
  437. * 增加固定金额
  438. */
  439. add_money(e) {
  440. this.amount = e.currentTarget.dataset.item
  441. },
  442. /**
  443. * 确认宿舍号
  444. */
  445. confirm_room(op) {
  446. // 检查房间号
  447. if (this.roomSelect == '' || this.roomSelect == '请选择宿舍号') {
  448. uni.showToast({
  449. title: '请选择宿舍号',
  450. icon: 'success'
  451. })
  452. return
  453. }
  454. // 输入金额进行充值
  455. if (op == 'input_money') {
  456. //判断输入是否为空或不是数字
  457. if (this.amount == '' || this.amount == null || this.amount == 0) {
  458. uni.showToast({
  459. title: '请输入充值金额',
  460. duration: 2000
  461. })
  462. return
  463. }
  464. if (isNaN(this.amount)) {
  465. uni.showToast({
  466. title: '请输入正确金额',
  467. duration: 2000
  468. })
  469. return
  470. }
  471. if (!this.test) { // 非测试环境
  472. if (this.amount > 200 || this.amount < 10) {
  473. uni.showToast({
  474. title: '限额10~200元',
  475. duration: 2000
  476. })
  477. return
  478. }
  479. }
  480. }
  481. // 确认充值对话框
  482. this.confirm_dialog()
  483. },
  484. /**
  485. * 确认充值对话框
  486. */
  487. confirm_dialog() {
  488. var _this = this;
  489. uni.showModal({
  490. // title: '确定充值'+this.amount+'元',
  491. title: '确定充值' + _this.amount + '元',
  492. success: (res) => {
  493. if (res.confirm) {
  494. // 获取code
  495. _this.getCode('options', 'comfirm')
  496. } else if (res.cancel) {
  497. // console.log('用户点击取消');
  498. }
  499. }
  500. })
  501. },
  502. //增加可变金额
  503. input_money(e) {
  504. // console.log(this.test);
  505. // console.log(e)
  506. this.confirm_room('input_money')
  507. },
  508. /**
  509. * 请求服务器,获取支付参数,并支付
  510. */
  511. async jsapi(param_code) {
  512. if (param_code == '' || this.amount == '' || this.roomSelect == '') {
  513. uni.showToast({
  514. title: 'code、充值金额、宿舍号或IP为空'
  515. });
  516. return
  517. }
  518. var _this = this;
  519. // console.log(_this.roomSelect);
  520. const res = await this.$myRequest({
  521. host: _this.ceshi,
  522. url: '/HotWaters/elpay_ns.action',
  523. method: 'POST',
  524. header: {
  525. 'content-type': 'application/x-www-form-urlencoded'
  526. },
  527. data: {
  528. code: param_code,
  529. num: _this.amount,
  530. stu_number: _this.stu_number,
  531. roomSelect: _this.roomSelect
  532. }
  533. })
  534. // console.log(res);
  535. if (res.data.code == 200 && res.data.sub_openid && res.data.sub_openid != '') {
  536. wx.requestPayment({
  537. appId: res.data.appId,
  538. timeStamp: res.data.timeStamp,
  539. nonceStr: res.data.nonceStr,
  540. package: res.data.package,
  541. signType: res.data.signType,
  542. paySign: res.data.paySign,
  543. success: res => {
  544. if (res.errMsg == 'requestPayment:ok') {
  545. uni.showToast({
  546. title: '支付成功',
  547. icon: 'success'
  548. });
  549. }
  550. },
  551. fail: (res) => {
  552. if (res.errMsg == 'requestPayment:fail cancel') {
  553. uni.showToast({
  554. title: '取消支付',
  555. icon: 'success',
  556. duration: 2000
  557. });
  558. }
  559. },
  560. complete: (res) => {
  561. // console.log(res);
  562. }
  563. });
  564. } else {
  565. uni.showToast({
  566. title: res.data.message,
  567. icon: 'none',
  568. duration: 3000
  569. });
  570. }
  571. },
  572. /**
  573. * 输入充值金额
  574. */
  575. onInput(e) {
  576. if (this.test) { // 测试环境
  577. return
  578. }
  579. const v = e.detail.value
  580. const zero = /^(0{1,})|[^0-9]/g
  581. let final = 0
  582. if (!v) {
  583. final = 0
  584. } else {
  585. final = v.toString().replace(zero, (v) => {
  586. return 0
  587. })
  588. if (final.split('')[0] * 1 === 0) {
  589. final = final.slice(1) - 0 || 0
  590. }
  591. if (final > 200) {
  592. final = 200
  593. }
  594. }
  595. this.$nextTick(() => {
  596. if (final.toString() == '0') {
  597. _this.amount = ''
  598. } else {
  599. _this.amount = final.toString() || '0'
  600. }
  601. })
  602. },
  603. /**
  604. * 失去焦点时
  605. */
  606. onBlur() {
  607. if (this.test) { // 测试环境
  608. return
  609. }
  610. if (this.amount < 10) {
  611. this.amount = 10
  612. }
  613. }
  614. },
  615. }
  616. </script>
  617. <style>
  618. @import url("jiaofei.css");
  619. </style>