index.vue 8.8 KB

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