index.vue 8.9 KB

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