index.vue 13 KB

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