selectArea.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view class="container">
  3. <!-- 顶部选择校区区域 -->
  4. <view class="top">
  5. <uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text" activeColor="#6FB6B8"></uni-segmented-control>
  6. </view>
  7. <view class="gap"></view>
  8. <!-- 主体内容区域 -->
  9. <view class="body">
  10. <!-- 左边区域 -->
  11. <view class="body_left">
  12. <view class="body_left_item" :class="{ active: active_left === index }" v-for="(item, index) in leftList" :key="index" @click="handleChange(index)">
  13. {{ item }}
  14. </view>
  15. </view>
  16. <!-- 右边区域 -->
  17. <view class="body_right">
  18. <view class="body_right_item" :class="{ active: active_right === index }" v-for="(item, index) in rightList" :key="index" @click="handleChange2(index)">
  19. {{ item.name }}
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. data() {
  28. return {
  29. // 顶部分段器选项数组
  30. items: [],
  31. // 分段器当前索引
  32. current: 0,
  33. // 校区ID
  34. schoolId: 0,
  35. // 楼栋ID
  36. buildId: null,
  37. // 左边分类数组
  38. leftList: [],
  39. // 左边分类数组当前索引
  40. active_left: 0,
  41. // 右边分类数组
  42. rightList: [],
  43. // 右边分类数组当前索引
  44. active_right: null,
  45. // 报修区域数组
  46. areaTreeList: [],
  47. // 校区数组
  48. schoolList: []
  49. }
  50. },
  51. mounted() {
  52. this.getSchoolList()
  53. },
  54. methods: {
  55. // 获取校区数据
  56. async getSchoolList() {
  57. const res = await this.$myRequest_repairs({
  58. url: '/repairArea/queryRepairSchools'
  59. })
  60. // console.log(res)
  61. if (res.code === '200') {
  62. this.schoolList = res.data
  63. this.items = this.schoolList.map((ele) => ele.name)
  64. this.schoolId = this.schoolList[this.current].id
  65. this.getRepairAreaTree()
  66. }
  67. },
  68. // 获取区域数据
  69. async getRepairAreaTree() {
  70. const res = await this.$myRequest_repairs({
  71. url: '/repairArea/queryRepairAreaTree',
  72. data: {
  73. schoolId: this.schoolId
  74. }
  75. })
  76. // console.log(res)
  77. if (res.code === '200') {
  78. this.areaTreeList = res.data
  79. this.leftList = this.areaTreeList.map((ele) => ele.name)
  80. this.rightList = this.areaTreeList[this.active_left].children || []
  81. this.buildId = this.areaTreeList[this.active_left].id
  82. }
  83. },
  84. // 顶部分段器切换选项回调
  85. onClickItem(e) {
  86. this.active_left = 0
  87. this.active_right = null
  88. if (this.current != e.currentIndex) {
  89. this.current = e.currentIndex
  90. this.schoolId = this.schoolList[this.current].id
  91. this.getRepairAreaTree()
  92. }
  93. },
  94. // 左边数组切换回调
  95. handleChange(index) {
  96. this.active_left = index
  97. this.active_right = null
  98. this.rightList = this.areaTreeList[this.active_left].children || []
  99. this.buildId = this.areaTreeList[this.active_left].id
  100. },
  101. // 右边数组切换回调
  102. handleChange2(index) {
  103. this.active_right = index
  104. const repairsArea = this.items[this.current] + this.leftList[this.active_left] + this.rightList[this.active_right].name
  105. uni.$emit('addRepairsArea', {
  106. data: repairsArea,
  107. schoolId: this.schoolId,
  108. buildId: this.buildId
  109. })
  110. uni.navigateBack(1)
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. .container {
  117. width: 100vw;
  118. height: 100vh;
  119. .top {
  120. height: 100rpx;
  121. }
  122. .gap {
  123. height: 10rpx;
  124. background-color: #f2f2f2;
  125. }
  126. .body {
  127. display: flex;
  128. height: calc(100vh - 110rpx);
  129. .body_left {
  130. box-sizing: border-box;
  131. padding: 15rpx;
  132. width: 198rpx;
  133. border-right: 1rpx solid #ccc;
  134. overflow-y: auto;
  135. .body_left_item {
  136. width: 100%;
  137. height: 80rpx;
  138. line-height: 80rpx;
  139. text-align: center;
  140. font-size: 28rpx;
  141. overflow: hidden;
  142. white-space: nowrap;
  143. text-overflow: ellipsis;
  144. }
  145. .active {
  146. color: #6fb6b8;
  147. }
  148. }
  149. .body_right {
  150. box-sizing: border-box;
  151. padding: 30rpx 40rpx;
  152. width: 552rpx;
  153. overflow-y: auto;
  154. .body_right_item {
  155. float: left;
  156. box-sizing: border-box;
  157. margin: 0 12rpx 28rpx 0;
  158. padding: 10rpx 30rpx;
  159. height: 50rpx;
  160. line-height: 30rpx;
  161. text-align: center;
  162. color: #808080;
  163. font-size: 28rpx;
  164. border-radius: 53rpx;
  165. background-color: #e6e6e6;
  166. overflow: hidden;
  167. white-space: nowrap;
  168. text-overflow: ellipsis;
  169. }
  170. .active {
  171. color: #fff;
  172. background-color: #6fb6b8;
  173. }
  174. }
  175. }
  176. }
  177. ::v-deep .segmented-control {
  178. height: 100rpx;
  179. }
  180. </style>