select.vue 18 KB

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