index.vue 9.2 KB

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