index.vue 13 KB

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