jiaofei.vue 17 KB

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