addPlace.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <view class="container" v-if="townList.length && hotelList.length">
  3. <view class="title">选择乡镇</view>
  4. <!-- 乡镇列表区域 -->
  5. <view class="town_list">
  6. <!-- 每一个乡镇 -->
  7. <view class="town_box" :class="{active:activeIndex ===index}" v-for="(item, index) in townList" :key="index"
  8. @click="handleChange(index)">{{ item.name }}</view>
  9. </view>
  10. <view class="title2">关联民宿</view>
  11. <!-- 民宿列表区域 -->
  12. <view class="hotel_list">
  13. <!-- 每一个民宿 -->
  14. <view class="hotel_box" v-for="item in hotelList" :key="item.id">
  15. <view class="box_radio">
  16. <radio style="transform:scale(1.2)" color="#096562" :checked="item.is_collect_hotel"
  17. @click="handleClickRadio(item)" /></label>
  18. </view>
  19. <view class="box_info">
  20. <img mode="aspectFill" :src="item.coverImg">
  21. <view class="info_detail">
  22. <view class="detail_name">
  23. {{item.hotel_name}}
  24. </view>
  25. <view class="detail_leave">
  26. {{item.hTypeName}}
  27. </view>
  28. <view class="detail_rate">
  29. {{item.score.toFixed(1)}}分
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 确定按钮区域 -->
  36. <view class="btn" @click="handleClickBtn">
  37. 确定
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. data() {
  44. return {
  45. // 乡镇数组
  46. townList: [],
  47. // 民宿列表
  48. hotelList: [],
  49. // 当前高亮索引
  50. activeIndex: 0,
  51. // 已经选中的数组
  52. oldList:[]
  53. }
  54. },
  55. onLoad(options) {
  56. this.oldList = JSON.parse(options.list)
  57. console.log(this.oldList);
  58. this.getTownList()
  59. this.getHotelList()
  60. },
  61. methods: {
  62. // 获取乡镇列表数组
  63. async getTownList() {
  64. const res = await this.$myRequest({
  65. url: '/mhotel/ahpgetResidueCount.action'
  66. })
  67. // console.log(res)
  68. if (res.code === 200) {
  69. this.townList = res.data
  70. }
  71. },
  72. // 获取民宿列表数组
  73. async getHotelList() {
  74. const res = await this.$myRequest({
  75. url: '/mhotel/ahphomePage.action',
  76. data: {
  77. page: 1,
  78. rows: 4,
  79. type: 3,
  80. userId: uni.getStorageSync('userInfo') ? uni.getStorageSync('userInfo').id : ''
  81. }
  82. })
  83. // console.log(res)
  84. if (res.code === 200) {
  85. this.hotelList = res.data.pageList
  86. this.hotelList.forEach((ele)=>{
  87. this.oldList.forEach((item)=>{
  88. if(item.id ===ele.id){
  89. ele.is_collect_hotel = true
  90. }
  91. })
  92. })
  93. }
  94. },
  95. // 切换乡镇回调
  96. handleChange(index) {
  97. this.activeIndex = index
  98. },
  99. // 点击radio回调
  100. handleClickRadio(item) {
  101. item.is_collect_hotel = !item.is_collect_hotel
  102. },
  103. // 确定按钮点击回调
  104. handleClickBtn() {
  105. let temList = this.hotelList.filter(ele => ele.is_collect_hotel)
  106. if (temList.length) {
  107. uni.$emit('add', {
  108. list: temList
  109. })
  110. uni.navigateBack(1)
  111. } else {
  112. uni.showToast({
  113. title: "请关联至少一个民宿",
  114. icon: 'none',
  115. mask: true
  116. })
  117. }
  118. }
  119. }
  120. }
  121. </script>
  122. <style lang="scss" scoped>
  123. .container {
  124. padding: 0 19rpx 80rpx;
  125. min-height: 100vh;
  126. background-color: #fff;
  127. .title {
  128. height: 90rpx;
  129. line-height: 90rpx;
  130. font-size: 32rpx;
  131. font-weight: bold;
  132. }
  133. .town_list {
  134. display: flex;
  135. flex-wrap: wrap;
  136. .town_box {
  137. display: flex;
  138. justify-content: center;
  139. align-items: center;
  140. padding: 0 39rpx;
  141. margin-right: 19rpx;
  142. margin-bottom: 24rpx;
  143. height: 65rpx;
  144. color: #808080;
  145. font-size: 28rpx;
  146. border-radius: 74rpx;
  147. background-color: #e6e6e6;
  148. }
  149. .active {
  150. color: #fff;
  151. background-color: #096562;
  152. }
  153. }
  154. .title2 {
  155. height: 80rpx;
  156. font-size: 32rpx;
  157. font-weight: bold;
  158. }
  159. .hotel_list {
  160. .hotel_box {
  161. display: flex;
  162. margin-bottom: 20rpx;
  163. width: 710rpx;
  164. height: 150rpx;
  165. .box_radio {
  166. display: flex;
  167. justify-content: center;
  168. align-items: center;
  169. width: 95rpx;
  170. }
  171. .box_info {
  172. flex: 1;
  173. display: flex;
  174. background-color: #F2F2F2;
  175. overflow: hidden;
  176. img {
  177. width: 126rpx;
  178. height: 150rpx;
  179. }
  180. .info_detail {
  181. flex: 1;
  182. display: flex;
  183. flex-direction: column;
  184. justify-content: space-evenly;
  185. padding: 0 23rpx;
  186. overflow: hidden;
  187. .detail_name {
  188. font-size: 28rpx;
  189. font-weight: bold;
  190. overflow: hidden;
  191. text-overflow: ellipsis;
  192. white-space: nowrap;
  193. }
  194. .detail_leave {
  195. color: #808080;
  196. font-size: 24rpx;
  197. }
  198. .detail_rate {
  199. color: #FF5733;
  200. font-size: 24rpx;
  201. }
  202. }
  203. }
  204. }
  205. }
  206. .btn {
  207. display: flex;
  208. justify-content: center;
  209. align-items: center;
  210. margin: 200rpx auto 0;
  211. width: 710rpx;
  212. height: 100rpx;
  213. color: #fff;
  214. font-size: 32rpx;
  215. border-radius: 64rpx;
  216. background-color: #096562;
  217. }
  218. }
  219. </style>