selectArea.vue 4.1 KB

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