index.vue 13 KB

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