select.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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="selectDiv">
  4. <div :class="selectName == $t('defaultText.pleaseChoose') ? 'selecttex selecttexXuan' : 'selecttex'">
  5. <ww-open-data type='userName' :openid='selectName'></ww-open-data>
  6. <!-- {{selectName}} -->
  7. </div>
  8. <i class="el-icon-arrow-down iostu"></i>
  9. </div>
  10. <transition name="el-zoom-in-top">
  11. <div v-show="show" style="position: relative;z-index: 99;">
  12. <div class="transitionBox">
  13. <ul class="transitionBoxUl">
  14. <li :class="transitionBoxLiIdx == index ? 'liHover' : ''" v-for="(item, index) in options" :key="index" @mouseover="liMouseOver(index)" @click="liClick(item)">
  15. <span v-if="item.name">
  16. <!-- {{item.name || item.auditorName}} -->
  17. <ww-open-data type='userName' :openid='item.name'></ww-open-data>
  18. </span>
  19. <span v-if="item.auditorName">
  20. <ww-open-data type='userName' :openid='item.auditorName'></ww-open-data>
  21. </span>
  22. <!-- {{item.name || item.auditorName}} -->
  23. </li>
  24. </ul>
  25. </div>
  26. </div>
  27. </transition>
  28. </div>
  29. </template>
  30. <script>
  31. export default {
  32. props: {
  33. subject:{
  34. type: Array
  35. },
  36. size: {
  37. type: String
  38. },
  39. subjectId: {
  40. type: String
  41. },
  42. distinction: {
  43. type: String,
  44. default: '1',
  45. },
  46. // 真对填写日报单独处理
  47. idx: {
  48. type: String
  49. },
  50. flg: {
  51. type: Boolean,
  52. default: false, // 默认值,不是填写日报
  53. },
  54. // 针对查任务的处理
  55. index: {
  56. type: String
  57. }
  58. },
  59. components: {
  60. selectWidth: '150',
  61. selectHeight: '28'
  62. },
  63. data() {
  64. return {
  65. selectWidth: '150',
  66. selectHeight: '28',
  67. show: false, // 下拉框
  68. options: [], // 列表数据
  69. transitionBoxLiIdx: '', // hover 背景色
  70. selectName: this.$t('defaultText.pleaseChoose'), // 显示的文字
  71. classDiv: false, // 获得焦点样式
  72. optionsOId: '', // 选中人的id
  73. dailyListObj: null, // 填写日报的数据
  74. dailyListIndex: null, // 日报点的索引
  75. };
  76. },
  77. computed: {},
  78. watch: {
  79. subject: {
  80. handler(newValue, oldValue) {
  81. this.options = newValue
  82. if(this.flg) {
  83. if(newValue) {
  84. this.selectName = newValue[0].name || newValue[0].auditorName
  85. this.optionsOId = newValue[0].id || newValue[0].auditorId
  86. }
  87. }
  88. },
  89. },
  90. // 日报点的索引, 真对填写的日报
  91. idx: {
  92. handler(newValue, oldValue) {
  93. console.log(newValue, oldValue)
  94. this.dailyListIndex = newValue
  95. },
  96. }
  97. },
  98. created() {},
  99. mounted() {
  100. if(this.size == 'mini') {
  101. this.selectWidth = '150'
  102. this.selectHeight = '28'
  103. } else if(this.size == 'small') {
  104. this.selectWidth = '191'
  105. this.selectHeight = '32'
  106. }
  107. if(this.subject) {
  108. this.options = JSON.parse(JSON.stringify(this.subject))
  109. }
  110. if(this.subjectId) {
  111. this.optionsOId = JSON.parse(JSON.stringify(this.subjectId))
  112. for(let i in this.options) {
  113. if(this.options[i].id == this.optionsOId || this.options[i].auditorId == this.optionsOId) {
  114. this.selectName = this.options[i].name || this.options[i].auditorName
  115. }
  116. }
  117. }
  118. console.log(this.options, this.optionsOId)
  119. this.dailyListIndex = this.idx
  120. },
  121. methods: {
  122. selectCli() {
  123. this.$refs.selectDiv.focus()
  124. this.classDiv = !this.classDiv
  125. this.show = !this.show
  126. },
  127. selectClihide() {
  128. if(this.classDiv) {
  129. this.transitionBoxLiIdx = ''
  130. this.show = !this.show
  131. this.classDiv = false
  132. }
  133. },
  134. liMouseOver(index) {
  135. this.transitionBoxLiIdx = index
  136. },
  137. liClick(item) {
  138. let nameId = item.id || item.auditorId
  139. if(this.flg) {
  140. let obj = {
  141. id: nameId,
  142. idx: this.dailyListIndex
  143. }
  144. this.$emit("selectCatCli", obj);
  145. } else {
  146. let obj = {
  147. id: nameId,
  148. distinction: this.distinction,
  149. index: this.index, // 选中的索引
  150. }
  151. this.$emit("selectCal", obj)
  152. }
  153. this.selectName = item.name || item.auditorName
  154. this.transitionBoxLiIdx = ''
  155. this.show = !this.show
  156. this.classDiv = false
  157. },
  158. },
  159. triggerOption(){
  160. },
  161. choose(item,value){
  162. },
  163. };
  164. </script>
  165. <style scoped lang="scss">
  166. .selectDiv {
  167. border-color: #409EFF !important;
  168. }
  169. .select {
  170. -webkit-appearance: none;
  171. background-color: #FFF;
  172. background-image: none;
  173. border-radius: 4px;
  174. border: 1px solid #DCDFE6;
  175. -webkit-box-sizing: border-box;
  176. box-sizing: border-box;
  177. color: #606266;
  178. display: inline-block;
  179. font-size: inherit;
  180. height: 40px;
  181. line-height: 40px;
  182. outline: 0;
  183. padding: 0 15px;
  184. -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  185. transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  186. width: 100%;
  187. position: relative;
  188. cursor: pointer;
  189. }
  190. .selecttex {
  191. height: 28px;
  192. line-height: 28px;
  193. text-overflow: ellipsis;
  194. font-size: 12px;
  195. }
  196. .iostu {
  197. position: absolute;
  198. top: 50%;
  199. margin-top: -4px;
  200. right: 8px;
  201. color: #C0C4CC;
  202. }
  203. .transitionBox {
  204. background: #FFF;
  205. position: absolute;
  206. width: 100%;
  207. border-radius: 2em;
  208. border: 1px solid #E4E7ED;
  209. border-radius: 4px;
  210. background-color: #FFF;
  211. box-sizing: border-box;
  212. margin: 5px 0;
  213. box-shadow: 0 2px 12px #dfdfdf;
  214. max-height: 274px;
  215. overflow: auto;
  216. }
  217. .transitionBoxUl {
  218. list-style: none;
  219. padding: 6px 0;
  220. margin: 0;
  221. -webkit-box-sizing: border-box;
  222. box-sizing: border-box;
  223. }
  224. .transitionBoxUl li {
  225. font-size: 14px;
  226. padding: 0 20px;
  227. position: relative;
  228. white-space: nowrap;
  229. overflow: hidden;
  230. text-overflow: ellipsis;
  231. color: #606266;
  232. height: 34px;
  233. line-height: 34px;
  234. -webkit-box-sizing: border-box;
  235. box-sizing: border-box;
  236. cursor: pointer;
  237. }
  238. .liHover {
  239. background-color: #F5F7FA;
  240. }
  241. .selecttexXuan {
  242. color: #C0C4CC;;
  243. }
  244. </style>