jiaofei.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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?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. uni.setStorageSync('roomSelect', this.roomSelect);
  417. uni.setStorageSync('stu_number', this.stu_number);
  418. return false
  419. },
  420. //跳转到台账页面
  421. navigateToShow(e) {
  422. if (this.haveSelectRoom()) {
  423. return
  424. }
  425. if (this.roomSelect == '' || typeof this.roomSelect == 'undefined') {
  426. uni.showToast({
  427. title: '请再次选择宿舍号',
  428. icon: 'success'
  429. })
  430. } else {
  431. uni.navigateTo({
  432. url: '../show/show?rooSelect=' + this.roomSelect + '&card_number=' + this.stu_number,
  433. success: function(res) {
  434. }
  435. });
  436. }
  437. },
  438. /**
  439. * 增加固定金额
  440. */
  441. add_money(e) {
  442. this.amount = e.currentTarget.dataset.item
  443. },
  444. /**
  445. * 确认宿舍号
  446. */
  447. confirm_room(op) {
  448. // 检查房间号
  449. if (this.roomSelect == '' || this.roomSelect == '请选择宿舍号') {
  450. uni.showToast({
  451. title: '请选择宿舍号',
  452. icon: 'success'
  453. })
  454. return
  455. }
  456. // 输入金额进行充值
  457. if (op == 'input_money') {
  458. //判断输入是否为空或不是数字
  459. if (this.amount == '' || this.amount == null || this.amount == 0) {
  460. uni.showToast({
  461. title: '请输入充值金额',
  462. duration: 2000
  463. })
  464. return
  465. }
  466. if (isNaN(this.amount)) {
  467. uni.showToast({
  468. title: '请输入正确金额',
  469. duration: 2000
  470. })
  471. return
  472. }
  473. if (!this.test) { // 非测试环境
  474. if (this.amount > 200 || this.amount < 10) {
  475. uni.showToast({
  476. title: '限额10~200元',
  477. duration: 2000
  478. })
  479. return
  480. }
  481. }
  482. }
  483. // 确认充值对话框
  484. this.confirm_dialog()
  485. },
  486. /**
  487. * 确认充值对话框
  488. */
  489. confirm_dialog() {
  490. var _this = this;
  491. uni.showModal({
  492. // title: '确定充值'+this.amount+'元',
  493. title: '确定充值' + _this.amount + '元',
  494. success: (res) => {
  495. if (res.confirm) {
  496. // 获取code
  497. _this.getCode('options', 'comfirm')
  498. } else if (res.cancel) {
  499. // console.log('用户点击取消');
  500. }
  501. }
  502. })
  503. },
  504. //增加可变金额
  505. input_money(e) {
  506. // console.log(this.test);
  507. // console.log(e)
  508. this.confirm_room('input_money')
  509. },
  510. /**
  511. * 请求服务器,获取支付参数,并支付
  512. */
  513. async jsapi(param_code) {
  514. if (param_code == '' || this.amount == '' || this.roomSelect == '') {
  515. uni.showToast({
  516. title: 'code、充值金额、宿舍号或IP为空'
  517. });
  518. return
  519. }
  520. var _this = this;
  521. // console.log(_this.roomSelect);
  522. const res = await this.$myRequest({
  523. host: _this.ceshi,
  524. url: '/HotWaters/elpay_ns.action',
  525. method: 'POST',
  526. header: {
  527. 'content-type': 'application/x-www-form-urlencoded'
  528. },
  529. data: {
  530. code: param_code,
  531. num: _this.amount,
  532. stu_number: _this.stu_number,
  533. roomSelect: _this.roomSelect
  534. }
  535. })
  536. // console.log(res);
  537. if (res.data.code == 200 && res.data.sub_openid && res.data.sub_openid != '') {
  538. wx.requestPayment({
  539. appId: res.data.appId,
  540. timeStamp: res.data.timeStamp,
  541. nonceStr: res.data.nonceStr,
  542. package: res.data.package,
  543. signType: res.data.signType,
  544. paySign: res.data.paySign,
  545. success: res => {
  546. if (res.errMsg == 'requestPayment:ok') {
  547. uni.showToast({
  548. title: '支付成功',
  549. icon: 'success'
  550. });
  551. }
  552. },
  553. fail: (res) => {
  554. if (res.errMsg == 'requestPayment:fail cancel') {
  555. uni.showToast({
  556. title: '取消支付',
  557. icon: 'success',
  558. duration: 2000
  559. });
  560. }
  561. },
  562. complete: (res) => {
  563. // console.log(res);
  564. }
  565. });
  566. } else {
  567. uni.showToast({
  568. title: res.data.message,
  569. icon: 'none',
  570. duration: 3000
  571. });
  572. }
  573. },
  574. /**
  575. * 输入充值金额
  576. */
  577. onInput(e) {
  578. if (this.test) { // 测试环境
  579. return
  580. }
  581. const v = e.detail.value
  582. const zero = /^(0{1,})|[^0-9]/g
  583. let final = 0
  584. if (!v) {
  585. final = 0
  586. } else {
  587. final = v.toString().replace(zero, (v) => {
  588. return 0
  589. })
  590. if (final.split('')[0] * 1 === 0) {
  591. final = final.slice(1) - 0 || 0
  592. }
  593. if (final > 200) {
  594. final = 200
  595. }
  596. }
  597. this.$nextTick(() => {
  598. if (final.toString() == '0') {
  599. _this.amount = ''
  600. } else {
  601. _this.amount = final.toString() || '0'
  602. }
  603. })
  604. },
  605. /**
  606. * 失去焦点时
  607. */
  608. onBlur() {
  609. if (this.test) { // 测试环境
  610. return
  611. }
  612. if (this.amount < 10) {
  613. this.amount = 10
  614. }
  615. }
  616. },
  617. }
  618. </script>
  619. <style>
  620. @import url("jiaofei.css");
  621. </style>