industry.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view class="default_page adffc" :style="{'height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='选择行业'></cus-header>
  4. <view class="data adf">
  5. <view class="data-left">
  6. <view class="data-left-item" :class="{'active':findex===index}" @click="selectFirstType(item,index)"
  7. v-for="(item,index) in firstList" :key="index">{{item.name}}</view>
  8. <view class="data-left-item" @click="handleAdd(1)">自定义</view>
  9. </view>
  10. <view class="data-right">
  11. <view class="data-right-item" :class="{'active':item.select}" @click="selectSecondType(item,index)"
  12. v-for="(item,index) in secondList" :key="index">
  13. {{item.name}}
  14. <image :src="imgBase+'icon_selected.png'" v-if="item.select"></image>
  15. </view>
  16. <view class="data-right-item" @click="handleAdd(2)" v-if="firstName">自定义</view>
  17. </view>
  18. </view>
  19. <view class="bottom">
  20. <!-- <view class="bottom-top adfac">
  21. <view class="bottom-top-left adfac">已选(<text>{{1}}</text>/{{3}})</view>
  22. <view class="bottom-top-right">
  23. <scroll-view class="scroll-view_H" scroll-x="true" scroll-with-animation="true" :scroll-left="scrollLeft">
  24. <view class="scroll-view-item_H" :id="'svih_'+index" v-for="(item,index) in selectedList" :key="index">
  25. <view class="cl_item">
  26. <text>{{item.name}}</text>
  27. </view>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. </view> -->
  32. <view class="bottom-top">
  33. 当前选择行业:<span>{{firstName}} - {{secondName}}</span>
  34. </view>
  35. <view class="bottom-btns adfacjb">
  36. <!-- <view class="bottom-btns-btn" @click="clear">清空条件</view> -->
  37. <view class="zt_btn" @click="confirm">确定</view>
  38. </view>
  39. </view>
  40. <view class="dialog adffc" v-if="show">
  41. <view class="box">
  42. <view class="box-top adfac">
  43. <view class="box-top-btn cancel" @click="show=false">取消</view>
  44. <view class="box-top-title">其他自定义</view>
  45. <view class="box-top-btn add" @click="addIndustry">添加</view>
  46. </view>
  47. <view class="box-inp">
  48. <u--input type="text" v-model="name" border="none" fontSize="30rpx" color="#002846" :placeholder="'请输入自定义'+(type==1?'主':'子')+'行业'" clearable></u--input>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. export default {
  56. data(){
  57. return {
  58. scrollLeft:0,
  59. findex:'',
  60. fid:'',
  61. fpid:'',
  62. firstName:'',
  63. secondName:'',
  64. sid:'',
  65. spid:'',
  66. firstList:[
  67. {
  68. name:'IT/互联网',
  69. children:[
  70. {name:'网络与信息安全'}
  71. ]
  72. }
  73. ],
  74. dataMap:new Map(),
  75. secondList:[],
  76. selectedList:[],
  77. show:false,
  78. name:'',
  79. type:1,
  80. }
  81. },
  82. onLoad() {
  83. this.getData()
  84. },
  85. methods:{
  86. getData(){
  87. this.$api.get('/core/industry/list').then(({data:res})=>{
  88. if(res.code!==0) return this.$showToast(res.msg)
  89. this.firstList = res.data;
  90. this.firstList.forEach((l,i)=>{
  91. this.$set(this.firstList[i],'select',false)
  92. this.dataMap.set(l.id,l.children)
  93. })
  94. })
  95. },
  96. selectFirstType(item,index){
  97. if(index!==this.findex){
  98. this.firstName = this.secondName = '';
  99. }
  100. this.findex = index;
  101. this.firstName = item.name;
  102. this.fid = item.id;
  103. this.fpid = item.pid;
  104. this.firstList.forEach((l,i)=>{
  105. this.$set(this.firstList[i],'select',i===index)
  106. })
  107. this.secondList = this.dataMap.get(item.id);
  108. this.secondList.forEach((l,i)=>{
  109. this.$set(this.secondList[i],'select',false)
  110. })
  111. },
  112. selectSecondType(item,index){
  113. this.secondName = item.name;
  114. this.sid = item.id;
  115. this.spid = item.pid;
  116. this.secondList.forEach((l,i)=>{
  117. this.$set(this.secondList[i],'select',i===index)
  118. })
  119. },
  120. handleAdd(type){
  121. this.type = type;
  122. this.show = true;
  123. },
  124. clear(){
  125. this.firstList.forEach((l,i)=>{
  126. this.$set(this.firstList[i],'select',false)
  127. })
  128. this.secondList.forEach((l,i)=>{
  129. this.$set(this.secondList[i],'select',false)
  130. })
  131. this.selectedList = [];
  132. },
  133. addIndustry(){
  134. if(!this.name) return this.$showToast('请输入行业名称')
  135. this.$api.post('/core/industry',{
  136. pid:this.type===1?'0':this.fid,
  137. name:this.name
  138. }).then(({data:res})=>{
  139. if(res.code!==0) return this.$showToast(res.msg)
  140. this.findex = '';
  141. this.fid = '';
  142. this.fpid = '';
  143. this.firstName = '';
  144. this.sid = '';
  145. this.spid = '';
  146. this.secondName = '';
  147. this.firstList = [];
  148. this.secondList = [];
  149. this.name = '';
  150. this.show = false;
  151. this.getData()
  152. })
  153. },
  154. confirm(){
  155. if(!this.secondName) return this.$showToast('请先选择行业')
  156. this.getOpenerEventChannel().emit('selectConfirm',{
  157. industryId:this.sid,
  158. industryName:this.secondName
  159. })
  160. uni.navigateBack()
  161. }
  162. }
  163. }
  164. </script>
  165. <style scoped lang="scss">
  166. .default_page{
  167. box-sizing: border-box;
  168. .data{
  169. flex: 1;
  170. &-left{
  171. width: 274rpx;
  172. background: #FFFFFF;
  173. overflow-y: auto;
  174. &-item{
  175. padding: 18rpx 36rpx;
  176. position: relative;
  177. font-family: PingFangSC, PingFang SC;
  178. font-weight: 400;
  179. font-size: 26rpx;
  180. color: #002846;
  181. line-height: 37rpx;
  182. &.active{
  183. font-weight: bold;
  184. color: #009191;
  185. &::before{
  186. content: '';
  187. width: 8rpx;
  188. height: 64rpx;
  189. background: #199C9C;
  190. position: absolute;
  191. left: 0;
  192. top: 50%;
  193. margin-top: -32rpx;
  194. }
  195. }
  196. }
  197. }
  198. &-right{
  199. flex: 1;
  200. background: #F7F7F7;
  201. overflow-y: auto;
  202. &-item{
  203. padding: 30rpx 100rpx 30rpx 30rpx;
  204. font-family: PingFang-SC, PingFang-SC;
  205. font-weight: bold;
  206. font-size: 26rpx;
  207. color: #002846;
  208. line-height: 37rpx;
  209. position: relative;
  210. &.active{
  211. color: #009191;
  212. }
  213. image{
  214. width: 36rpx;
  215. height: 36rpx;
  216. position: absolute;
  217. right: 30rpx;
  218. top: 50%;
  219. margin-top: -18rpx;
  220. }
  221. }
  222. }
  223. }
  224. .bottom{
  225. width: 100%;
  226. height: 290rpx;
  227. background: #FFFFFF;
  228. padding: 36rpx 30rpx;
  229. box-sizing: border-box;
  230. &-top{
  231. font-family: PingFangSC, PingFang SC;
  232. font-weight: 400;
  233. font-size: 30rpx;
  234. color: #667E90;
  235. line-height: 42rpx;
  236. span{
  237. color: #002846;
  238. }
  239. }
  240. &-btns{
  241. margin-top: 50rpx;
  242. &-btn{
  243. width: 268rpx;
  244. height: 88rpx;
  245. background: #EBF6F6;
  246. border-radius: 44rpx;
  247. font-family: PingFang-SC, PingFang-SC;
  248. font-weight: bold;
  249. font-size: 32rpx;
  250. color: #009191;
  251. line-height: 88rpx;
  252. text-align: center;
  253. }
  254. .zt_btn{
  255. // width: calc(100% - 298rpx);
  256. width: 100%;
  257. }
  258. }
  259. }
  260. .dialog{
  261. position: fixed;
  262. left: 0;
  263. right: 0;
  264. top: 0;
  265. bottom: 0;
  266. z-index: 1000;
  267. background: rgba(0, 0, 0, .4);
  268. .box{
  269. width: 100%;
  270. border-radius: 24rpx 24rpx 0 0;
  271. background: #FFFFFF;
  272. padding: 36rpx 36rpx 300rpx;
  273. box-sizing: border-box;
  274. position: absolute;
  275. bottom: 0;
  276. left: 0;
  277. &-top{
  278. &-btn{
  279. font-family: PingFangSC, PingFang SC;
  280. font-weight: 400;
  281. font-size: 30rpx;
  282. line-height: 42rpx;
  283. width: 80rpx;
  284. &.cancel{
  285. color: #002846;
  286. }
  287. &.add{
  288. color: #009191;
  289. text-align: right;
  290. }
  291. }
  292. &-title{
  293. flex: 1;
  294. font-family: PingFang-SC, PingFang-SC;
  295. font-weight: bold;
  296. font-size: 36rpx;
  297. color: #002846;
  298. line-height: 50rpx;
  299. text-align: center;
  300. }
  301. }
  302. &-inp{
  303. margin-top: 98rpx;
  304. padding-bottom: 30rpx;
  305. border-bottom: 1rpx solid #E2E2E2;
  306. }
  307. &-textarea{
  308. margin-top: 30rpx;
  309. padding-bottom: 30rpx;
  310. border-bottom: 1rpx solid #E2E2E2;
  311. }
  312. }
  313. }
  314. }
  315. </style>