宜轩到家/服务到家第三版,换个颜色
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

533 lines
12 KiB

9 months ago
  1. <template>
  2. <view class="home">
  3. <!-- <view class="home-top"> -->
  4. <!-- <view class="search">
  5. <view @click="showSelectArea" class="left-area">
  6. <image src="@/static/home/address-icon.png"></image>
  7. <view class="area">{{ area }}</view>
  8. <image src="../../static/home/arrow-icon.png" mode="aspectFit"></image>
  9. <view class="parting-line">|</view>
  10. </view>
  11. <view class="center-area">
  12. <image src="@/static/home/search-icon.png"></image>
  13. <van-field @click="searchAddress" v-model="queryParams.title" center placeholder="请选择地区" />
  14. </view>
  15. <view class="right-area">
  16. <view @click="searchAddress" class="search-button">
  17. 搜索
  18. </view>
  19. </view>
  20. </view> -->
  21. <!-- </view> -->
  22. <view class="banner b-relative">
  23. <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
  24. <van-swipe-item v-for="item in bannerList" :key="item.id">
  25. <image class="banner-image" :src="item.image" mode="widthFix"></image>
  26. </van-swipe-item>
  27. </van-swipe>
  28. </view>
  29. <view class="home-content">
  30. <!-- <view class="banner b-relative">
  31. <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
  32. <van-swipe-item v-for="item in bannerList" :key="item.id">
  33. <image class="banner-image" :src="item.image" mode="widthFix"></image>
  34. </van-swipe-item>
  35. </van-swipe>
  36. </view> -->
  37. <view class="search">
  38. <view @click="showSelectArea" class="left-area">
  39. <image src="@/static/home/address-icon.png"></image>
  40. <view class="area">{{ area }}</view>
  41. <image src="../../static/home/arrow-icon.png" mode="aspectFit"></image>
  42. <view class="parting-line">|</view>
  43. </view>
  44. <view class="center-area">
  45. <image src="@/static/home/search-icon.png"></image>
  46. <van-field @click="searchAddress" v-model="queryParams.title" center placeholder="请选择地区" />
  47. </view>
  48. <view class="right-area">
  49. <view @click="searchAddress" class="search-button">
  50. 搜索
  51. </view>
  52. </view>
  53. </view>
  54. <view v-if="projectList.length > 0" class="server-list">
  55. <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" ref="list"
  56. @load="onLoad">
  57. <view v-for="item in projectList" class="server-item" @click="toServiceDetail(item.id)">
  58. <view class="img-box">
  59. <image :src="item.image" mode="aspectFill"></image>
  60. </view>
  61. <view class="server-info">
  62. <view class="server-title">{{ item.title }}</view>
  63. <view class="time-coupon">
  64. <image src="@/static/home/time-icon.png"></image>
  65. <view class="time">{{ item.times }}分钟</view>
  66. <!-- <view class="coupon">{{ item.subTitle }}</view> -->
  67. </view>
  68. <view class="price">
  69. <view class="current-price">
  70. <text class="unit"></text>{{ item.price }}
  71. </view>
  72. <view class="original-price">
  73. <text class="unit"></text>{{ item.oldPrice }}
  74. </view>
  75. </view>
  76. <view class="sales-volume">
  77. <image src="@/static/icons/icon1.png"></image>
  78. <view class="desc">已售出{{ item.payNum }}+</view>
  79. </view>
  80. </view>
  81. <view class="selective-technician">
  82. <view @click.stop="selectTechnician(item.id)" class="btn">
  83. 选择技师
  84. </view>
  85. </view>
  86. </view>
  87. </van-list>
  88. </view>
  89. <van-empty v-else image="/static/empty/data.png" image-size="400rpx" description="暂无项目" />
  90. </view>
  91. <selectArea :show="showAeraPro" @close="closeAreaPro" @select="selectArea"></selectArea>
  92. </view>
  93. </template>
  94. <script>
  95. import selectArea from '../../components/selectArea.vue';
  96. import Position from '@/utils/position.js'
  97. export default {
  98. components: {
  99. selectArea
  100. },
  101. data() {
  102. return {
  103. bannerList: [],
  104. projectList: [],
  105. queryParams: {
  106. pageNo: 1,
  107. pageSize: 10,
  108. title: ''
  109. },
  110. loading: false,
  111. finished: false,
  112. technicianList: [],
  113. showAeraPro: false,
  114. area: ''
  115. }
  116. },
  117. onShow() {
  118. this.getBanner()
  119. this.getProject()
  120. this.getLocation()
  121. },
  122. methods: {
  123. //list列表滑动到底部自动新增数据列表
  124. onLoad() {
  125. this.queryParams.pageSize += 10;
  126. this.getProject()
  127. },
  128. //获取banner
  129. getBanner() {
  130. this.$api('getBanner', {}, res => {
  131. this.bannerList = res.result;
  132. })
  133. },
  134. //获取项目列表
  135. getProject() {
  136. this.$api('getProjectList', this.queryParams, res => {
  137. if (res.code == 200) {
  138. this.projectList = res.result.records;
  139. } else {
  140. this.finished = true
  141. }
  142. if (this.queryParams.pageSize > res.result.total) {
  143. this.finished = true
  144. }
  145. this.loading = false
  146. })
  147. },
  148. //获取技师详情
  149. selectTechnician(id) {
  150. this.$api('getProjectDetail', {
  151. id
  152. }, res => {
  153. if (res.code == 200) {
  154. uni.navigateTo({
  155. url: `/pages/technician/selectTechnician?serviceId=${id}`
  156. })
  157. sessionStorage.setItem('technicianList', JSON.stringify(res.result.tenPageList))
  158. }
  159. })
  160. },
  161. //跳转技师详情
  162. toServiceDetail(id) {
  163. uni.navigateTo({
  164. url: '/pages/technician/subscribeService?id=' + id
  165. })
  166. },
  167. //显示选择地区
  168. showSelectArea() {
  169. this.showAeraPro = true;
  170. },
  171. //关闭选择地区
  172. closeAreaPro() {
  173. this.showAeraPro = false;
  174. },
  175. //选择了地区信息
  176. selectArea(area) {
  177. this.area = area;
  178. this.showAeraPro = false;
  179. //后端逻辑
  180. this.updateSessionPositon(area)
  181. },
  182. //搜索地址
  183. searchAddress() {
  184. Position.getLocation(res => {
  185. Position.selectAddress(res.longitude, res.latitude, success => {
  186. let address = this.extractProvinceAndCity(success)
  187. this.queryParams.title = address.city
  188. })
  189. })
  190. },
  191. //提取用户选择的地址信息(省市县信息)
  192. extractProvinceAndCity(res) { //提取用户选择的地址信息(省市)
  193. if (!res.address && res.name) { //用户直接选择城市的逻辑
  194. return {
  195. province: '',
  196. city: res.name
  197. };
  198. }
  199. if (res.address) { //用户选择了详细地址,要从详细地址中提取出省市县信息
  200. // 使用正则表达式匹配省市县
  201. const regex = /(?<province>[\u4e00-\u9fa5]+?省)(?<city>[\u4e00-\u9fa5]+?(?:市|自治州|盟|地区))/;
  202. const match = res.address.match(regex);
  203. if (match) { // 如果匹配成功,则返回省和市的信息
  204. return {
  205. province: match.groups.province,
  206. city: match.groups.city
  207. };
  208. }
  209. }
  210. return { //用户没选择地址就点了确定按钮
  211. province: '',
  212. city: ''
  213. }
  214. },
  215. //获取用户详细地址(省市县)
  216. getLocation() {
  217. Position.getLocationDetail().then(res => {
  218. sessionStorage.setItem("position", JSON.stringify(res))
  219. this.area = res.addressDetail.district
  220. })
  221. },
  222. //初始化用户所在地区
  223. initUserArea() {
  224. if (!sessionStorage.getItem('position')) return this.getLocation()
  225. let positionInfo = JSON.parse(sessionStorage.getItem('position'))
  226. this.area = positionInfo.addressDetail.district
  227. },
  228. //更新用户所在区域(更新区县信息)
  229. updateSessionPositon(area) {
  230. if (sessionStorage.getItem('position')) {
  231. let position = JSON.parse(sessionStorage.getItem('position'))
  232. position.addressDetail.district = area
  233. sessionStorage.setItem('position', JSON.stringify(position))
  234. }
  235. }
  236. }
  237. }
  238. </script>
  239. <style lang="scss" scoped>
  240. .home {
  241. width: 750rpx;
  242. background: #F5F5F5;
  243. margin: 0 auto;
  244. .home-top {
  245. height: 400rpx;
  246. // height: 350rpx;
  247. background: linear-gradient(38deg, #4899A6, #60BDA2);
  248. padding-top: 60rpx;
  249. }
  250. .search {
  251. height: 82rpx;
  252. width: 710rpx;
  253. background: #FFFFFF;
  254. margin: 20rpx auto;
  255. border-radius: 41rpx;
  256. box-sizing: border-box;
  257. padding: 0 15rpx;
  258. display: flex;
  259. align-items: center;
  260. justify-content: space-between;
  261. .left-area,
  262. .center-area {
  263. display: flex;
  264. align-items: center;
  265. }
  266. .left-area {
  267. max-width: 160rpx;
  268. image {
  269. flex-shrink: 0;
  270. width: 26rpx;
  271. height: 26rpx;
  272. }
  273. .area {
  274. font-size: 24rpx;
  275. display: -webkit-box;
  276. -webkit-line-clamp: 2;
  277. /* 限制显示两行 */
  278. -webkit-box-orient: vertical;
  279. overflow: hidden;
  280. text-overflow: ellipsis;
  281. color: #292929;
  282. }
  283. .parting-line {
  284. flex-shrink: 0;
  285. font-size: 26rpx;
  286. color: #ccc;
  287. margin: 0rpx 5rpx;
  288. }
  289. }
  290. .center-area {
  291. display: flex;
  292. flex-wrap: nowrap;
  293. align-items: center;
  294. width: calc(100% - 290rpx);
  295. image {
  296. width: 26rpx;
  297. height: 26rpx;
  298. }
  299. .van-field {
  300. background-color: transparent;
  301. box-sizing: border-box;
  302. height: 82rpx;
  303. line-height: 82rpx;
  304. width: calc(100% - 30rpx);
  305. padding: 0rpx 10rpx 0rpx 0rpx;
  306. input {
  307. height: 82rpx;
  308. font-size: 60rpx;
  309. }
  310. }
  311. }
  312. .right-area {
  313. .search-button {
  314. background: #60BDA2;
  315. height: 60rpx;
  316. width: 130rpx;
  317. font-size: 26rpx;
  318. border-radius: 35rpx;
  319. color: white;
  320. display: flex;
  321. align-items: center;
  322. justify-content: center;
  323. }
  324. }
  325. }
  326. .banner {
  327. box-sizing: border-box;
  328. .my-swipe {
  329. width: 100%;
  330. margin: 0px auto;
  331. // border-radius: 20rpx;
  332. // height: 334rpx;
  333. overflow: hidden;
  334. .van-swipe-item {
  335. width: 100%;
  336. .banner-image {
  337. width: 100%;
  338. image {
  339. width: 100%;
  340. }
  341. }
  342. }
  343. }
  344. }
  345. .home-content {
  346. width: calc(100% - 40rpx);
  347. margin: 20rpx 20rpx 0rpx 20rpx;
  348. // margin: -440rpx 20rpx 0rpx 20rpx;
  349. // margin: -240rpx 20rpx 0rpx 20rpx;
  350. .server-list {
  351. padding-bottom: 80rpx;
  352. .server-item {
  353. display: flex;
  354. flex-wrap: wrap;
  355. justify-content: space-between;
  356. background: white;
  357. border-radius: 15rpx;
  358. box-sizing: border-box;
  359. padding: 15rpx;
  360. margin: 20rpx 0rpx;
  361. .img-box {
  362. width: 150rpx;
  363. height: 150rpx;
  364. border-radius: 10rpx;
  365. overflow: hidden;
  366. image {
  367. width: 100%;
  368. height: 100%;
  369. }
  370. }
  371. .server-info {
  372. display: flex;
  373. flex-direction: column;
  374. justify-content: space-around;
  375. width: calc(100% - 330rpx);
  376. box-sizing: border-box;
  377. padding: 0 10rpx;
  378. .server-title {}
  379. .time-coupon,
  380. .price {
  381. display: flex;
  382. flex-wrap: wrap;
  383. align-items: center;
  384. }
  385. .time-coupon {
  386. font-size: 26rpx;
  387. image {
  388. width: 22rpx;
  389. height: 22rpx;
  390. }
  391. .time {
  392. color: #B8B8B8;
  393. margin-left: 6rpx;
  394. }
  395. .coupon {
  396. display: flex;
  397. justify-content: center;
  398. align-items: center;
  399. background: #F29E45;
  400. color: white;
  401. width: 140rpx;
  402. height: 45rpx;
  403. border-radius: 10rpx;
  404. margin-left: 10rpx;
  405. }
  406. }
  407. .price {
  408. display: flex;
  409. align-items: center;
  410. color: #B8B8B8;
  411. .current-price {
  412. font-size: 30rpx;
  413. font-weight: 600;
  414. color: #D34430;
  415. margin-right: 5rpx;
  416. }
  417. .unit {
  418. font-size: 20rpx;
  419. }
  420. }
  421. .sales-volume {
  422. display: flex;
  423. align-items: center;
  424. color: #B8B8B8;
  425. font-size: 26rpx;
  426. image {
  427. width: 23rpx;
  428. height: 23rpx;
  429. }
  430. }
  431. }
  432. .selective-technician {
  433. display: flex;
  434. flex-wrap: wrap;
  435. align-items: center;
  436. width: 170rpx;
  437. .btn {
  438. display: flex;
  439. align-items: center;
  440. justify-content: center;
  441. height: 60rpx;
  442. width: 170rpx;
  443. border-radius: 40rpx;
  444. color: white;
  445. background: linear-gradient(170deg, #53CEAC, #5AC796);
  446. }
  447. }
  448. }
  449. }
  450. }
  451. }
  452. </style>