123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690 |
- <template>
- <div style="display: inline-block;">
- <div tabindex="0" @blur="selectClihide()" style="display: inline-block;" v-if="!wxCope">
- <!-- <div :style="'width:' + selectWidth + 'px;height:' + selectHeight + 'px'" :class="classDiv ? 'select selectDiv' : 'select'" @click="selectCli" :ref="disabled ? '' : 'selectDiv'"> -->
- <div :class="disabled ? 'disabledTrue' : 'disabledFalse'" @mouseenter="moveIonDiv" @mouseleave="outIonDiv">
- <div :style="`width:${selectWidth}px;height:${selectHeight}px`" :class="classDiv ? 'select selectDiv' : 'select'" @click="selectCli" :ref="disabled ? '' : 'selectDiv'">
- <div v-if="!multiSelect" :style="'line-height: '+selectHeight+'px;font-size: '+selectFontSize+'px;'" :class="selectName == $t('defaultText.pleaseChoose') ? 'selecttex selecttexXuan' : 'selecttex'">
- <ww-open-data type='userName' :openid='selectName'></ww-open-data>
- <!-- {{selectName}} -->
- </div>
- <div v-if="multiSelect" :style="'line-height: '+selectHeight+'px;margin-left: -10px'" :class="selectName == $t('defaultText.pleaseChoose') ? 'selecttex selecttexXuan' : 'selecttex'">
- <span v-if="multiSelectList.length > 0">
- <span v-if="!tile" style="width: 100%">
- <span class="all">
- <ww-open-data type='userName' :openid='multiSelectList[0].name'></ww-open-data>
- <!-- {{multiSelectList[0].name}} -->
- <i class="el-icon-error" v-if="!disabled" @click.stop="deleteMultiSelectList('-1')"></i>
- </span>
- <span class="all" v-if="multiSelectList.length > 1"> + {{multiSelectList.length - 1}}</span>
- </span>
- <span v-if="tile" style="width: 100%">
- <span class="all" style="margin-right: 6px" v-for="(items, indexs) in multiSelectList" :key="indexs">
- <ww-open-data type='userName' :openid='items.name'></ww-open-data>
- <!-- {{items.name}} -->
- <span v-if="items.jobNumber" class="spanFllat">{{items.jobNumber}}</span>
- <i class="el-icon-error" @click.stop="deleteMultiSelectList(indexs)" v-if="!disabled"></i>
- </span>
- </span>
- </span>
- <span v-else class="allTwo">{{$t('defaultText.pleaseChoose')}}</span>
- </div>
- <i :class=" move ? 'el-icon-arrow-down iostu iostuHover' : 'el-icon-arrow-down iostu'" v-if="!moveIon"></i>
- <i v-if="moveIon" class="el-icon-circle-close iostu" @click.stop="clearDelete"></i>
- </div>
- </div>
- <transition name="el-zoom-in-top">
- <div v-show="show" style="position: relative;z-index: 999;">
- <!-- 搜索框 -->
- <div class="searchBox" v-if="filterable" :style="`top: ${searchBoxTop}px`">
- <el-input placeholder="请输入名称搜索" size="mini" v-model="searchTex" style="width: 100%" @input="searchLick()" @focus="selectCli()"></el-input>
- </div>
- <div class="transitionBox" :style="filterable ? 'margin: 30px 0;' : ''">
- <ul class="transitionBoxUl">
- <li :class="transitionBoxLiIdx == index ? 'liHover' : ''" v-for="(item, index) in options" :key="index" @mouseover="liMouseOver(index)" @click="liClick(item, index)">
- <span v-if="!multiSelect" style="width: 100%">
- <span v-if="item.name">
- <ww-open-data type='userName' :openid='item.name'></ww-open-data>
- </span>
- <span v-if="item.auditorName">
- <ww-open-data type='userName' :openid='item.auditorName'></ww-open-data>
- </span>
- <!-- {{item.name || item.auditorName}} -->
- <span v-if="item.jobNumber" class="spanFllat">{{item.jobNumber}}</span>
- </span>
- <span v-if="multiSelect" style="width: 100%">
- <span :class="item.flg ? 'hoverSpan hoverSpanHover' : 'hoverSpan'">
- <span style="width: 100%;display: inline-block;">
- <ww-open-data type='userName' :openid='item.name'></ww-open-data>
- <!-- {{item.name}} -->
- <span v-if="item.jobNumber" class="spanFllat">{{item.jobNumber}}</span>
- </span>
- <span v-if="item.flg"><i class="el-icon-check"></i></span>
- </span>
- </span>
- </li>
- </ul>
- </div>
- </div>
- </transition>
- </div>
- <div v-if="wxCope" class="waihez">
- <!-- <div @click="dianjis()">点击</div> -->
- <div :style="`width:${selectWidth}px;height:${selectHeight}px;line-height:${selectHeight}px;background:#fff`" class="select selectDandu" @click="dianjis()">
- <span v-if="!multiSelect"><ww-open-data type='userName' :openid='selectName'></ww-open-data></span>
- <!-- <span>你好</span> -->
- </div>
- </div>
- </div>
- </template>
- <script>
- export default {
- props: {
- subject:{
- type: Array
- },
- size: {
- type: String,
- },
- subjectId: {
- type: [String, Number, Array]
- },
- wxCope: {
- type: Boolean,
- default: false,
- },
- // 是否支持多选
- multiSelect: {
- type: Boolean,
- default: false
- },
- // 是否平铺 (需要 multiSelect 为 true)
- tile: {
- type: Boolean,
- default: false
- },
- // 当前页面用到的第几个
- distinction: {
- type: String,
- default: '1',
- },
- // 真对填写日报单独处理
- idx: {
- type: String
- },
- flg: {
- type: Boolean,
- default: false, // 默认值,不是填写日报
- },
- // 宽度
- widthStr: {
- type: String,
- default: false
- },
- // 剩下统一索引
- index: {
- type: String
- },
- // 是否禁用
- disabled: {
- type: Boolean,
- default: false
- },
- // 是否可清空
- clearable: {
- type: Boolean,
- default: false
- },
- // 是否可搜索
- filterable: {
- type: Boolean,
- default: false
- },
- // 其他数据
- other: {
- type: [String, Number, Boolean],
- default: false
- },
- // 是否执行到日报单独的函数
- flgs: {
- type: Boolean,
- default: false
- },
- // searchBoxTop 搜索框距离顶部的距离
- searchBoxTop: {
- type: String,
- default: '-9'
- }
- },
- components: {
- selectWidth: '150',
- selectHeight: '28'
- },
- data() {
- return {
- selectWidth: '150',
- selectHeight: '28',
- selectFontSize: '12',
- show: false, // 下拉框
- options: [], // 列表数据
- optionsCopy: [], // 列表数据复制
- transitionBoxLiIdx: '', // hover 背景色
- selectName: this.$t('defaultText.pleaseChoose'), // 显示的文字
- classDiv: false, // 获得焦点样式
- optionsOId: '', // 选中人的id
- dailyListObj: null, // 填写日报的数据
- dailyListIndex: null, // 日报点的索引
- move: false,
- moveIon: false,
- multiSelectList: [],
- searchTex: '', // 搜索文字
- cursor: '', // 搜索的标记(需传给后端)
- time: null,//防抖
- fistArrList: [], // 第一次进来的人员数组
- fistArrListOne: [], // 第一次进来的人员初始数组
- };
- },
- computed: {},
- watch: {
- subject: {
- handler(newValue, oldValue) {
- this.options = newValue
- this.optionsCopy = JSON.parse(JSON.stringify(newValue))
- if(this.flg) {
- if(newValue) {
- this.selectName = newValue[0].auditorName || newValue[0].name
- this.optionsOId = newValue[0].auditorId || newValue[0].id
- }
- }
- },
- },
- // 日报点的索引, 真对填写的日报
- idx: {
- handler(newValue, oldValue) {
- console.log(newValue, oldValue)
- this.dailyListIndex = newValue
- },
- },
- subjectId: {
- handler(newValue, oldValue) {
- console.log(newValue, oldValue)
- this.optionsOId = newValue
- this.multiSelectList = []
- if(!this.multiSelect) {
- if(this.optionsOId) {
- for(let i in this.options) {
- if(this.options[i].userId == this.optionsOId || this.options[i].auditorId == this.optionsOId || this.options[i].id == this.optionsOId) {
- this.selectName = this.options[i].name || this.options[i].auditorName
- }
- }
- } else {
- this.selectName = this.$t('defaultText.pleaseChoose')
- }
- }
- if(this.multiSelect) {
- for(var i in this.options) {
- for(var j in this.optionsOId) {
- if(this.options[i].userId == this.optionsOId || this.options[i].auditorId == this.optionsOId[j] || this.options[i].id == this.optionsOId[j]) {
- this.multiSelectList.push(this.options[i])
- this.options[i].flg = true
- }
- }
- }
- }
- },
- },
- widthStr: {
- handler(newValue, oldValue) {
- this.selectWidth = newValue
- },
- }
- },
- created() {},
- mounted() {
- if(this.size == 'mini') {
- this.selectWidth = '150'
- this.selectHeight = '28'
- } else if(this.size == 'small') {
- this.selectWidth = '191'
- this.selectHeight = '32'
- } else if(this.size == 'medium') {
- this.selectWidth = '205'
- this.selectHeight = '40'
- this.selectFontSize = '14'
- }
- if(this.widthStr) {
- this.selectWidth = this.widthStr
- }
-
- if(this.subject) {
- this.options = JSON.parse(JSON.stringify(this.subject))
- }
- if(this.subjectId) {
- this.multiSelectList = []
- if(!this.multiSelect) {
- this.optionsOId = JSON.parse(JSON.stringify(this.subjectId))
- for(let i in this.options) {
- if(this.options[i].userId == this.optionsOId || this.options[i].auditorId == this.optionsOId || this.options[i].id == this.optionsOId) {
- this.selectName = this.options[i].auditorName || this.options[i].name
- }
- }
- }
- console.log(this.options, this.subjectId)
- if(this.multiSelect) {
- for(var i in this.options) {
- for(var j in this.subjectId) {
- if(this.options[i].id == this.subjectId[j] || this.options[i].auditorId == this.subjectId[j]) {
- this.multiSelectList.push(this.options[i])
- this.options[i].flg = true
- }
- }
- }
- }
- }
- console.log(this.subject, this.subjectId)
- var thats = this
- var phoneArr = []
- setTimeout(()=>{
- for(var s in thats.subject) {
- phoneArr.push(thats.subject[s].optionsOId || thats.subject[s].auditorId || thats.subject[s].id)
- }
- thats.fistArrListOne = thats.subject
- }, 500)
-
- thats.fistArrList = phoneArr
- console.log(thats.fistArrList)
- this.dailyListIndex = this.idx
- },
- methods: {
- dianjis() {
- if(!this.disabled) {
- let modes = this.multiSelect ? 'multi' : 'single'
- let that = this
- wx.invoke("selectEnterpriseContact", {
- "fromDepartmentId": 0,// 必填,表示打开的通讯录从指定的部门开始展示,-1表示自己所在部门开始, 0表示从最上层开始
- "mode": modes,// 必填,选择模式,single表示单选,multi表示多选
- "type": ["user"],// 必填,选择限制类型,指定department、user中的一个或者多个
- "selectedDepartmentIds": [],// 非必填,已选部门ID列表。用于多次选人时可重入,single模式下请勿填入多个id
- "selectedUserIds": []// 非必填,已选用户ID列表。用于多次选人时可重入,single模式下请勿填入多个id
- },function(res){
- console.log(res)
- if (res.err_msg == "selectEnterpriseContact:ok"){
- console.log(res, '数据来源')
- if(typeof res.result == 'string'){
- res.result = JSON.parse(res.result) //由于目前各个终端尚未完全兼容,需要开发者额外判断result类型以保证在各个终端的兼容性
- }
- var selectedUserList = res.result.userList; // 已选的成员列表
- var userId = ''
- var userName = ''
- for (var i = 0; i < selectedUserList.length; i++) {
- var user = selectedUserList[i];
- userId = user.id; // 已选的单个成员ID
- userName = user.name;// 已选的单个成员名称
- console.log(userId, userName)
- }
- for(var s in that.options) {
- if(that.options[s].name == userId) {
- that.selectName = userId
- that.wxCoper(that.options[s].id)
- }
- }
- }
- }
- );
- }
- },
- wxCoper(id) {
- let obj = {
- id: id,
- distinction: this.distinction,
- index: this.index, // 选中的索引
- other: this.other,
- name: this.selectName
- }
- console.log(obj)
- this.$emit("selectCal", obj)
- },
- selectCli() {
- if(!this.disabled) {
- this.$refs.selectDiv.focus()
- this.classDiv = !this.classDiv
- this.show = !this.show
- this.move = !this.move
- this.searchTex = ''
- if(this.optionsCopy.length > 0) {
- this.$set(this, 'options', JSON.parse(JSON.stringify(this.optionsCopy)))
- }
- }
- },
- selectClihide() {
- if(this.classDiv) {
- this.transitionBoxLiIdx = ''
- this.show = !this.show
- this.classDiv = false
- this.move = false
- if(this.multiSelect) {
- let obj = {
- // id: nameId,
- distinction: this.distinction,
- index: this.index, // 选中的索引
- other: this.other,
- arrUserList: this.multiSelectList,
- name: this.selectName
- }
- this.$emit("selectCal", obj)
- this.options = this.fistArrListOne
- }
- }
- },
- liMouseOver(index) {
- this.transitionBoxLiIdx = index
- },
- liClick(item, itemIndex) {
- console.log(item, '进来的')
- let nameId = item.auditorId || item.id
- this.selectName = item.auditorName || item.name
- if(!this.multiSelect) {
- console.log('我进来了', this.flg)
- if(this.flgs) {
- let obj = {
- id: nameId,
- idx: this.dailyListIndex
- }
- this.$emit("selectCatCli", obj);
- this.options = this.fistArrListOne
- } else {
- let obj = {
- id: nameId,
- distinction: this.distinction,
- index: this.index, // 选中的索引
- other: this.other,
- name: this.selectName
- }
- this.$emit("selectCal", obj)
- this.options = this.fistArrListOne
- }
- this.transitionBoxLiIdx = ''
- this.show = false
- this.classDiv = false
- this.move = false
- }
- if(this.multiSelect) {
- if(this.options[itemIndex].flg) {
- this.options[itemIndex].flg = !this.options[itemIndex].flg
- for(var i in this.multiSelectList) {
- if(this.multiSelectList[i].id == item.id) {
- this.multiSelectList.splice(i, 1)
- }
- }
- } else {
- this.options[itemIndex].flg = false
- this.options[itemIndex].flg = !this.options[itemIndex].flg
- this.multiSelectList.push(item)
- }
- }
- },
- moveIonDiv() {
- if(this.clearable) {
- this.moveIon = true
- }
- },
- outIonDiv() {
- if(this.clearable) {
- this.moveIon = false
- }
- },
- clearDelete() {
- if(!this.multiSelect) {
- this.selectName = this.$t('defaultText.pleaseChoose')
- let obj = {
- name: this.$t('defaultText.pleaseChoose'),
- id: ''
- }
- this.liClick(obj)
- }
- if(this.multiSelect) {
- this.multiSelectList = []
- let obj = {
- distinction: this.distinction,
- index: this.index, // 选中的索引
- other: this.other,
- arrUserList: []
- }
- for(var i in this.options) {
- if(this.options[i].flg) {
- this.options[i].flg = false
- }
- }
- this.$emit("selectCal", obj)
- this.options = this.fistArrListOne
- }
- },
- deleteMultiSelectList(str) {
- let userId
- if(str == '-1') {
- userId = this.multiSelectList[0].id
- this.multiSelectList.splice(0, 1)
- } else {
- userId = this.multiSelectList[str].id
- this.multiSelectList.splice(str, 1)
- }
- for(var i in this.options) {
- if(this.options[i].id == userId) {
- if(this.options[i].flg) {
- this.options[i].flg = false
- }
- }
- }
-
- let obj = {
- distinction: this.distinction,
- index: this.index, // 选中的索引
- other: this.other,
- arrUserList: this.multiSelectList,
- name: this.selectName
- }
- this.$emit("selectCal", obj)
- this.options = this.fistArrListOne
- },
- // searchBox() {
- // this.selectCli()
- // },
- // // 搜索
- searchLick() {
- if (this.time != null) {
- clearTimeout(this.time)
- }
- var that = this
- this.time = setTimeout(() => {
- that.getSimpleActiveUserList()
- }, 500)
-
- },
- // 针对 getSimpleActiveUserList 获取所有人员接口
- getSimpleActiveUserList() {
- this.http.post('/user/getEmployeeList', {
- departmentId: -1,
- pageIndex: 1,
- pageSize: 200,
- keyword: this.searchTex,
- status: 1,
- roleId: '',
- cursor: '',
- onlyDirect: 0,
- },
- res => {
- if (res.code == "ok") {
- var arr = res.data.records.filter((item) => {
- if (this.fistArrList.indexOf(item.id) != '-1') {
- return item;
- }
- })
- // this.options = arr
- console.log('将要赋值')
- var newArr = arr.length > 0 ? arr : res.data.records
- this.$set(this, 'options', newArr)
- this.cursor = res.data.nextCursor
- } else {
- this.$message({
- message: res.msg,
- type: "error"
- });
- }
- },
- error => {
- this.$message({
- message: error,
- type: "error"
- });
- });
- }
- },
- triggerOption(){
- },
- choose(item,value){
-
- },
- };
- </script>
- <style scoped lang="scss">
- .selectDandu {
- font-size: 16px;
- }
- .waihez {
- // padding-top: 7px;
- // box-sizing: border-box;
- // background: #FFF;
- display: inline-block;
- }
- .selectDiv {
- border-color: #409EFF !important;
- }
- .disabledTrue {
- background: #F5F7FA !important;
- border-radius: 4px;
- cursor: not-allowed !important;
- position: relative;
- }
- .disabledFalse .select {
- background: #FFF !important;
- border-radius: 4px;
- }
- .select {
- -webkit-appearance: none;
- // background-color: #FFF;
- background-image: none;
- border-radius: 4px;
- border: 1px solid #DCDFE6;
- -webkit-box-sizing: border-box;
- box-sizing: border-box;
- color: #606266;
- display: inline-block;
- font-size: inherit;
- height: 40px;
- line-height: 40px;
- outline: 0;
- padding: 0 15px;
- -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
- transition: border-color .2s cubic-bezier(.645,.045,.355,1);
- width: 100%;
- position: relative;
- cursor: pointer;
- }
- .selecttex {
- height: 28px;
- line-height: 28px;
- text-overflow: ellipsis;
- font-size: 12px;
- }
- .iostu {
- position: absolute;
- top: 50%;
- margin-top: -4px;
- right: 8px;
- color: #C0C4CC;
- transition: All 0.2s ease-in-out;
- }
- .iostuHover {
- transform: rotate(-180deg);
- }
- .searchBox {
- position: absolute;
- width: 100%;
- top: -9px;
- // top: 0px;
- }
- .transitionBox {
- background: #FFF;
- position: absolute;
- width: 100%;
- border-radius: 2em;
- border: 1px solid #E4E7ED;
- border-radius: 4px;
- background-color: #FFF;
- box-sizing: border-box;
- margin: 5px 0;
- box-shadow: 0 2px 12px #dfdfdf;
- max-height: 274px;
- overflow: auto;
- z-index: 500 !important;
- }
- .transitionBoxUl {
- list-style: none;
- padding: 6px 0;
- margin: 0;
- -webkit-box-sizing: border-box;
- box-sizing: border-box;
- }
- .transitionBoxUl li {
- font-size: 14px;
- padding: 0 20px;
- position: relative;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- color: #606266;
- height: 34px;
- line-height: 34px;
- -webkit-box-sizing: border-box;
- box-sizing: border-box;
- cursor: pointer;
- }
- .liHover {
- background-color: #F5F7FA;
- }
- .selecttexXuan {
- color: #C0C4CC;;
- }
- .all {
- display: inline-block;
- font-size: 10px;
- background: #f4f4f5;
- height: 20px;
- line-height: 24px;
- padding: 0px 8px;
- color: #909399;
- }
- .allTwo {
- display: inline-block;
- margin-left: 10px;
- }
- .hoverSpan {
- display: flex;
- width: 100%;
- justify-content: space-between;
- }
- .hoverSpanHover {
- color: #409eff;
- font-weight: 700;
- }
- .spanFllat {
- display: inline-block;
- float: right;
- }
- </style>
|