cascader.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <template>
  2. <div tabindex="0" @blur="selectClihide()" style="display: inline-block;position: relative;">
  3. <div :class="disabled ? 'disabledTrue' : 'disabledFalse'" @mouseenter="moveIonDiv" @mouseleave="outIonDiv">
  4. <div :style="`width:${selectWidth}px;height:${selectHeight}px`" :class="classDiv ? 'select selectDiv' : 'select'" @click.stop="selectCli" :ref="disabled ? '' : 'selectDiv'">
  5. <div :style="'line-height: '+selectHeight+'px;font-size: '+selectFontSize+'px;'" :class="(selectName == $t('defaultText.pleaseChoose') || selectName == $t('qing-xuan-ze-bu-men') || selectName == $t('other.allDepartments')) ? 'selecttex selecttexXuan' : 'selecttex'">
  6. <!-- <ww-open-data type='departmentName' :openid='selectName'></ww-open-data> -->
  7. <!-- {{selectName}} -->
  8. <span v-if="userName">
  9. <span v-if="selectNameType == 'dep'">
  10. <ww-open-data type='departmentName' :openid='selectName'></ww-open-data>
  11. </span>
  12. <span v-if="selectNameType == 'user'">
  13. <ww-open-data type='userName' :openid='selectName'></ww-open-data>
  14. </span>
  15. </span>
  16. <span v-if="!userName">
  17. <ww-open-data type='departmentName' :openid='selectName'></ww-open-data>
  18. </span>
  19. </div>
  20. <i :class=" move ? 'el-icon-arrow-down iostu iostuHover' : 'el-icon-arrow-down iostu'" v-if="!moveIon"></i>
  21. <i v-if="moveIon" class="el-icon-circle-close iostu" @click.stop="clearDelete"></i>
  22. </div>
  23. </div>
  24. <transition name="el-zoom-in-top">
  25. <div v-show="show" style="position: relative;z-index: 99;">
  26. <div class="transitionBox">
  27. <ul class="transitionBoxUl">
  28. <li :class="transitionBoxLiIdx == index ? 'liHover' : ''" v-for="(item, index) in options" :key="index" @mouseover="liMouseOver(index, item)" @click.stop="liClist(item)">
  29. <span :class="item.children ? 'idxspan' : ''" v-if="!radios || fistRadio">
  30. <!-- {{item.label}} -->
  31. <span v-if="userName">
  32. <span v-if="item.type == 'dep'">
  33. <ww-open-data type='departmentName' :openid='item.label'></ww-open-data>
  34. </span>
  35. <span v-if="item.type == 'user'">
  36. <ww-open-data type='userName' :openid='item.label'></ww-open-data>
  37. </span>
  38. </span>
  39. <span v-if="!userName">
  40. <ww-open-data type='departmentName' :openid='item.label'></ww-open-data>
  41. </span>
  42. <!-- <ww-open-data type='departmentName' :openid='item.label'></ww-open-data> -->
  43. </span>
  44. <span v-if="radios && !fistRadio" style="margin-left: -15px">
  45. <el-radio v-model="optionsOId" :label="item.value">
  46. <span class="idxspan" style="margin-left: -10px">
  47. <!-- {{item.label}} -->
  48. <span v-if="userName">
  49. <span v-if="item.type == 'dep'">
  50. <ww-open-data type='departmentName' :openid='item.label'></ww-open-data>
  51. </span>
  52. <span v-if="item.type == 'user'">
  53. <ww-open-data type='userName' :openid='item.label'></ww-open-data>
  54. </span>
  55. </span>
  56. <span v-if="!userName">
  57. <ww-open-data type='departmentName' :openid='item.label'></ww-open-data>
  58. </span>
  59. <!-- <ww-open-data type='departmentName' :openid='item.label'></ww-open-data> -->
  60. </span>
  61. </el-radio>
  62. </span>
  63. <i class="el-icon-arrow-right" v-if="item.children"></i>
  64. </li>
  65. </ul>
  66. </div>
  67. <div v-for="(item, index) in options" :key="index">
  68. <div v-if="item.children" style="position: absolute;left: 200px;top: 6px">
  69. <cascaderOption :subject="item.children" :userName="userName" :radios="radios" v-show="transitionBoxLiIdx == index" @cascaderOptionClick="cascaderOptionClick"></cascaderOption>
  70. </div>
  71. </div>
  72. </div>
  73. </transition>
  74. </div>
  75. </template>
  76. <script>
  77. // 引入里面的
  78. import cascaderOption from "@/components/cascaderOption.vue"
  79. export default {
  80. components: {
  81. cascaderOption
  82. },
  83. props: {
  84. subject:{
  85. type: Array
  86. },
  87. size: {
  88. type: String,
  89. },
  90. subjectId: {
  91. type: [String, Number]
  92. },
  93. // 是否为单选
  94. radios: {
  95. type: Boolean,
  96. default: false
  97. },
  98. // 当前页面用到的第几个
  99. distinction: {
  100. type: String,
  101. default: '1',
  102. },
  103. // 真对填写日报单独处理
  104. idx: {
  105. type: String
  106. },
  107. flg: {
  108. type: Boolean,
  109. default: false, // 默认值,不是填写日报
  110. },
  111. // 剩下统一索引
  112. index: {
  113. type: String
  114. },
  115. // 是否禁用
  116. disabled: {
  117. type: Boolean,
  118. default: false
  119. },
  120. // 是否可清空
  121. clearable: {
  122. type: Boolean,
  123. default: false
  124. },
  125. // 是否可搜索
  126. filterable: {
  127. type: Boolean,
  128. default: false
  129. },
  130. // 其他数据
  131. other: {
  132. type: [String, Number, Boolean],
  133. default: false
  134. },
  135. // 宽度
  136. widthStr: {
  137. type: String,
  138. default: false
  139. },
  140. // 默认文字
  141. selectNameChuan: {
  142. type: String
  143. },
  144. userName: {
  145. type: Boolean,
  146. default: false
  147. },
  148. // 第一季是否不选中
  149. fistRadio: {
  150. type: Boolean,
  151. default: false
  152. }
  153. },
  154. data() {
  155. return {
  156. selectWidth: '150',
  157. selectHeight: '28',
  158. selectFontSize: '12',
  159. show: false, // 下拉框
  160. options: [], // 列表数据
  161. transitionBoxLiIdx: '-1', // hover 背景色
  162. selectName: this.$t('defaultText.pleaseChoose'), // 显示的文字
  163. classDiv: false, // 获得焦点样式
  164. optionsOId: '', // 选中人的id
  165. dailyListObj: null, // 填写日报的数据
  166. dailyListIndex: null, // 日报点的索引
  167. move: false,
  168. moveIon: false,
  169. hoverValIdx: '-1', // 鼠标移入的值
  170. hoverList: [],
  171. radioVal: ''
  172. };
  173. },
  174. computed: {},
  175. watch: {
  176. subject: {
  177. handler(newValue, oldValue) {
  178. this.options = newValue
  179. console.log(this.options, '我收到的数据')
  180. if(newValue) {
  181. }
  182. },
  183. },
  184. // 日报点的索引, 真对填写的日报
  185. idx: {
  186. handler(newValue, oldValue) {
  187. console.log(newValue, oldValue)
  188. this.dailyListIndex = newValue
  189. },
  190. },
  191. subjectId: {
  192. handler(newValue, oldValue) {
  193. console.log(newValue, '过来的id')
  194. this.optionsOId = newValue
  195. if(this.optionsOId && this.optionsOId.length != 0) {
  196. this.traverseArr(this.options, this.optionsOId)
  197. } else {
  198. this.selectName = this.$t('defaultText.pleaseChoose')
  199. }
  200. },
  201. },
  202. widthStr: {
  203. handler(newValue, oldValue) {
  204. this.selectWidth = newValue
  205. },
  206. }
  207. },
  208. created() {
  209. console.log(this.size)
  210. if(this.size == 'mini') {
  211. this.selectWidth = '150'
  212. this.selectHeight = '28'
  213. } else if(this.size == 'small') {
  214. this.selectWidth = '191'
  215. this.selectHeight = '32'
  216. } else if(this.size == 'medium') {
  217. this.selectWidth = '205'
  218. this.selectHeight = '40'
  219. this.selectFontSize = '14'
  220. }
  221. if(this.widthStr) {
  222. this.selectWidth = this.widthStr
  223. }
  224. },
  225. mounted() {
  226. if(this.selectNameChuan) {
  227. this.selectName = this.selectNameChuan
  228. }
  229. if(this.subject) {
  230. this.options = JSON.parse(JSON.stringify(this.subject))
  231. console.log(this.options, '我收到的数据')
  232. }
  233. if(this.subjectId) {
  234. this.optionsOId = JSON.parse(JSON.stringify(this.subjectId))
  235. console.log(this.options, '过来的数据')
  236. this.traverseArr(this.options, this.optionsOId)
  237. for(let i in this.options) {
  238. if(this.options[i].id == this.optionsOId || this.options[i].auditorId == this.optionsOId) {
  239. this.selectName = this.options[i].name || this.options[i].auditorName
  240. if(this.options[i].type) {
  241. this.selectNameType = this.options[i].type
  242. }
  243. }
  244. }
  245. }
  246. this.dailyListIndex = this.idx
  247. console.log(this.selectWidth, this.selectHeight)
  248. // this.moveIon = JSON.parse(JSON.stringify(this.clearable))
  249. },
  250. methods: {
  251. // 循环取值
  252. traverseArr(arr, idd){
  253. let id = idd[0]
  254. if(arr) {
  255. for(var i in arr) {
  256. console.log(arr[i].value, idd)
  257. if(arr[i].label != this.$t('lable.department') && arr[i].label != this.$t('designatedpersonnel')) {
  258. if(arr[i].value == idd) {
  259. console.log('将要付给的值', arr[i])
  260. this.selectName = arr[i].label
  261. if(arr[i].type) {
  262. this.selectNameType = arr[i].type
  263. }
  264. return
  265. }
  266. }
  267. if(arr[i].children) {
  268. this.traverseArr(arr[i].children, idd)
  269. }
  270. }
  271. }
  272. },
  273. selectCli() {
  274. if(!this.disabled) {
  275. this.$refs.selectDiv.focus()
  276. this.classDiv = !this.classDiv
  277. this.show = !this.show
  278. this.move = !this.move
  279. }
  280. },
  281. selectClihide() {
  282. if(this.classDiv) {
  283. let that = this
  284. setTimeout(function () {
  285. that.transitionBoxLiIdx = ''
  286. that.show = !that.show
  287. that.classDiv = false
  288. that.move = false
  289. }, 100)
  290. }
  291. },
  292. liMouseOver(index, item) {
  293. this.transitionBoxLiIdx = index
  294. if(item.children) {
  295. this.hoverList = []
  296. this.hoverList = item.children
  297. this.$forceUpdate()
  298. } else {
  299. this.hoverList = []
  300. }
  301. },
  302. // 点击
  303. liClist(item) {
  304. if(item.label != this.$t('lable.department') && item.label != this.$t('designatedpersonnel')) {
  305. if(!item.children) {
  306. this.selectName = item.label
  307. if(item.type) {
  308. this.selectNameType = item.type
  309. }
  310. let obj = {
  311. id: item.value,
  312. distinction: this.distinction
  313. }
  314. this.$emit('vueCasader', obj)
  315. }
  316. if(this.radios) {
  317. this.selectName = item.label
  318. if(item.type) {
  319. this.selectNameType = item.type
  320. }
  321. let obj = {
  322. id: item.value,
  323. distinction: this.distinction,
  324. item: item
  325. }
  326. this.$emit('vueCasader', obj)
  327. } else {
  328. this.transitionBoxLiIdx = ''
  329. this.show = !this.show
  330. this.classDiv = false
  331. this.move = false
  332. }
  333. }
  334. },
  335. // 接受子组件传过来的值
  336. cascaderOptionClick(item) {
  337. this.liClist(item)
  338. },
  339. moveIonDiv() {
  340. console.log(this.selectName)
  341. if(this.clearable) {
  342. if(this.selectName != this.$t('defaultText.pleaseChoose')) {
  343. this.moveIon = true
  344. }
  345. }
  346. },
  347. outIonDiv() {
  348. if(this.clearable) {
  349. this.moveIon = false
  350. }
  351. },
  352. clearDelete() {
  353. this.selectName = this.$t('defaultText.pleaseChoose')
  354. let obj = {
  355. label: this.$t('defaultText.pleaseChoose'),
  356. value: ''
  357. }
  358. this.show = false
  359. this.classDiv = false
  360. this.move = false
  361. this.liClist(obj)
  362. }
  363. },
  364. triggerOption(){
  365. },
  366. choose(item,value){
  367. },
  368. };
  369. </script>
  370. <style scoped lang="scss">
  371. .selectDiv {
  372. border-color: #409EFF !important;
  373. }
  374. .disabledTrue {
  375. background: #F5F7FA !important;
  376. border-radius: 4px;
  377. cursor: not-allowed !important;
  378. position: relative;
  379. }
  380. .disabledFalse .select {
  381. background: #FFF;
  382. border-radius: 4px;
  383. }
  384. .select {
  385. -webkit-appearance: none;
  386. // background-color: #FFF;
  387. background-image: none;
  388. border-radius: 4px;
  389. border: 1px solid #DCDFE6;
  390. -webkit-box-sizing: border-box;
  391. box-sizing: border-box;
  392. color: #606266;
  393. display: inline-block;
  394. font-size: inherit;
  395. height: 40px;
  396. line-height: 40px;
  397. outline: 0;
  398. padding: 0 15px;
  399. -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  400. transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  401. width: 100%;
  402. position: relative;
  403. cursor: pointer;
  404. }
  405. .selecttex {
  406. height: 28px;
  407. line-height: 28px;
  408. text-overflow: ellipsis;
  409. font-size: 12px;
  410. }
  411. .selecttex span {
  412. padding: 0 !important;
  413. }
  414. .iostu {
  415. position: absolute;
  416. top: 50%;
  417. margin-top: -4px;
  418. right: 8px;
  419. color: #C0C4CC;
  420. transition: All 0.2s ease-in-out;
  421. }
  422. .iostuHover {
  423. transform: rotate(-180deg);
  424. }
  425. .transitionBox {
  426. background: #FFF;
  427. position: absolute;
  428. min-width: 200px;
  429. border-radius: 2em;
  430. border: 1px solid #E4E7ED;
  431. border-radius: 4px;
  432. background-color: #FFF;
  433. box-sizing: border-box;
  434. margin: 5px 0;
  435. // box-shadow: 0 2px 12px #dfdfdf;
  436. height: 274px;
  437. overflow: auto;
  438. z-index: 500 !important;
  439. }
  440. .transitionBoxUl {
  441. list-style: none;
  442. padding: 6px 0;
  443. margin: 0;
  444. -webkit-box-sizing: border-box;
  445. box-sizing: border-box;
  446. }
  447. .transitionBoxUl li {
  448. font-size: 14px;
  449. padding: 0 20px;
  450. // position: relative;
  451. white-space: nowrap;
  452. overflow: hidden;
  453. text-overflow: ellipsis;
  454. color: #606266;
  455. height: 34px;
  456. line-height: 34px;
  457. -webkit-box-sizing: border-box;
  458. box-sizing: border-box;
  459. cursor: pointer;
  460. display: flex;
  461. align-items: center;
  462. }
  463. .liHover {
  464. background-color: #F5F7FA;
  465. // color: #409eff !important;
  466. }
  467. .liHover .idxspan {
  468. color: #409eff !important;
  469. font-weight: 700;
  470. }
  471. .idxspan span{
  472. padding: 0 !important;
  473. }
  474. .transitionBoxUl span {
  475. flex: 1;
  476. width: 110px;
  477. width: 20px;
  478. padding: 0 10px;
  479. white-space: nowrap;
  480. overflow: hidden;
  481. text-overflow: ellipsis;
  482. }
  483. .selecttexXuan {
  484. color: #C0C4CC;;
  485. }
  486. </style>