select.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 :style="'line-height: '+selectHeight+'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. <i :class=" move ? 'el-icon-arrow-down iostu iostuHover' : 'el-icon-arrow-down iostu'" v-if="!moveIon"></i>
  11. <i v-if="moveIon" class="el-icon-circle-close iostu" @click="clearDelete"></i>
  12. </div>
  13. </div>
  14. <transition name="el-zoom-in-top">
  15. <div v-show="show" style="position: relative;z-index: 99;">
  16. <div class="transitionBox">
  17. <ul class="transitionBoxUl">
  18. <li :class="transitionBoxLiIdx == index ? 'liHover' : ''" v-for="(item, index) in options" :key="index" @mouseover="liMouseOver(index)" @click="liClick(item)">
  19. <span v-if="item.name">
  20. <ww-open-data type='userName' :openid='item.name'></ww-open-data>
  21. </span>
  22. <span v-if="item.auditorName">
  23. <ww-open-data type='userName' :openid='item.auditorName'></ww-open-data>
  24. </span>
  25. <!-- {{item.name || item.auditorName}} -->
  26. </li>
  27. </ul>
  28. </div>
  29. </div>
  30. </transition>
  31. </div>
  32. </template>
  33. <script>
  34. export default {
  35. props: {
  36. subject:{
  37. type: Array
  38. },
  39. size: {
  40. type: String,
  41. },
  42. subjectId: {
  43. type: [String, Number]
  44. },
  45. // 当前页面用到的第几个
  46. distinction: {
  47. type: String,
  48. default: '1',
  49. },
  50. // 真对填写日报单独处理
  51. idx: {
  52. type: String
  53. },
  54. flg: {
  55. type: Boolean,
  56. default: false, // 默认值,不是填写日报
  57. },
  58. // 剩下统一索引
  59. index: {
  60. type: String
  61. },
  62. // 是否禁用
  63. disabled: {
  64. type: Boolean,
  65. default: false
  66. },
  67. // 是否可清空
  68. clearable: {
  69. type: Boolean,
  70. default: false
  71. },
  72. // 是否可搜索
  73. filterable: {
  74. type: Boolean,
  75. default: false
  76. },
  77. // 其他数据
  78. other: {
  79. type: [String, Number, Boolean],
  80. default: false
  81. }
  82. },
  83. components: {
  84. selectWidth: '150',
  85. selectHeight: '28'
  86. },
  87. data() {
  88. return {
  89. selectWidth: '150',
  90. selectHeight: '28',
  91. show: false, // 下拉框
  92. options: [], // 列表数据
  93. transitionBoxLiIdx: '', // hover 背景色
  94. selectName: this.$t('defaultText.pleaseChoose'), // 显示的文字
  95. classDiv: false, // 获得焦点样式
  96. optionsOId: '', // 选中人的id
  97. dailyListObj: null, // 填写日报的数据
  98. dailyListIndex: null, // 日报点的索引
  99. move: false,
  100. moveIon: false
  101. };
  102. },
  103. computed: {},
  104. watch: {
  105. subject: {
  106. handler(newValue, oldValue) {
  107. this.options = newValue
  108. if(this.flg) {
  109. if(newValue) {
  110. this.selectName = newValue[0].name || newValue[0].auditorName
  111. this.optionsOId = newValue[0].id || newValue[0].auditorId
  112. }
  113. }
  114. },
  115. },
  116. // 日报点的索引, 真对填写的日报
  117. idx: {
  118. handler(newValue, oldValue) {
  119. console.log(newValue, oldValue)
  120. this.dailyListIndex = newValue
  121. },
  122. },
  123. subjectId: {
  124. handler(newValue, oldValue) {
  125. console.log(newValue, oldValue)
  126. this.optionsOId = newValue
  127. if(this.optionsOId) {
  128. for(let i in this.options) {
  129. if(this.options[i].id == this.optionsOId || this.options[i].auditorId == this.optionsOId) {
  130. this.selectName = this.options[i].name || this.options[i].auditorName
  131. }
  132. }
  133. }
  134. },
  135. }
  136. },
  137. created() {},
  138. mounted() {
  139. if(this.size == 'mini') {
  140. this.selectWidth = '150'
  141. this.selectHeight = '28'
  142. } else if(this.size == 'small') {
  143. this.selectWidth = '191'
  144. this.selectHeight = '32'
  145. }
  146. if(this.subject) {
  147. this.options = JSON.parse(JSON.stringify(this.subject))
  148. }
  149. if(this.subjectId) {
  150. this.optionsOId = JSON.parse(JSON.stringify(this.subjectId))
  151. for(let i in this.options) {
  152. if(this.options[i].id == this.optionsOId || this.options[i].auditorId == this.optionsOId) {
  153. this.selectName = this.options[i].name || this.options[i].auditorName
  154. }
  155. }
  156. }
  157. console.log(this.subjectId)
  158. this.dailyListIndex = this.idx
  159. // this.moveIon = JSON.parse(JSON.stringify(this.clearable))
  160. },
  161. methods: {
  162. selectCli() {
  163. if(!this.disabled) {
  164. this.$refs.selectDiv.focus()
  165. this.classDiv = !this.classDiv
  166. this.show = !this.show
  167. this.move = !this.move
  168. }
  169. },
  170. selectClihide() {
  171. if(this.classDiv) {
  172. this.transitionBoxLiIdx = ''
  173. this.show = !this.show
  174. this.classDiv = false
  175. this.move = false
  176. }
  177. },
  178. liMouseOver(index) {
  179. this.transitionBoxLiIdx = index
  180. },
  181. liClick(item) {
  182. let nameId = item.id || item.auditorId
  183. if(this.flg) {
  184. let obj = {
  185. id: nameId,
  186. idx: this.dailyListIndex
  187. }
  188. this.$emit("selectCatCli", obj);
  189. } else {
  190. let obj = {
  191. id: nameId,
  192. distinction: this.distinction,
  193. index: this.index, // 选中的索引
  194. other: this.other
  195. }
  196. this.$emit("selectCal", obj)
  197. }
  198. this.selectName = item.name || item.auditorName
  199. this.transitionBoxLiIdx = ''
  200. this.show = !this.show
  201. this.classDiv = false
  202. this.move = false
  203. },
  204. moveIonDiv() {
  205. if(this.clearable) {
  206. this.moveIon = true
  207. }
  208. },
  209. outIonDiv() {
  210. if(this.clearable) {
  211. this.moveIon = false
  212. }
  213. },
  214. clearDelete() {
  215. this.selectName = this.$t('defaultText.pleaseChoose')
  216. let obj = {
  217. name: this.$t('defaultText.pleaseChoose'),
  218. id: ''
  219. }
  220. this.liClick(obj)
  221. }
  222. },
  223. triggerOption(){
  224. },
  225. choose(item,value){
  226. },
  227. };
  228. </script>
  229. <style scoped lang="scss">
  230. .selectDiv {
  231. border-color: #409EFF !important;
  232. }
  233. .disabledTrue {
  234. background: #F5F7FA !important;
  235. border-radius: 4px;
  236. cursor: not-allowed !important;
  237. position: relative;
  238. }
  239. .disabledFalse .select {
  240. background: #FFF !important;
  241. border-radius: 4px;
  242. }
  243. .select {
  244. -webkit-appearance: none;
  245. // background-color: #FFF;
  246. background-image: none;
  247. border-radius: 4px;
  248. border: 1px solid #DCDFE6;
  249. -webkit-box-sizing: border-box;
  250. box-sizing: border-box;
  251. color: #606266;
  252. display: inline-block;
  253. font-size: inherit;
  254. height: 40px;
  255. line-height: 40px;
  256. outline: 0;
  257. padding: 0 15px;
  258. -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  259. transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  260. width: 100%;
  261. position: relative;
  262. cursor: pointer;
  263. }
  264. .selecttex {
  265. height: 28px;
  266. line-height: 28px;
  267. text-overflow: ellipsis;
  268. font-size: 12px;
  269. }
  270. .iostu {
  271. position: absolute;
  272. top: 50%;
  273. margin-top: -4px;
  274. right: 8px;
  275. color: #C0C4CC;
  276. transition: All 0.2s ease-in-out;
  277. }
  278. .iostuHover {
  279. transform: rotate(-180deg);
  280. }
  281. .transitionBox {
  282. background: #FFF;
  283. position: absolute;
  284. width: 100%;
  285. border-radius: 2em;
  286. border: 1px solid #E4E7ED;
  287. border-radius: 4px;
  288. background-color: #FFF;
  289. box-sizing: border-box;
  290. margin: 5px 0;
  291. box-shadow: 0 2px 12px #dfdfdf;
  292. max-height: 274px;
  293. overflow: auto;
  294. z-index: 500 !important;
  295. }
  296. .transitionBoxUl {
  297. list-style: none;
  298. padding: 6px 0;
  299. margin: 0;
  300. -webkit-box-sizing: border-box;
  301. box-sizing: border-box;
  302. }
  303. .transitionBoxUl li {
  304. font-size: 14px;
  305. padding: 0 20px;
  306. position: relative;
  307. white-space: nowrap;
  308. overflow: hidden;
  309. text-overflow: ellipsis;
  310. color: #606266;
  311. height: 34px;
  312. line-height: 34px;
  313. -webkit-box-sizing: border-box;
  314. box-sizing: border-box;
  315. cursor: pointer;
  316. }
  317. .liHover {
  318. background-color: #F5F7FA;
  319. }
  320. .selecttexXuan {
  321. color: #C0C4CC;;
  322. }
  323. </style>