index.vue 13 KB

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