select.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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">
  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].auditorName || newValue[0].name
  188. this.optionsOId = newValue[0].auditorId || newValue[0].id
  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].userId == this.optionsOId || this.options[i].auditorId == this.optionsOId || this.options[i].id == 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].userId == this.optionsOId || this.options[i].auditorId == this.optionsOId[j] || this.options[i].id == 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].userId == this.optionsOId || this.options[i].auditorId == this.optionsOId || this.options[i].id == this.optionsOId) {
  259. this.selectName = this.options[i].auditorName || this.options[i].name
  260. }
  261. }
  262. }
  263. console.log(this.options, this.subjectId)
  264. if(this.multiSelect) {
  265. for(var i in this.options) {
  266. for(var j in this.subjectId) {
  267. if(this.options[i].id == this.subjectId[j] || this.options[i].auditorId == this.subjectId[j]) {
  268. this.multiSelectList.push(this.options[i])
  269. this.options[i].flg = true
  270. }
  271. }
  272. }
  273. }
  274. }
  275. console.log(this.subject, this.subjectId)
  276. this.dailyListIndex = this.idx
  277. },
  278. methods: {
  279. dianjis() {
  280. if(!this.disabled) {
  281. let modes = this.multiSelect ? 'multi' : 'single'
  282. let that = this
  283. wx.invoke("selectEnterpriseContact", {
  284. "fromDepartmentId": 0,// 必填,表示打开的通讯录从指定的部门开始展示,-1表示自己所在部门开始, 0表示从最上层开始
  285. "mode": modes,// 必填,选择模式,single表示单选,multi表示多选
  286. "type": ["user"],// 必填,选择限制类型,指定department、user中的一个或者多个
  287. "selectedDepartmentIds": [],// 非必填,已选部门ID列表。用于多次选人时可重入,single模式下请勿填入多个id
  288. "selectedUserIds": []// 非必填,已选用户ID列表。用于多次选人时可重入,single模式下请勿填入多个id
  289. },function(res){
  290. console.log(res)
  291. if (res.err_msg == "selectEnterpriseContact:ok"){
  292. console.log(res, '数据来源')
  293. if(typeof res.result == 'string'){
  294. res.result = JSON.parse(res.result) //由于目前各个终端尚未完全兼容,需要开发者额外判断result类型以保证在各个终端的兼容性
  295. }
  296. var selectedUserList = res.result.userList; // 已选的成员列表
  297. var userId = ''
  298. var userName = ''
  299. for (var i = 0; i < selectedUserList.length; i++) {
  300. var user = selectedUserList[i];
  301. userId = user.id; // 已选的单个成员ID
  302. userName = user.name;// 已选的单个成员名称
  303. console.log(userId, userName)
  304. }
  305. for(var s in that.options) {
  306. if(that.options[s].name == userId) {
  307. that.selectName = userId
  308. that.wxCoper(that.options[s].id)
  309. }
  310. }
  311. }
  312. }
  313. );
  314. }
  315. },
  316. wxCoper(id) {
  317. let obj = {
  318. id: id,
  319. distinction: this.distinction,
  320. index: this.index, // 选中的索引
  321. other: this.other,
  322. name: this.selectName
  323. }
  324. console.log(obj)
  325. this.$emit("selectCal", obj)
  326. },
  327. selectCli() {
  328. if(!this.disabled) {
  329. this.$refs.selectDiv.focus()
  330. this.classDiv = !this.classDiv
  331. this.show = !this.show
  332. this.move = !this.move
  333. this.searchTex = ''
  334. }
  335. },
  336. selectClihide() {
  337. if(this.classDiv) {
  338. this.transitionBoxLiIdx = ''
  339. this.show = !this.show
  340. this.classDiv = false
  341. this.move = false
  342. if(this.multiSelect) {
  343. let obj = {
  344. // id: nameId,
  345. distinction: this.distinction,
  346. index: this.index, // 选中的索引
  347. other: this.other,
  348. arrUserList: this.multiSelectList,
  349. name: this.selectName
  350. }
  351. this.$emit("selectCal", obj)
  352. }
  353. }
  354. },
  355. liMouseOver(index) {
  356. this.transitionBoxLiIdx = index
  357. },
  358. liClick(item, itemIndex) {
  359. console.log(item, '进来的')
  360. let nameId = item.auditorId || item.id
  361. this.selectName = item.auditorName || item.name
  362. if(!this.multiSelect) {
  363. console.log('我进来了', this.flg)
  364. if(this.flgs) {
  365. let obj = {
  366. id: nameId,
  367. idx: this.dailyListIndex
  368. }
  369. this.$emit("selectCatCli", obj);
  370. } else {
  371. let obj = {
  372. id: nameId,
  373. distinction: this.distinction,
  374. index: this.index, // 选中的索引
  375. other: this.other,
  376. name: this.selectName
  377. }
  378. this.$emit("selectCal", obj)
  379. }
  380. this.transitionBoxLiIdx = ''
  381. this.show = false
  382. this.classDiv = false
  383. this.move = false
  384. }
  385. if(this.multiSelect) {
  386. if(this.options[itemIndex].flg) {
  387. this.options[itemIndex].flg = !this.options[itemIndex].flg
  388. for(var i in this.multiSelectList) {
  389. if(this.multiSelectList[i].id == item.id) {
  390. this.multiSelectList.splice(i, 1)
  391. }
  392. }
  393. } else {
  394. this.options[itemIndex].flg = false
  395. this.options[itemIndex].flg = !this.options[itemIndex].flg
  396. this.multiSelectList.push(item)
  397. }
  398. }
  399. },
  400. moveIonDiv() {
  401. if(this.clearable) {
  402. this.moveIon = true
  403. }
  404. },
  405. outIonDiv() {
  406. if(this.clearable) {
  407. this.moveIon = false
  408. }
  409. },
  410. clearDelete() {
  411. if(!this.multiSelect) {
  412. this.selectName = this.$t('defaultText.pleaseChoose')
  413. let obj = {
  414. name: this.$t('defaultText.pleaseChoose'),
  415. id: ''
  416. }
  417. this.liClick(obj)
  418. }
  419. if(this.multiSelect) {
  420. this.multiSelectList = []
  421. let obj = {
  422. distinction: this.distinction,
  423. index: this.index, // 选中的索引
  424. other: this.other,
  425. arrUserList: []
  426. }
  427. for(var i in this.options) {
  428. if(this.options[i].flg) {
  429. this.options[i].flg = false
  430. }
  431. }
  432. this.$emit("selectCal", obj)
  433. }
  434. },
  435. deleteMultiSelectList(str) {
  436. let userId
  437. if(str == '-1') {
  438. userId = this.multiSelectList[0].id
  439. this.multiSelectList.splice(0, 1)
  440. } else {
  441. userId = this.multiSelectList[str].id
  442. this.multiSelectList.splice(str, 1)
  443. }
  444. for(var i in this.options) {
  445. if(this.options[i].id == userId) {
  446. if(this.options[i].flg) {
  447. this.options[i].flg = false
  448. }
  449. }
  450. }
  451. let obj = {
  452. distinction: this.distinction,
  453. index: this.index, // 选中的索引
  454. other: this.other,
  455. arrUserList: this.multiSelectList,
  456. name: this.selectName
  457. }
  458. this.$emit("selectCal", obj)
  459. },
  460. searchBox() {
  461. this.selectCli()
  462. },
  463. // 搜索
  464. searchLick() {
  465. console.log('文字')
  466. this.getSimpleActiveUserList()
  467. },
  468. // 针对 getSimpleActiveUserList 获取所有人员接口
  469. getSimpleActiveUserList() {
  470. this.http.post('/user/getSimpleActiveUserList', {
  471. keyword: this.searchTex,
  472. cursor: this.cursor
  473. },
  474. res => {
  475. if (res.code == "ok") {
  476. console.log('数据')
  477. this.options = res.data.retUser
  478. this.cursor = res.data.nextCursor
  479. } else {
  480. this.$message({
  481. message: res.msg,
  482. type: "error"
  483. });
  484. }
  485. },
  486. error => {
  487. this.$message({
  488. message: error,
  489. type: "error"
  490. });
  491. });
  492. }
  493. },
  494. triggerOption(){
  495. },
  496. choose(item,value){
  497. },
  498. };
  499. </script>
  500. <style scoped lang="scss">
  501. .selectDandu {
  502. font-size: 16px;
  503. }
  504. .waihez {
  505. // padding-top: 7px;
  506. // box-sizing: border-box;
  507. // background: #FFF;
  508. display: inline-block;
  509. }
  510. .selectDiv {
  511. border-color: #409EFF !important;
  512. }
  513. .disabledTrue {
  514. background: #F5F7FA !important;
  515. border-radius: 4px;
  516. cursor: not-allowed !important;
  517. position: relative;
  518. }
  519. .disabledFalse .select {
  520. background: #FFF !important;
  521. border-radius: 4px;
  522. }
  523. .select {
  524. -webkit-appearance: none;
  525. // background-color: #FFF;
  526. background-image: none;
  527. border-radius: 4px;
  528. border: 1px solid #DCDFE6;
  529. -webkit-box-sizing: border-box;
  530. box-sizing: border-box;
  531. color: #606266;
  532. display: inline-block;
  533. font-size: inherit;
  534. height: 40px;
  535. line-height: 40px;
  536. outline: 0;
  537. padding: 0 15px;
  538. -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  539. transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  540. width: 100%;
  541. position: relative;
  542. cursor: pointer;
  543. }
  544. .selecttex {
  545. height: 28px;
  546. line-height: 28px;
  547. text-overflow: ellipsis;
  548. font-size: 12px;
  549. }
  550. .iostu {
  551. position: absolute;
  552. top: 50%;
  553. margin-top: -4px;
  554. right: 8px;
  555. color: #C0C4CC;
  556. transition: All 0.2s ease-in-out;
  557. }
  558. .iostuHover {
  559. transform: rotate(-180deg);
  560. }
  561. .searchBox {
  562. position: absolute;
  563. width: 100%;
  564. }
  565. .transitionBox {
  566. background: #FFF;
  567. position: absolute;
  568. width: 100%;
  569. border-radius: 2em;
  570. border: 1px solid #E4E7ED;
  571. border-radius: 4px;
  572. background-color: #FFF;
  573. box-sizing: border-box;
  574. margin: 5px 0;
  575. box-shadow: 0 2px 12px #dfdfdf;
  576. max-height: 274px;
  577. overflow: auto;
  578. z-index: 500 !important;
  579. }
  580. .transitionBoxUl {
  581. list-style: none;
  582. padding: 6px 0;
  583. margin: 0;
  584. -webkit-box-sizing: border-box;
  585. box-sizing: border-box;
  586. }
  587. .transitionBoxUl li {
  588. font-size: 14px;
  589. padding: 0 20px;
  590. position: relative;
  591. white-space: nowrap;
  592. overflow: hidden;
  593. text-overflow: ellipsis;
  594. color: #606266;
  595. height: 34px;
  596. line-height: 34px;
  597. -webkit-box-sizing: border-box;
  598. box-sizing: border-box;
  599. cursor: pointer;
  600. }
  601. .liHover {
  602. background-color: #F5F7FA;
  603. }
  604. .selecttexXuan {
  605. color: #C0C4CC;;
  606. }
  607. .all {
  608. display: inline-block;
  609. font-size: 10px;
  610. background: #f4f4f5;
  611. height: 20px;
  612. line-height: 24px;
  613. padding: 0px 8px;
  614. color: #909399;
  615. }
  616. .allTwo {
  617. display: inline-block;
  618. margin-left: 10px;
  619. }
  620. .hoverSpan {
  621. display: flex;
  622. width: 100%;
  623. justify-content: space-between;
  624. }
  625. .hoverSpanHover {
  626. color: #409eff;
  627. font-weight: 700;
  628. }
  629. .spanFllat {
  630. display: inline-block;
  631. float: right;
  632. }
  633. </style>