index.vue 8.3 KB

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