index.vue 9.8 KB

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