index.vue 12 KB

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