home.wpy 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <style lang="less">
  2. page {
  3. height: 100%;
  4. background-color: #EBF5FA;
  5. }
  6. .page-container {
  7. width: 100%;
  8. height: 100%;
  9. overflow: hidden;
  10. box-sizing: border-box;
  11. position: relative;
  12. .bg {
  13. width: 100%;
  14. height: 726rpx;
  15. background-color:#EBF5FA;
  16. position: absolute;
  17. top: 0;
  18. left: 0;
  19. z-index: 0;
  20. }
  21. .loadImg {
  22. padding-top: 20rpx;
  23. height: 40rpx;
  24. width: 40rpx;
  25. }
  26. .countHead {
  27. position: relative;
  28. padding: 44rpx;
  29. padding-top: 222rpx;
  30. display: flex;
  31. justify-content: space-between;
  32. align-items: center;
  33. z-index: 1;
  34. .leftCont {
  35. font-family: PingFang SC;
  36. font-size: 48rpx;
  37. font-weight: 600;
  38. line-height: 68rpx;
  39. color: #1B2129;
  40. }
  41. .rightCont {
  42. display: flex;
  43. flex-direction: column;
  44. text-align: right;
  45. .name {
  46. font-family: PingFang SC;
  47. font-size: 28rpx;
  48. font-weight: 400;
  49. line-height: 44rpx;
  50. color: #626C78;
  51. }
  52. .value {
  53. font-family: Persagy2.0;
  54. font-size: 56rpx;
  55. font-weight: 600;
  56. line-height: 72rpx;
  57. color: #1B2129;
  58. }
  59. }
  60. }
  61. .allCard {
  62. position: relative;
  63. padding: 0 40rpx;
  64. overflow: hidden;
  65. .eachCard {
  66. position: relative;
  67. width: 322rpx;
  68. height: 280rpx;
  69. margin-right: 24rpx;
  70. margin-bottom: 18rpx;
  71. box-sizing: border-box;
  72. padding: 40rpx 0 0 36rpx;
  73. float: left;
  74. border-radius: 40rpx;
  75. background: #ffffff;
  76. .imgPosition {
  77. position: absolute;
  78. bottom: 0;
  79. right: 0;
  80. &.imgLamp {
  81. top: 0;
  82. right: 17rpx;
  83. }
  84. }
  85. .name {
  86. font-family: PingFang SC;
  87. font-size: 30rpx;
  88. font-weight: 400;
  89. line-height: 42rpx;
  90. color: #626C78;
  91. }
  92. .each_value {
  93. display: flex;
  94. padding-top: 8rpx;
  95. }
  96. .value {
  97. font-family: Persagy2.0;
  98. font-size: 56rpx;
  99. font-weight: 400;
  100. line-height: 68rpx;
  101. }
  102. .unit {
  103. font-size: 24rpx;
  104. color: #c4c4c4;
  105. padding-left: 6rpx;
  106. }
  107. &:nth-child(2n) {
  108. margin-right: 0%;
  109. }
  110. }
  111. }
  112. .logo-text {
  113. position: absolute;
  114. bottom: 0;
  115. display: flex;
  116. justify-content: center;
  117. width: 100%;
  118. height: 24rpx;
  119. padding: 98rpx 0 80rpx;
  120. }
  121. }
  122. </style>
  123. <template>
  124. <div class="page-container">
  125. <page-top-bar
  126. icon="{{h5Static+'/page-top-bar/return-icon.svg'}}"
  127. ></page-top-bar>
  128. <image
  129. class="bg"
  130. src="{{h5StaticPath}}/protrait-bg.png"
  131. mode="widthFix"
  132. alt
  133. />
  134. <div class="countHead">
  135. <div class="leftCont">使用统计</div>
  136. <navigator url="/packagesEnv/pages/portrait/energy">
  137. <div
  138. class="rightCont"
  139. @tap="showEnergyPage('total','total','节能分')"
  140. >
  141. <div class="name">我的{{carbonCreditText}}</div>
  142. <div class="value">
  143. {{energyHeadData.totalPoints||energyHeadData.totalPoints==0?energyHeadData.totalPoints:'--'}}</div>
  144. </div>
  145. </navigator>
  146. </div>
  147. <div class="allCard">
  148. <navigator
  149. v-for="(item,idx) in arr"
  150. v-if="item.isshow"
  151. :url="item.url"
  152. class="eachCard"
  153. @click="showEnergyPage('card',item.code,item.name)"
  154. >
  155. <div class="name">{{item.name}}</div>
  156. <!-- <div v-show="item.load">
  157. <image
  158. class="loadImg"
  159. src="{{h5StaticPath}}/page-officehome/loading.svg"
  160. ></image>
  161. </div> -->
  162. <div class="each_value">
  163. <div class="value">{{item.num}}</div>
  164. <div
  165. class="unit"
  166. v-if="item.unit !== ''"
  167. >{{item.unit}}</div>
  168. </div>
  169. <image
  170. style="width:{{item.imgWidth}}rpx;height:{{item.imgHeight}}rpx"
  171. class="imgPosition {{item.class}}"
  172. src="{{h5StaticPath}}/{{item.img}}"
  173. lazyload
  174. ></image>
  175. </navigator>
  176. </div>
  177. <!-- <image
  178. class="logo-text"
  179. src="{{h5StaticPath}}/page-home/tenatslink.svg"
  180. ></image> -->
  181. </div>
  182. </template>
  183. <script>
  184. import wepy from '@wepy/core'
  185. import store from '@/store'
  186. import config from '@/config'
  187. import moment from 'moment'
  188. import { mapState } from '@wepy/x'
  189. import { queryTotalIntegral, queryPortraitTempUserTotal, queryTotalPortraitLight, queryPortraitModule } from '@/packagesEnv/api/portrait'
  190. import { getCompmayUsers } from '@/api/user'
  191. // import { saveCompanyConfig } from '@/service/companyConfig'
  192. import { umaInit } from '../common.js'
  193. import { checkHasUserInfo } from '@/service/user'
  194. import { carbonCredit } from '../common.js'
  195. wepy.page({
  196. store,
  197. data: {
  198. carbonCreditText: '',
  199. pageTopBarTop: 0,
  200. h5StaticPath: config.h5StaticPath + '/page-portrait',
  201. h5Static: config.h5StaticPath,
  202. totalPoints: 0,
  203. arr: [
  204. { id: 'airConditioner', code: 'air', name: '空调调节', num: '--', unit: '', class: '', imgWidth: 170, imgHeight: 202, url: '/packagesEnv/pages/portrait/energy?sel=temp', img: 'portrait_air.svg', isshow: false },
  205. { id: 'light', code: 'lamp', name: '开关照明', num: '--', unit: '', class: 'imgLamp', imgWidth: 146, imgHeight: 194, url: '/packagesEnv/pages/portrait/energy?sel=light', img: 'portrait_lamp.svg', isshow: false }
  206. ]
  207. },
  208. computed: {
  209. ...mapState({
  210. token: state => state.user.token,
  211. energyHeadData: state => state.portrait.energyHeadData,
  212. projectId: state => state.company && state.company.companyConfig && state.company.companyConfig.sagacareProjectId
  213. })
  214. },
  215. onLoad() {
  216. umaInit()
  217. checkHasUserInfo()
  218. this.getData()
  219. this.carbonCreditText = carbonCredit(this.projectId)
  220. },
  221. onReady() { },
  222. methods: {
  223. getData() {
  224. this.queryUserIntegral()
  225. this.getAir()
  226. this.getLamp()
  227. this.queryPortraitModule()
  228. // this.getUsersFace()
  229. },
  230. // getUsersFace() { // 用户信息
  231. // getCompmayUsers().then(res => {
  232. // store.commit('setUserData', res.data || {})
  233. // })
  234. // },
  235. showEnergyPage(page, pointType, pointName) { // 跳转到排行
  236. wx.uma.trackEvent(`portrait_home_${pointType}`, { key: pointName })
  237. // if (page === 'total') {
  238. // wx.navigateTo({
  239. // url: './energy'
  240. // });
  241. // }
  242. },
  243. getAir() { // 空调统计
  244. queryPortraitTempUserTotal().then(res => {
  245. this.arr[0].num = JSON.stringify(res.data) != '{}' ? this.dealNumToPoint(res.data.adjustDownNum + res.data.adjustUpNum, 0) : '--'
  246. })
  247. },
  248. getLamp() { // 灯
  249. queryTotalPortraitLight().then(res => {
  250. this.arr[1].num = res.data.totalNum ? this.dealNumToPoint(res.data.totalNum, 1) : '--'
  251. })
  252. },
  253. dealNumToPoint(num, arrIndex) {
  254. if (num >= 10000) {
  255. num = Math.floor(num / 10000 * 10) / 10
  256. this.arr[arrIndex].unit = '万'
  257. } else {
  258. this.arr[arrIndex].unit = ''
  259. return num
  260. }
  261. return num
  262. },
  263. queryUserIntegral() { // 获取头部的 累计积分 月排名 日积分
  264. var _this = this
  265. var today = moment().format('YYYYMMDD')
  266. var lastMonth = moment().subtract(1, 'month').format('YYYYMM')
  267. queryTotalIntegral({
  268. date: today,
  269. month: lastMonth
  270. }).then(function (res) {
  271. store.commit('setEnergyHeadData', res || {})
  272. })
  273. },
  274. queryPortraitModule() { // 获取头部的 累计积分 月排名 日积分
  275. var _this = this
  276. queryPortraitModule().then(function (res) {
  277. // store.dispatch('setPortraitModule', res || {});
  278. var data = res.data || []
  279. console.log('queryPortraitModule', data)
  280. _this.arr.forEach(function (item) {
  281. if (data.indexOf(item.id) > -1) {
  282. item.isshow = true
  283. } else {
  284. item.isshow = false
  285. }
  286. })
  287. var portraitModule = { airConditioner: false, light: false }
  288. if (data.indexOf('airConditioner') > -1) {
  289. portraitModule.airConditioner = true
  290. } else {
  291. portraitModule.airConditioner = false
  292. }
  293. if (data.indexOf('light') > -1) {
  294. portraitModule.light = true
  295. } else {
  296. portraitModule.light = false
  297. }
  298. store.dispatch('setPortraitModule', portraitModule)
  299. })
  300. }
  301. }
  302. })
  303. </script>
  304. <config>
  305. {
  306. 'navigationBarTitleText': '',
  307. navigationStyle:"custom",
  308. backgroundColor: '#EBF5FA',
  309. usingComponents: {
  310. 'page-top-bar': '~@/components/common/page-top-bar',
  311. },
  312. }
  313. </config>