select.vue 25 KB

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