jiaofei.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  1. <template>
  2. <view class="container">
  3. <view class="select-item" @tap="navigateToSelect">
  4. <view class="picker-item-logol"><image class="picker-item-logo-left" src="../static/images/room.png"></image></view>
  5. <view class="picker-item-label">已选房间</view>
  6. <view class="picker-item-content" :class="{ 'font-txt': add_class == 1 }">{{ roomSelect }}</view>
  7. <view class="picker-item-logor"><image class="picker-item-logo-right" src="../static/images/right.png"></image></view>
  8. </view>
  9. <view class="show-item">
  10. <view class="picker-item-logol"><image class="picker-item-logo-left" src="../static/images/elec.png"></image></view>
  11. <view class="picker-item-label">账户金额</view>
  12. <view class="picker-item-content font-txt">¥ {{ remainElec }}</view>
  13. </view>
  14. <view class="show-item details">
  15. <view class="xiangqing" @tap="dfxq_click">
  16. <image class="xiangqing-icon" src="../static/images/dfxq.png"></image>
  17. <view>电费详情</view>
  18. </view>
  19. <view class="xiangqing" @tap="sfxq_click">
  20. <image class="xiangqing-icon" src="../static/images/sfxq.png"></image>
  21. <view>水费详情</view>
  22. </view>
  23. </view>
  24. <view class="show-item add-money">
  25. <view class="add-money-show">
  26. <view class="picker-item-logol money-logo"><image class="picker-item-logo-left" src="../static/images/money.png"></image></view>
  27. <view class="picker-item-label money-show">请选择充值金额</view>
  28. </view>
  29. <view class="add-money-list">
  30. <view class="add-money-button"><button class="select-submit" :data-item="10" @tap="add_money" :class="{ selStyle: amount == 10 }">10元</button></view>
  31. <view class="add-money-button"><button class="select-submit" :data-item="20" @tap="add_money" :class="{ selStyle: amount == 20 }">20元</button></view>
  32. <view class="add-money-button"><button class="select-submit" :data-item="30" @tap="add_money" :class="{ selStyle: amount == 30 }">30元</button></view>
  33. <view class="add-money-button"><button class="select-submit" :data-item="50" @tap="add_money" :class="{ selStyle: amount == 50 }">50元</button></view>
  34. <view class="add-money-button"><button class="select-submit" :data-item="100" @tap="add_money" :class="{ selStyle: amount == 100 }">100元</button></view>
  35. <view class="add-money-button"><button class="select-submit" :data-item="200" @tap="add_money" :class="{ selStyle: amount == 200 }">200元</button></view>
  36. </view>
  37. </view>
  38. <view class="show-item jine">
  39. <input
  40. type="number"
  41. class="input-money"
  42. maxlength="4"
  43. placeholder="请输入金额(10-200)"
  44. placeholder-class="input-ph-color"
  45. v-model:value="amount"
  46. @input="onInput"
  47. @blur="onBlur"
  48. />
  49. </view>
  50. <view class="submit-item" v-if="true"><button class="submit" :data-rooms="room" @tap="input_money">充值</button></view>
  51. <view class="change-show" @tap="navigateToShow">台账管理</view>
  52. <view v-if="img_url !== ''" class="ad"><image :src="img_url" mode="aspectFill" class="ad_img" @tap="ad_redirect" @error="loadImgError"></image></view>
  53. </view>
  54. </template>
  55. <script>
  56. <<<<<<< HEAD
  57. export default {
  58. data() {
  59. return {
  60. roomSelect: '', //校区宿舍号
  61. remainElec: (0.0).toFixed(2), //剩余电量
  62. add_class: '', //增加class属性
  63. amount: '',
  64. sub_appid: '', //商户号
  65. xiaofei_items: '', // 消费记录
  66. dorm_number: '', //栋宿舍号
  67. stu_number: '',
  68. compus: '', //校区
  69. ceshi: 'code',
  70. test: this.$store.state.test,
  71. img_url: ''
  72. }
  73. },
  74. onLoad(options) {
  75. console.log(options)
  76. if (typeof options.from != 'undefined' && options.from == 2) {
  77. uni.navigateTo({
  78. url: '../../pages/index/index?from=' + options.from
  79. })
  80. return
  81. }
  82. // 系统正在维护...
  83. if (this.test == 'weihuzhong') {
  84. uni.redirectTo({
  85. url: '../../pages/index/index'
  86. })
  87. return
  88. }
  89. // 测试环境
  90. if (this.test) {
  91. this.amount = 0.01
  92. }
  93. // 获取基本信息
  94. this.get_base_info(options, 'onLoad')
  95. this.get_img()
  96. },
  97. onShow() {
  98. // 获取基本信息
  99. // this.get_base_info('options', 'onShow')
  100. // 获取电量
  101. if (this.$store.state.building.roomSelect != '') {
  102. // 如果是选择宿舍号返回
  103. this.roomSelect = this.$store.state.building.roomSelect
  104. this.add_class = this.$store.state.building.add_class
  105. this.dorm_number = this.$store.state.building.dorm_number
  106. this.add_class = 1
  107. if (this.roomSelect && typeof this.roomSelect != 'undefined') {
  108. this.getDianLiang()
  109. }
  110. // 初始化参数
  111. this.$store.state.building.add_class = 0
  112. // 获取code
  113. this.getCode('options', 'onShow')
  114. }
  115. },
  116. methods: {
  117. /**
  118. * 获取广告缩略图出错
  119. */
  120. loadImgError(e) {
  121. // console.log(e);
  122. this.img_url = ''
  123. },
  124. /**
  125. * 获取广告缩略图
  126. */
  127. async get_img() {
  128. var _this = this
  129. let res = await this.$myRequest({
  130. host: _this.ceshi,
  131. url: '/HotWaters/advertquery_h.action',
  132. method: 'POST',
  133. header: {
  134. 'content-type': 'application/x-www-form-urlencoded'
  135. },
  136. data: {
  137. url_name: '水电广告'
  138. }
  139. })
  140. // console.log(res.data)
  141. if (typeof res.data.data == 'undefined' || res.data.data.length == 0) {
  142. return
  143. }
  144. if (res.data.code == 200) {
  145. let tf = false
  146. let tmpData = res.data.data
  147. for (var i = 0; i < tmpData.length; i++) {
  148. if (tmpData[i].state == 1 && tmpData[i].remark.indexOf('缩略图') != -1) {
  149. this.img_url = tmpData[i].url
  150. tf = true
  151. }
  152. =======
  153. export default {
  154. data() {
  155. return {
  156. roomSelect: '', //校区宿舍号
  157. remainElec: 0.00.toFixed(2), //剩余电量
  158. add_class: '', //增加class属性
  159. amount: '',
  160. sub_appid: '', //商户号
  161. xiaofei_items: '', // 消费记录
  162. dorm_number: '', //栋宿舍号
  163. stu_number: '',
  164. compus: '', //校区
  165. ceshi: 'code',
  166. test: this.$store.state.test,
  167. img_url: ''
  168. }
  169. },
  170. onLoad(options) {
  171. // console.log(options);
  172. if (typeof(options.from) != 'undefined' && options.from == 2) {
  173. wx.navigateTo({
  174. url: '../../pages/index/index?from=' + options.from
  175. });
  176. return;
  177. }
  178. // 系统正在维护...
  179. if (this.test == 'weihuzhong') {
  180. wx.redirectTo({
  181. url: '../../pages/index/index'
  182. });
  183. return;
  184. }
  185. // 测试环境
  186. if (this.test) {
  187. this.amount = 0.01;
  188. }
  189. // 获取基本信息
  190. this.get_base_info(options, 'onLoad');
  191. this.get_img();
  192. },
  193. onShow() {
  194. // 获取基本信息
  195. // this.get_base_info('options', 'onShow')
  196. // 获取电量
  197. if (this.$store.state.building.roomSelect != '') {
  198. // 如果是选择宿舍号返回
  199. this.roomSelect = this.$store.state.building.roomSelect;
  200. this.add_class = this.$store.state.building.add_class;
  201. this.dorm_number = this.$store.state.building.dorm_number;
  202. this.add_class = 1;
  203. if (this.roomSelect && typeof(this.roomSelect) != 'undefined') {
  204. this.getDianLiang();
  205. >>>>>>> 6053889f3dfa6311a84f90e852b785418b4083da
  206. }
  207. if (tf == false) {
  208. uni.showToast({
  209. icon: 'none',
  210. title: '没有启用的缩略图',
  211. duration: 2000
  212. })
  213. }
  214. } else {
  215. uni.showToast({
  216. title: '加载数据异常',
  217. duration: 1500
  218. })
  219. return
  220. }
  221. },
  222. /**
  223. * 电费详情页面
  224. */
  225. dfxq_click() {
  226. if (this.haveSelectRoom()) {
  227. return
  228. }
  229. if (this.roomSelect == '' || typeof this.roomSelect == 'undefined') {
  230. uni.showToast({
  231. title: '请再次选择宿舍号',
  232. icon: 'success'
  233. })
  234. } else {
  235. uni.navigateTo({
  236. url: '../dfxq/dfxq?rooSelect=' + this.roomSelect + '&card_number=' + this.stu_number,
  237. success: function(res) {}
  238. })
  239. }
  240. },
  241. /**
  242. * 水费详情页面
  243. */
  244. sfxq_click() {
  245. if (this.haveSelectRoom()) {
  246. return
  247. }
  248. if (this.roomSelect == '' || typeof this.roomSelect == 'undefined') {
  249. uni.showToast({
  250. title: '请再次选择宿舍号',
  251. icon: 'success'
  252. })
  253. } else {
  254. uni.navigateTo({
  255. url: '../sfxq/sfxq?rooSelect=' + this.roomSelect + '&card_number=' + this.stu_number,
  256. success: function(res) {}
  257. })
  258. }
  259. },
  260. /**
  261. * 跳转到ad页面
  262. */
  263. ad_redirect() {
  264. uni.navigateTo({
  265. url: 'ad_dianfei'
  266. })
  267. },
  268. /**
  269. * 获取基本信息
  270. */
  271. get_base_info(options, param) {
  272. try {
  273. if (this.stu_number == '' || typeof this.stu_number == 'undefined') {
  274. // 获取学号
  275. this.stu_number = this.$store.state.userInfo.card_number
  276. }
  277. if (this.stu_number == '' || typeof this.stu_number == 'undefined') {
  278. const userinfo = uni.getStorageSync('userinfo_storage_key')
  279. if (userinfo) {
  280. this.stu_number = userinfo.card_number
  281. } else {
  282. uni.navigateTo({
  283. url: '../../pages/index/index?from=' + options.from
  284. })
  285. uni.showToast({
  286. icon: 'none',
  287. title: '学号为空,请进行授权',
  288. duration: 3000
  289. })
  290. return
  291. }
  292. }
  293. } catch (e) {
  294. console.log(e)
  295. }
  296. <<<<<<< HEAD
  297. // 初始化参数
  298. this.$store.state.building.add_class = 0
  299. // 获取code
  300. this.getCode(options, param)
  301. },
  302. /**
  303. * 获取code
  304. */
  305. getCode(options, param) {
  306. // console.log(options, param)
  307. var _this = this
  308. uni.login({
  309. success: res => {
  310. if (res.code) {
  311. if (param == 'comfirm') {
  312. // 组合地址,发起支付
  313. _this.jsapi(res.code)
  314. =======
  315. if (this.roomSelect == '' || typeof this.roomSelect == 'undefined') {
  316. uni.showToast({
  317. title: '请再次选择宿舍',
  318. icon: 'success'
  319. })
  320. } else {
  321. uni.navigateTo({
  322. url: '../dfxq/dfxq?rooSelect=' + this.roomSelect + '&card_number=' + this.stu_number,
  323. success: function(res) {
  324. }
  325. });
  326. }
  327. },
  328. /**
  329. * 水费详情页面
  330. */
  331. sfxq_click() {
  332. if (this.haveSelectRoom()) {
  333. return;
  334. }
  335. if (this.roomSelect == '' || typeof this.roomSelect == 'undefined') {
  336. uni.showToast({
  337. title: '请再次选择宿舍',
  338. icon: 'success'
  339. })
  340. } else {
  341. uni.navigateTo({
  342. url: '../sfxq/sfxq?rooSelect=' + this.roomSelect + '&card_number=' + this.stu_number,
  343. success: function(res) {
  344. }
  345. });
  346. }
  347. },
  348. /**
  349. * 跳转到ad页面
  350. */
  351. ad_redirect() {
  352. uni.navigateTo({
  353. url: 'ad_dianfei'
  354. })
  355. },
  356. /**
  357. * 获取基本信息
  358. */
  359. get_base_info(options, param) {
  360. try {
  361. if (this.stu_number == '' || typeof(this.stu_number) == 'undefined') {
  362. // 获取学号
  363. this.stu_number = this.$store.state.userInfo.card_number
  364. }
  365. if (this.stu_number == '' || typeof(this.stu_number) == 'undefined') {
  366. const userinfo = uni.getStorageSync('userinfo_storage_key')
  367. if (userinfo) {
  368. this.stu_number = userinfo.card_number
  369. >>>>>>> 6053889f3dfa6311a84f90e852b785418b4083da
  370. } else {
  371. // 请求服务器,获得openid
  372. _this.getOpenId(options, res.code)
  373. }
  374. <<<<<<< HEAD
  375. } else {
  376. =======
  377. }
  378. } catch (e) {
  379. console.log(e);
  380. }
  381. // 初始化参数
  382. this.$store.state.building.add_class = 0;
  383. // 获取code
  384. this.getCode(options, param)
  385. },
  386. /**
  387. * 获取code
  388. */
  389. getCode(options, param) {
  390. // console.log(options, param)
  391. var _this = this;
  392. uni.login({
  393. success: (res) => {
  394. if (res.code) {
  395. if (param == 'comfirm') {
  396. // 组合地址,发起支付
  397. _this.jsapi(res.code)
  398. } else {
  399. // 请求服务器,获得openid
  400. _this.getOpenId(options, res.code)
  401. }
  402. } else {
  403. uni.showToast({
  404. title: res.errMsg,
  405. icon: 'none'
  406. });
  407. // 跳转到首页
  408. uni.redirectTo({
  409. url: '../../pages/index/index?from=0'
  410. });
  411. }
  412. }
  413. })
  414. },
  415. /**
  416. * 请求服务器,获得openid
  417. */
  418. async getOpenId(options, param_code) {
  419. // console.log(options, param_code)
  420. var _this = this;
  421. if (param_code != '') {
  422. const res = await this.$myRequest({
  423. host: _this.ceshi,
  424. url: '/HotWaters/wpget_stu.action',
  425. method: 'POST',
  426. header: {
  427. 'content-type': 'application/x-www-form-urlencoded'
  428. },
  429. data: {
  430. code: param_code
  431. }
  432. })
  433. // console.log('获得openid', res);
  434. if (res.data.mess == '返回成功') {
  435. if (!(this.$store.state.building.roomSelect && typeof this.$store.state.building.roomSelect !=
  436. 'undefined')) {
  437. // 栋宿舍号
  438. this.dorm_number = res.data.info[0].build + res.data.info[0].dom
  439. // 校区
  440. this.compus = res.data.info[0].campus
  441. // 填充校区宿舍号
  442. if (typeof(this.dorm_number.split('栋')[1]) == 'undefined') {
  443. this.roomSelect = this.compus + ''
  444. } else {
  445. this.roomSelect = this.compus + this.dorm_number.split('栋')[1]
  446. }
  447. // 存储选择
  448. this.$store.state.building.roomSelect = this.roomSelect
  449. // 样式
  450. this.add_class = 1
  451. }
  452. // 请求选定的月份消费记录
  453. this.getDianLiang()
  454. } else if (res.data.mess == '未查询到用户信息') {
  455. // 数据库中 未查询到用户信息,就清除本地存储
  456. uni.removeStorageSync('userinfo_storage_key');
  457. >>>>>>> 6053889f3dfa6311a84f90e852b785418b4083da
  458. uni.showToast({
  459. title: res.errMsg,
  460. icon: 'none'
  461. })
  462. // 跳转到首页
  463. <<<<<<< HEAD
  464. uni.redirectTo({
  465. url: '../../pages/index/index?from=0'
  466. =======
  467. if (options && typeof(options.from) != 'undefined' && typeof(options.from) != '') {
  468. uni.navigateTo({
  469. url: '../../pages/index/index?from=' + options.from
  470. })
  471. } else {
  472. uni.redirectTo({
  473. url: '../../pages/index/index/index?from=0'
  474. });
  475. }
  476. }
  477. if (this.roomSelect == '' || typeof this.roomSelect == 'undefined' || !this.roomSelect) {
  478. const userinfo = uni.getStorageSync('userinfo_storage_key')
  479. if (userinfo && typeof(userinfo) != 'undefined' && typeof(userinfo.campus) != 'undefined' &&
  480. typeof(userinfo.dorm_number) != 'undefined' && userinfo.campus != '' && userinfo
  481. .dorm_number != '') {
  482. this.roomSelect = userinfo.campus + userinfo.dorm_number
  483. } else {
  484. this.roomSelect = '请选择宿舍号'
  485. }
  486. }
  487. } else {
  488. uni.showToast({
  489. title: 'code为空!',
  490. icon: 'success'
  491. });
  492. }
  493. },
  494. /**
  495. * 取得电费额度
  496. */
  497. async getDianLiang() {
  498. var _this = this;
  499. if (this.roomSelect != '' && typeof(this.roomSelect) != 'undefined') {
  500. const res = await this.$myRequest({
  501. host: _this.ceshi,
  502. url: '/HotWaters/buildoverElec.action',
  503. method: 'POST',
  504. header: {
  505. 'content-type': 'application/x-www-form-urlencoded'
  506. },
  507. data: {
  508. 'roomSelect': _this.roomSelect
  509. }
  510. })
  511. // console.log('取得电费额度', res);
  512. if (res.data.mess == '0') {
  513. setTimeout(() => {
  514. _this.remainElec = res.data.amount.toFixed(2)
  515. }, 30);
  516. } else {
  517. this.remainElec = 0.00.toFixed(2)
  518. }
  519. } else {
  520. uni.showToast({
  521. title: '请先选择宿舍号,\n再查询详情 或 充值',
  522. icon: 'none',
  523. duration: 3000
  524. });
  525. }
  526. },
  527. //跳转到选择页面
  528. navigateToSelect() {
  529. uni.navigateTo({
  530. url: '../select/select',
  531. });
  532. },
  533. // 是否选择了宿舍号
  534. haveSelectRoom() {
  535. if (this.roomSelect == '请选择宿舍') {
  536. uni.showToast({
  537. title: '请选择宿舍',
  538. icon: 'success'
  539. })
  540. return true
  541. }
  542. uni.setStorageSync('roomSelect', this.roomSelect);
  543. uni.setStorageSync('stu_number', this.stu_number);
  544. return false
  545. },
  546. //跳转到台账页面
  547. navigateToShow(e) {
  548. if (this.haveSelectRoom()) {
  549. return
  550. }
  551. if (this.roomSelect == '' || typeof this.roomSelect == 'undefined') {
  552. uni.showToast({
  553. title: '请再次选择宿舍号',
  554. icon: 'success'
  555. })
  556. } else {
  557. uni.navigateTo({
  558. url: '../show/show?rooSelect=' + this.roomSelect + '&card_number=' + this.stu_number,
  559. success: function(res) {
  560. }
  561. });
  562. }
  563. },
  564. /**
  565. * 增加固定金额
  566. */
  567. add_money(e) {
  568. this.amount = e.currentTarget.dataset.item
  569. },
  570. /**
  571. * 确认宿舍号
  572. */
  573. confirm_room(op) {
  574. // 检查房间号
  575. if (this.roomSelect == '' || this.roomSelect == '请选择宿舍号') {
  576. uni.showToast({
  577. title: '请选择宿舍号',
  578. icon: 'success'
  579. })
  580. return
  581. }
  582. // 输入金额进行充值
  583. if (op == 'input_money') {
  584. //判断输入是否为空或不是数字
  585. if (this.amount == '' || this.amount == null || this.amount == 0) {
  586. uni.showToast({
  587. title: '请输入充值金额',
  588. duration: 2000
  589. >>>>>>> 6053889f3dfa6311a84f90e852b785418b4083da
  590. })
  591. }
  592. }
  593. })
  594. },
  595. /**
  596. * 请求服务器,获得openid
  597. */
  598. async getOpenId(options, param_code) {
  599. // console.log(options, param_code)
  600. var _this = this
  601. if (param_code != '') {
  602. const res = await this.$myRequest({
  603. host: _this.ceshi,
  604. url: '/HotWaters/wpget_stu.action',
  605. method: 'POST',
  606. header: {
  607. 'content-type': 'application/x-www-form-urlencoded'
  608. },
  609. data: {
  610. code: param_code
  611. }
  612. })
  613. // console.log('获得openid', res);
  614. if (res.data.mess == '返回成功') {
  615. if (!(this.$store.state.building.roomSelect && typeof this.$store.state.building.roomSelect != 'undefined')) {
  616. // 栋宿舍号
  617. this.dorm_number = res.data.info[0].build + res.data.info[0].dom
  618. // 校区
  619. this.compus = res.data.info[0].campus
  620. // 填充校区宿舍号
  621. if (typeof this.dorm_number.split('栋')[1] == 'undefined') {
  622. this.roomSelect = this.compus + ''
  623. } else {
  624. this.roomSelect = this.compus + this.dorm_number.split('栋')[1]
  625. }
  626. // 存储选择
  627. this.$store.state.building.roomSelect = this.roomSelect
  628. // 样式
  629. this.add_class = 1
  630. }
  631. // 请求选定的月份消费记录
  632. this.getDianLiang()
  633. } else if (res.data.mess == '未查询到用户信息') {
  634. // 数据库中 未查询到用户信息,就清除本地存储
  635. uni.removeStorageSync('userinfo_storage_key')
  636. uni.showToast({
  637. title: '获取用户信息失败!'
  638. })
  639. // 跳转到首页
  640. if (options && typeof options.from != 'undefined' && typeof options.from != '') {
  641. uni.navigateTo({
  642. url: '../../pages/index/index?from=' + options.from
  643. })
  644. } else {
  645. uni.redirectTo({
  646. url: '../../pages/index/index/index?from=0'
  647. })
  648. }
  649. }
  650. if (this.roomSelect == '' || typeof this.roomSelect == 'undefined' || !this.roomSelect) {
  651. const userinfo = uni.getStorageSync('userinfo_storage_key')
  652. if (
  653. userinfo &&
  654. typeof userinfo != 'undefined' &&
  655. typeof userinfo.campus != 'undefined' &&
  656. typeof userinfo.dorm_number != 'undefined' &&
  657. userinfo.campus != '' &&
  658. userinfo.dorm_number != ''
  659. ) {
  660. this.roomSelect = userinfo.campus + userinfo.dorm_number
  661. } else {
  662. this.roomSelect = '请选择宿舍号'
  663. }
  664. }
  665. } else {
  666. uni.showToast({
  667. title: 'code为空!',
  668. icon: 'success'
  669. })
  670. }
  671. },
  672. /**
  673. * 取得电费额度
  674. */
  675. async getDianLiang() {
  676. var _this = this
  677. if (this.roomSelect != '' && typeof this.roomSelect != 'undefined') {
  678. const res = await this.$myRequest({
  679. host: _this.ceshi,
  680. url: '/HotWaters/buildoverElec.action',
  681. method: 'POST',
  682. header: {
  683. 'content-type': 'application/x-www-form-urlencoded'
  684. },
  685. data: {
  686. roomSelect: _this.roomSelect
  687. }
  688. })
  689. // console.log('取得电费额度', res);
  690. if (res.data.mess == '0') {
  691. setTimeout(() => {
  692. _this.remainElec = res.data.amount.toFixed(2)
  693. }, 30)
  694. } else {
  695. this.remainElec = (0.0).toFixed(2)
  696. }
  697. } else {
  698. uni.showToast({
  699. title: '请先选择宿舍号,\n再查询详情 或 充值',
  700. icon: 'none',
  701. duration: 3000
  702. })
  703. }
  704. },
  705. //跳转到选择页面
  706. navigateToSelect() {
  707. uni.navigateTo({
  708. url: '../select/select'
  709. })
  710. },
  711. // 是否选择了宿舍号
  712. haveSelectRoom() {
  713. if (this.roomSelect == '请选择宿舍号') {
  714. uni.showToast({
  715. title: '请选择宿舍号',
  716. icon: 'success'
  717. })
  718. return true
  719. }
  720. return false
  721. },
  722. //跳转到台账页面
  723. navigateToShow(e) {
  724. if (this.haveSelectRoom()) {
  725. return
  726. }
  727. if (this.roomSelect == '' || typeof this.roomSelect == 'undefined') {
  728. uni.showToast({
  729. title: '请再次选择宿舍号',
  730. icon: 'success'
  731. })
  732. } else {
  733. uni.navigateTo({
  734. url: '../show/show?rooSelect=' + this.roomSelect + '&card_number=' + this.stu_number,
  735. success: function(res) {}
  736. })
  737. }
  738. },
  739. /**
  740. * 增加固定金额
  741. */
  742. add_money(e) {
  743. this.amount = e.currentTarget.dataset.item
  744. },
  745. /**
  746. * 确认宿舍号
  747. */
  748. confirm_room(op) {
  749. // 检查房间号
  750. if (this.roomSelect == '' || this.roomSelect == '请选择宿舍号') {
  751. uni.showToast({
  752. title: '请选择宿舍号',
  753. icon: 'success'
  754. })
  755. return
  756. }
  757. // 输入金额进行充值
  758. if (op == 'input_money') {
  759. //判断输入是否为空或不是数字
  760. if (this.amount == '' || this.amount == null || this.amount == 0) {
  761. uni.showToast({
  762. title: '请输入充值金额',
  763. duration: 2000
  764. })
  765. return
  766. }
  767. if (isNaN(this.amount)) {
  768. uni.showToast({
  769. title: '请输入正确金额',
  770. duration: 2000
  771. })
  772. return
  773. }
  774. if (!this.test) {
  775. // 非测试环境
  776. if (this.amount > 200 || this.amount < 10) {
  777. uni.showToast({
  778. title: '限额10~200元',
  779. duration: 2000
  780. })
  781. return
  782. }
  783. }
  784. }
  785. // 确认充值对话框
  786. this.confirm_dialog()
  787. },
  788. /**
  789. * 确认充值对话框
  790. */
  791. confirm_dialog() {
  792. var _this = this
  793. uni.showModal({
  794. // title: '确定充值'+this.amount+'元',
  795. title: '确定充值' + _this.amount + '元',
  796. success: res => {
  797. if (res.confirm) {
  798. // 获取code
  799. _this.getCode('options', 'comfirm')
  800. } else if (res.cancel) {
  801. // console.log('用户点击取消');
  802. }
  803. }
  804. })
  805. },
  806. //增加可变金额
  807. input_money(e) {
  808. // console.log(this.test);
  809. // console.log(e)
  810. this.confirm_room('input_money')
  811. },
  812. /**
  813. * 请求服务器,获取支付参数,并支付
  814. */
  815. async jsapi(param_code) {
  816. if (param_code == '' || this.amount == '' || this.roomSelect == '') {
  817. uni.showToast({
  818. title: 'code、充值金额、宿舍号或IP为空'
  819. })
  820. return
  821. }
  822. var _this = this
  823. // console.log(_this.roomSelect);
  824. const res = await this.$myRequest({
  825. host: _this.ceshi,
  826. url: '/HotWaters/elpay_ns.action',
  827. method: 'POST',
  828. header: {
  829. 'content-type': 'application/x-www-form-urlencoded'
  830. },
  831. data: {
  832. code: param_code,
  833. num: _this.amount,
  834. stu_number: _this.stu_number,
  835. roomSelect: _this.roomSelect
  836. }
  837. })
  838. // console.log(res);
  839. if (res.data.code == 200 && res.data.sub_openid && res.data.sub_openid != '') {
  840. wx.requestPayment({
  841. appId: res.data.appId,
  842. timeStamp: res.data.timeStamp,
  843. nonceStr: res.data.nonceStr,
  844. package: res.data.package,
  845. signType: res.data.signType,
  846. paySign: res.data.paySign,
  847. success: res => {
  848. if (res.errMsg == 'requestPayment:ok') {
  849. uni.showToast({
  850. title: '支付成功',
  851. icon: 'success'
  852. })
  853. }
  854. },
  855. fail: res => {
  856. if (res.errMsg == 'requestPayment:fail cancel') {
  857. uni.showToast({
  858. title: '取消支付',
  859. icon: 'success',
  860. duration: 2000
  861. })
  862. }
  863. },
  864. complete: res => {
  865. // console.log(res);
  866. }
  867. })
  868. } else {
  869. uni.showToast({
  870. title: res.data.message,
  871. icon: 'none',
  872. duration: 3000
  873. })
  874. }
  875. },
  876. /**
  877. * 输入充值金额
  878. */
  879. onInput(e) {
  880. if (this.test) {
  881. // 测试环境
  882. return
  883. }
  884. const v = e.detail.value
  885. const zero = /^(0{1,})|[^0-9]/g
  886. let final = 0
  887. if (!v) {
  888. final = 0
  889. } else {
  890. final = v.toString().replace(zero, v => {
  891. return 0
  892. })
  893. if (final.split('')[0] * 1 === 0) {
  894. final = final.slice(1) - 0 || 0
  895. }
  896. if (final > 200) {
  897. final = 200
  898. }
  899. }
  900. this.$nextTick(() => {
  901. if (final.toString() == '0') {
  902. _this.amount = ''
  903. } else {
  904. _this.amount = final.toString() || '0'
  905. }
  906. })
  907. },
  908. /**
  909. * 失去焦点时
  910. */
  911. onBlur() {
  912. if (this.test) {
  913. // 测试环境
  914. return
  915. }
  916. if (this.amount < 10) {
  917. this.amount = 10
  918. }
  919. }
  920. }
  921. }
  922. </script>
  923. <style>
  924. @import url('jiaofei.css');
  925. </style>