index.vue 11 KB

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