index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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("addCart",item =>{
  93. this.addGoodToCart(item)
  94. })
  95. // 删除购物车的商品
  96. uni.$on("delCartGood",item => {
  97. this.delGoodFormCart(item)
  98. })
  99. // 更新购物车商品数量
  100. uni.$on("updateGoodsBuyQty",item=>{
  101. this.updateGoodsBuyQty(item)
  102. })
  103. // 查询用户信息
  104. uni.$on("getUserInfo",item=>{
  105. this.getUserInfo(item)
  106. })
  107. },
  108. onShow() {
  109. // 获取订单状态数据字典
  110. this.getCodeList('RUBBISH_TYPE','vuex_rubbishType')
  111. // 获取顶部轮播图
  112. this.getbannerList()
  113. // 获取经纬度
  114. this.getLocation()
  115. // 是否登录
  116. checkLogin().then(res => {
  117. console.log(res,'checkLogin')
  118. this.hasLogin = res.status == 200
  119. if(!this.hasLogin&&!this.$store.state.vuex_noLogin){
  120. uni.navigateTo({
  121. url:"/pages/login/login"
  122. })
  123. }
  124. })
  125. },
  126. methods: {
  127. // 获取用户信息
  128. getUserInfo(){
  129. getUserInfo().then(res => {
  130. if(res.status == 200){
  131. this.$u.vuex("vuex_userData",res.data)
  132. }
  133. })
  134. },
  135. // 获取数据字典
  136. getCodeList(code,key) {
  137. getLookUpDatas({
  138. type: code
  139. }).then(res => {
  140. if (res.status == 200) {
  141. this.$u.vuex(key, res.data)
  142. }
  143. })
  144. },
  145. // 获取经纬度
  146. getLocation() {
  147. const _this = this;
  148. uni.getLocation({
  149. type: 'wgs84',
  150. success: function(res) {
  151. _this.getStationList(res.longitude, res.latitude)
  152. },
  153. fail: function(error) {
  154. console.log(error)
  155. uni.showToast({ icon: 'none', title: '定位失败' })
  156. }
  157. });
  158. },
  159. // 获取网点列表
  160. getStationList(lng, lat) {
  161. stationList({ lng: lng, lat: lat }).then(res => {
  162. if (res.status == 200) {
  163. this.stationDataList = res.data
  164. } else {
  165. this.stationDataList = []
  166. }
  167. });
  168. },
  169. // 获取banner
  170. getbannerList(){
  171. bannerList({type:'banner',location:'HOME_TOP'}).then(res=>{
  172. if(res.status==200){
  173. this.imageTopList=res.data
  174. }
  175. })
  176. },
  177. // 点击banner
  178. clickBanner(index){
  179. let row = this.imageTopList[index]
  180. console.log(index,row)
  181. if(row.jumpType !== 'NONE'){
  182. uni.navigateTo({
  183. url: row.jumpUrl
  184. })
  185. }
  186. },
  187. // 查询购物车
  188. getCartList(){
  189. getCartList({}).then(res => {
  190. console.log(res)
  191. if(res.status == 200){
  192. this.$u.vuex('vuex_cartList', res.data)
  193. }
  194. })
  195. },
  196. // 添加购物车
  197. addGoodToCart(item){
  198. addGoodsToCart(item).then(res => {
  199. if(res.status == 200){
  200. uni.showToast({
  201. title:"商品添加成功",
  202. icon:"none"
  203. })
  204. // 刷新购物车
  205. this.getCartList()
  206. }
  207. })
  208. },
  209. // 删除购物车
  210. delGoodFormCart(ids){
  211. uni.showLoading({
  212. mask: true,
  213. title: "删除中..."
  214. })
  215. deleteGoodsFormCart({idList:ids}).then(res => {
  216. if(res.status == 200){
  217. uni.showToast({
  218. title:"商品删除成功",
  219. icon:"none"
  220. })
  221. // 刷新购物车
  222. this.getCartList()
  223. }
  224. uni.hideLoading()
  225. })
  226. },
  227. // 更新商品数量
  228. updateGoodsBuyQty(item){
  229. uni.showLoading({
  230. mask: true,
  231. title: "更新数量中..."
  232. })
  233. updateGoodsBuyQty(item).then(res => {
  234. uni.hideLoading()
  235. })
  236. },
  237. // 更多商品
  238. toGoods(clsId){
  239. uni.navigateTo({
  240. url:"/pages/goods/goods?id="+clsId
  241. })
  242. },
  243. // 去登录
  244. toLoginPage(){
  245. uni.navigateTo({
  246. url: '/pages/login/login'
  247. })
  248. },
  249. // 快速导航
  250. toPage(e){
  251. let path=[
  252. '/pages/userCenter/fenlei',
  253. '/pages/userCenter/zhinan',
  254. '/pages/userCenter/myCode/myCode',
  255. ''
  256. ]
  257. if(e>1){
  258. //判断是否登录
  259. if(this.hasLogin){
  260. if(path[e]!=''){
  261. uni.navigateTo({
  262. url: path[e]
  263. })
  264. }else{
  265. // 核销
  266. this.smHx()
  267. }
  268. }else{
  269. this.toLoginPage()
  270. }
  271. }else{
  272. uni.navigateTo({
  273. url: path[e]
  274. })
  275. }
  276. },
  277. // 扫码核销
  278. smHx(){
  279. const _this = this
  280. uni.scanCode({
  281. success(e) {
  282. console.log(e)
  283. // 普通二维码,用户扫箱体的二维码开箱
  284. if(e.scanType == 'QR_CODE'){
  285. _this.openDevice(e.result)
  286. }
  287. // 小程序码,用户核销
  288. if(e.scanType == 'WX_CODE'){
  289. let scene = e.path.split('?')[1]
  290. uni.navigateTo({
  291. url: '/pages/checkOut/checkOut?scene='+scene.split("=")[1]
  292. })
  293. }
  294. },
  295. fail(err) {
  296. console.log(err)
  297. }
  298. })
  299. },
  300. // 开箱
  301. openDevice(data){
  302. let params = parseQueryString(data)
  303. openDevice(params).then(res => {
  304. console.log(res)
  305. if(res.status == 200){
  306. // uni.showToast({
  307. // icon:"none",
  308. // title:"认证成功,请点击设备开启按钮"
  309. // })
  310. }
  311. })
  312. },
  313. // 查看网点
  314. viewStore(item){
  315. uni.navigateTo({
  316. url: '/pages/store/store?id=' + item.id + '&stationNo=' + item.stationNo
  317. })
  318. }
  319. }
  320. }
  321. </script>
  322. <style lang="scss" scoped>
  323. .content {
  324. // background: url(../../static/topBg.png) no-repeat top center;
  325. // background-size: 100%;
  326. width: 100%;
  327. .nav {
  328. margin: 20upx 0;
  329. border-radius: 15upx;
  330. box-shadow: 0upx 3upx 6upx #eee;
  331. overflow: hidden;
  332. .grid-text {
  333. padding-top: 10upx;
  334. }
  335. }
  336. .storeList {
  337. padding: 25upx 0 20upx;
  338. .store-section {
  339. display: block;
  340. margin-bottom: 20rpx;
  341. }
  342. .stores-box {
  343. padding-top: 5upx;
  344. .stores-item {
  345. background: #ffffff;
  346. border-radius: 15upx;
  347. box-shadow: 0upx 3upx 6upx #eee;
  348. border-bottom: 1px solid #f8f8f8;
  349. padding: 10upx 20upx;
  350. margin-bottom: 20rpx;
  351. &:last-child {
  352. border: 0;
  353. }
  354. .item-con {
  355. display: flex;
  356. align-items: center;
  357. &:last-child {
  358. .item-main {
  359. border: none;
  360. }
  361. }
  362. .item-icon {
  363. width: 30rpx;
  364. height: 30rpx;
  365. margin-right: 10rpx;
  366. flex-shrink: 0;
  367. padding: 22rpx 0;
  368. }
  369. .item-main {
  370. font-size: 28rpx;
  371. color: #666;
  372. padding: 22rpx 0;
  373. border-bottom: 1rpx solid #f2f2f2;
  374. flex-grow: 1;
  375. }
  376. .s-name{
  377. font-size: 30rpx;
  378. color: #333;
  379. }
  380. .s-address {
  381. display: flex;
  382. align-items: center;
  383. justify-content: space-between;
  384. }
  385. }
  386. }
  387. }
  388. }
  389. }
  390. </style>