industry.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 adfac">
  33. 已选:<span>{{firstName}}</span><span v-if="secondName" style="margin: 0 10rpx;">-</span><span v-if="secondName">{{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.secondList.length===0&&!this.firstName) return this.$showToast('请选择主行业')
  156. if(this.secondList.length&&!this.secondName) return this.$showToast(`请选择子行业`)
  157. const industryId = this.secondList.length?this.sid:this.fid;
  158. const industryName = this.secondList.length?this.secondName:this.firstName;
  159. this.getOpenerEventChannel().emit('selectConfirm',{
  160. industryId,
  161. industryName
  162. })
  163. uni.navigateBack()
  164. }
  165. }
  166. }
  167. </script>
  168. <style scoped lang="scss">
  169. .default_page{
  170. box-sizing: border-box;
  171. .data{
  172. flex: 1;
  173. &-left{
  174. width: 324rpx;
  175. background: #FFFFFF;
  176. overflow-y: auto;
  177. &-item{
  178. padding: 18rpx 36rpx;
  179. position: relative;
  180. font-family: PingFangSC, PingFang SC;
  181. font-weight: 400;
  182. font-size: 26rpx;
  183. color: #002846;
  184. line-height: 37rpx;
  185. &.active{
  186. font-weight: bold;
  187. color: #009191;
  188. &::before{
  189. content: '';
  190. width: 8rpx;
  191. height: 64rpx;
  192. background: #199C9C;
  193. position: absolute;
  194. left: 0;
  195. top: 50%;
  196. margin-top: -32rpx;
  197. }
  198. }
  199. }
  200. }
  201. &-right{
  202. flex: 1;
  203. background: #F7F7F7;
  204. overflow-y: auto;
  205. &-item{
  206. padding: 30rpx 100rpx 30rpx 30rpx;
  207. font-family: PingFang-SC, PingFang-SC;
  208. font-weight: 400;
  209. font-size: 26rpx;
  210. color: #002846;
  211. line-height: 37rpx;
  212. position: relative;
  213. &.active{
  214. color: #009191;
  215. }
  216. image{
  217. width: 36rpx;
  218. height: 36rpx;
  219. position: absolute;
  220. right: 30rpx;
  221. top: 50%;
  222. margin-top: -18rpx;
  223. }
  224. }
  225. }
  226. }
  227. .bottom{
  228. width: 100%;
  229. height: 290rpx;
  230. background: #FFFFFF;
  231. padding: 36rpx 30rpx;
  232. box-sizing: border-box;
  233. &-top{
  234. font-family: PingFangSC, PingFang SC;
  235. font-weight: 400;
  236. font-size: 30rpx;
  237. color: #667E90;
  238. line-height: 42rpx;
  239. span{
  240. color: #002846;
  241. }
  242. }
  243. &-btns{
  244. margin-top: 50rpx;
  245. &-btn{
  246. width: 268rpx;
  247. height: 88rpx;
  248. background: #EBF6F6;
  249. border-radius: 44rpx;
  250. font-family: PingFang-SC, PingFang-SC;
  251. font-weight: bold;
  252. font-size: 32rpx;
  253. color: #009191;
  254. line-height: 88rpx;
  255. text-align: center;
  256. }
  257. .zt_btn{
  258. // width: calc(100% - 298rpx);
  259. width: 100%;
  260. }
  261. }
  262. }
  263. .dialog{
  264. position: fixed;
  265. left: 0;
  266. right: 0;
  267. top: 0;
  268. bottom: 0;
  269. z-index: 1000;
  270. background: rgba(0, 0, 0, .4);
  271. .box{
  272. width: 100%;
  273. border-radius: 24rpx 24rpx 0 0;
  274. background: #FFFFFF;
  275. padding: 36rpx 36rpx 300rpx;
  276. box-sizing: border-box;
  277. position: absolute;
  278. bottom: 0;
  279. left: 0;
  280. &-top{
  281. &-btn{
  282. font-family: PingFangSC, PingFang SC;
  283. font-weight: 400;
  284. font-size: 30rpx;
  285. line-height: 42rpx;
  286. width: 80rpx;
  287. &.cancel{
  288. color: #002846;
  289. }
  290. &.add{
  291. color: #009191;
  292. text-align: right;
  293. }
  294. }
  295. &-title{
  296. flex: 1;
  297. font-family: PingFang-SC, PingFang-SC;
  298. font-weight: bold;
  299. font-size: 36rpx;
  300. color: #002846;
  301. line-height: 50rpx;
  302. text-align: center;
  303. }
  304. }
  305. &-inp{
  306. margin-top: 98rpx;
  307. padding-bottom: 30rpx;
  308. border-bottom: 1rpx solid #E2E2E2;
  309. }
  310. &-textarea{
  311. margin-top: 30rpx;
  312. padding-bottom: 30rpx;
  313. border-bottom: 1rpx solid #E2E2E2;
  314. }
  315. }
  316. }
  317. }
  318. </style>