宜轩到家/服务到家第三版,换个颜色
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.

534 lines
12 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
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: $uni-bg-color;
  248. padding-top: 60rpx;
  249. // color: $uni-color;
  250. }
  251. .search {
  252. height: 82rpx;
  253. width: 710rpx;
  254. background: #FFFFFF;
  255. margin: 20rpx auto;
  256. border-radius: 41rpx;
  257. box-sizing: border-box;
  258. padding: 0 15rpx;
  259. display: flex;
  260. align-items: center;
  261. justify-content: space-between;
  262. .left-area,
  263. .center-area {
  264. display: flex;
  265. align-items: center;
  266. }
  267. .left-area {
  268. max-width: 160rpx;
  269. image {
  270. flex-shrink: 0;
  271. width: 26rpx;
  272. height: 26rpx;
  273. }
  274. .area {
  275. font-size: 24rpx;
  276. display: -webkit-box;
  277. -webkit-line-clamp: 2;
  278. /* 限制显示两行 */
  279. -webkit-box-orient: vertical;
  280. overflow: hidden;
  281. text-overflow: ellipsis;
  282. color: #292929;
  283. }
  284. .parting-line {
  285. flex-shrink: 0;
  286. font-size: 26rpx;
  287. color: #ccc;
  288. margin: 0rpx 5rpx;
  289. }
  290. }
  291. .center-area {
  292. display: flex;
  293. flex-wrap: nowrap;
  294. align-items: center;
  295. width: calc(100% - 290rpx);
  296. image {
  297. width: 26rpx;
  298. height: 26rpx;
  299. }
  300. .van-field {
  301. background-color: transparent;
  302. box-sizing: border-box;
  303. height: 82rpx;
  304. line-height: 82rpx;
  305. width: calc(100% - 30rpx);
  306. padding: 0rpx 10rpx 0rpx 0rpx;
  307. input {
  308. height: 82rpx;
  309. font-size: 60rpx;
  310. }
  311. }
  312. }
  313. .right-area {
  314. .search-button {
  315. background: linear-gradient(178deg, #ffe6ed, #ecb978);
  316. color: #6e3009;
  317. height: 60rpx;
  318. width: 130rpx;
  319. font-size: 26rpx;
  320. border-radius: 35rpx;
  321. display: flex;
  322. align-items: center;
  323. justify-content: center;
  324. }
  325. }
  326. }
  327. .banner {
  328. box-sizing: border-box;
  329. .my-swipe {
  330. width: 100%;
  331. margin: 0px auto;
  332. // border-radius: 20rpx;
  333. // height: 334rpx;
  334. overflow: hidden;
  335. .van-swipe-item {
  336. width: 100%;
  337. .banner-image {
  338. width: 100%;
  339. image {
  340. width: 100%;
  341. }
  342. }
  343. }
  344. }
  345. }
  346. .home-content {
  347. width: calc(100% - 40rpx);
  348. margin: 20rpx 20rpx 0rpx 20rpx;
  349. // margin: -440rpx 20rpx 0rpx 20rpx;
  350. // margin: -240rpx 20rpx 0rpx 20rpx;
  351. .server-list {
  352. padding-bottom: 80rpx;
  353. .server-item {
  354. display: flex;
  355. flex-wrap: wrap;
  356. justify-content: space-between;
  357. background: white;
  358. border-radius: 15rpx;
  359. box-sizing: border-box;
  360. padding: 15rpx;
  361. margin: 20rpx 0rpx;
  362. .img-box {
  363. width: 150rpx;
  364. height: 150rpx;
  365. border-radius: 10rpx;
  366. overflow: hidden;
  367. image {
  368. width: 100%;
  369. height: 100%;
  370. }
  371. }
  372. .server-info {
  373. display: flex;
  374. flex-direction: column;
  375. justify-content: space-around;
  376. width: calc(100% - 330rpx);
  377. box-sizing: border-box;
  378. padding: 0 10rpx;
  379. .server-title {}
  380. .time-coupon,
  381. .price {
  382. display: flex;
  383. flex-wrap: wrap;
  384. align-items: center;
  385. }
  386. .time-coupon {
  387. font-size: 26rpx;
  388. image {
  389. width: 22rpx;
  390. height: 22rpx;
  391. }
  392. .time {
  393. color: #B8B8B8;
  394. margin-left: 6rpx;
  395. }
  396. .coupon {
  397. display: flex;
  398. justify-content: center;
  399. align-items: center;
  400. background: #F29E45;
  401. color: white;
  402. width: 140rpx;
  403. height: 45rpx;
  404. border-radius: 10rpx;
  405. margin-left: 10rpx;
  406. }
  407. }
  408. .price {
  409. display: flex;
  410. align-items: center;
  411. color: #B8B8B8;
  412. .current-price {
  413. font-size: 30rpx;
  414. font-weight: 600;
  415. color: #D34430;
  416. margin-right: 5rpx;
  417. }
  418. .unit {
  419. font-size: 20rpx;
  420. }
  421. }
  422. .sales-volume {
  423. display: flex;
  424. align-items: center;
  425. color: #B8B8B8;
  426. font-size: 26rpx;
  427. image {
  428. width: 23rpx;
  429. height: 23rpx;
  430. }
  431. }
  432. }
  433. .selective-technician {
  434. display: flex;
  435. flex-wrap: wrap;
  436. align-items: center;
  437. width: 170rpx;
  438. .btn {
  439. display: flex;
  440. align-items: center;
  441. justify-content: center;
  442. height: 60rpx;
  443. width: 170rpx;
  444. border-radius: 40rpx;
  445. background: linear-gradient(178deg, #ffe6ed, #ecb978);
  446. color: #6e3009;
  447. }
  448. }
  449. }
  450. }
  451. }
  452. }
  453. </style>