index.vue 11 KB

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