index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. // 开启分享
  105. uni.showShareMenu({
  106. withShareTicket: true,
  107. menus: ['shareAppMessage', 'shareTimeline']
  108. })
  109. },
  110. onUnload() {
  111. },
  112. onShareAppMessage(res) {
  113. },
  114. onShareTimeline(res) {
  115. },
  116. onShow() {
  117. checkLogin().then(res => {
  118. this.hasLogin = res.status == 200
  119. if(this.hasLogin){
  120. this.pageInit()
  121. } else {
  122. this.noDataText = '您尚未登录或登录已过期,完成登录后可查看录入信息!'
  123. }
  124. })
  125. },
  126. methods: {
  127. pageInit() {
  128. this.pageNo = 1
  129. this.pageSize = 10
  130. this.total = 0
  131. this.scrollTop = 0
  132. this.otherTotal= 0 // 其它垃圾总和
  133. this.jianzhuTotal= 0 // 建筑垃圾总和
  134. this.chuyuTotal= 0 // 厨余垃圾总和
  135. this.searchForm.beginDate = getDate.getRecentday().starttime
  136. this.searchForm.endDate = getDate.getRecentday().endtime
  137. console.log(this.searchForm,'this.searchForm')
  138. this.searchHandle()
  139. this.getTotal()
  140. },
  141. // 打开查询弹窗
  142. openSearch(){
  143. if(this.hasLogin){
  144. this.openScreen = true
  145. }
  146. },
  147. // 获取查询参数 刷新列表
  148. refresh(params){
  149. this.searchForm = params
  150. this.listdata = []
  151. this.total = 0
  152. this.searchHandle(1)
  153. this.getTotal()
  154. },
  155. // 搜索查询
  156. searchHandle (pageNo) {
  157. this.status = "loading"
  158. pageNo ? this.pageNo = pageNo : null
  159. gatherList({
  160. pageNo: this.pageNo,
  161. pageSize: this.pageSize,
  162. beginDate: this.searchForm.beginDate?moment(this.searchForm.beginDate).format('YYYY-MM-DD 00:00:00'):'',
  163. endDate: this.searchForm.endDate ? moment(this.searchForm.endDate).format('YYYY-MM-DD 23:59:59'):'',
  164. }).then(res => {
  165. if (res.status == 200) {
  166. if(this.pageNo>1){
  167. this.listdata = this.listdata.concat(res.data.list || [])
  168. }else{
  169. this.listdata = res.data.list || []
  170. this.scrollTop = 0
  171. }
  172. this.total = res.data.count || 0
  173. this.noDataText = '暂无数据'
  174. } else {
  175. this.noDataText = res.message
  176. this.listdata = []
  177. this.total = 0
  178. }
  179. this.status = "loadmore"
  180. })
  181. },
  182. // scroll-view到底部加载更多
  183. onreachBottom() {
  184. console.log(111111)
  185. if(this.listdata.length < this.total){
  186. this.pageNo += 1
  187. this.searchHandle()
  188. }else{
  189. uni.showToast({ title: '已经到底了', icon: 'none' })
  190. this.status = "nomore"
  191. }
  192. },
  193. // 总计
  194. getTotal(){
  195. this.titleStatus = true
  196. gatherTotal({
  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'):''}).then(res=>{
  199. if(res.status==200){
  200. const a = res.data.find(item=>item.rubbishType=='GATHER_BUILDING')
  201. const b = res.data.find(item=>item.rubbishType=='GATHER_OTHER')
  202. const c = res.data.find(item=>item.rubbishType=='GATHER_KITCHEN')
  203. this.jianzhuTotal= a ? (a.rubbishWeight/1000).toFixed(3)/1 : '0'
  204. this.chuyuTotal= c ? (c.rubbishWeight/1000).toFixed(3)/1 : '0'
  205. this.otherTotal= b ? (b.rubbishWeight/1000).toFixed(3)/1 : '0'
  206. }
  207. console.log(res)
  208. this.titleStatus = false
  209. })
  210. },
  211. // 打开垃圾数据录入页面
  212. intoPage(item) {
  213. const flag=item ? item.gatherId : ''
  214. console.log(flag,'---------hangid,;;;;')
  215. let url = flag ? `/pages/index/addData?id=${flag}` : `/pages/index/addData`
  216. // uni.navigateTo({
  217. // url: url
  218. // })
  219. if(!this.hasLogin){
  220. uni.showModal({
  221. title: '提示',
  222. content: '您尚未登录或登录已过期,请登录后使用',
  223. success: (res)=> {
  224. if (res.confirm) {
  225. uni.navigateTo({
  226. url: '/pages/login/login'
  227. })
  228. } else if (res.cancel) {
  229. console.log('用户点击取消');
  230. }
  231. }
  232. });
  233. } else {
  234. uni.navigateTo({
  235. url: url
  236. })
  237. }
  238. }
  239. }
  240. }
  241. </script>
  242. <style lang="scss" scoped>
  243. .content {
  244. width: 100%;
  245. height: 100vh;
  246. display: flex;
  247. flex-direction: column;
  248. justify-content: center;
  249. align-items: center;
  250. .header{
  251. width: 100%;
  252. background-color: #FFFFFF;
  253. display: flex;
  254. flex-direction: column;
  255. border-radius: 15upx;
  256. padding: 30upx;
  257. box-shadow: 0upx 3upx 6upx #eee;
  258. margin-bottom: 20upx;
  259. :first-child {
  260. display: flex;
  261. justify-content: space-between;
  262. align-items: center;
  263. }
  264. .header-cont{
  265. margin-top: 20upx;
  266. display: flex;
  267. align-items: center;
  268. justify-content: space-around;
  269. .cont-item{
  270. display: flex;
  271. flex-direction: column;
  272. align-items: center;
  273. text{
  274. line-height: 50upx;
  275. }
  276. text:last-child{
  277. font-weight: 600;
  278. font-size: 28upx;
  279. }
  280. }
  281. .other{
  282. color: #FB1E1E;
  283. }
  284. .chuyu{
  285. color: #FCAE53;
  286. }
  287. .jianzhu{
  288. color: #4EACFA;
  289. }
  290. }
  291. .filter-img{
  292. padding: 10upx;
  293. }
  294. }
  295. .scroll-con{
  296. flex: 1;
  297. width: 100%;
  298. -webkit-box-flex:1;
  299. -webkit-flex:1;
  300. -ms-flex:1;
  301. overflow: auto;
  302. .cell-item{
  303. width: 100%;
  304. background-color: #fff;
  305. border-radius: 15upx;
  306. // padding: 20upx;
  307. box-shadow: 0upx 3upx 6upx #eee;
  308. .cell-item-title{
  309. padding: 20upx 20upx 10upx;
  310. width: 100%;
  311. display: flex;
  312. justify-content: space-between;
  313. // border-bottom: 1px solid #e6e6e6;
  314. .view{
  315. color: #999999;
  316. margin-right: 12upx;
  317. }
  318. }
  319. .cell-item-cont{
  320. width: 100%;
  321. display: flex;
  322. justify-content: space-between;
  323. padding: 20upx;
  324. margin-bottom: 20upx;
  325. .cont-item{
  326. display: flex;
  327. flex-direction: column;
  328. align-items: center;
  329. width: 33%;
  330. // border-right: 1px solid #e6e6e6;
  331. :first-child {
  332. width: 120upx;
  333. height: 120upx;
  334. margin-bottom: 20upx;
  335. }
  336. }
  337. :last-child {
  338. border: none;
  339. }
  340. }
  341. }
  342. }
  343. .footer{
  344. z-index: 9999;
  345. // position: absolute;
  346. // bottom: 30upx;
  347. // margin: 20upx;
  348. width: 95%;
  349. height: 80upx;
  350. background-color: #0DC55F;
  351. opacity: 1;
  352. border-radius: 50upx;
  353. color: #fff;
  354. font-size: 30rpx;
  355. display: flex;
  356. align-items: center;
  357. justify-content: center;
  358. }
  359. }
  360. </style>