index.vue 11 KB

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