index.vue 13 KB

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