index.vue 9.5 KB

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