addPlace.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <view class="container" v-if="townList.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" v-if="hotelList.length">
  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.isCheck"
  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.name}}
  24. </view>
  25. <view class="detail_leave" v-if="item.type===1">
  26. 银宿级
  27. </view>
  28. <view class="detail_leave" v-if="item.type===2">
  29. 金宿级
  30. </view>
  31. <view class="detail_leave" v-if="item.type===3">
  32. 白金级
  33. </view>
  34. <view class="detail_rate" v-if="item.score">
  35. {{item.score.toFixed(1)}}分
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. <!-- 没有数据时展示的区域 -->
  42. <view class="noData" v-else>
  43. <img src="../../static/images/noData.png" />
  44. 暂无数据
  45. </view>
  46. <!-- 确定按钮区域 -->
  47. <view class="btn" @click="handleClickBtn">
  48. 确定
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. export default {
  54. data() {
  55. return {
  56. // 乡镇数组
  57. townList: [],
  58. // 民宿列表
  59. hotelList: [],
  60. // 当前高亮索引
  61. activeIndex: 0,
  62. // 之前选中的数组
  63. oldList:[],
  64. // 之前选中的城镇id
  65. oldTownId:''
  66. }
  67. },
  68. onLoad(options) {
  69. this.oldList = JSON.parse(options.list)
  70. this.oldTownId = options.townId
  71. this.getTownList()
  72. },
  73. methods: {
  74. // 获取乡镇列表数组
  75. async getTownList() {
  76. const res = await this.$myRequest({
  77. url: '/mhotel/articletownShips.action'
  78. })
  79. // console.log(res)
  80. if (res.code === 200) {
  81. this.townList = res.data
  82. this.townList.forEach((ele,index)=>{
  83. if(ele.id == this.oldTownId){
  84. this.activeIndex = index
  85. }
  86. })
  87. this.getHotelList()
  88. }
  89. },
  90. // 获取民宿列表数组
  91. async getHotelList() {
  92. const res = await this.$myRequest({
  93. url: '/mhotel/articlehotelByid.action',
  94. data: {
  95. townId:this.townList[this.activeIndex].id,
  96. page: 1,
  97. rows: 999,
  98. }
  99. })
  100. // console.log(res)
  101. if (res.code === 200) {
  102. this.hotelList = res.data.pageList
  103. // 添加isCheck属性
  104. this.hotelList.forEach(ele=>{
  105. this.$set(ele,'isCheck',false)
  106. })
  107. this.hotelList.forEach(ele=>{
  108. this.oldList.forEach((item)=>{
  109. if(item.id ===ele.id){
  110. ele.isCheck = true
  111. }
  112. })
  113. })
  114. }
  115. },
  116. // 切换乡镇回调
  117. handleChange(index) {
  118. this.activeIndex = index
  119. this.getHotelList()
  120. },
  121. // 点击radio回调
  122. handleClickRadio(item) {
  123. item.isCheck = !item.isCheck
  124. },
  125. // 确定按钮点击回调
  126. handleClickBtn() {
  127. let temList = this.hotelList.filter(ele => ele.isCheck)
  128. if (temList.length) {
  129. uni.$emit('add', {
  130. list: temList,
  131. townId:this.townList[this.activeIndex].id
  132. })
  133. uni.navigateBack(1)
  134. } else {
  135. uni.showToast({
  136. title: "请关联至少一个乡村民宿",
  137. icon: 'none',
  138. mask: true
  139. })
  140. }
  141. }
  142. }
  143. }
  144. </script>
  145. <style lang="scss" scoped>
  146. .container {
  147. box-sizing: border-box;
  148. padding: 0 19rpx 80rpx;
  149. min-height: 100vh;
  150. background-color: #fff;
  151. .title {
  152. height: 90rpx;
  153. line-height: 90rpx;
  154. font-size: 32rpx;
  155. font-weight: bold;
  156. }
  157. .town_list {
  158. display: flex;
  159. flex-wrap: wrap;
  160. .town_box {
  161. display: flex;
  162. justify-content: center;
  163. align-items: center;
  164. padding: 0 39rpx;
  165. margin-right: 19rpx;
  166. margin-bottom: 24rpx;
  167. height: 65rpx;
  168. color: #808080;
  169. font-size: 28rpx;
  170. border-radius: 74rpx;
  171. background-color: #e6e6e6;
  172. }
  173. .active {
  174. color: #fff;
  175. background-color: #096562;
  176. }
  177. }
  178. .title2 {
  179. height: 80rpx;
  180. font-size: 32rpx;
  181. font-weight: bold;
  182. }
  183. .hotel_list {
  184. .hotel_box {
  185. display: flex;
  186. margin-bottom: 20rpx;
  187. width: 710rpx;
  188. height: 150rpx;
  189. .box_radio {
  190. display: flex;
  191. justify-content: center;
  192. align-items: center;
  193. width: 95rpx;
  194. }
  195. .box_info {
  196. flex: 1;
  197. display: flex;
  198. background-color: #F2F2F2;
  199. overflow: hidden;
  200. img {
  201. width: 126rpx;
  202. height: 150rpx;
  203. }
  204. .info_detail {
  205. flex: 1;
  206. display: flex;
  207. flex-direction: column;
  208. justify-content: space-evenly;
  209. padding: 0 23rpx;
  210. overflow: hidden;
  211. .detail_name {
  212. font-size: 28rpx;
  213. font-weight: bold;
  214. overflow: hidden;
  215. text-overflow: ellipsis;
  216. white-space: nowrap;
  217. }
  218. .detail_leave {
  219. color: #808080;
  220. font-size: 24rpx;
  221. }
  222. .detail_rate {
  223. color: #FF5733;
  224. font-size: 24rpx;
  225. }
  226. }
  227. }
  228. }
  229. }
  230. .noData {
  231. display: flex;
  232. flex-direction: column;
  233. justify-content: center;
  234. align-items: center;
  235. img {
  236. margin-top: 60rpx;
  237. width: 400rpx;
  238. height: 400rpx;
  239. }
  240. }
  241. .btn {
  242. display: flex;
  243. justify-content: center;
  244. align-items: center;
  245. margin: 200rpx auto 0;
  246. width: 710rpx;
  247. height: 100rpx;
  248. color: #fff;
  249. font-size: 32rpx;
  250. border-radius: 64rpx;
  251. background-color: #096562;
  252. }
  253. }
  254. </style>