select.vue 18 KB

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