index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <view class="content">
  3. <u-swiper height="320" :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. 营业时间:
  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>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import {
  63. getCartList,
  64. addGoodsToCart,
  65. deleteGoodsFormCart,
  66. updateGoodsBuyQty
  67. } from '@/api/shoppingCart.js'
  68. import {bannerList} from '@/api/banner.js'
  69. import {getLookUpDatas} from '@/api/data.js'
  70. import {stationList} from '@/api/station.js'
  71. import { checkLogin } from '@/api/login.js'
  72. export default {
  73. data() {
  74. return {
  75. imageTopList: [],
  76. stationDataList: [] ,// 附近网点列表
  77. hasLogin: false
  78. }
  79. },
  80. onLoad() {
  81. // 是否登录
  82. checkLogin().then(res => {
  83. console.log(res,'checkLogin')
  84. this.hasLogin = res.status == 200
  85. if(!this.hasLogin){
  86. this.toLoginPage()
  87. }
  88. })
  89. // 获取订单状态数据字典
  90. this.getCodeList('RUBBISH_TYPE','vuex_rubbishType')
  91. // 获取顶部轮播图
  92. this.getbannerList()
  93. // 获取经纬度
  94. this.getLocation()
  95. // 查询购物车列表
  96. this.getCartList()
  97. // 加入购物车
  98. uni.$on("addCart",item =>{
  99. this.addGoodToCart(item)
  100. })
  101. // 删除购物车的商品
  102. uni.$on("delCartGood",item => {
  103. this.delGoodFormCart(item)
  104. })
  105. // 更新购物车商品数量
  106. uni.$on("updateGoodsBuyQty",item=>{
  107. this.updateGoodsBuyQty(item)
  108. })
  109. },
  110. onShow() {
  111. },
  112. methods: {
  113. // 获取数据字典
  114. getCodeList(code,key) {
  115. getLookUpDatas({
  116. type: code
  117. }).then(res => {
  118. if (res.status == 200) {
  119. this.$u.vuex(key, res.data)
  120. }
  121. })
  122. },
  123. // 获取经纬度
  124. getLocation() {
  125. const _this = this;
  126. uni.getLocation({
  127. type: 'wgs84',
  128. success: function(res) {
  129. _this.getStationList(res.longitude, res.latitude)
  130. },
  131. fail: function(error) {
  132. console.log(error)
  133. uni.showToast({ icon: 'none', title: '定位失败' })
  134. }
  135. });
  136. },
  137. // 获取网点列表
  138. getStationList(lng, lat) {
  139. stationList({ lng: lng, lat: lat }).then(res => {
  140. if (res.status == 200) {
  141. this.stationDataList = res.data
  142. } else {
  143. this.stationDataList = []
  144. }
  145. });
  146. },
  147. // 获取banner
  148. getbannerList(){
  149. bannerList({type:'banner',location:'HOME_TOP'}).then(res=>{
  150. if(res.status==200){
  151. this.imageTopList=res.data
  152. }
  153. })
  154. },
  155. // 查询购物车
  156. getCartList(){
  157. getCartList({}).then(res => {
  158. console.log(res)
  159. if(res.status == 200){
  160. this.$u.vuex('vuex_cartList', res.data)
  161. }
  162. })
  163. },
  164. // 添加购物车
  165. addGoodToCart(item){
  166. addGoodsToCart(item).then(res => {
  167. if(res.status == 200){
  168. uni.showToast({
  169. title:"商品添加成功",
  170. icon:"none"
  171. })
  172. // 刷新购物车
  173. this.getCartList()
  174. }
  175. })
  176. },
  177. // 删除购物车
  178. delGoodFormCart(ids){
  179. uni.showLoading({
  180. mask: true,
  181. title: "删除中..."
  182. })
  183. deleteGoodsFormCart({idList:ids}).then(res => {
  184. if(res.status == 200){
  185. uni.showToast({
  186. title:"商品删除成功",
  187. icon:"none"
  188. })
  189. // 刷新购物车
  190. this.getCartList()
  191. }
  192. uni.hideLoading()
  193. })
  194. },
  195. // 更新商品数量
  196. updateGoodsBuyQty(item){
  197. uni.showLoading({
  198. mask: true,
  199. title: "更新数量中..."
  200. })
  201. updateGoodsBuyQty(item).then(res => {
  202. uni.hideLoading()
  203. })
  204. },
  205. // 更多商品
  206. toGoods(clsId){
  207. uni.navigateTo({
  208. url:"/pages/goods/goods?id="+clsId
  209. })
  210. },
  211. // 去登录
  212. toLoginPage(){
  213. uni.navigateTo({
  214. url: '/pages/login/login'
  215. })
  216. },
  217. // 快速导航
  218. toPage(e){
  219. let path=[
  220. '/pages/userCenter/zhinan',
  221. '/pages/userCenter/liucheng',
  222. '/pages/userCenter/ldDetailed',
  223. ''
  224. ]
  225. if(e>1){
  226. //判断是否登录
  227. if(this.hasLogin){
  228. if(path[e]!=''){
  229. uni.navigateTo({
  230. url: path[e]
  231. })
  232. }else{
  233. // 核销
  234. this.smHx()
  235. }
  236. }else{
  237. this.toLoginPage()
  238. }
  239. }else{
  240. uni.navigateTo({
  241. url: path[e]
  242. })
  243. }
  244. },
  245. // 扫码核销
  246. smHx(){
  247. uni.navigateTo({
  248. url: '/pages/checkOut/checkOut'
  249. })
  250. return
  251. uni.scanCode({
  252. success(e) {
  253. console.log(e)
  254. },
  255. fail(err) {
  256. console.log(err)
  257. }
  258. })
  259. },
  260. // 查看网点
  261. viewStore(item){
  262. uni.navigateTo({
  263. url: '/pages/store/store?id=' + item.id + '&stationNo=' + item.stationNo
  264. })
  265. }
  266. }
  267. }
  268. </script>
  269. <style lang="scss" scoped>
  270. .content {
  271. // background: url(../../static/topBg.png) no-repeat top center;
  272. // background-size: 100%;
  273. width: 100%;
  274. .nav {
  275. margin: 20upx 0;
  276. border-radius: 15upx;
  277. box-shadow: 0upx 3upx 6upx #eee;
  278. overflow: hidden;
  279. .grid-text {
  280. padding-top: 10upx;
  281. }
  282. }
  283. .storeList {
  284. padding: 25upx 20upx 20upx;
  285. .store-section {
  286. display: block;
  287. margin-bottom: 20rpx;
  288. }
  289. .stores-box {
  290. padding-top: 5upx;
  291. .stores-item {
  292. background: #ffffff;
  293. border-radius: 15upx;
  294. box-shadow: 0upx 3upx 6upx #eee;
  295. border-bottom: 1px solid #f8f8f8;
  296. padding: 10upx 20upx;
  297. margin-bottom: 20rpx;
  298. &:last-child {
  299. border: 0;
  300. }
  301. .item-con {
  302. display: flex;
  303. &:last-child {
  304. .item-main {
  305. border: none;
  306. }
  307. }
  308. .item-icon {
  309. width: 34rpx;
  310. height: 34rpx;
  311. margin-right: 10rpx;
  312. flex-shrink: 0;
  313. padding: 18rpx 0;
  314. }
  315. .item-main {
  316. font-size: 24rpx;
  317. color: #666;
  318. padding: 18rpx 0;
  319. border-bottom: 1rpx solid #f2f2f2;
  320. flex-grow: 1;
  321. }
  322. .s-address {
  323. display: flex;
  324. align-items: center;
  325. justify-content: space-between;
  326. }
  327. }
  328. }
  329. }
  330. }
  331. }
  332. </style>