index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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. if(row.jumpUrl.indexOf('pagesA/luckDraw') >= 0){
  272. uni.navigateTo({
  273. url:this.hasLogin ? row.jumpUrl :"/pages/login/login"
  274. })
  275. }else{
  276. uni.navigateTo({
  277. url: row.jumpUrl
  278. })
  279. }
  280. }
  281. },
  282. // 查询购物车
  283. getCartList(){
  284. getCartList({}).then(res => {
  285. if(res.status == 200){
  286. this.$u.vuex('vuex_cartList', res.data)
  287. this.getCarCount()
  288. }
  289. uni.hideLoading()
  290. })
  291. },
  292. // 计算购物车数量
  293. getCarCount(){
  294. let arr = this.$store.state.vuex_cartList || []
  295. let count = 0
  296. arr.map(item=>{
  297. count = count + item.shoppingCartGoodsList.length
  298. })
  299. this.$u.vuex('vuex_cartNums', count)
  300. },
  301. // 更多商品
  302. toGoods(clsId){
  303. uni.navigateTo({
  304. url:"/pages/goods/goods?id="+clsId
  305. })
  306. },
  307. // 去登录
  308. toLoginPage(){
  309. uni.navigateTo({
  310. url: '/pages/login/login'
  311. })
  312. },
  313. // 快速导航
  314. toPage(e){
  315. let path=[
  316. '/pages/userCenter/fenlei',
  317. '/pages/userCenter/zhinan',
  318. '/pages/userCenter/myCode/myCode',
  319. ''
  320. ]
  321. if(e>1){
  322. //判断是否登录
  323. if(this.hasLogin){
  324. if(path[e]!=''){
  325. uni.navigateTo({
  326. url: path[e]
  327. })
  328. }else{
  329. // 核销
  330. this.smHx()
  331. }
  332. }else{
  333. this.toLoginPage()
  334. }
  335. }else{
  336. uni.navigateTo({
  337. url: path[e]
  338. })
  339. }
  340. },
  341. // 扫码核销
  342. smHx(){
  343. const _this = this
  344. uni.scanCode({
  345. success(e) {
  346. console.log(e)
  347. // 普通二维码,用户扫箱体的二维码开箱
  348. if(e.scanType == 'QR_CODE'){
  349. let params = parseQueryString(e.result)
  350. console.log(params)
  351. if(params.codeType == 'hexiao'){ // 扫商户码
  352. _this.getStoreData(params.officialPartnerNo)
  353. }else{ // 扫箱体码
  354. _this.openDevice(e.result)
  355. }
  356. }
  357. // 小程序码,用户核销
  358. // if(e.scanType == 'WX_CODE'){
  359. // let scene = e.path.split('?')[1]
  360. // uni.navigateTo({
  361. // url: '/pages/checkOut/checkOut?scene='+scene.split("=")[1]
  362. // })
  363. // }
  364. },
  365. fail(err) {
  366. console.log(err)
  367. }
  368. })
  369. },
  370. // 扫商户码,获取商户信息
  371. getStoreData(params) {
  372. let userData = this.$store.state.vuex_userData
  373. if(userData.customerRole == 9){
  374. uni.showToast({
  375. icon:"none",
  376. title:"抱歉,您目前无法使用乐豆"
  377. })
  378. }else{
  379. sellerFindByPartnerNo({officialPartnerNo: params}).then(res => {
  380. if(res.status == 200){
  381. let store = res.data
  382. uni.navigateTo({
  383. url: '/pages/checkOut/checkOut?store='+encodeURIComponent(JSON.stringify(store))
  384. })
  385. }
  386. })
  387. }
  388. },
  389. // 开箱
  390. openDevice(data){
  391. let params = parseQueryString(data)
  392. openDevice(params).then(res => {
  393. console.log(res)
  394. if(res.status == 200){
  395. // uni.showToast({
  396. // icon:"none",
  397. // title:"认证成功,请点击设备开启按钮"
  398. // })
  399. }
  400. })
  401. },
  402. // 查看网点
  403. viewStore(item){
  404. uni.navigateTo({
  405. url: '/pages/store/store?id=' + item.id + '&stationNo=' + item.stationNo
  406. })
  407. },
  408. // 去抽奖
  409. toLuckDraw(){
  410. uni.navigateTo({
  411. url: '/pagesA/luckDraw/luckDraw'
  412. })
  413. }
  414. }
  415. }
  416. </script>
  417. <style lang="scss" scoped>
  418. .content {
  419. // background: url(../../static/topBg.png) no-repeat top center;
  420. // background-size: 100%;
  421. width: 100%;
  422. .nav {
  423. margin: 20upx 0;
  424. border-radius: 15upx;
  425. box-shadow: 0upx 3upx 6upx #eee;
  426. overflow: hidden;
  427. .grid-text {
  428. padding-top: 10upx;
  429. }
  430. }
  431. .luckwheel-fixed{
  432. position: fixed;
  433. right: 50rpx;
  434. bottom: 20%;
  435. }
  436. .lottery-content{
  437. display: flex;
  438. align-items: center;
  439. justify-content: center;
  440. height: 100%;
  441. > view{
  442. width: 495rpx;
  443. height: 466rpx;
  444. position: relative;
  445. .close-btn{
  446. position: absolute;
  447. right: 32rpx;
  448. top: 0 ;
  449. }
  450. .bg{
  451. position: absolute;
  452. left: 0;
  453. top: 0 ;
  454. }
  455. }
  456. }
  457. .storeList {
  458. padding: 25upx 0 20upx;
  459. .store-section {
  460. display: block;
  461. margin-bottom: 20rpx;
  462. }
  463. .stores-box {
  464. padding-top: 5upx;
  465. .stores-item {
  466. background: #ffffff;
  467. border-radius: 15upx;
  468. box-shadow: 0upx 3upx 6upx #eee;
  469. border-bottom: 1px solid #f8f8f8;
  470. padding: 10upx 20upx;
  471. margin-bottom: 20rpx;
  472. &:last-child {
  473. border: 0;
  474. }
  475. .item-con {
  476. display: flex;
  477. align-items: center;
  478. &:last-child {
  479. .item-main {
  480. border: none;
  481. }
  482. }
  483. .item-icon {
  484. width: 30rpx;
  485. height: 30rpx;
  486. margin-right: 10rpx;
  487. flex-shrink: 0;
  488. padding: 22rpx 0;
  489. }
  490. .item-main {
  491. font-size: 28rpx;
  492. color: #666;
  493. padding: 22rpx 0;
  494. border-bottom: 1rpx solid #f2f2f2;
  495. flex-grow: 1;
  496. }
  497. .s-name{
  498. font-size: 30rpx;
  499. color: #333;
  500. }
  501. .s-address {
  502. display: flex;
  503. align-items: center;
  504. justify-content: space-between;
  505. >view{
  506. &:last-child{
  507. width: 30%;
  508. display: flex;
  509. align-items: center;
  510. justify-content: flex-end;
  511. }
  512. }
  513. }
  514. }
  515. }
  516. }
  517. }
  518. }
  519. </style>