index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. <template>
  2. <scroll-view scroll-y class="page">
  3. <!-- Header -->
  4. <view class="title-card">
  5. <text class="title">物联网智能抄表管理系统</text>
  6. </view>
  7. <!-- 应缴金额区域 -->
  8. <view class="amount-area">
  9. <view class="row between">
  10. <text class="label">应缴金额(元)</text>
  11. <text class="amount" v-if="userInfo.settledType === 1">{{ userInfo.shouldCollectMoney }}</text>
  12. <text class="amount" v-else>0.00</text>
  13. </view>
  14. <view class="row between">
  15. <text></text>
  16. <text class="warn" v-if="userInfo.settledType === 1">有欠费,请尽快缴费</text>
  17. </view>
  18. <view class="info">
  19. <view class="row between info-item">
  20. <text>截止时间</text>
  21. <text class="warn">{{ userInfo.lastExamineTime }}</text>
  22. </view>
  23. <view class="row between">
  24. <text>户号信息</text>
  25. <text class="warn">{{ userInfo.userCode }}</text>
  26. </view>
  27. <view class="row between">
  28. <text>地址信息</text>
  29. <text class="warn">{{ userInfo.roomNumber }}</text>
  30. </view>
  31. <view class="row between info-mani">
  32. <text>缴费单位</text>
  33. <text class="warn">{{ userInfo.companyName }}</text>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="floating-view"></view>
  38. <!-- 缴费金额选择 -->
  39. <view class="pay-select">
  40. <text class="label">缴费金额</text>
  41. <view class="preset">
  42. <button class="amount-btn" @click="duplicationEvents(20)">20元</button>
  43. <button class="amount-btn" @click="duplicationEvents(50)">50元</button>
  44. <button class="amount-btn" @click="duplicationEvents(100)">100元</button>
  45. </view>
  46. <view class="input-wrapper">
  47. <text class="prefix">¥</text>
  48. <input class="custom-input" v-model="moneyvalue" type="number" min="0" step="0.01" placeholder="点击输入缴费金额" />
  49. </view>
  50. <view class="current-debt" v-if="userInfo.settledType === 1">
  51. <text>当前欠费金额 {{ userInfo.shouldCollectMoney }} 元 </text>
  52. <text class="auto-fill warn" @click="duplicationEvents(money.value)">点击自动填入</text>
  53. </view>
  54. <view class="current-debt" v-else>
  55. <text>当前暂为欠费 </text>
  56. </view>
  57. </view>
  58. <!-- 支付按钮 -->
  59. <view class="pay-buttons">
  60. <button class="wxpay" @click="qita('weiPay')">微信支付</button>
  61. <button class="otherpay" @click="qita('zfbPay')">其他支付</button>
  62. </view>
  63. <!-- 二维码弹框 -->
  64. <uni-popup ref="popup" type="center" z-index="999" >
  65. <view class="modal">
  66. <text class="modal-title">物联网智能抄表管理系统</text>
  67. <view class="qrcode-container">
  68. <img v-if="qrcodeContainer" :src="qrcodeContainer" alt="" />
  69. </view>
  70. <button class="modal_button" @click="saveScreenshot">截屏保存</button>
  71. </view>
  72. </uni-popup>
  73. <!-- 账单信息 -->
  74. <view class="bill-info">
  75. <view class="bill-head">
  76. <text class="label">账单信息</text>
  77. <!-- <text class="date">2024年10月</text> -->
  78. <view class="container">
  79. <!-- <picker mode="date" fields="month" :value="single" start="2000-01-01" end="2030-12-31"
  80. @change="onMonthChange">
  81. <view class="uni-input">{{ single || defaultDate }} <text>▼</text></view>
  82. </picker> -->
  83. <picker
  84. mode="date"
  85. fields="month"
  86. :value="single"
  87. :start="startDate"
  88. :end="endDate"
  89. @change="onMonthChange"
  90. >
  91. <view class="uni-input">{{ single || defaultDate }} <text>▼</text></view>
  92. </picker>
  93. </view>
  94. </view>
  95. <view class="bill-detail">
  96. <text>本期用水量(m³):<text class="bold">{{ currentWater }}</text></text>
  97. <text>本期水费(元):<text class="bold">{{ currentMoney }}</text></text>
  98. </view>
  99. <!-- 用水柱状图 -->
  100. <LEchart force-use-old-canvas="false" class="chart" ref="barChartref" @finished="init"></LEchart>
  101. <text class="label">用水量情况</text>
  102. <!-- 用水曲线图 -->
  103. <LEchart force-use-old-canvas="false" class="chart2" ref="lineChartref" @finished="init"></LEchart>
  104. </view>
  105. </scroll-view>
  106. </template>
  107. <script setup>
  108. import {
  109. onMounted,
  110. reactive,
  111. ref,
  112. nextTick
  113. } from 'vue'
  114. import { get } from '@/utils/request'
  115. import { onLoad } from '@dcloudio/uni-app'
  116. import QRCode from 'qrcode-generator';
  117. import LEchart from '@/components/l-echart/l-echart.vue';
  118. const userInfo = ref({})
  119. // 图表 柱状 折线
  120. const barChartref = ref();
  121. const lineChartref = ref();
  122. onLoad(() => {
  123. userInfo.value = uni.getStorageSync('userInfo')
  124. setTimeout(() => {
  125. getCurrentYearMonth();
  126. }, 1000)
  127. })
  128. const echarts = require('../../static/echarts.min');
  129. // 点击选择年月
  130. const single = ref('');
  131. // 默认年月
  132. const defaultDate = ref('');
  133. // 欠费金额
  134. const money = ref(87.12)
  135. // 缴费金额
  136. const moneyvalue = ref()
  137. // 是否显示二维码弹框
  138. const showQRCodeModal = ref(false);
  139. const popup = ref(null);
  140. // 二维码容器
  141. const qrcodeContainer = ref('http://192.168.50.127:18001/api/images/63a8db7bfb4f190d6aed819088bfb396.jpg');
  142. // 本期用水量
  143. const currentWater = ref(0)
  144. // 本期水费
  145. const currentMoney = ref(0)
  146. // 自动填入
  147. const duplicationEvents = (data) => {
  148. moneyvalue.value = data
  149. }
  150. // 支付
  151. const qita = async (value) => {
  152. try {
  153. const res = await get('/api/payConfig/pay', {
  154. payType: value
  155. })
  156. if (res.code === '200') {
  157. qrcodeContainer.value = res.data
  158. popup.value.open();
  159. } else {
  160. uni.showToast({ title: res.message || '绑定失败', icon: 'none' })
  161. }
  162. } catch (err) {
  163. // console.log('请求失败:', err)
  164. uni.showToast({ title: '请求失败,请稍后重试', icon: 'none' })
  165. }
  166. }
  167. // 截屏保存按钮点击事件
  168. const saveScreenshot = () => {
  169. // 这里可以实现截屏保存的逻辑,例如使用 HTML2Canvas 库
  170. console.log('截屏保存');
  171. };
  172. // 获取当前年份
  173. const currentYear = new Date().getFullYear()
  174. // 设置起始和结束为今年范围
  175. const startDate = `${currentYear}-01-01`
  176. const endDate = `${currentYear}-12-31`
  177. // 默认月份:当前月
  178. const now = new Date()
  179. const defaultMonth = `${currentYear}-${String(now.getMonth() + 1).padStart(2, '0')}`
  180. const selectedMonth = ref('')
  181. // 点击弹框获取年月
  182. const onMonthChange = (e) => {
  183. // 截取到年月,如 "2025-06"
  184. const value = e.detail.value.slice(0, 7)
  185. single.value = value
  186. // console.log(single.value, 'selected month')
  187. // 提取月份部分(注意转为数字)
  188. const month = Number(value.slice(5, 7))
  189. if (month <= 6) {
  190. // console.log('上半年逻辑')
  191. findByTimes(1, 6)
  192. } else {
  193. // console.log('下半年逻辑')
  194. findByTimes(7, 12)
  195. }
  196. }
  197. // 默认显示时间
  198. const getCurrentYearMonth = () => {
  199. const date = new Date()
  200. const year = date.getFullYear()
  201. const month = date.getMonth() + 1 // JS 中月份从 0 开始
  202. // 格式化为 "YYYY-MM"
  203. const formattedMonth = String(month).padStart(2, '0')
  204. const shij = `${year}-${formattedMonth}`
  205. defaultDate.value = shij
  206. single.value = shij
  207. // 根据月份判断逻辑
  208. if (month <= 6) {
  209. // console.log('当前为上半年,执行上半年默认逻辑')
  210. findByTimes(1, 6)
  211. } else {
  212. // console.log('当前为下半年,执行下半年默认逻辑')
  213. findByTimes(7, 12)
  214. }
  215. }
  216. const realCollectMoneylist = ref([])
  217. const waterlist = ref([])
  218. const monthLabelslist = ref([])
  219. const findByTimes = async (startTime, endTime) => {
  220. try {
  221. const res = await get('/api/waterUser/findByTime', {
  222. startTime: startTime,
  223. endTime: endTime,
  224. phoneNumber: userInfo.value.phoneNumber
  225. })
  226. if (res.code === '200') {
  227. currentMoney.value = res.data.currentMoney
  228. currentWater.value = res.data.currentWater
  229. realCollectMoneylist.value = res.data.data.map(item => Number(item.realCollectMoney));
  230. waterlist.value = res.data.data.map(item => item.waterData);
  231. monthLabelslist.value = res.data.months.map(item => `${item}月`);
  232. // 动态更新柱状图配置
  233. state.option.xAxis.data = monthLabelslist.value; // 更新 X 轴数据
  234. state.option.series[0].data = realCollectMoneylist.value; // 更新柱状图数据
  235. // 动态更新柱状图配置
  236. state.option.xAxis.data = monthLabelslist.value;
  237. state.option.series[0].data = realCollectMoneylist.value;
  238. // 动态更新折线图配置
  239. state2.option.xAxis.data = monthLabelslist.value;
  240. state2.option.series[0].data = waterlist.value;
  241. // 立即初始化图表
  242. barChartref.value.init(echarts, (chart) => {
  243. chart.setOption(state.option);
  244. });
  245. lineChartref.value.init(echarts, (chart) => {
  246. chart.setOption(state2.option);
  247. });
  248. } else {
  249. uni.showToast({ title: res.message || '查询失败', icon: 'none' })
  250. }
  251. } catch (err) {
  252. uni.showToast({ title: '请求失败,请稍后重试', icon: 'none' })
  253. }
  254. }
  255. // 折线图
  256. const state2 = reactive({
  257. option: {}
  258. });
  259. state2.option = {
  260. grid: {
  261. right: '2%',
  262. top: '18%',
  263. left: '8%',
  264. bottom: '18%'
  265. },
  266. xAxis: {
  267. type: 'category',
  268. data: monthLabelslist.value,
  269. axisTick: {
  270. // 不显示刻度线
  271. show: false
  272. }
  273. },
  274. yAxis: {
  275. type: 'value',
  276. name: '(m³)',
  277. },
  278. series: [{
  279. data: waterlist.value,
  280. type: 'line',
  281. areaStyle: {},
  282. smooth: true,
  283. color: '#7bed8b',
  284. symbol: 'none',
  285. emphasis: {
  286. // 鼠标悬停时显示数据点
  287. itemStyle: {
  288. borderWidth: 2,
  289. borderColor: '#fff'
  290. },
  291. label: {
  292. show: true
  293. },
  294. // 鼠标悬停时显示圆形数据点
  295. symbol: 'circle',
  296. symbolSize: 8,
  297. }
  298. }]
  299. }
  300. // 柱状图
  301. const state = reactive({
  302. option: {}
  303. })
  304. // 获取当前月份(注意:getMonth() 返回值是 0 - 11,所以需要加 1)
  305. // const currentMonth = new Date().getMonth() + 1;
  306. // const months = ['5月', '6月', '7月', '8月', '9月'];
  307. // const data = realCollectMoneylist.value;
  308. const colors = new Array(realCollectMoneylist.value.length).fill('#cfdfff');
  309. // // 找到当前月份在 months 数组中的索引
  310. // const index = realCollectMoneylist.value.indexOf(`${currentMonth}月`);
  311. // if (index !== -1) {
  312. // // 如果找到当前月份对应的索引,将该柱子颜色修改为 #1756d9
  313. // colors[index] = '#1756d9';
  314. // }
  315. state.option = {
  316. grid: {
  317. right: '2%',
  318. top: '18%',
  319. left: '9%',
  320. bottom: '20%'
  321. },
  322. xAxis: {
  323. type: 'category',
  324. data: monthLabelslist.value, // X 轴数据
  325. axisTick: {
  326. // 不显示刻度线
  327. show: false
  328. }
  329. },
  330. yAxis: {
  331. type: 'value',
  332. name: '(元)'
  333. },
  334. series: [{
  335. data: realCollectMoneylist.value,
  336. type: 'bar',
  337. // 使用 colors 数组来设置每个柱子的颜色
  338. itemStyle: {
  339. color:'#1756d9'
  340. },
  341. barWidth: '40%',
  342. label: {
  343. show: true,
  344. position: 'top',
  345. color: '#1756d9'
  346. }
  347. }]
  348. };
  349. // 渲染完成
  350. const init = () => {
  351. console.log('渲染完成');
  352. }
  353. </script>
  354. <style scoped lang="scss">
  355. :deep .uni-popup {
  356. z-index: 999 !important;
  357. }
  358. /* 遮罩层样式 */
  359. .modal-overlay {
  360. z-index: 99999 !important;
  361. width: 100%;
  362. height: 100%;
  363. display: flex;
  364. justify-content: center;
  365. align-items: center;
  366. /* 修改为 align-items 以垂直居中 */
  367. position: fixed;
  368. top: 0;
  369. left: 0;
  370. background-color: rgba(0, 0, 0, 0.5);
  371. /* 加深背景透明度 */
  372. backdrop-filter: blur(3rpx);
  373. /* 添加模糊效果 */
  374. }
  375. /* 模态框样式 */
  376. .modal {
  377. width: 600rpx;
  378. height: 850rpx;
  379. background: #ffffff;
  380. /* 白色背景 */
  381. border-radius: 15rpx;
  382. /* 增大圆角 */
  383. text-align: center;
  384. position: relative;
  385. box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.2);
  386. /* 添加阴影效果 */
  387. padding: 40rpx;
  388. /* 添加内边距 */
  389. box-sizing: border-box;
  390. /* 包含内边距在宽度内 */
  391. }
  392. /* 模态框标题样式 */
  393. .modal-title {
  394. font-size: 36rpx;
  395. font-weight: bold;
  396. color: #333333;
  397. margin-bottom: 30rpx;
  398. /* 增加底部间距 */
  399. }
  400. /* 二维码容器样式 */
  401. .qrcode-container {
  402. width: 520rpx;
  403. height: 520rpx;
  404. /* 调整二维码容器高度 */
  405. display: flex;
  406. justify-content: center;
  407. align-items: center;
  408. margin-bottom: 40rpx;
  409. /* 增加底部间距 */
  410. }
  411. /* 按钮样式 */
  412. .modal_button {
  413. position: absolute;
  414. /* 修改为相对定位 */
  415. left: 0;
  416. bottom: 0;
  417. width: 100%;
  418. border: none;
  419. background: linear-gradient(to right, #6ea5ff, #3d81fd);
  420. /* 蓝色背景 */
  421. color: #ffffff;
  422. /* 白色文字 */
  423. font-size: 32rpx;
  424. padding: 15rpx 0;
  425. border-radius: 0rpx;
  426. }
  427. /* 按钮悬停效果 */
  428. .modal_button:hover {
  429. background-color: #0056b3;
  430. /* 悬停时颜色加深 */
  431. }
  432. .page {
  433. width: calc(100% - 60rpx);
  434. background-color: #f7f8fa;
  435. padding: 30rpx;
  436. }
  437. .title-card {
  438. background: linear-gradient(to right, #6ea5ff, #3c80fd);
  439. padding: 25rpx 25rpx 45rpx 25rpx;
  440. border-radius: 20rpx 20rpx 0 0;
  441. }
  442. .title {
  443. color: #fff;
  444. font-size: 30rpx;
  445. font-weight: bold;
  446. text-align: center;
  447. }
  448. .amount-area {
  449. background: #fff;
  450. padding: 30rpx;
  451. border-radius: 20rpx;
  452. margin-top: -20rpx;
  453. margin-bottom: 2rpx;
  454. }
  455. .amount-area .row {
  456. display: flex;
  457. justify-content: space-between;
  458. align-items: center;
  459. }
  460. .floating-view {
  461. border-top: 2rpx dashed #d8d8d8;
  462. width: calc(100% - 40rpx);
  463. margin: 0 20rpx;
  464. }
  465. .amount {
  466. font-size: 50rpx;
  467. color: #000;
  468. font-weight: bold;
  469. }
  470. .label {
  471. font-weight: 600;
  472. font-size: 35rpx;
  473. color: #515151;
  474. }
  475. .warn {
  476. color: red;
  477. margin-top: 10rpx;
  478. font-size: 24rpx;
  479. }
  480. .info text {
  481. display: block;
  482. margin-top: 10rpx;
  483. font-size: 26rpx;
  484. color: #666;
  485. margin: 13rpx;
  486. }
  487. .info-item {
  488. margin-top: 16px;
  489. border-bottom: 1rpx solid #e6e6e6;
  490. }
  491. .info-mani {
  492. /* border-bottom: 1rpx solid #e6e6e6; */
  493. }
  494. .pay-select {
  495. background: #fff;
  496. padding: 30rpx;
  497. border-radius: 20rpx;
  498. margin-bottom: 20rpx;
  499. }
  500. .preset {
  501. display: flex;
  502. justify-content: space-between;
  503. margin: 35rpx 0;
  504. }
  505. .amount-btn {
  506. background-color: #f5f5f5;
  507. color: #333;
  508. font-weight: bold;
  509. padding: 0rpx 40rpx;
  510. border: none;
  511. border-radius: 10rpx;
  512. font-size: 28rpx;
  513. }
  514. .amount-btn::after {
  515. border: 0px solid rgba(0, 0, 0, 0.2);
  516. }
  517. .input-wrapper {
  518. display: flex;
  519. align-items: center;
  520. height: 70rpx;
  521. border-bottom: 1rpx solid #e6e6e6;
  522. }
  523. .prefix {
  524. font-size: 32rpx;
  525. font-weight: 600;
  526. color: #3e3e3e;
  527. margin-right: 10rpx;
  528. }
  529. .custom-input {
  530. flex: 1;
  531. font-size: 32rpx;
  532. color: #333;
  533. border: none;
  534. outline: none;
  535. }
  536. .current-debt {
  537. display: flex;
  538. justify-content: space-between;
  539. align-items: center;
  540. font-size: 24rpx;
  541. color: #666;
  542. margin-top: 16rpx;
  543. }
  544. .auto-fill {
  545. color: #2f80ed;
  546. margin-left: 10rpx;
  547. }
  548. .pay-buttons {
  549. display: flex;
  550. justify-content: space-around;
  551. margin: 40rpx 0;
  552. }
  553. .wxpay {
  554. background-color: #2f80ed;
  555. color: white;
  556. border-radius: 50rpx;
  557. flex: 1;
  558. margin-right: 20rpx;
  559. }
  560. .otherpay {
  561. border: 1rpx solid #2f80ed;
  562. color: #2f80ed;
  563. background-color: white;
  564. border-radius: 50rpx;
  565. flex: 1;
  566. }
  567. .bill-info {
  568. background: #fff;
  569. padding: 30rpx;
  570. border-radius: 20rpx;
  571. margin-bottom: 40rpx;
  572. }
  573. .bill-head {
  574. display: flex;
  575. justify-content: space-between;
  576. font-weight: bold;
  577. font-size: 28rpx;
  578. margin-bottom: 20rpx;
  579. }
  580. .bill-detail {
  581. display: flex;
  582. justify-content: space-between;
  583. margin-bottom: 20rpx;
  584. }
  585. .bold {
  586. font-weight: bold;
  587. font-size: 30rpx;
  588. }
  589. .chart {
  590. height: 300rpx;
  591. width: 100%;
  592. z-index: 2 !important;
  593. }
  594. .chart2 {
  595. margin-top: 16rpx;
  596. height: 300rpx;
  597. width: 100%;
  598. z-index: 2 !important;
  599. }
  600. </style>