index.vue 10 KB

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