index.vue 12 KB

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