index.vue 12 KB

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