jiaofei.vue 16 KB

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