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

549 lines
12 KiB

9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
8 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
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. copyToken(){
  124. uni.setClipboardData({
  125. data: uni.getStorageSync('token'),
  126. success: () => {
  127. uni.showToast({
  128. title: 'token复制成功',
  129. icon: 'none'
  130. })
  131. }
  132. })
  133. },
  134. //list列表滑动到底部自动新增数据列表
  135. onLoad() {
  136. this.queryParams.pageSize += 10;
  137. this.getProject()
  138. },
  139. //获取banner
  140. getBanner() {
  141. this.$api('getBanner', {}, res => {
  142. this.bannerList = res.result;
  143. })
  144. },
  145. //获取项目列表
  146. getProject() {
  147. this.$api('getProjectList', this.queryParams, res => {
  148. if (res.code == 200) {
  149. this.projectList = res.result.records;
  150. } else {
  151. this.finished = true
  152. }
  153. if (this.queryParams.pageSize > res.result.total) {
  154. this.finished = true
  155. }
  156. this.loading = false
  157. })
  158. },
  159. //获取技师详情
  160. selectTechnician(id) {
  161. this.$api('getProjectDetail', {
  162. id
  163. }, res => {
  164. if (res.code == 200) {
  165. uni.navigateTo({
  166. url: `/pages/technician/selectTechnician?serviceId=${id}`
  167. })
  168. sessionStorage.setItem('technicianList', JSON.stringify(res.result.tenPageList))
  169. }
  170. })
  171. },
  172. //跳转技师详情
  173. toServiceDetail(id) {
  174. uni.navigateTo({
  175. url: '/pages/technician/subscribeService?id=' + id
  176. })
  177. },
  178. //显示选择地区
  179. showSelectArea() {
  180. this.showAeraPro = true;
  181. },
  182. //关闭选择地区
  183. closeAreaPro() {
  184. this.showAeraPro = false;
  185. },
  186. //选择了地区信息
  187. selectArea(area) {
  188. this.area = area;
  189. this.showAeraPro = false;
  190. //后端逻辑
  191. this.updateSessionPositon(area)
  192. },
  193. //搜索地址
  194. searchAddress() {
  195. Position.getLocation(res => {
  196. Position.selectAddress(res.longitude, res.latitude, success => {
  197. let address = this.extractProvinceAndCity(success)
  198. this.queryParams.title = address.city
  199. })
  200. })
  201. },
  202. //提取用户选择的地址信息(省市县信息)
  203. extractProvinceAndCity(res) { //提取用户选择的地址信息(省市)
  204. if (!res.address && res.name) { //用户直接选择城市的逻辑
  205. return {
  206. province: '',
  207. city: res.name
  208. };
  209. }
  210. if (res.address) { //用户选择了详细地址,要从详细地址中提取出省市县信息
  211. // 使用正则表达式匹配省市县
  212. const regex = /(?<province>[\u4e00-\u9fa5]+?省)(?<city>[\u4e00-\u9fa5]+?(?:市|自治州|盟|地区))/;
  213. const match = res.address.match(regex);
  214. if (match) { // 如果匹配成功,则返回省和市的信息
  215. return {
  216. province: match.groups.province,
  217. city: match.groups.city
  218. };
  219. }
  220. }
  221. return { //用户没选择地址就点了确定按钮
  222. province: '',
  223. city: ''
  224. }
  225. },
  226. //获取用户详细地址(省市县)
  227. getLocation() {
  228. Position.getLocationDetail().then(res => {
  229. sessionStorage.setItem("position", JSON.stringify(res))
  230. this.area = res.addressDetail.district
  231. })
  232. },
  233. //初始化用户所在地区
  234. initUserArea() {
  235. if (!sessionStorage.getItem('position')) return this.getLocation()
  236. let positionInfo = JSON.parse(sessionStorage.getItem('position'))
  237. this.area = positionInfo.addressDetail.district
  238. },
  239. //更新用户所在区域(更新区县信息)
  240. updateSessionPositon(area) {
  241. if (sessionStorage.getItem('position')) {
  242. let position = JSON.parse(sessionStorage.getItem('position'))
  243. position.addressDetail.district = area
  244. sessionStorage.setItem('position', JSON.stringify(position))
  245. }
  246. }
  247. }
  248. }
  249. </script>
  250. <style lang="scss" scoped>
  251. .home {
  252. width: 750rpx;
  253. background: #F5F5F5;
  254. margin: 0 auto;
  255. .home-top {
  256. height: 400rpx;
  257. // height: 350rpx;
  258. background: $uni-bg-color;
  259. padding-top: 60rpx;
  260. // color: $uni-color;
  261. }
  262. .search {
  263. height: 82rpx;
  264. width: 710rpx;
  265. background: #FFFFFF;
  266. margin: 20rpx auto;
  267. border-radius: 41rpx;
  268. box-sizing: border-box;
  269. padding: 0 15rpx;
  270. display: flex;
  271. align-items: center;
  272. justify-content: space-between;
  273. .left-area,
  274. .center-area {
  275. display: flex;
  276. align-items: center;
  277. }
  278. .left-area {
  279. max-width: 160rpx;
  280. image {
  281. flex-shrink: 0;
  282. width: 26rpx;
  283. height: 26rpx;
  284. }
  285. .area {
  286. font-size: 24rpx;
  287. display: -webkit-box;
  288. -webkit-line-clamp: 2;
  289. /* 限制显示两行 */
  290. -webkit-box-orient: vertical;
  291. overflow: hidden;
  292. text-overflow: ellipsis;
  293. color: #292929;
  294. }
  295. .parting-line {
  296. flex-shrink: 0;
  297. font-size: 26rpx;
  298. color: #ccc;
  299. margin: 0rpx 5rpx;
  300. }
  301. }
  302. .center-area {
  303. display: flex;
  304. flex-wrap: nowrap;
  305. align-items: center;
  306. width: calc(100% - 290rpx);
  307. image {
  308. width: 26rpx;
  309. height: 26rpx;
  310. }
  311. .van-field {
  312. background-color: transparent;
  313. box-sizing: border-box;
  314. height: 82rpx;
  315. line-height: 82rpx;
  316. width: calc(100% - 30rpx);
  317. padding: 0rpx 10rpx 0rpx 0rpx;
  318. input {
  319. height: 82rpx;
  320. font-size: 60rpx;
  321. }
  322. }
  323. }
  324. .right-area {
  325. .search-button {
  326. background: linear-gradient(178deg, #ffe6ed, #ecb978);
  327. color: #6e3009;
  328. height: 60rpx;
  329. width: 130rpx;
  330. font-size: 26rpx;
  331. border-radius: 35rpx;
  332. display: flex;
  333. align-items: center;
  334. justify-content: center;
  335. }
  336. }
  337. }
  338. .banner {
  339. box-sizing: border-box;
  340. .my-swipe {
  341. width: 100%;
  342. margin: 0px auto;
  343. // border-radius: 20rpx;
  344. // height: 334rpx;
  345. overflow: hidden;
  346. .van-swipe-item {
  347. width: 100%;
  348. .banner-image {
  349. width: 100%;
  350. image {
  351. width: 100%;
  352. }
  353. }
  354. }
  355. }
  356. }
  357. .home-content {
  358. width: calc(100% - 40rpx);
  359. margin: 20rpx 20rpx 0rpx 20rpx;
  360. // margin: -440rpx 20rpx 0rpx 20rpx;
  361. // margin: -240rpx 20rpx 0rpx 20rpx;
  362. .server-list {
  363. padding-bottom: 80rpx;
  364. .server-item {
  365. display: flex;
  366. flex-wrap: wrap;
  367. justify-content: space-between;
  368. background: white;
  369. border-radius: 15rpx;
  370. box-sizing: border-box;
  371. padding: 15rpx;
  372. margin: 20rpx 0rpx;
  373. .img-box {
  374. width: 150rpx;
  375. height: 150rpx;
  376. border-radius: 10rpx;
  377. overflow: hidden;
  378. image {
  379. width: 100%;
  380. height: 100%;
  381. }
  382. }
  383. .server-info {
  384. display: flex;
  385. flex-direction: column;
  386. justify-content: space-around;
  387. width: calc(100% - 330rpx);
  388. box-sizing: border-box;
  389. padding: 0 10rpx;
  390. .server-title {}
  391. .time-coupon,
  392. .price {
  393. display: flex;
  394. flex-wrap: wrap;
  395. align-items: center;
  396. }
  397. .time-coupon {
  398. font-size: 26rpx;
  399. image {
  400. width: 22rpx;
  401. height: 22rpx;
  402. }
  403. .time {
  404. color: #B8B8B8;
  405. margin-left: 6rpx;
  406. }
  407. .coupon {
  408. display: flex;
  409. justify-content: center;
  410. align-items: center;
  411. background: #F29E45;
  412. color: white;
  413. width: 140rpx;
  414. height: 45rpx;
  415. border-radius: 10rpx;
  416. margin-left: 10rpx;
  417. }
  418. }
  419. .price {
  420. display: flex;
  421. align-items: center;
  422. color: #B8B8B8;
  423. .current-price {
  424. font-size: 30rpx;
  425. font-weight: 600;
  426. color: #D34430;
  427. margin-right: 5rpx;
  428. }
  429. .unit {
  430. font-size: 20rpx;
  431. }
  432. }
  433. .sales-volume {
  434. display: flex;
  435. align-items: center;
  436. color: #B8B8B8;
  437. font-size: 26rpx;
  438. image {
  439. width: 23rpx;
  440. height: 23rpx;
  441. }
  442. }
  443. }
  444. .selective-technician {
  445. display: flex;
  446. flex-wrap: wrap;
  447. align-items: center;
  448. width: 170rpx;
  449. .btn {
  450. display: flex;
  451. align-items: center;
  452. justify-content: center;
  453. height: 60rpx;
  454. width: 170rpx;
  455. border-radius: 40rpx;
  456. background: linear-gradient(178deg, #ffe6ed, #ecb978);
  457. color: #6e3009;
  458. }
  459. }
  460. }
  461. }
  462. }
  463. }
  464. .copyToken{
  465. padding: 100rpx;
  466. }
  467. </style>