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.

268 lines
5.9 KiB

8 months ago
  1. <template>
  2. <view class="technician">
  3. <view class="technician-top">
  4. <view class="technician-search">
  5. <view class="search">
  6. <view @click="showSelectArea" class="left-area">
  7. <image src="@/static/home/address-icon.png"></image>
  8. <view class="area">{{ area }}</view>
  9. <image src="../../static/home/arrow-icon.png"></image>
  10. <view class="parting-line">|</view>
  11. </view>
  12. <view class="center-area">
  13. <image src="@/static/home/search-icon.png"></image>
  14. <van-field v-model="queryParams.title" :clearable="true" @clear="clearKey" center placeholder="请输入技师" />
  15. </view>
  16. <view class="right-area">
  17. <view @click="getTechnicianList" class="search-button">搜索</view>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="technician-bottm">
  22. <view class="a"><van-icon name="chat-o" />24小时在线接单</view>
  23. <view class="a"><uni-icons type="staff" color="#fff" size="13" />随时随地</view>
  24. <view class="a"><uni-icons type="staff" color="#fff" size="13" />绿色安全</view>
  25. </view>
  26. </view>
  27. <van-list v-model:loading="loading" :finished="finished" @load="onLoad">
  28. <technician-list :technicianList="technicianList"></technician-list>
  29. </van-list>
  30. <selectArea :show="showAeraPro" @close="closeAreaPro" @select="selectArea"></selectArea>
  31. </view>
  32. </template>
  33. <script>
  34. import technicianList from "../../components/technicianList.vue"
  35. import selectArea from '../../components/selectArea.vue';
  36. import Position from '@/utils/position.js'
  37. export default {
  38. components: { technicianList , selectArea },
  39. data() {
  40. return {
  41. list: [],
  42. queryParams: {
  43. pageNo: 1,
  44. pageSize: 10,
  45. title: ''
  46. },
  47. technicianList: [],
  48. loading: false,
  49. finished: false,
  50. showAeraPro: false,
  51. area: ''
  52. }
  53. },
  54. onShow() {
  55. this.getTechnicianList()
  56. this.initUserArea()
  57. },
  58. methods: {
  59. //list列表滑动到底部自动新增数据列表
  60. onLoad() {
  61. this.queryParams.pageSize += 10
  62. this.getTechnicianList()
  63. },
  64. //获取技师列表
  65. getTechnicianList() {
  66. this.$api('getTechnicianList', this.queryParams, res => {
  67. if (res.code == 200) {
  68. this.technicianList = res.result.records
  69. if (this.queryParams.pageSize > res.result.total) {
  70. this.finished = true
  71. }
  72. this.calculatedDistance() //计算用户与技师距离
  73. }
  74. this.loading = false
  75. })
  76. },
  77. //清空输入框数据
  78. clearKey() {
  79. this.getTechnicianList();
  80. },
  81. //关闭选择地区
  82. closeAreaPro() {
  83. this.showAeraPro = false;
  84. },
  85. //选择了地区信息
  86. selectArea(area) {
  87. this.area = area;
  88. this.showAeraPro = false;
  89. //更新所在地区
  90. this.updateSessionPositon(area)
  91. },
  92. //显示选择地区
  93. showSelectArea() {
  94. this.showAeraPro = true;
  95. },
  96. //获取用户详细地址(省市县)
  97. getLocation() {
  98. Position.getLocationDetail().then(res => {
  99. sessionStorage.setItem("position", JSON.stringify(res))
  100. this.area = res.addressDetail.district
  101. })
  102. },
  103. //初始化用户所在地区
  104. initUserArea(){
  105. if(!sessionStorage.getItem('position')) return this.getLocation() //获取(详细地址,包括省市区)
  106. let positionInfo = JSON.parse(sessionStorage.getItem('position'))
  107. this.area = positionInfo.addressDetail.district
  108. },
  109. //计算距离
  110. calculatedDistance() {
  111. Position.getLocation(result => {
  112. this.technicianList.forEach(item => {
  113. item.km = Position.calculateDistance(result.latitude, result.longitude, item.latitude, item.longitude)
  114. })
  115. })
  116. },
  117. //更新用户所在区域(更新区县信息)
  118. updateSessionPositon(area){
  119. if(sessionStorage.getItem('position')){
  120. let position = JSON.parse(sessionStorage.getItem('position'))
  121. position.addressDetail.district = area
  122. sessionStorage.setItem('position',JSON.stringify(position))
  123. }
  124. }
  125. }
  126. }
  127. </script>
  128. <style lang="scss" scoped>
  129. body {
  130. background-color: #f3f3f3;
  131. }
  132. .technician-top {
  133. background: linear-gradient(38deg, #4899A6, #60BDA2);
  134. }
  135. .technician-bottm {
  136. display: flex;
  137. justify-content: space-around;
  138. font-size: 28rpx;
  139. height: 110rpx;
  140. align-items: center;
  141. color: #fff;
  142. }
  143. .technician-search {
  144. padding-top: 60rpx;
  145. .search {
  146. height: 82rpx;
  147. width: 710rpx;
  148. background: #FFFFFF;
  149. margin: 0px auto;
  150. border-radius: 41rpx;
  151. box-sizing: border-box;
  152. padding: 0 15rpx;
  153. display: flex;
  154. align-items: center;
  155. justify-content: space-between;
  156. .left-area,
  157. .center-area {
  158. display: flex;
  159. align-items: center;
  160. }
  161. .left-area {
  162. max-width: 160rpx;
  163. image {
  164. flex-shrink: 0;
  165. width: 26rpx;
  166. height: 26rpx;
  167. }
  168. .area {
  169. font-size: 24rpx;
  170. display: -webkit-box;
  171. -webkit-line-clamp: 2;
  172. /* 限制显示两行 */
  173. -webkit-box-orient: vertical;
  174. overflow: hidden;
  175. text-overflow: ellipsis;
  176. color: #292929;
  177. }
  178. .parting-line {
  179. flex-shrink: 0;
  180. font-size: 26rpx;
  181. color: #ccc;
  182. margin: 0rpx 5rpx;
  183. }
  184. }
  185. .center-area {
  186. display: flex;
  187. flex-wrap: nowrap;
  188. align-items: center;
  189. width: calc(100% - 290rpx);
  190. image {
  191. width: 26rpx;
  192. height: 26rpx;
  193. }
  194. .van-field {
  195. background-color: transparent;
  196. box-sizing: border-box;
  197. height: 82rpx;
  198. line-height: 82rpx;
  199. width: calc(100% - 30rpx);
  200. padding: 0rpx 10rpx 0rpx 0rpx;
  201. input {
  202. height: 82rpx;
  203. font-size: 60rpx;
  204. }
  205. }
  206. }
  207. .right-area {
  208. .search-button {
  209. background: #60BDA2;
  210. height: 60rpx;
  211. width: 130rpx;
  212. font-size: 26rpx;
  213. border-radius: 35rpx;
  214. color: white;
  215. display: flex;
  216. align-items: center;
  217. justify-content: center;
  218. }
  219. }
  220. }
  221. }
  222. .technician-search-button {
  223. background-color: #60BDA2;
  224. color: #fff;
  225. font-size: 26rpx;
  226. padding: 2rpx 24rpx;
  227. border-radius: 40rpx;
  228. }
  229. </style>