classification.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <!-- 分类 -->
  3. <view>
  4. <view class="flex" style="height: 600rpx">
  5. <scroll-view scroll-y="true" class="box1" style="height: 600rpx">
  6. <view
  7. class="itemClass text-overflow"
  8. v-for="(item, index) in provinceList"
  9. :key="item.id"
  10. :class="{ selectedProvice: provinceIndex == index }"
  11. :style="{ color: provinceIndex == index ? '#00D36D' : '' }"
  12. @click="getClassificationList2(item.id, index)"
  13. >
  14. {{ item.className }}
  15. </view>
  16. </scroll-view>
  17. <scroll-view scroll-y="true" class="box2" style="height: 600rpx">
  18. <view
  19. class="itemClass text-overflow"
  20. v-for="(item, index) in cityList"
  21. :key="item.id"
  22. :style="{ color: cityIndex == index ? '#00D36D' : '' }"
  23. @click="getClassificationList3(item.id, index)"
  24. >
  25. {{ item.className }}
  26. </view>
  27. </scroll-view>
  28. <scroll-view
  29. scroll-y="true"
  30. class="box3"
  31. style="height: 600rpx"
  32. :class="{ bl: countyList.length > 0 }"
  33. >
  34. <view
  35. class="itemClass text-overflow"
  36. v-for="(item, index) in countyList"
  37. :key="item.id"
  38. :style="{ color: countyIndex == index ? '#00D36D' : '' }"
  39. @click="selectCounty({ className: item.className, id: item.id }, index)"
  40. >
  41. {{ item.className }}
  42. </view>
  43. </scroll-view>
  44. </view>
  45. <view class="class-btn d-flex-center" v-if="showBottomConfim">
  46. <view class="d-flex-center" @click="reset">重置</view>
  47. <view class="d-flex-center" @click="submitForm">确定</view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import { getClassificationList, getClassCateSelf } from "@/api/home/index.js";
  53. export default {
  54. props: {
  55. showBottomConfim: {
  56. type: Boolean,
  57. default: false,
  58. },
  59. isPublish: {
  60. type: Boolean,
  61. default: false,
  62. },
  63. },
  64. data() {
  65. return {
  66. provinceIndex: null,
  67. cityIndex: 0,
  68. countyIndex: 0,
  69. provinceList: [],
  70. cityList: [],
  71. countyList: [],
  72. className: "分类",
  73. id: "",
  74. selectCode: [], //三级id
  75. };
  76. },
  77. mounted() {
  78. this.getClassificationList1();
  79. },
  80. methods: {
  81. // 获取一级分类
  82. getClassificationList1() {
  83. let param = {
  84. className: "",
  85. parentId: "",
  86. };
  87. if (this.isPublish) {
  88. this.api.getClassCateSelf().then((res) => {
  89. if (res.code == 200) {
  90. this.provinceList = res.data;
  91. }
  92. });
  93. } else {
  94. this.api.getClassificationList(param).then((res) => {
  95. if (res.code == 200) {
  96. this.provinceList = res.data;
  97. }
  98. });
  99. }
  100. },
  101. // 获取二级分类
  102. getClassificationList2(id, index) {
  103. this.provinceIndex = index;
  104. this.cityIndex = 0;
  105. this.countyIndex = 0;
  106. let param = {
  107. className: "",
  108. parentId: id,
  109. };
  110. this.selectCode[0] = id;
  111. this.api.getClassificationList(param).then((res) => {
  112. if (res.code == 200) {
  113. this.cityList = res.data;
  114. this.countyList = [];
  115. }
  116. });
  117. },
  118. // 获取三级分类
  119. getClassificationList3(id, index) {
  120. this.cityIndex = index;
  121. this.countyIndex = 0;
  122. let param = {
  123. className: "",
  124. parentId: id,
  125. };
  126. this.selectCode[1] = id;
  127. this.api.getClassificationList(param).then((res) => {
  128. if (res.code == 200) {
  129. this.countyList = res.data;
  130. }
  131. });
  132. },
  133. selectCounty(item, index) {
  134. this.countyIndex = index;
  135. this.className = item.className;
  136. this.id = item.id;
  137. this.selectCode[2] = item.id;
  138. this.$emit("select", {
  139. className: item.className,
  140. id: item.id,
  141. selectCode: this.selectCode,
  142. });
  143. },
  144. reset() {
  145. this.countyIndex = 0;
  146. this.$emit("search", {
  147. className: "分类",
  148. id: "",
  149. });
  150. },
  151. submitForm() {
  152. this.$emit("search", {
  153. className: this.className,
  154. id: this.id,
  155. });
  156. },
  157. },
  158. };
  159. </script>
  160. <style lang="scss" scoped>
  161. .class-btn {
  162. height: 120rpx;
  163. background: #ffffff;
  164. font-size: 32rpx;
  165. color: white;
  166. display: flex;
  167. flex-direction: row;
  168. align-items: center;
  169. justify-content: space-around;
  170. & > view:nth-of-type(1) {
  171. width: 334rpx;
  172. height: 90rpx;
  173. background: #e6faf1;
  174. border-radius: 44rpx;
  175. border: 2rpx solid #00d36d;
  176. color: #00d36d;
  177. }
  178. & > view:nth-of-type(2) {
  179. width: 334rpx;
  180. height: 90rpx;
  181. color: #fff;
  182. background: linear-gradient(275deg, #01cf6c 0%, #07e278 100%);
  183. border-radius: 44rpx;
  184. }
  185. }
  186. .flex {
  187. display: flex;
  188. }
  189. .box1 {
  190. width: 220rpx;
  191. background-color: #f5f7f7;
  192. }
  193. .box2 {
  194. width: 220rpx;
  195. }
  196. .bl {
  197. border-left: 1rpx solid #eeeeee;
  198. }
  199. .box3 {
  200. width: calc(100% - 440rpx);
  201. }
  202. .itemClass {
  203. height: 90rpx;
  204. line-height: 90rpx;
  205. padding-left: 20rpx;
  206. padding-right: 15rpx;
  207. font-size: 28rpx;
  208. color: #333333;
  209. }
  210. .selectedProvice {
  211. background-color: #ffffff;
  212. }
  213. /deep/::-webkit-scrollbar {
  214. display: none;
  215. width: 0;
  216. height: 0;
  217. }
  218. </style>