index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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="3">
  8. <u-image width="90rpx" height="90rpx" src="/static/hexiao.png"></u-image>
  9. <view class="grid-text">投递/兑换</view>
  10. </u-grid-item>
  11. <u-grid-item :index="0">
  12. <u-image width="90rpx" height="90rpx" src="/static/zhinan.png"></u-image>
  13. <view class="grid-text">回收分类</view>
  14. </u-grid-item>
  15. <u-grid-item :index="1">
  16. <u-image width="90rpx" height="90rpx" src="/static/liucheng.png"></u-image>
  17. <view class="grid-text">使用指南</view>
  18. </u-grid-item>
  19. <u-grid-item :index="2">
  20. <u-image width="90rpx" height="90rpx" src="/static/shouyi.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" :key="item.id" @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. {{ getDistanct(item) }}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. <!-- 抽奖活动弹框 -->
  63. <u-mask :show="showLottery" @click="showLottery = false">
  64. <view class="lottery-content">
  65. <view>
  66. <view class="bg">
  67. <u-image src="/static/toLottery.png" width="495rpx" height="466rpx" @click="toLuckDraw"></u-image>
  68. </view>
  69. <view class="close-btn" @click="showLottery = false">
  70. <u-image src="/static/closeLottery.png" width="54rpx" height="163rpx"></u-image>
  71. </view>
  72. </view>
  73. </view>
  74. </u-mask>
  75. </view>
  76. </template>
  77. <script>
  78. import {
  79. getCartList,
  80. addGoodsToCart,
  81. deleteGoodsFormCart,
  82. updateGoodsBuyQty
  83. } from '@/api/shoppingCart.js'
  84. import {findEnable} from '@/api/luckyDraw.js'
  85. import {bannerList} from '@/api/banner.js'
  86. import {getLookUpDatas,openDevice} from '@/api/data.js'
  87. import {stationList} from '@/api/station.js'
  88. import {checkLogin,getUserInfo} from '@/api/login.js'
  89. import {parseQueryString} from '@/libs/tools.js'
  90. import {sellerFindByPartnerNo} from '@/api/user.js'
  91. export default {
  92. data() {
  93. return {
  94. imageTopList: [],
  95. stationDataList: [] ,// 附近网点列表
  96. hasLogin: false,
  97. userData: null,
  98. showLottery: false, // 是否显示抽奖弹框
  99. }
  100. },
  101. onLoad() {
  102. // 检查更新
  103. this.checkUpdate()
  104. // 查询购物车列表
  105. this.getCartList()
  106. // 刷新购物车列表
  107. uni.$on("getCartList",item =>{
  108. this.getCartList()
  109. })
  110. // 更新购物车数量
  111. uni.$on('getCarCount',item => {
  112. this.getCarCount()
  113. })
  114. // 查询用户信息
  115. uni.$on("getUserInfo",item=>{
  116. this.getUserInfo(item)
  117. })
  118. },
  119. onUnload() {
  120. console.log('onUnload')
  121. uni.$off('getCarCount')
  122. uni.$off('getCartList')
  123. uni.$off('getUserInfo')
  124. // 开启分享
  125. uni.showShareMenu({
  126. withShareTicket: true,
  127. menus: ['shareAppMessage', 'shareTimeline']
  128. })
  129. },
  130. onShareAppMessage(res) {
  131. console.log(res)
  132. },
  133. onShareTimeline(res) {
  134. console.log(res)
  135. },
  136. onShow() {
  137. // 获取订单状态数据字典
  138. // this.getCodeList('RUBBISH_TYPE','vuex_rubbishType')
  139. // 判断是否有抽奖活动
  140. this.getLuckDraw()
  141. // 获取顶部轮播图
  142. this.getbannerList()
  143. // 获取经纬度
  144. this.getLocation()
  145. // 是否登录
  146. checkLogin().then(res => {
  147. console.log(res,'checkLogin')
  148. this.hasLogin = res.status == 200
  149. if(!this.hasLogin&&!this.$store.state.vuex_noLogin){
  150. uni.navigateTo({
  151. url:"/pages/login/login"
  152. })
  153. }
  154. })
  155. },
  156. methods: {
  157. checkUpdate(){
  158. const updateManager = uni.getUpdateManager();
  159. updateManager.onCheckForUpdate(function (res) {
  160. // 请求完新版本信息的回调
  161. console.log(res.hasUpdate);
  162. });
  163. updateManager.onUpdateReady(function (res) {
  164. uni.showModal({
  165. title: '更新提示',
  166. content: '新版本已经准备好,是否重启应用?',
  167. success(res) {
  168. if (res.confirm) {
  169. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  170. updateManager.applyUpdate();
  171. }
  172. }
  173. });
  174. });
  175. updateManager.onUpdateFailed(function (res) {
  176. // 新的版本下载失败
  177. });
  178. },
  179. // 计算距离
  180. getDistanct(item){
  181. return item.distanct&&item.distanct.distance ? (item.distanct.distance / 1000).toFixed(1) : 0
  182. },
  183. // 抽奖弹框
  184. getLuckDraw(){
  185. findEnable().then(res => {
  186. if(res.status == 200 && res.data){
  187. this.$u.vuex('vuex_LuckDraw',res.data)
  188. this.showLottery = true
  189. }else{
  190. this.$u.vuex('vuex_LuckDraw',null)
  191. this.showLottery = false
  192. }
  193. })
  194. },
  195. // 获取用户信息
  196. getUserInfo(){
  197. getUserInfo().then(res => {
  198. console.log('getUserInfo',res.data)
  199. if(res.status == 200){
  200. this.$u.vuex("vuex_userData",res.data)
  201. }
  202. })
  203. },
  204. // 获取数据字典
  205. getCodeList(code,key) {
  206. getLookUpDatas({
  207. type: code
  208. }).then(res => {
  209. if (res.status == 200) {
  210. this.$u.vuex(key, res.data)
  211. }
  212. })
  213. },
  214. // 获取经纬度
  215. getLocation() {
  216. const _this = this;
  217. uni.getLocation({
  218. type: 'wgs84',
  219. success: function(res) {
  220. _this.getStationList(res.longitude, res.latitude)
  221. },
  222. fail: function(error) {
  223. console.log(error)
  224. uni.showToast({ icon: 'none', title: '定位失败' })
  225. }
  226. });
  227. },
  228. // 获取网点列表
  229. getStationList(lng, lat) {
  230. stationList({ lng: lng, lat: lat }).then(res => {
  231. if (res.status == 200) {
  232. this.stationDataList = res.data
  233. } else {
  234. this.stationDataList = []
  235. }
  236. });
  237. },
  238. // 获取banner
  239. getbannerList(){
  240. bannerList({type:'banner',location:'HOME_TOP'}).then(res=>{
  241. if(res.status==200){
  242. this.imageTopList=res.data
  243. }
  244. })
  245. },
  246. // 点击banner
  247. clickBanner(index){
  248. let row = this.imageTopList[index]
  249. console.log(index,row)
  250. if(row.jumpType !== 'NONE'){
  251. uni.navigateTo({
  252. url: row.jumpUrl
  253. })
  254. }
  255. },
  256. // 查询购物车
  257. getCartList(){
  258. getCartList({}).then(res => {
  259. if(res.status == 200){
  260. this.$u.vuex('vuex_cartList', res.data)
  261. this.getCarCount()
  262. }
  263. uni.hideLoading()
  264. })
  265. },
  266. // 计算购物车数量
  267. getCarCount(){
  268. let arr = this.$store.state.vuex_cartList || []
  269. let count = 0
  270. arr.map(item=>{
  271. count = count + item.shoppingCartGoodsList.length
  272. })
  273. this.$u.vuex('vuex_cartNums', count)
  274. },
  275. // 更多商品
  276. toGoods(clsId){
  277. uni.navigateTo({
  278. url:"/pages/goods/goods?id="+clsId
  279. })
  280. },
  281. // 去登录
  282. toLoginPage(){
  283. uni.navigateTo({
  284. url: '/pages/login/login'
  285. })
  286. },
  287. // 快速导航
  288. toPage(e){
  289. let path=[
  290. '/pages/userCenter/fenlei',
  291. '/pages/userCenter/zhinan',
  292. '/pages/userCenter/myCode/myCode',
  293. ''
  294. ]
  295. if(e>1){
  296. //判断是否登录
  297. if(this.hasLogin){
  298. if(path[e]!=''){
  299. uni.navigateTo({
  300. url: path[e]
  301. })
  302. }else{
  303. // 核销
  304. this.smHx()
  305. }
  306. }else{
  307. this.toLoginPage()
  308. }
  309. }else{
  310. uni.navigateTo({
  311. url: path[e]
  312. })
  313. }
  314. },
  315. // 扫码核销
  316. smHx(){
  317. const _this = this
  318. uni.scanCode({
  319. success(e) {
  320. console.log(e)
  321. // 普通二维码,用户扫箱体的二维码开箱
  322. if(e.scanType == 'QR_CODE'){
  323. let params = parseQueryString(e.result)
  324. console.log(params)
  325. if(params.codeType == 'hexiao'){ // 扫商户码
  326. _this.getStoreData(params.officialPartnerNo)
  327. }else{ // 扫箱体码
  328. _this.openDevice(e.result)
  329. }
  330. }
  331. // 小程序码,用户核销
  332. // if(e.scanType == 'WX_CODE'){
  333. // let scene = e.path.split('?')[1]
  334. // uni.navigateTo({
  335. // url: '/pages/checkOut/checkOut?scene='+scene.split("=")[1]
  336. // })
  337. // }
  338. },
  339. fail(err) {
  340. console.log(err)
  341. }
  342. })
  343. },
  344. // 扫商户码,获取商户信息
  345. getStoreData(params) {
  346. let userData = this.$store.state.vuex_userData
  347. if(userData.customerRole == 9){
  348. uni.showToast({
  349. icon:"none",
  350. title:"抱歉,您目前无法使用乐豆"
  351. })
  352. }else{
  353. sellerFindByPartnerNo({officialPartnerNo: params}).then(res => {
  354. if(res.status == 200){
  355. let store = res.data
  356. uni.navigateTo({
  357. url: '/pages/checkOut/checkOut?store='+encodeURIComponent(JSON.stringify(store))
  358. })
  359. }
  360. })
  361. }
  362. },
  363. // 开箱
  364. openDevice(data){
  365. let params = parseQueryString(data)
  366. openDevice(params).then(res => {
  367. console.log(res)
  368. if(res.status == 200){
  369. // uni.showToast({
  370. // icon:"none",
  371. // title:"认证成功,请点击设备开启按钮"
  372. // })
  373. }
  374. })
  375. },
  376. // 查看网点
  377. viewStore(item){
  378. uni.navigateTo({
  379. url: '/pages/store/store?id=' + item.id + '&stationNo=' + item.stationNo
  380. })
  381. },
  382. // 去抽奖
  383. toLuckDraw(){
  384. uni.navigateTo({
  385. url: '/pagesA/luckDraw/luckDraw'
  386. })
  387. }
  388. }
  389. }
  390. </script>
  391. <style lang="scss" scoped>
  392. .content {
  393. // background: url(../../static/topBg.png) no-repeat top center;
  394. // background-size: 100%;
  395. width: 100%;
  396. .nav {
  397. margin: 20upx 0;
  398. border-radius: 15upx;
  399. box-shadow: 0upx 3upx 6upx #eee;
  400. overflow: hidden;
  401. .grid-text {
  402. padding-top: 10upx;
  403. }
  404. }
  405. .lottery-content{
  406. display: flex;
  407. align-items: center;
  408. justify-content: center;
  409. height: 100%;
  410. > view{
  411. width: 495rpx;
  412. height: 466rpx;
  413. position: relative;
  414. .close-btn{
  415. position: absolute;
  416. right: 32rpx;
  417. top: 0 ;
  418. }
  419. .bg{
  420. position: absolute;
  421. left: 0;
  422. top: 0 ;
  423. }
  424. }
  425. }
  426. .storeList {
  427. padding: 25upx 0 20upx;
  428. .store-section {
  429. display: block;
  430. margin-bottom: 20rpx;
  431. }
  432. .stores-box {
  433. padding-top: 5upx;
  434. .stores-item {
  435. background: #ffffff;
  436. border-radius: 15upx;
  437. box-shadow: 0upx 3upx 6upx #eee;
  438. border-bottom: 1px solid #f8f8f8;
  439. padding: 10upx 20upx;
  440. margin-bottom: 20rpx;
  441. &:last-child {
  442. border: 0;
  443. }
  444. .item-con {
  445. display: flex;
  446. align-items: center;
  447. &:last-child {
  448. .item-main {
  449. border: none;
  450. }
  451. }
  452. .item-icon {
  453. width: 30rpx;
  454. height: 30rpx;
  455. margin-right: 10rpx;
  456. flex-shrink: 0;
  457. padding: 22rpx 0;
  458. }
  459. .item-main {
  460. font-size: 28rpx;
  461. color: #666;
  462. padding: 22rpx 0;
  463. border-bottom: 1rpx solid #f2f2f2;
  464. flex-grow: 1;
  465. }
  466. .s-name{
  467. font-size: 30rpx;
  468. color: #333;
  469. }
  470. .s-address {
  471. display: flex;
  472. align-items: center;
  473. justify-content: space-between;
  474. >view{
  475. &:last-child{
  476. width: 30%;
  477. display: flex;
  478. align-items: center;
  479. justify-content: flex-end;
  480. }
  481. }
  482. }
  483. }
  484. }
  485. }
  486. }
  487. }
  488. </style>