industry.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view>
  3. <!-- 标题 -->
  4. <view class="title flex justify-center">
  5. <view class="title-box">
  6. <view class="title-box-top">
  7. {{type==2?'选择行业':'期望行业'}}
  8. </view>
  9. <view class="title-box-btn">
  10. {{type==2?'请选择行业':'请选择期望行业'}},最多三个
  11. </view>
  12. </view>
  13. </view>
  14. <!-- 行业列表 -->
  15. <view class="list flex justify-center">
  16. <view class="list-box">
  17. <scroll-view scroll-y="true" style="width: 100%;height: 100%;">
  18. <u-collapse>
  19. <u-collapse-item :title="item.industryName" v-for="(item, index) in itemList" :key="index">
  20. <view class="flex align-center flex-wrap" style="width: 100%;">
  21. <view class="" @click="select(item.industryId,ite)"
  22. :class="ite.select==true?'active':''"
  23. style="box-sizing: border-box;color: #1F1F1F;font-size: 24rpx;padding: 16rpx 20rpx 16rpx 20rpx;background-color: #F2F2F7;margin-right: 20rpx;margin-bottom: 20rpx;"
  24. v-for="(ite,ind) in item.childrenList" :key="ind">
  25. {{ite.industryName}}
  26. </view>
  27. </view>
  28. </u-collapse-item>
  29. </u-collapse>
  30. </scroll-view>
  31. </view>
  32. </view>
  33. <!-- 底部操作按钮 -->
  34. <view class="btncz flex justify-center align-center flex-wrap">
  35. <view class="btncz-box1" v-if="selectList.length>0">
  36. <scroll-view scroll-x="true" style="width: 100%;height: 100%;white-space: nowrap;">
  37. <view class="flex align-center" style="width: 100%;height: 100%;">
  38. <text style="margin-right: 20rpx;">已选</text>
  39. <view class="flex align-center"
  40. style="margin-right: 10rpx;font-size: 26rpx;padding: 10rpx 15rpx 10rpx 15rpx;border-radius: 24rpx;background-color: #e7f6fd;color: #00B88F;"
  41. v-for="(item,index) in selectList" :key="index">
  42. {{item.industryName}}
  43. <u-icon name="close" @click="closeS(item)" color="#00B88F" style="margin-left: 10rpx;"
  44. size="20"></u-icon>
  45. </view>
  46. </view>
  47. </scroll-view>
  48. </view>
  49. <view class="btncz-box flex align-center justify-between">
  50. <view class="btncz-box-l flex justify-center align-center" @click="closeAll()">
  51. 清除
  52. </view>
  53. <view class="btncz-box-r flex justify-center align-center" @click="selectAll()">
  54. 确认
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. export default {
  62. data() {
  63. return {
  64. selectList: [],
  65. itemList: [],
  66. topList: [],
  67. type: 1,
  68. };
  69. },
  70. onLoad(option) {
  71. if (option.type == 2) {
  72. this.type = option.type
  73. uni.setNavigationBarTitle({
  74. title: '选择行业'
  75. })
  76. }
  77. this.getIndustryList()
  78. },
  79. methods: {
  80. /**
  81. * 确认选择的行业
  82. */
  83. selectAll() {
  84. let arr = this.selectList
  85. let strArr = []
  86. arr.map(item => {
  87. strArr.push(item.industryName)
  88. })
  89. uni.$emit('industry', {
  90. industry: strArr.toString(',')
  91. })
  92. uni.navigateBack()
  93. this.selectList = []
  94. },
  95. /**
  96. * 获取行业数据
  97. */
  98. getIndustryList() {
  99. this.$Request.get('/app/industry/getIndustryList').then(res => {
  100. if (res.code == 0) {
  101. let arr = res.data
  102. arr.map(item => {
  103. item.childrenList.map(ite => {
  104. ite.select = false
  105. })
  106. })
  107. this.itemList = arr
  108. }
  109. })
  110. },
  111. //清除选择
  112. closeAll() {
  113. this.selectList = []
  114. this.itemList.map(item => {
  115. item.childrenList.map(ite => {
  116. ite.select = false
  117. })
  118. })
  119. },
  120. //取消选择
  121. closeS(item) {
  122. let res = this.selectList.findIndex((ev) => {
  123. return ev.name === item.name;
  124. });
  125. if (res != -1) { //找到了 res为该下标
  126. this.selectList.splice(res, 1)
  127. this.itemList.map(ite => {
  128. if (ite.id == item.id) {
  129. ite.body.map(ite2 => {
  130. if (ite2.name == item.name) {
  131. ite2.select = false
  132. }
  133. })
  134. }
  135. })
  136. }
  137. },
  138. select(id, ite) {
  139. if (this.selectList.length >= 3) {
  140. let res = this.selectList.findIndex((ev) => {
  141. return ev.industryName === ite.industryName;
  142. });
  143. if (res != -1) { //找到了 res为该下标
  144. this.selectList.splice(res, 1)
  145. ite.select = !ite.select
  146. } else { //没找到
  147. uni.showToast({
  148. title: '最多选择三个',
  149. icon: 'none'
  150. })
  151. }
  152. } else {
  153. let res = this.selectList.findIndex((ev) => {
  154. return ev.industryName === ite.industryName;
  155. });
  156. if (res != -1) { //找到了 res为该下标
  157. this.selectList.splice(res, 1)
  158. } else { //没找到
  159. let data = {
  160. industryId: id,
  161. industryName: ite.industryName
  162. }
  163. this.selectList.push(data)
  164. }
  165. ite.select = !ite.select
  166. }
  167. }
  168. }
  169. }
  170. </script>
  171. <style lang="scss">
  172. .active {
  173. color: #00B88F !important;
  174. background-color: #e7f6fd !important;
  175. padding: 16rpx 20rpx !important;
  176. }
  177. .title {
  178. width: 100%;
  179. padding-top: 40rpx;
  180. height: 180rpx;
  181. .title-box {
  182. width: 686rpx;
  183. .title-box-top {
  184. font-size: 48rpx;
  185. font-weight: bold;
  186. }
  187. .title-box-btn {
  188. font-size: 28rpx;
  189. margin-top: 20rpx;
  190. }
  191. }
  192. }
  193. .list {
  194. width: 100%;
  195. height: calc(100vh - 320rpx);
  196. .list-box {
  197. width: 686rpx;
  198. height: 100%;
  199. }
  200. }
  201. .btncz {
  202. width: 100%;
  203. // height: 140rpx;
  204. position: fixed;
  205. bottom: 0;
  206. border-top: 1rpx solid #F2F2F7;
  207. padding-top: 20rpx;
  208. padding-bottom: 20rpx;
  209. .btncz-box1 {
  210. width: 686rpx;
  211. height: 80rpx;
  212. }
  213. .btncz-box {
  214. width: 686rpx;
  215. height: 70rpx;
  216. margin-top: 20rpx;
  217. .btncz-box-l {
  218. width: 30%;
  219. height: 100%;
  220. background-color: #F2F2F7;
  221. }
  222. .btncz-box-r {
  223. width: 60%;
  224. height: 100%;
  225. color: #ffffff;
  226. background-color: #00B88F;
  227. }
  228. }
  229. }
  230. </style>