index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <view class="content">
  3. <view class="header">
  4. <view @click="openSearch">
  5. <text v-if="searchForm.beginDate">{{searchForm.beginDate}}至{{searchForm.endDate}}</text>
  6. <text v-else>全部</text>
  7. <!-- <u-icon name="arrow-right" color="#999999" size="28"></u-icon> -->
  8. <u-image v-if="hasLogin" @click="openScreen=true" class="filter-img" width="36rpx" height="36rpx" src="/static/filter.png"></u-image>
  9. </view>
  10. <!-- 总计 -->
  11. <view class="header-cont">
  12. <view class="cont-item">
  13. <u-loading :show="titleStatus"></u-loading>
  14. <text v-if="!titleStatus" class="other">{{huishouTotal}}</text>
  15. <text class="header-cont-item-title">可回收物(KG)</text>
  16. </view>
  17. <view class="cont-item">
  18. <u-loading :show="titleStatus"></u-loading>
  19. <text v-if="!titleStatus" class="other">{{harmTotal}}</text>
  20. <text class="header-cont-item-title">有害收物(KG)</text>
  21. </view>
  22. <view class="cont-item">
  23. <u-loading :show="titleStatus"></u-loading>
  24. <text v-if="!titleStatus" class="other">{{chuyuTotal}}</text>
  25. <text class="header-cont-item-title">厨余垃圾(L)</text>
  26. </view>
  27. <view class="cont-item">
  28. <u-loading :show="titleStatus"></u-loading>
  29. <text v-if="!titleStatus" class="other">{{otherTotal}}</text>
  30. <text class="header-cont-item-title">其它垃圾(L)</text>
  31. </view>
  32. <view class="cont-item">
  33. <text v-if="!titleStatus" class="other">{{jianzhuTotal}}</text>
  34. <text class="header-cont-item-title">建筑垃圾(KG)</text>
  35. </view>
  36. </view>
  37. </view>
  38. <scroll-view class="scroll-con" :scroll-top="scrollTop" scroll-y @scrolltolower="onreachBottom">
  39. <!-- 列表数据 -->
  40. <view class="cell-item" v-for="item in listdata">
  41. <view class="cell-item-title" >
  42. <view>
  43. <text>{{item.createDate}}</text>
  44. </view>
  45. <view @click="intoPage(item)">
  46. <span class="view">查看详情</span>
  47. <u-icon name="arrow-right" color="#999999" size="28"></u-icon>
  48. </view>
  49. </view>
  50. <view class="cell-item-cont">
  51. <!-- 可收回物 -->
  52. <view class="cont-item">
  53. <u-image src="/static/huishou.png" width="90" height="90"></u-image>
  54. <text class="item-title">可回收物</text>
  55. <text>{{item.gatherRecycling? (item.gatherRecycling/1000).toFixed(3)/1 :0}}KG</text>
  56. </view>
  57. <!-- 有害垃圾 -->
  58. <view class="cont-item">
  59. <u-image src="/static/youhai.png"></u-image>
  60. <text class="item-title">有害垃圾</text>
  61. <text>{{item.gatherHarm? (item.gatherHarm/1000).toFixed(3)/1 :0}}KG</text>
  62. </view>
  63. <!-- 厨余垃圾 -->
  64. <view class="cont-item">
  65. <u-image src="/static/chuyu.png"></u-image>
  66. <text class="item-title">厨余垃圾</text>
  67. <text>{{item.gatherKitchen ? (item.gatherKitchen/1000).toFixed(3)/1 :0}}L</text>
  68. </view>
  69. <!-- 其他垃圾 -->
  70. <view class="cont-item">
  71. <u-image src="/static/qita.png"></u-image>
  72. <text class="item-title">其他垃圾</text>
  73. <text>{{item.gatherOther? (item.gatherOther/1000).toFixed(3)/1 :0}}L</text>
  74. </view>
  75. <!-- 建筑垃圾 -->
  76. <view class="cont-item">
  77. <u-image src="/static/jianzhu.png"></u-image>
  78. <text class="item-title">建筑垃圾</text>
  79. <text>{{item.gatherBuilding ? (item.gatherBuilding/1000).toFixed(3)/1 :0}}KG</text>
  80. </view>
  81. </view>
  82. </view>
  83. <view class="nodata" v-if="listdata.length==0 && status!='loading'">
  84. <u-empty :text="noDataText" mode="list"></u-empty>
  85. </view>
  86. <view class="loadmore">
  87. <u-loadmore v-if="total>pageSize || status=='loading'" :status="status" />
  88. </view>
  89. </scroll-view>
  90. <view @click="intoPage()" class="footer">
  91. <!-- <u-icon name="edit-pen" size="30"></u-icon> -->
  92. <text>垃圾数据录入</text>
  93. </view>
  94. <!-- 筛选弹框 -->
  95. <search-modal v-if="openScreen" :visible="openScreen" :defaultParams="searchForm" @refresh="refresh" @close="openScreen=false"></search-modal>
  96. </view>
  97. </template>
  98. <script>
  99. import searchModal from './searchModal.vue'
  100. import {gatherList,gatherTotal} from '@/api/index.js'
  101. import { checkLogin } from '@/api/login.js'
  102. import moment from 'moment'
  103. import getDate from '@/libs/getDate.js'
  104. export default {
  105. components: { searchModal },
  106. data() {
  107. return {
  108. hasLogin: false, // 是否登录
  109. listdata: [], // 列表数据
  110. huishouTotal:0, // 可回收物总和
  111. harmTotal:0, // 有害垃圾物总和
  112. otherTotal: 0, // 其它垃圾总和
  113. jianzhuTotal: 0, // 建筑垃圾总和
  114. chuyuTotal: 0, // 厨余垃圾总和
  115. pageNo: 1, // 当前页码
  116. pageSize: 10, // 每页条数
  117. total: 0, // 数据总条数
  118. noDataText: '暂无数据', // 列表请求状态提示语
  119. status: 'loadmore', // 加载中状态
  120. titleStatus: false, // 顶部加载中状态
  121. openScreen: false, // 是否打开筛选
  122. searchForm: { // 查询条件
  123. beginDate: getDate.getRecentday().starttime, // 创建时间默认筛选近7天
  124. endDate: getDate.getRecentday().endtime, // 创建时间默认筛选近7天
  125. },
  126. scrollTop: 0, // 滚动条位置
  127. }
  128. },
  129. onLoad() {
  130. this.checkUpdate()
  131. // 开启分享
  132. uni.showShareMenu({
  133. withShareTicket: true,
  134. menus: ['shareAppMessage', 'shareTimeline']
  135. })
  136. },
  137. onUnload() {
  138. },
  139. onShareAppMessage(res) {
  140. },
  141. onShareTimeline(res) {
  142. },
  143. onShow() {
  144. checkLogin().then(res => {
  145. this.hasLogin = res.status == 200
  146. if(this.hasLogin){
  147. this.pageInit()
  148. } else {
  149. this.noDataText = '您尚未登录或登录已过期,完成登录后可查看录入信息!'
  150. }
  151. })
  152. },
  153. methods: {
  154. pageInit() {
  155. this.pageNo = 1
  156. this.pageSize = 10
  157. this.total = 0
  158. this.scrollTop = 0
  159. this.otherTotal= 0 // 其它垃圾总和
  160. this.jianzhuTotal= 0 // 建筑垃圾总和
  161. this.chuyuTotal= 0 // 厨余垃圾总和
  162. this.harmTotal= 0
  163. this.huishouTotal=0
  164. this.searchForm.beginDate = getDate.getRecentday().starttime
  165. this.searchForm.endDate = getDate.getRecentday().endtime
  166. console.log(this.searchForm,'this.searchForm')
  167. this.searchHandle()
  168. this.getTotal()
  169. },
  170. // 检查更新
  171. checkUpdate(){
  172. if (uni.canIUse('getUpdateManager')) {
  173. const updateManager = uni.getUpdateManager()
  174. updateManager.onCheckForUpdate(function (res) {
  175. console.log('onCheckForUpdate====', res)
  176. // 请求完新版本信息的回调
  177. if (res.hasUpdate) {
  178. console.log('res.hasUpdate====')
  179. updateManager.onUpdateReady(function () {
  180. uni.showModal({
  181. title: '更新提示',
  182. content: '新版本已经准备好,是否重启应用?',
  183. success: function (res) {
  184. console.log('success====', res)
  185. // res: {errMsg: "showModal: ok", cancel: false, confirm: true}
  186. if (res.confirm) {
  187. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  188. updateManager.applyUpdate()
  189. }
  190. }
  191. })
  192. })
  193. updateManager.onUpdateFailed(function () {
  194. // 新的版本下载失败
  195. uni.showModal({
  196. title: '已经有新版本了哟~',
  197. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  198. })
  199. })
  200. }
  201. })
  202. }
  203. },
  204. // 打开查询弹窗
  205. openSearch(){
  206. if(this.hasLogin){
  207. this.openScreen = true
  208. }
  209. },
  210. // 获取查询参数 刷新列表
  211. refresh(params){
  212. this.searchForm = params
  213. this.listdata = []
  214. this.total = 0
  215. this.searchHandle(1)
  216. this.getTotal()
  217. },
  218. // 搜索查询
  219. searchHandle (pageNo) {
  220. this.status = "loading"
  221. pageNo ? this.pageNo = pageNo : null
  222. gatherList({
  223. pageNo: this.pageNo,
  224. pageSize: this.pageSize,
  225. beginDate: this.searchForm.beginDate?moment(this.searchForm.beginDate).format('YYYY-MM-DD 00:00:00'):'',
  226. endDate: this.searchForm.endDate ? moment(this.searchForm.endDate).format('YYYY-MM-DD 23:59:59'):'',
  227. }).then(res => {
  228. if (res.status == 200) {
  229. if(this.pageNo>1){
  230. this.listdata = this.listdata.concat(res.data.list || [])
  231. }else{
  232. this.listdata = res.data.list || []
  233. this.scrollTop = 0
  234. }
  235. this.total = res.data.count || 0
  236. this.noDataText = '暂无数据'
  237. } else {
  238. this.noDataText = res.message
  239. this.listdata = []
  240. this.total = 0
  241. }
  242. this.status = "loadmore"
  243. })
  244. },
  245. // scroll-view到底部加载更多
  246. onreachBottom() {
  247. console.log(111111)
  248. if(this.listdata.length < this.total){
  249. this.pageNo += 1
  250. this.searchHandle()
  251. }else{
  252. uni.showToast({ title: '已经到底了', icon: 'none' })
  253. this.status = "nomore"
  254. }
  255. },
  256. // 总计
  257. getTotal(){
  258. this.titleStatus = true
  259. gatherTotal({
  260. beginDate: this.searchForm.beginDate?moment(this.searchForm.beginDate).format('YYYY-MM-DD 00:00:00'):'',
  261. endDate: this.searchForm.endDate ? moment(this.searchForm.endDate).format('YYYY-MM-DD 23:59:59'):''}).then(res=>{
  262. if(res.status==200){
  263. const a = res.data.find(item=>item.rubbishType=='GATHER_BUILDING')
  264. const b = res.data.find(item=>item.rubbishType=='GATHER_OTHER')
  265. const c = res.data.find(item=>item.rubbishType=='GATHER_KITCHEN')
  266. const d = res.data.find(item=>item.rubbishType=='GATHER_HARM')
  267. const e = res.data.find(item=>item.rubbishType=='GATHER_RECYCLING')
  268. this.jianzhuTotal= a ? (a.rubbishWeight/1000).toFixed(3)/1 : '0'
  269. this.chuyuTotal= c ? (c.rubbishWeight/1000).toFixed(3)/1 : '0'
  270. this.otherTotal= b ? (b.rubbishWeight/1000).toFixed(3)/1 : '0'
  271. this.harmTotal= d ? (d.rubbishWeight/1000).toFixed(3)/1 : '0'
  272. this.huishouTotal= e ? (e.rubbishWeight/1000).toFixed(3)/1 : '0'
  273. }
  274. console.log(res)
  275. this.titleStatus = false
  276. })
  277. },
  278. // 打开垃圾数据录入页面
  279. intoPage(item) {
  280. const flag=item ? item.gatherId : ''
  281. console.log(flag,'---------hangid,;;;;')
  282. let url = flag ? `/pages/index/addData?id=${flag}` : `/pages/index/addData`
  283. // uni.navigateTo({
  284. // url: url
  285. // })
  286. if(!this.hasLogin){
  287. uni.showModal({
  288. title: '提示',
  289. content: '您尚未登录或登录已过期,请登录后使用',
  290. success: (res)=> {
  291. if (res.confirm) {
  292. uni.navigateTo({
  293. url: '/pages/login/login'
  294. })
  295. } else if (res.cancel) {
  296. console.log('用户点击取消');
  297. }
  298. }
  299. });
  300. } else {
  301. uni.navigateTo({
  302. url: url
  303. })
  304. }
  305. }
  306. }
  307. }
  308. </script>
  309. <style lang="scss" scoped>
  310. .content {
  311. width: 100%;
  312. height: 100vh;
  313. display: flex;
  314. flex-direction: column;
  315. justify-content: center;
  316. align-items: center;
  317. .header{
  318. width: 100%;
  319. background: #456990;
  320. opacity: 1;
  321. border-radius: 12px;
  322. display: flex;
  323. flex-direction: column;
  324. padding: 20upx 30upx;
  325. color: #fff;
  326. margin-bottom: 20upx;
  327. :first-child {
  328. display: flex;
  329. justify-content: space-between;
  330. align-items: center;
  331. }
  332. .header-cont{
  333. margin-top: 20upx;
  334. display: flex;
  335. flex-direction: row;
  336. flex-wrap:wrap;
  337. align-items: center;
  338. // justify-content: space-around;
  339. .cont-item{
  340. display: flex;
  341. flex-direction: column;
  342. align-items: center;
  343. width: 33%;
  344. text{
  345. line-height: 50upx;
  346. }
  347. text:last-child{
  348. font-weight: 600;
  349. font-size: 28upx;
  350. }
  351. .header-cont-item-title{
  352. display: inline-block;
  353. margin-top: 10upx;
  354. }
  355. .item-title{
  356. font-family: PingFang SC;
  357. font-weight: 400;
  358. color: #444444;
  359. opacity: 1;
  360. }
  361. }
  362. .other{
  363. display: inline-block;
  364. margin: 30upx 0 10upx;
  365. font-size: 18px;
  366. font-weight: normal;
  367. color: #FFFFFF;
  368. opacity: 1;
  369. font-style: italic;
  370. }
  371. }
  372. .filter-img{
  373. padding: 10upx;
  374. }
  375. }
  376. .scroll-con{
  377. flex: 1;
  378. width: 100%;
  379. -webkit-box-flex:1;
  380. -webkit-flex:1;
  381. -ms-flex:1;
  382. overflow: auto;
  383. .cell-item{
  384. width: 100%;
  385. background-color: #fff;
  386. border-radius: 15upx;
  387. // padding: 20upx;
  388. box-shadow: 0upx 3upx 6upx #eee;
  389. .cell-item-title{
  390. padding: 20upx 20upx 10upx;
  391. width: 100%;
  392. display: flex;
  393. justify-content: space-between;
  394. // border-bottom: 1px solid #e6e6e6;
  395. .view{
  396. color: #999999;
  397. margin-right: 12upx;
  398. }
  399. }
  400. .cell-item-cont{
  401. width: 100%;
  402. display: flex;
  403. justify-content: space-between;
  404. padding: 20upx;
  405. margin-bottom: 20upx;
  406. .cont-item{
  407. display: flex;
  408. flex-direction: column;
  409. align-items: center;
  410. width: 33%;
  411. // border-right: 1px solid #e6e6e6;
  412. :first-child {
  413. width: 90upx;
  414. height: 90upx;
  415. margin-bottom: 20upx;
  416. }
  417. }
  418. :last-child {
  419. border: none;
  420. }
  421. }
  422. }
  423. }
  424. .footer{
  425. z-index: 9999;
  426. // position: absolute;
  427. // bottom: 30upx;
  428. // margin: 20upx;
  429. width: 95%;
  430. height: 80upx;
  431. background-color: #0DC55F;
  432. opacity: 1;
  433. border-radius: 50upx;
  434. color: #fff;
  435. font-size: 30rpx;
  436. display: flex;
  437. align-items: center;
  438. justify-content: center;
  439. }
  440. }
  441. </style>