cascader.vue 12 KB

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