index.vue 14 KB

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