select.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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. components: {
  130. selectWidth: '150',
  131. selectHeight: '28'
  132. },
  133. data() {
  134. return {
  135. selectWidth: '150',
  136. selectHeight: '28',
  137. selectFontSize: '12',
  138. show: false, // 下拉框
  139. options: [], // 列表数据
  140. transitionBoxLiIdx: '', // hover 背景色
  141. selectName: this.$t('defaultText.pleaseChoose'), // 显示的文字
  142. classDiv: false, // 获得焦点样式
  143. optionsOId: '', // 选中人的id
  144. dailyListObj: null, // 填写日报的数据
  145. dailyListIndex: null, // 日报点的索引
  146. move: false,
  147. moveIon: false,
  148. multiSelectList: []
  149. };
  150. },
  151. computed: {},
  152. watch: {
  153. subject: {
  154. handler(newValue, oldValue) {
  155. this.options = newValue
  156. if(this.flg) {
  157. if(newValue) {
  158. this.selectName = newValue[0].name || newValue[0].auditorName
  159. this.optionsOId = newValue[0].id || newValue[0].auditorId
  160. }
  161. }
  162. },
  163. },
  164. // 日报点的索引, 真对填写的日报
  165. idx: {
  166. handler(newValue, oldValue) {
  167. console.log(newValue, oldValue)
  168. this.dailyListIndex = newValue
  169. },
  170. },
  171. subjectId: {
  172. handler(newValue, oldValue) {
  173. console.log(newValue, oldValue)
  174. this.optionsOId = newValue
  175. this.multiSelectList = []
  176. if(!this.multiSelect) {
  177. if(this.optionsOId) {
  178. for(let i in this.options) {
  179. if(this.options[i].id == this.optionsOId || this.options[i].auditorId == this.optionsOId) {
  180. this.selectName = this.options[i].name || this.options[i].auditorName
  181. }
  182. }
  183. } else {
  184. this.selectName = this.$t('defaultText.pleaseChoose')
  185. }
  186. }
  187. if(this.multiSelect) {
  188. for(var i in this.options) {
  189. for(var j in this.optionsOId) {
  190. if(this.options[i].id == this.optionsOId[j] || this.options[i].auditorId == this.optionsOId[j]) {
  191. this.multiSelectList.push(this.options[i])
  192. this.options[i].flg = true
  193. }
  194. }
  195. }
  196. }
  197. },
  198. },
  199. widthStr: {
  200. handler(newValue, oldValue) {
  201. this.selectWidth = newValue
  202. },
  203. }
  204. },
  205. created() {},
  206. mounted() {
  207. if(this.size == 'mini') {
  208. this.selectWidth = '150'
  209. this.selectHeight = '28'
  210. } else if(this.size == 'small') {
  211. this.selectWidth = '191'
  212. this.selectHeight = '32'
  213. } else if(this.size == 'medium') {
  214. this.selectWidth = '205'
  215. this.selectHeight = '40'
  216. this.selectFontSize = '14'
  217. }
  218. if(this.widthStr) {
  219. this.selectWidth = this.widthStr
  220. }
  221. if(this.subject) {
  222. this.options = JSON.parse(JSON.stringify(this.subject))
  223. }
  224. if(this.subjectId) {
  225. this.multiSelectList = []
  226. if(!this.multiSelect) {
  227. this.optionsOId = JSON.parse(JSON.stringify(this.subjectId))
  228. for(let i in this.options) {
  229. if(this.options[i].id == this.optionsOId || this.options[i].auditorId == this.optionsOId) {
  230. this.selectName = this.options[i].name || this.options[i].auditorName
  231. }
  232. }
  233. }
  234. if(this.multiSelect) {
  235. for(var i in this.options) {
  236. for(var j in this.optionsOId) {
  237. if(this.options[i].id == this.optionsOId[j] || this.options[i].auditorId == this.optionsOId[j]) {
  238. this.multiSelectList.push(this.options[i])
  239. this.options[i].flg = true
  240. }
  241. }
  242. }
  243. }
  244. }
  245. console.log(this.subject)
  246. this.dailyListIndex = this.idx
  247. },
  248. methods: {
  249. selectCli() {
  250. if(!this.disabled) {
  251. this.$refs.selectDiv.focus()
  252. this.classDiv = !this.classDiv
  253. this.show = !this.show
  254. this.move = !this.move
  255. }
  256. },
  257. selectClihide() {
  258. if(this.classDiv) {
  259. this.transitionBoxLiIdx = ''
  260. this.show = !this.show
  261. this.classDiv = false
  262. this.move = false
  263. if(this.multiSelect) {
  264. let obj = {
  265. // id: nameId,
  266. distinction: this.distinction,
  267. index: this.index, // 选中的索引
  268. other: this.other,
  269. arrUserList: this.multiSelectList
  270. }
  271. this.$emit("selectCal", obj)
  272. }
  273. }
  274. },
  275. liMouseOver(index) {
  276. this.transitionBoxLiIdx = index
  277. },
  278. liClick(item, itemIndex) {
  279. let nameId = item.id || item.auditorId
  280. if(!this.multiSelect) {
  281. if(this.flg) {
  282. let obj = {
  283. id: nameId,
  284. idx: this.dailyListIndex
  285. }
  286. this.$emit("selectCatCli", obj);
  287. } else {
  288. let obj = {
  289. id: nameId,
  290. distinction: this.distinction,
  291. index: this.index, // 选中的索引
  292. other: this.other
  293. }
  294. this.$emit("selectCal", obj)
  295. }
  296. this.selectName = item.name || item.auditorName
  297. this.transitionBoxLiIdx = ''
  298. this.show = false
  299. this.classDiv = false
  300. this.move = false
  301. }
  302. if(this.multiSelect) {
  303. if(this.options[itemIndex].flg) {
  304. this.options[itemIndex].flg = !this.options[itemIndex].flg
  305. for(var i in this.multiSelectList) {
  306. if(this.multiSelectList[i].id == item.id) {
  307. this.multiSelectList.splice(i, 1)
  308. }
  309. }
  310. } else {
  311. this.options[itemIndex].flg = false
  312. this.options[itemIndex].flg = !this.options[itemIndex].flg
  313. this.multiSelectList.push(item)
  314. }
  315. }
  316. },
  317. moveIonDiv() {
  318. if(this.clearable) {
  319. this.moveIon = true
  320. }
  321. },
  322. outIonDiv() {
  323. if(this.clearable) {
  324. this.moveIon = false
  325. }
  326. },
  327. clearDelete() {
  328. if(!this.multiSelect) {
  329. this.selectName = this.$t('defaultText.pleaseChoose')
  330. let obj = {
  331. name: this.$t('defaultText.pleaseChoose'),
  332. id: ''
  333. }
  334. this.liClick(obj)
  335. }
  336. if(this.multiSelect) {
  337. this.multiSelectList = []
  338. let obj = {
  339. distinction: this.distinction,
  340. index: this.index, // 选中的索引
  341. other: this.other,
  342. arrUserList: []
  343. }
  344. for(var i in this.options) {
  345. if(this.options[i].flg) {
  346. this.options[i].flg = false
  347. }
  348. }
  349. this.$emit("selectCal", obj)
  350. }
  351. },
  352. deleteMultiSelectList(str) {
  353. let userId
  354. if(str == '-1') {
  355. userId = this.multiSelectList[0].id
  356. this.multiSelectList.splice(0, 1)
  357. } else {
  358. userId = this.multiSelectList[str].id
  359. this.multiSelectList.splice(str, 1)
  360. }
  361. for(var i in this.options) {
  362. if(this.options[i].id == userId) {
  363. if(this.options[i].flg) {
  364. this.options[i].flg = false
  365. }
  366. }
  367. }
  368. let obj = {
  369. distinction: this.distinction,
  370. index: this.index, // 选中的索引
  371. other: this.other,
  372. arrUserList: this.multiSelectList
  373. }
  374. this.$emit("selectCal", obj)
  375. }
  376. },
  377. triggerOption(){
  378. },
  379. choose(item,value){
  380. },
  381. };
  382. </script>
  383. <style scoped lang="scss">
  384. .selectDiv {
  385. border-color: #409EFF !important;
  386. }
  387. .disabledTrue {
  388. background: #F5F7FA !important;
  389. border-radius: 4px;
  390. cursor: not-allowed !important;
  391. position: relative;
  392. }
  393. .disabledFalse .select {
  394. background: #FFF !important;
  395. border-radius: 4px;
  396. }
  397. .select {
  398. -webkit-appearance: none;
  399. // background-color: #FFF;
  400. background-image: none;
  401. border-radius: 4px;
  402. border: 1px solid #DCDFE6;
  403. -webkit-box-sizing: border-box;
  404. box-sizing: border-box;
  405. color: #606266;
  406. display: inline-block;
  407. font-size: inherit;
  408. height: 40px;
  409. line-height: 40px;
  410. outline: 0;
  411. padding: 0 15px;
  412. -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  413. transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  414. width: 100%;
  415. position: relative;
  416. cursor: pointer;
  417. }
  418. .selecttex {
  419. height: 28px;
  420. line-height: 28px;
  421. text-overflow: ellipsis;
  422. font-size: 12px;
  423. }
  424. .iostu {
  425. position: absolute;
  426. top: 50%;
  427. margin-top: -4px;
  428. right: 8px;
  429. color: #C0C4CC;
  430. transition: All 0.2s ease-in-out;
  431. }
  432. .iostuHover {
  433. transform: rotate(-180deg);
  434. }
  435. .transitionBox {
  436. background: #FFF;
  437. position: absolute;
  438. width: 100%;
  439. border-radius: 2em;
  440. border: 1px solid #E4E7ED;
  441. border-radius: 4px;
  442. background-color: #FFF;
  443. box-sizing: border-box;
  444. margin: 5px 0;
  445. box-shadow: 0 2px 12px #dfdfdf;
  446. max-height: 274px;
  447. overflow: auto;
  448. z-index: 500 !important;
  449. }
  450. .transitionBoxUl {
  451. list-style: none;
  452. padding: 6px 0;
  453. margin: 0;
  454. -webkit-box-sizing: border-box;
  455. box-sizing: border-box;
  456. }
  457. .transitionBoxUl li {
  458. font-size: 14px;
  459. padding: 0 20px;
  460. position: relative;
  461. white-space: nowrap;
  462. overflow: hidden;
  463. text-overflow: ellipsis;
  464. color: #606266;
  465. height: 34px;
  466. line-height: 34px;
  467. -webkit-box-sizing: border-box;
  468. box-sizing: border-box;
  469. cursor: pointer;
  470. }
  471. .liHover {
  472. background-color: #F5F7FA;
  473. }
  474. .selecttexXuan {
  475. color: #C0C4CC;;
  476. }
  477. .all {
  478. display: inline-block;
  479. font-size: 10px;
  480. background: #f4f4f5;
  481. height: 20px;
  482. line-height: 24px;
  483. padding: 0px 8px;
  484. color: #909399;
  485. }
  486. .allTwo {
  487. display: inline-block;
  488. margin-left: 10px;
  489. }
  490. .hoverSpan {
  491. display: flex;
  492. width: 100%;
  493. justify-content: space-between;
  494. }
  495. .hoverSpanHover {
  496. color: #409eff;
  497. font-weight: 700;
  498. }
  499. </style>