industry.vue 5.8 KB

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