select.vue 19 KB

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