sfxq.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <view class="container">
  3. <view class="line"></view>
  4. <view class="same-month">
  5. <view class="title">
  6. <view class="vertical-line"></view>
  7. <view class="title-txt"><text class="caption">当月详情</text><text class="hah">/</text>时间更新到{{sameMonthData.dataTime}}</view>
  8. </view>
  9. <view class="content-details">
  10. <view class="item">
  11. <view class="num">{{sameMonthData.zongStart}}</view>
  12. <view class="description">起码(吨)</view>
  13. </view>
  14. <view class="item">
  15. <view class="num">{{sameMonthData.zongEnd}}</view>
  16. <view class="description">止码(吨)</view>
  17. </view>
  18. <view class="item">
  19. <view class="num">{{sameMonthData.totalPower}}</view>
  20. <view class="description">用量(吨)</view>
  21. </view>
  22. <view class="item">
  23. <view class="num">{{sameMonthData.totalMoney}}</view>
  24. <view class="description">消费(元)</view>
  25. </view>
  26. </view>
  27. <view class="txt-color">(注:水费标准:{{moneyPer}}元/吨)</view>
  28. </view>
  29. <view class="line"></view>
  30. <view class="same-month">
  31. <view class="title">
  32. <view class="vertical-line"></view>
  33. <view class="title-txt"><text class="caption">每月账单</text></view>
  34. </view>
  35. <view class="content-details">
  36. <uni-table :border="true" :stripe="true" emptyText="暂无更多数据">
  37. <!-- 表头行 -->
  38. <uni-tr>
  39. <uni-th width="66" align="center">时间</uni-th>
  40. <uni-th width="64" align="center">起码(吨)</uni-th>
  41. <uni-th width="64" align="center">止码(吨)</uni-th>
  42. <uni-th width="64" align="center">用量(吨)</uni-th>
  43. <uni-th width="64" align="center">消费</uni-th>
  44. </uni-tr>
  45. <!-- 表格数据行 -->
  46. <uni-tr v-for="(item, index) in tableData" :key="index">
  47. <uni-td align="center">{{item.dataTime}}</uni-td>
  48. <uni-td align="center">{{item.zongStart}}</uni-td>
  49. <uni-td align="center">{{item.zongEnd}}</uni-td>
  50. <uni-td align="center">{{item.totalPower}}</uni-td>
  51. <uni-td align="center">{{item.totalMoney}}</uni-td>
  52. </uni-tr>
  53. </uni-table>
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. export default {
  60. data() {
  61. return {
  62. sameMonthData: {
  63. dataTime: '',
  64. zongEnd: 0.00.toFixed(2),
  65. totalMoney: 0.00.toFixed(2),
  66. totalPower: 0.00.toFixed(2),
  67. zongStart: 0.00.toFixed(2)
  68. },
  69. moneyPer: 2.1.toFixed(2),
  70. tableData: [],
  71. ceshi: 'code',
  72. stu_number: '', // 学号
  73. roomSelect: '', // 选择的宿舍号
  74. dom: ''
  75. }
  76. },
  77. onLoad() {
  78. try {
  79. // const eventChannel = this.getOpenerEventChannel();
  80. // // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  81. // let _this = this;
  82. // eventChannel.on('params', function(data) {
  83. // console.log('eventChannel', data);
  84. // // 获取学号
  85. // _this.stu_number = data.data.card_number;
  86. // _this.roomSelect = data.data.roomSelect;
  87. // });
  88. if (this.stu_number == '' || this.roomSelect == '' || typeof(this.stu_number) == 'undefined' || typeof(this.roomSelect) == 'undefined') {
  89. // 获取学号
  90. this.stu_number = this.$store.state.userInfo.card_number
  91. this.roomSelect = this.$store.state.building.roomSelect
  92. if (this.stu_number == '' || this.roomSelect == '' || typeof(this.stu_number) == 'undefined' || typeof(this.roomSelect) == 'undefined') {
  93. const userinfo = uni.getStorageSync('userinfo_storage_key')
  94. if (userinfo) {
  95. this.stu_number = userinfo.card_number
  96. this.roomSelect = userinfo.campus + userinfo.dorm_number
  97. } else {
  98. uni.redirectTo({
  99. url: '../index/index'
  100. })
  101. uni.showToast({
  102. icon: 'none',
  103. title: '学号或宿舍号为空,请授权',
  104. duration: 1500
  105. })
  106. return
  107. }
  108. }
  109. }
  110. // console.log(this.stu_number);
  111. // console.log(this.roomSelect);
  112. // 判断是否选择了宿舍号
  113. if (this.haveSelectRoom()) {
  114. uni.showToast({
  115. title: '宿舍号为空',
  116. icon: 'success'
  117. })
  118. }
  119. } catch (e) {
  120. console.log(e);
  121. }
  122. },
  123. methods: {
  124. /**
  125. * 判断是否选择了宿舍号
  126. */
  127. haveSelectRoom() {
  128. if (this.roomSelect == '' || typeof(this.roomSelect) == 'undefined') {
  129. return true
  130. } else {
  131. // 当月详情
  132. try {
  133. this.get_sameMonthDetails()
  134. } catch (e) {
  135. uni.showToast({
  136. title: '当月详情异常'
  137. })
  138. }
  139. // 每月账单
  140. try {
  141. this.get_history()
  142. } catch (e) {
  143. uni.showToast({
  144. title: '每月账单异常'
  145. })
  146. }
  147. return false
  148. }
  149. },
  150. /**
  151. * 当月详情
  152. */
  153. async get_sameMonthDetails() {
  154. let res = await this.$myRequest({
  155. host: this.ceshi,
  156. url: '/HotWaters/cwaterqueryNow.action',
  157. method: 'POST',
  158. header: {
  159. 'content-type': 'application/x-www-form-urlencoded'
  160. },
  161. data: {
  162. 'roomSelect': this.roomSelect
  163. }
  164. })
  165. // console.log(res.data)
  166. if (res.data.mess === '返回成功') {
  167. if (res.data.data.length == 0) {
  168. return
  169. }
  170. let zongEnd = res.data.data[0].zongEnd
  171. let totalMoney = res.data.data[0].totalMoney
  172. let totalPower = res.data.data[0].totalPower
  173. let zongStart = res.data.data[0].zongStart
  174. let dataTime = res.data.data[0].dataTime
  175. let dt = dataTime.split('-')
  176. this.sameMonthData.dataTime = dt[0] + '年' + parseInt(dt[1]) + '月'
  177. this.sameMonthData.zongEnd = zongEnd.toFixed(2)
  178. this.sameMonthData.totalMoney = totalMoney.toFixed(2)
  179. this.sameMonthData.totalPower = totalPower.toFixed(2)
  180. this.sameMonthData.zongStart = zongStart.toFixed(2)
  181. } else {
  182. uni.showToast({
  183. title: '加载数据异常',
  184. duration: 1500
  185. })
  186. return
  187. }
  188. },
  189. /**
  190. * 每月账单
  191. */
  192. async get_history() {
  193. var reg = /[\u4e00-\u9fa5]/g;
  194. var str = this.roomSelect;
  195. this.dom = str.replace(reg, "");
  196. let res = await this.$myRequest({
  197. host: this.ceshi,
  198. url: '/HotWaters/cwaterMonthlist.action',
  199. method: 'POST',
  200. header: {
  201. 'content-type': 'application/x-www-form-urlencoded'
  202. },
  203. data: {
  204. 'dom': this.dom,
  205. 'page': 1,
  206. 'rows': 12
  207. }
  208. })
  209. // console.log(res.data)
  210. if (res.data.rows.length == 0) {
  211. return
  212. }
  213. if (typeof res.data.rows === 'undefined') {
  214. uni.showToast({
  215. title: '加载数据异常',
  216. duration: 1500
  217. });
  218. return;
  219. } else {
  220. var tableData = []
  221. for (let i = 0; i < res.data.rows.length; i++) {
  222. let dataTime = res.data.rows[i].dataTime;
  223. let zongStart = res.data.rows[i].zongStart;
  224. let zongEnd = res.data.rows[i].zongEnd;
  225. let totalPower = res.data.rows[i].totalPower;
  226. let totalMoney = res.data.rows[i].totalMoney;
  227. zongStart = zongStart.toFixed(2);
  228. zongEnd = zongEnd.toFixed(2);
  229. totalPower = totalPower.toFixed(2);
  230. totalMoney = totalMoney.toFixed(2);
  231. if (this.moneyPer <= 0.00) {
  232. if (totalPower > 0.00 && totalMoney > 0.00) {
  233. let moneyPer = totalMoney / totalPower;
  234. this.moneyPer = moneyPer.toFixed(2);
  235. if (this.moneyPer <= 0.00) {
  236. this.moneyPer = 0.61;
  237. }
  238. }
  239. }
  240. totalMoney = '¥' + totalMoney;
  241. tableData.push({
  242. dataTime,
  243. zongStart,
  244. zongEnd,
  245. totalPower,
  246. totalMoney
  247. });
  248. }
  249. this.tableData = tableData.filter(function(item, index, self) {
  250. return index === self.findIndex(function(t) {
  251. return t.dataTime === item.dataTime && t.totalPower === item.totalPower && t.totalMoney === item.totalMoney;
  252. });
  253. });
  254. }
  255. }
  256. }
  257. }
  258. </script>
  259. <style scoped lang="scss">
  260. .container {
  261. display: flex;
  262. flex-direction: column;
  263. font-size: 29upx;
  264. font-family: "Microsoft YaHei";
  265. .line {
  266. height: 10rpx;
  267. background-color: #f5f5f5;
  268. }
  269. .same-month {
  270. display: flex;
  271. flex-direction: column;
  272. padding: 20rpx 30rpx;
  273. .title {
  274. display: flex;
  275. align-items: center;
  276. margin-bottom: 30rpx;
  277. .vertical-line {
  278. display: inline-block;
  279. margin-right: 20rpx;
  280. width: 10rpx;
  281. height: 45rpx;
  282. background-color: #0282F8;
  283. }
  284. .title-txt {
  285. display: flex;
  286. flex-direction: row;
  287. align-items: flex-end;
  288. color: #C1C1C1;
  289. .caption {
  290. color: #2b2b2b;
  291. font-size: 40upx;
  292. }
  293. .hah {
  294. display: flex;
  295. margin: 0 10rpx;
  296. }
  297. }
  298. }
  299. .content-details {
  300. display: flex;
  301. justify-content: space-around;
  302. .item {
  303. display: flex;
  304. flex-direction: column;
  305. align-items: center;
  306. .num {
  307. font-size: 40upx;
  308. }
  309. .description {
  310. color: #9a9a9a;
  311. }
  312. }
  313. /deep/ .uni-table {
  314. .uni-table-th {
  315. padding: 6px 8px;
  316. font-size: 26upx;
  317. white-space: nowrap;
  318. text-align: center;
  319. background-color: #E5F2FE;
  320. color: #39393A;
  321. }
  322. .uni-table-td {
  323. padding: 3px 5px;
  324. font-size: 26upx;
  325. white-space: nowrap;
  326. text-align: center;
  327. }
  328. }
  329. }
  330. .txt-color {
  331. margin: 20rpx 0;
  332. color: #C1C1C1;
  333. }
  334. }
  335. }
  336. </style>