selectArea.vue 5.0 KB

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