select.vue 17 KB

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