index.vue 12 KB

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