index.vue 12 KB

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