RuleCategorySelDropdown.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <div class="dept-select-drodown__wrap">
  3. <div class="dept_path" style=" white-space:nowrap;">
  4. <div class="dept_paths">
  5. <a href="javascript:void(0);" style="display: flex; align-items: center;" @click="backToIndex(-1)" >全部</a>
  6. <a
  7. v-for="(item, i) in selectedDeptStack"
  8. :key="i"
  9. href="javascript:void(0);"
  10. @click.stop="backToIndex(i)"
  11. >
  12. <van-icon name="arrow"/>
  13. {{item.name}}
  14. </a>
  15. </div>
  16. </div>
  17. <div class="select-dropdown__content" :style="contentStyle">
  18. <scroller class="selector-left _v-container">
  19. <van-cell-group style="margin-top:0;">
  20. <van-cell
  21. :class="{on: item.id === selectedLeftDeptId}"
  22. v-for="(item,index) in deptData"
  23. :key="index"
  24. :title="item.name"
  25. v-show="item.pid == 0"
  26. class="employee_cell"
  27. @click.stop="onselectedLeftDepart(item)"
  28. />
  29. <ListEmptyDataCell :data="deptData" :loading="loading"/>
  30. </van-cell-group>
  31. </scroller>
  32. <scroller ref="scroller_com" class="selector-right _v-container" style="left:2.2rem; width:5.4rem;">
  33. <van-cell
  34. :is-link="selectedRightDeptId !== item.id"
  35. v-for="(item, i) in rightDepartData"
  36. :key="i"
  37. :title="item.name"
  38. class="employee_cell"
  39. :class="{on: selectedRightDeptId === item.id}"
  40. @click.stop="onselectedRightDepart(item)"
  41. >
  42. <template slot="right-icon">
  43. <van-icon name="success" v-if="selectedRightDeptId === item.id"/>
  44. </template>
  45. </van-cell>
  46. </scroller>
  47. </div>
  48. <div class="date-picker__toolbar">
  49. <van-button
  50. class="reset-button"
  51. block
  52. square
  53. color="rgba(38,162,255,0.2)"
  54. @click.stop="onResetDepart"
  55. >{{ resetBtnText }}
  56. </van-button>
  57. <van-button block square type="info" @click="onConfirmDepart">确认</van-button>
  58. </div>
  59. </div>
  60. </template>
  61. <script>
  62. import Vue from 'vue'
  63. import {CellGroup, Cell, Icon, Loading} from 'vant'
  64. import ListEmptyDataCell from './ListEmptyDataCell'
  65. Vue.use(CellGroup).use(Cell).use(Icon).use(Loading)
  66. export default {
  67. props: {
  68. contentHeight: {type: String, default: '5rem'},
  69. resetBtnText: {type: String, default: '恢复默认'}
  70. },
  71. name: 'RuleCategorySelDropdown',
  72. data () {
  73. return {
  74. loading: false,
  75. deptData: null,
  76. rightDepartData: null,
  77. selectedDeptStack: null,
  78. selectedLeftDeptId: null,
  79. selectedLeftDeptItem: null,
  80. selectedRightDeptId: null,
  81. selectedRightDeptItem: null
  82. }
  83. },
  84. components: {ListEmptyDataCell},
  85. computed: {
  86. contentStyle () {
  87. return {height: this.contentHeight}
  88. }
  89. },
  90. methods: {
  91. backToIndex (index) {
  92. if (index < 0) {
  93. this.restoreDefaults()
  94. // this.$emit('onchange', 0)
  95. } else {
  96. this.Paging_return(index)// 传入当前点击下标
  97. const deptItem = this.selectedDeptStack[index]
  98. this.selectedRightDeptId = deptItem.id
  99. this.selectedRightDeptItem = deptItem
  100. this.rightDepartData = [].concat(deptItem, deptItem.child)
  101. // this.$emit('onchange', deptItem)
  102. }
  103. },
  104. Paging_return (deptItem) {
  105. // 1.循环遍历重新插入数组
  106. // let Paging_return_Arrer = []
  107. // for(let i=0;i<this.selectedDeptStack.length;i++){//循环当前有的面包屑,获取当前点击下标及前面的面包屑
  108. // if(i <= deptItem){
  109. // Paging_return_Arrer.push(this.selectedDeptStack[i])
  110. // }
  111. // }
  112. // this.selectedDeptStack = Paging_return_Arrer
  113. // 2.删除点击的下标后边所有
  114. this.selectedDeptStack.splice(deptItem + 1, 1 * 1000)
  115. },
  116. onselectedLeftDepart (deptItem) {
  117. this.selectedLeftDeptId = deptItem.id
  118. this.selectedLeftDeptItem = deptItem
  119. this.selectedRightDeptId = deptItem.id
  120. this.selectedRightDeptItem = deptItem
  121. this.selectedDeptStack = [deptItem]
  122. this.rightDepartData = [].concat(deptItem, deptItem.child)
  123. // this.$emit('onchange', deptItem)
  124. },
  125. onselectedRightDepart (deptItem) {
  126. if (deptItem.id === this.selectedRightDeptId) {
  127. return
  128. }
  129. this.selectedRightDeptId = deptItem.id
  130. this.selectedRightDeptItem = deptItem
  131. this.selectedDeptStack.push(deptItem)
  132. this.rightDepartData = [].concat(deptItem, deptItem.child)
  133. },
  134. onResetDepart () {
  135. this.backToIndex(-1)
  136. },
  137. onConfirmDepart () {
  138. this.$emit('onConfirm', this.selectedRightDeptItem == null ? '' : this.selectedRightDeptItem.id)
  139. },
  140. getDepartData () {
  141. this.loading = true
  142. this.$axiosUser('get', '/api/pro/integral/rule/trees', {cycle_type: '1'}).then((res) => {
  143. const result = res.data
  144. if (result.code === 1) {
  145. const arr = []
  146. const {rule_tree: items} = result.data
  147. for (let key in items) {
  148. arr.push(items[key])
  149. }
  150. this.deptData = arr
  151. }
  152. }).finally(() => {
  153. this.$toast.clear()
  154. this.loading = false
  155. })
  156. },
  157. restoreDefaults () {
  158. this.selectedLeftDeptId = null
  159. this.selectedLeftDeptItem = null
  160. this.selectedRightDeptId = null
  161. this.selectedRightDeptItem = null
  162. this.selectedDeptStack = null
  163. this.rightDepartData = null
  164. }
  165. },
  166. mounted () {
  167. this.getDepartData()
  168. }
  169. }
  170. </script>
  171. <style lang="less" scoped>
  172. .dept-select-drodown__wrap {
  173. position: relative;
  174. overflow: hidden;
  175. }
  176. .select-dropdown__content {
  177. position: relative;
  178. }
  179. .employee_cell {
  180. display: flex;
  181. align-items: center;
  182. padding: 0.16rem 0.32rem;
  183. touch-action: none;
  184. }
  185. .employee_cell .van-cell__title {
  186. line-height: 0.8rem;
  187. & > span {
  188. font-size: 0.3rem;
  189. }
  190. }
  191. .dept_path a {
  192. color: #238dfa;
  193. font-size: 0.3rem;
  194. }
  195. .dept_path a:nth-last-child(1) {
  196. color: #999;
  197. }
  198. .dept_path a * {
  199. vertical-align: middle;
  200. }
  201. //滚动条
  202. .dept_paths{
  203. overflow-x: scroll;
  204. height: 0.8rem;
  205. display: flex;
  206. align-items: center;
  207. }
  208. .dept_path {
  209. width: 7rem;
  210. // position: relative;
  211. display: flex;
  212. flex-wrap: nowrap;
  213. height: 0.8rem;
  214. font-size: 0.32rem;
  215. padding: 0 0.32rem;
  216. align-items: center;
  217. touch-action: none;
  218. }
  219. .dept_path:after {
  220. content: ' ';
  221. bottom: 0;
  222. left: 0;
  223. right: 0;
  224. background-color: #efefef;
  225. height: 1px;
  226. position: absolute;
  227. transform: scaleY(0.5);
  228. }
  229. .selector-left {
  230. width: 2.2rem !important;
  231. background-color: #f5f5f5;
  232. }
  233. .selector-left .van-cell {
  234. background-color: #f5f5f5;
  235. }
  236. .selector-left .employee_cell {
  237. padding-left: 0.32rem;
  238. }
  239. .selector-left .employee_cell.on {
  240. position: relative;
  241. &:before {
  242. position: absolute;
  243. top: 50%;
  244. left: 0.08rem;
  245. content: '';
  246. width: 0.04rem;
  247. height: 0.36rem;
  248. background: #26a2ff;
  249. border-radius: 0.04rem;
  250. transform: translateY(-50%);
  251. }
  252. }
  253. /deep/ .selector-left .van-cell:not(:last-child):after {
  254. left: 0;
  255. }
  256. .selector-right {
  257. width: 5.4rem !important;
  258. background-color: #fff;
  259. }
  260. .van-cell {
  261. &.on {
  262. color: #238dfa;
  263. & .van-cell__title > span {
  264. font-size: 0.3rem;
  265. }
  266. }
  267. & .van-cell__title > span {
  268. font-size: 0.3rem;
  269. }
  270. & .van-icon-success {
  271. align-self: center;
  272. }
  273. }
  274. .date-picker__toolbar {
  275. display: flex;
  276. flex-direction: row;
  277. & .reset-button {
  278. touch-action: none;
  279. color: #26a2ff !important;
  280. border: transparent !important;
  281. }
  282. }
  283. // .rule-selector__wrap {
  284. // display: flex;
  285. // position: relative;
  286. // overflow: hidden;
  287. // height: 7rem;
  288. // flex-direction: column;
  289. // & .rule-selector__conetent {
  290. // display: flex;
  291. // position: relative;
  292. // flex: 1;
  293. // padding: 0.26rem 0.19rem;
  294. // flex-direction: column;
  295. // overflow-y: auto;
  296. // overflow-x: hidden;
  297. // & .rule-category__content {
  298. // position: relative;
  299. // & .rule-category___title {
  300. // padding: 0 0.13rem;
  301. // color: #333;
  302. // font-size: 0.3rem;
  303. // }
  304. // & .rule-category__sub-items {
  305. // display: flex;
  306. // padding-bottom: 0.24rem;
  307. // flex-flow: row wrap;
  308. // & .rule-sub__item {
  309. // display: flex;
  310. // margin: 0.24rem 0.13rem 0 0.13rem;
  311. // width: 1.52rem;
  312. // height: 0.72rem;
  313. // background: #f5f7fa;
  314. // border-radius: 0.04rem;
  315. // align-items: center;
  316. // justify-content: center;
  317. // touch-action: none;
  318. // &.selected {
  319. // color: #26a2ff;
  320. // background: #26a2ff33;
  321. // }
  322. // & > span {
  323. // font-size: 0.28rem;
  324. // }
  325. // }
  326. // }
  327. // }
  328. // }
  329. // & .date-picker__toolbar {
  330. // display: flex;
  331. // flex-direction: row;
  332. // & .reset-button {
  333. // color: #26a2ff !important;
  334. // border: transparent !important;
  335. // }
  336. // }
  337. // }
  338. </style>