cascader.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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. <!-- <TranslationOpenDataText type='departmentName' :openid='selectName'></TranslationOpenDataText> -->
  7. <!-- {{selectName}} -->
  8. <span v-if="userName">
  9. <span v-if="selectNameType == 'dep'">
  10. <TranslationOpenDataText type='departmentName' :openid='selectName'></TranslationOpenDataText>
  11. </span>
  12. <span v-if="selectNameType == 'user'">
  13. <TranslationOpenDataText type='userName' :openid='selectName'></TranslationOpenDataText>
  14. </span>
  15. </span>
  16. <span v-if="!userName">
  17. <TranslationOpenDataText type='departmentName' :openid='selectName'></TranslationOpenDataText>
  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. <TranslationOpenDataText type='departmentName' :openid='item.label'></TranslationOpenDataText>
  34. </span>
  35. <span v-if="item.type == 'user'">
  36. <TranslationOpenDataText type='userName' :openid='item.label'></TranslationOpenDataText>
  37. </span>
  38. </span>
  39. <span v-if="!userName">
  40. <TranslationOpenDataText type='departmentName' :openid='item.label'></TranslationOpenDataText>
  41. </span>
  42. <!-- <TranslationOpenDataText type='departmentName' :openid='item.label'></TranslationOpenDataText> -->
  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. <TranslationOpenDataText type='departmentName' :openid='item.label'></TranslationOpenDataText>
  51. </span>
  52. <span v-if="item.type == 'user'">
  53. <TranslationOpenDataText type='userName' :openid='item.label'></TranslationOpenDataText>
  54. </span>
  55. </span>
  56. <span v-if="!userName">
  57. <TranslationOpenDataText type='departmentName' :openid='item.label'></TranslationOpenDataText>
  58. </span>
  59. <!-- <TranslationOpenDataText type='departmentName' :openid='item.label'></TranslationOpenDataText> -->
  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 = null
  254. if(Array.isArray(idd)) {
  255. id = idd[idd.length - 1]
  256. } else {
  257. id = idd[0]
  258. }
  259. if(arr) {
  260. for(var i in arr) {
  261. // console.log(arr[i].value, idd, id)
  262. if(arr[i].label != this.$t('lable.department') && arr[i].label != this.$t('designatedpersonnel')) {
  263. if(arr[i].value == id) {
  264. console.log('将要付给的值', arr[i])
  265. this.selectName = arr[i].label
  266. if(arr[i].type) {
  267. this.selectNameType = arr[i].type
  268. }
  269. return
  270. }
  271. }
  272. if(arr[i].children) {
  273. this.traverseArr(arr[i].children, idd)
  274. }
  275. }
  276. }
  277. },
  278. selectCli() {
  279. if(!this.disabled) {
  280. this.$refs.selectDiv.focus()
  281. this.classDiv = !this.classDiv
  282. this.show = !this.show
  283. this.move = !this.move
  284. }
  285. },
  286. selectClihide() {
  287. if(this.classDiv) {
  288. let that = this
  289. setTimeout(function () {
  290. that.transitionBoxLiIdx = ''
  291. that.show = !that.show
  292. that.classDiv = false
  293. that.move = false
  294. }, 150)
  295. }
  296. },
  297. liMouseOver(index, item) {
  298. this.transitionBoxLiIdx = index
  299. if(item.children) {
  300. this.hoverList = []
  301. this.hoverList = item.children
  302. this.$forceUpdate()
  303. } else {
  304. this.hoverList = []
  305. }
  306. },
  307. // 点击
  308. liClist(item) {
  309. if(item.label != this.$t('lable.department') && item.label != this.$t('designatedpersonnel')) {
  310. if(!item.children) {
  311. this.selectName = item.label
  312. if(item.type) {
  313. this.selectNameType = item.type
  314. }
  315. let obj = {
  316. id: item.value,
  317. distinction: this.distinction,
  318. other: this.other
  319. }
  320. this.$emit('vueCasader', obj)
  321. }
  322. if(this.radios) {
  323. this.selectName = item.label
  324. if(item.type) {
  325. this.selectNameType = item.type
  326. }
  327. let obj = {
  328. id: item.value,
  329. distinction: this.distinction,
  330. item: item,
  331. other: this.other
  332. }
  333. this.$emit('vueCasader', obj)
  334. } else {
  335. this.transitionBoxLiIdx = ''
  336. this.show = !this.show
  337. this.classDiv = false
  338. this.move = false
  339. }
  340. }
  341. },
  342. // 接受子组件传过来的值
  343. cascaderOptionClick(item) {
  344. this.liClist(item)
  345. },
  346. moveIonDiv() {
  347. // console.log(this.selectName)
  348. if(this.clearable) {
  349. if(this.selectName != this.$t('defaultText.pleaseChoose')) {
  350. this.moveIon = true
  351. }
  352. }
  353. },
  354. outIonDiv() {
  355. if(this.clearable) {
  356. this.moveIon = false
  357. }
  358. },
  359. clearDelete() {
  360. this.selectName = this.$t('defaultText.pleaseChoose')
  361. let obj = {
  362. label: this.$t('defaultText.pleaseChoose'),
  363. value: ''
  364. }
  365. const that = this
  366. setTimeout(()=>{
  367. that.show = false
  368. that.classDiv = false
  369. that.move = false
  370. }, 200)
  371. this.liClist(obj)
  372. }
  373. },
  374. triggerOption(){
  375. },
  376. choose(item,value){
  377. },
  378. };
  379. </script>
  380. <style scoped lang="scss">
  381. @import "../assets/scss/handle";
  382. .selectDiv {
  383. @include background_color("background_color");
  384. }
  385. .disabledTrue {
  386. background: #F5F7FA !important;
  387. border-radius: 4px;
  388. cursor: not-allowed !important;
  389. position: relative;
  390. }
  391. .disabledFalse .select {
  392. background: #FFF;
  393. border-radius: 4px;
  394. }
  395. .select {
  396. -webkit-appearance: none;
  397. // background-color: #FFF;
  398. background-image: none;
  399. border-radius: 4px;
  400. border: 1px solid #DCDFE6;
  401. -webkit-box-sizing: border-box;
  402. box-sizing: border-box;
  403. color: #606266;
  404. display: inline-block;
  405. font-size: inherit;
  406. height: 40px;
  407. line-height: 40px;
  408. outline: 0;
  409. padding: 0 15px;
  410. -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  411. transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  412. width: 100%;
  413. position: relative;
  414. cursor: pointer;
  415. }
  416. .selecttex {
  417. height: 28px;
  418. line-height: 28px;
  419. text-overflow: ellipsis;
  420. font-size: 12px;
  421. }
  422. .selecttex span {
  423. padding: 0 !important;
  424. }
  425. .iostu {
  426. position: absolute;
  427. top: 50%;
  428. margin-top: -4px;
  429. right: 8px;
  430. color: #C0C4CC;
  431. transition: All 0.2s ease-in-out;
  432. }
  433. .iostuHover {
  434. transform: rotate(-180deg);
  435. }
  436. .transitionBox {
  437. background: #FFF;
  438. position: absolute;
  439. min-width: 200px;
  440. border-radius: 2em;
  441. border: 1px solid #E4E7ED;
  442. border-radius: 4px;
  443. background-color: #FFF;
  444. box-sizing: border-box;
  445. margin: 5px 0;
  446. // box-shadow: 0 2px 12px #dfdfdf;
  447. height: 274px;
  448. overflow: auto;
  449. z-index: 500 !important;
  450. }
  451. .transitionBoxUl {
  452. list-style: none;
  453. padding: 6px 0;
  454. margin: 0;
  455. -webkit-box-sizing: border-box;
  456. box-sizing: border-box;
  457. }
  458. .transitionBoxUl li {
  459. font-size: 14px;
  460. padding: 0 20px;
  461. // position: relative;
  462. white-space: nowrap;
  463. overflow: hidden;
  464. text-overflow: ellipsis;
  465. color: #606266;
  466. height: 34px;
  467. line-height: 34px;
  468. -webkit-box-sizing: border-box;
  469. box-sizing: border-box;
  470. cursor: pointer;
  471. display: flex;
  472. align-items: center;
  473. }
  474. .liHover {
  475. background-color: #F5F7FA;
  476. }
  477. .liHover .idxspan {
  478. @include font_color("color");
  479. font-weight: 700;
  480. }
  481. .idxspan span{
  482. padding: 0 !important;
  483. }
  484. .transitionBoxUl span {
  485. flex: 1;
  486. width: 110px;
  487. width: 20px;
  488. padding: 0 10px;
  489. white-space: nowrap;
  490. overflow: hidden;
  491. text-overflow: ellipsis;
  492. }
  493. .selecttexXuan {
  494. color: #C0C4CC;;
  495. }
  496. </style>