jiaofei.vue 16 KB

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