selectGoods.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <view class="container">
  3. <view class="gap"></view>
  4. <view class="body">
  5. <!-- 左边区域 -->
  6. <view class="left">
  7. <view class="left_item" :class="{ active: active_left === index }" v-for="(item, index) in leftList" :key="index" @click="handleChange(index)">
  8. {{ item }}
  9. </view>
  10. </view>
  11. <!-- 右边区域 -->
  12. <view class="right">
  13. <view class="right_item" :class="{ active: active_right === index }" v-for="(item, index) in rightList" :key="index" @click="handleChange2(index)">
  14. {{ item.name }}
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. data() {
  23. return {
  24. // 左边分类数组当前索引
  25. active_left: 0,
  26. // 左边分类数组
  27. leftList: [],
  28. // 右边分类数组当前索引
  29. active_right: null,
  30. // 右边分类数组
  31. rightList: [],
  32. // 当前校区Id
  33. schoolId: null,
  34. // 报修物品数组
  35. articleList: [],
  36. // 报修物品ID
  37. articleId: ''
  38. }
  39. },
  40. onLoad(options) {
  41. this.schoolId = options.schoolId
  42. // console.log(this.schoolId)
  43. this.getArticleList()
  44. },
  45. methods: {
  46. // 获取物品类型数组
  47. async getArticleList() {
  48. const res = await this.$myRequest_repairs({
  49. url: '/repairArticleType/queryRepairArticleTypeTree',
  50. data: {
  51. schoolId: this.schoolId
  52. }
  53. })
  54. // console.log(res)
  55. if (res.code == '200') {
  56. this.articleList = res.data
  57. this.leftList = this.articleList.map((ele) => ele.name)
  58. this.rightList = this.articleList[this.active_left].children || []
  59. }
  60. },
  61. // 左边数组切换回调
  62. handleChange(index) {
  63. this.active_left = index
  64. this.active_right = null
  65. this.rightList = this.articleList[this.active_left].children || []
  66. },
  67. // 右边数组切换回调
  68. handleChange2(index) {
  69. this.active_right = index
  70. this.articleId = this.articleList[this.active_left].children[this.active_right].id
  71. const repairsGoods = this.leftList[this.active_left] + '-' + this.rightList[this.active_right].name
  72. uni.$emit('addRepairsGoods', {
  73. data: repairsGoods,
  74. articleId: this.articleId
  75. })
  76. uni.navigateBack(1)
  77. }
  78. }
  79. }
  80. </script>
  81. <style lang="scss" scoped>
  82. .container {
  83. width: 100vw;
  84. height: 100vh;
  85. .gap {
  86. height: 10rpx;
  87. background-color: #f2f2f2;
  88. }
  89. .body {
  90. display: flex;
  91. height: calc(100vh - 10rpx);
  92. .left {
  93. box-sizing: border-box;
  94. padding: 15rpx;
  95. width: 198rpx;
  96. border-right: 1rpx solid #ccc;
  97. overflow-y: auto;
  98. .left_item {
  99. width: 100%;
  100. height: 80rpx;
  101. line-height: 80rpx;
  102. text-align: center;
  103. font-size: 28rpx;
  104. overflow: hidden;
  105. white-space: nowrap;
  106. text-overflow: ellipsis;
  107. }
  108. .active {
  109. color: #6fb6b8;
  110. }
  111. }
  112. .right {
  113. box-sizing: border-box;
  114. padding: 30rpx 40rpx;
  115. width: 552rpx;
  116. overflow-y: auto;
  117. .right_item {
  118. float: left;
  119. box-sizing: border-box;
  120. padding: 10rpx 30rpx;
  121. margin: 0 32rpx 37rpx 0;
  122. height: 50rpx;
  123. line-height: 30rpx;
  124. text-align: center;
  125. color: #808080;
  126. font-size: 28rpx;
  127. border-radius: 53rpx;
  128. background-color: #e6e6e6;
  129. overflow: hidden;
  130. white-space: nowrap;
  131. text-overflow: ellipsis;
  132. }
  133. .active {
  134. color: #fff;
  135. background-color: #6fb6b8;
  136. }
  137. }
  138. }
  139. }
  140. </style>