index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <view class="content">
  3. <u-swiper height="250" @click="clickBanner" :list="imageTopList"></u-swiper>
  4. <!-- 导航按钮 -->
  5. <view class="nav">
  6. <u-grid :col="4" :border="false" @click="toPage">
  7. <u-grid-item :index="0">
  8. <u-image width="90rpx" height="90rpx" src="/static/zhinan.png"></u-image>
  9. <view class="grid-text">回收分类</view>
  10. </u-grid-item>
  11. <u-grid-item :index="1">
  12. <u-image width="90rpx" height="90rpx" src="/static/liucheng.png"></u-image>
  13. <view class="grid-text">使用指南</view>
  14. </u-grid-item>
  15. <u-grid-item :index="2">
  16. <u-image width="90rpx" height="90rpx" src="/static/shouyi.png"></u-image>
  17. <view class="grid-text">我的投递码</view>
  18. </u-grid-item>
  19. <u-grid-item :index="3">
  20. <u-image width="90rpx" height="90rpx" src="/static/hexiao.png"></u-image>
  21. <view class="grid-text">扫一扫</view>
  22. </u-grid-item>
  23. </u-grid>
  24. </view>
  25. <!-- 网点 -->
  26. <view class="storeList">
  27. <u-section title="附近的回收机" :right="false" line-color="#01c9b2" class="store-section"></u-section>
  28. <view class="stores-box">
  29. <view class="stores-item" v-for="item in stationDataList" @click="viewStore(item)">
  30. <view class="item-con">
  31. <image src="/static/md-icon.png" class="item-icon"></image>
  32. <view class="s-name item-main">{{ item.name }}</view>
  33. </view>
  34. <view class="item-con">
  35. <image src="/static/dz-icon.png" class="item-icon"></image>
  36. <view class="s-address item-main">
  37. <view>{{ item.provinceName }}{{ item.cityName }}{{ item.districtName }}{{ item.address }}</view>
  38. <view>
  39. <u-icon name="map-fill" color="#01c9b2" size="30"></u-icon>
  40. {{ item.distanct.distance ? (item.distanct.distance / 1000).toFixed(1) : 0 }}KM
  41. <u-icon name="arrow-right" color="#999" size="20"></u-icon>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="item-con">
  46. <image src="/static/time-icon.png" class="item-icon"></image>
  47. <view class="s-time item-main">
  48. <view>
  49. <text>营业时间:</text>
  50. <text v-for="(tItem, tInd) in item.deliveryTimeRuleItemList" :key="tInd">
  51. {{ tItem.openTime }} - {{ tItem.closeTime }}{{ tInd == item.deliveryTimeRuleItemList.length - 1 ? '' : ',' }}
  52. </text>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <view v-if="stationDataList.length==0">
  58. <u-empty icon-size="60" text="暂无数据" mode="list"></u-empty>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. import {
  66. getCartList,
  67. addGoodsToCart,
  68. deleteGoodsFormCart,
  69. updateGoodsBuyQty
  70. } from '@/api/shoppingCart.js'
  71. import {bannerList} from '@/api/banner.js'
  72. import {getLookUpDatas,openDevice} from '@/api/data.js'
  73. import {stationList} from '@/api/station.js'
  74. import {checkLogin,getUserInfo} from '@/api/login.js'
  75. import {parseQueryString} from '@/libs/tools.js'
  76. export default {
  77. data() {
  78. return {
  79. imageTopList: [],
  80. stationDataList: [] ,// 附近网点列表
  81. hasLogin: false
  82. }
  83. },
  84. onLoad() {
  85. // 查询购物车列表
  86. this.getCartList()
  87. // 刷新购物车列表
  88. uni.$on("getCartList",item =>{
  89. this.getCartList()
  90. })
  91. // 更新购物车数量
  92. uni.$on('getCarCount',item => {
  93. this.getCarCount()
  94. })
  95. // 查询用户信息
  96. uni.$on("getUserInfo",item=>{
  97. this.getUserInfo(item)
  98. })
  99. },
  100. onUnload() {
  101. console.log('onUnload')
  102. uni.$off('getCarCount')
  103. uni.$off('getCartList')
  104. uni.$off('getUserInfo')
  105. },
  106. onShow() {
  107. // 获取订单状态数据字典
  108. // this.getCodeList('RUBBISH_TYPE','vuex_rubbishType')
  109. // 获取顶部轮播图
  110. this.getbannerList()
  111. // 获取经纬度
  112. this.getLocation()
  113. // 是否登录
  114. checkLogin().then(res => {
  115. console.log(res,'checkLogin')
  116. this.hasLogin = res.status == 200
  117. if(!this.hasLogin&&!this.$store.state.vuex_noLogin){
  118. uni.navigateTo({
  119. url:"/pages/login/login"
  120. })
  121. }
  122. })
  123. },
  124. methods: {
  125. // 获取用户信息
  126. getUserInfo(){
  127. getUserInfo().then(res => {
  128. if(res.status == 200){
  129. this.$u.vuex("vuex_userData",res.data)
  130. }
  131. })
  132. },
  133. // 获取数据字典
  134. getCodeList(code,key) {
  135. getLookUpDatas({
  136. type: code
  137. }).then(res => {
  138. if (res.status == 200) {
  139. this.$u.vuex(key, res.data)
  140. }
  141. })
  142. },
  143. // 获取经纬度
  144. getLocation() {
  145. const _this = this;
  146. uni.getLocation({
  147. type: 'wgs84',
  148. success: function(res) {
  149. _this.getStationList(res.longitude, res.latitude)
  150. },
  151. fail: function(error) {
  152. console.log(error)
  153. uni.showToast({ icon: 'none', title: '定位失败' })
  154. }
  155. });
  156. },
  157. // 获取网点列表
  158. getStationList(lng, lat) {
  159. stationList({ lng: lng, lat: lat }).then(res => {
  160. if (res.status == 200) {
  161. this.stationDataList = res.data
  162. } else {
  163. this.stationDataList = []
  164. }
  165. });
  166. },
  167. // 获取banner
  168. getbannerList(){
  169. bannerList({type:'banner',location:'HOME_TOP'}).then(res=>{
  170. if(res.status==200){
  171. this.imageTopList=res.data
  172. }
  173. })
  174. },
  175. // 点击banner
  176. clickBanner(index){
  177. let row = this.imageTopList[index]
  178. console.log(index,row)
  179. if(row.jumpType !== 'NONE'){
  180. uni.navigateTo({
  181. url: row.jumpUrl
  182. })
  183. }
  184. },
  185. // 查询购物车
  186. getCartList(){
  187. getCartList({}).then(res => {
  188. if(res.status == 200){
  189. this.$u.vuex('vuex_cartList', res.data)
  190. this.getCarCount()
  191. }
  192. uni.hideLoading()
  193. })
  194. },
  195. // 计算购物车数量
  196. getCarCount(){
  197. let arr = this.$store.state.vuex_cartList || []
  198. let count = 0
  199. arr.map(item=>{
  200. count = count + item.shoppingCartGoodsList.length
  201. })
  202. this.$u.vuex('vuex_cartNums', count)
  203. },
  204. // 更多商品
  205. toGoods(clsId){
  206. uni.navigateTo({
  207. url:"/pages/goods/goods?id="+clsId
  208. })
  209. },
  210. // 去登录
  211. toLoginPage(){
  212. uni.navigateTo({
  213. url: '/pages/login/login'
  214. })
  215. },
  216. // 快速导航
  217. toPage(e){
  218. let path=[
  219. '/pages/userCenter/fenlei',
  220. '/pages/userCenter/zhinan',
  221. '/pages/userCenter/myCode/myCode',
  222. ''
  223. ]
  224. if(e>1){
  225. //判断是否登录
  226. if(this.hasLogin){
  227. if(path[e]!=''){
  228. uni.navigateTo({
  229. url: path[e]
  230. })
  231. }else{
  232. // 核销
  233. this.smHx()
  234. }
  235. }else{
  236. this.toLoginPage()
  237. }
  238. }else{
  239. uni.navigateTo({
  240. url: path[e]
  241. })
  242. }
  243. },
  244. // 扫码核销
  245. smHx(){
  246. const _this = this
  247. uni.scanCode({
  248. success(e) {
  249. console.log(e)
  250. // 普通二维码,用户扫箱体的二维码开箱
  251. if(e.scanType == 'QR_CODE'){
  252. let params = parseQueryString(e.result)
  253. if(params.codeType == 'hexiao'){ // 扫商户码
  254. uni.navigateTo({
  255. url: '/pages/checkOut/checkOut?scene='+params.officialPartnerNo
  256. })
  257. }else{ // 扫箱体码
  258. _this.openDevice(e.result)
  259. }
  260. }
  261. // 小程序码,用户核销
  262. // if(e.scanType == 'WX_CODE'){
  263. // let scene = e.path.split('?')[1]
  264. // uni.navigateTo({
  265. // url: '/pages/checkOut/checkOut?scene='+scene.split("=")[1]
  266. // })
  267. // }
  268. },
  269. fail(err) {
  270. console.log(err)
  271. }
  272. })
  273. },
  274. // 开箱
  275. openDevice(data){
  276. let params = parseQueryString(data)
  277. openDevice(params).then(res => {
  278. console.log(res)
  279. if(res.status == 200){
  280. // uni.showToast({
  281. // icon:"none",
  282. // title:"认证成功,请点击设备开启按钮"
  283. // })
  284. }
  285. })
  286. },
  287. // 查看网点
  288. viewStore(item){
  289. uni.navigateTo({
  290. url: '/pages/store/store?id=' + item.id + '&stationNo=' + item.stationNo
  291. })
  292. }
  293. }
  294. }
  295. </script>
  296. <style lang="scss" scoped>
  297. .content {
  298. // background: url(../../static/topBg.png) no-repeat top center;
  299. // background-size: 100%;
  300. width: 100%;
  301. .nav {
  302. margin: 20upx 0;
  303. border-radius: 15upx;
  304. box-shadow: 0upx 3upx 6upx #eee;
  305. overflow: hidden;
  306. .grid-text {
  307. padding-top: 10upx;
  308. }
  309. }
  310. .storeList {
  311. padding: 25upx 0 20upx;
  312. .store-section {
  313. display: block;
  314. margin-bottom: 20rpx;
  315. }
  316. .stores-box {
  317. padding-top: 5upx;
  318. .stores-item {
  319. background: #ffffff;
  320. border-radius: 15upx;
  321. box-shadow: 0upx 3upx 6upx #eee;
  322. border-bottom: 1px solid #f8f8f8;
  323. padding: 10upx 20upx;
  324. margin-bottom: 20rpx;
  325. &:last-child {
  326. border: 0;
  327. }
  328. .item-con {
  329. display: flex;
  330. align-items: center;
  331. &:last-child {
  332. .item-main {
  333. border: none;
  334. }
  335. }
  336. .item-icon {
  337. width: 30rpx;
  338. height: 30rpx;
  339. margin-right: 10rpx;
  340. flex-shrink: 0;
  341. padding: 22rpx 0;
  342. }
  343. .item-main {
  344. font-size: 28rpx;
  345. color: #666;
  346. padding: 22rpx 0;
  347. border-bottom: 1rpx solid #f2f2f2;
  348. flex-grow: 1;
  349. }
  350. .s-name{
  351. font-size: 30rpx;
  352. color: #333;
  353. }
  354. .s-address {
  355. display: flex;
  356. align-items: center;
  357. justify-content: space-between;
  358. }
  359. }
  360. }
  361. }
  362. }
  363. }
  364. </style>