select.vue 23 KB

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