index.vue 9.7 KB

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