lin-select.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <view class="yealuo-select">
  3. <view class="yealuo-background" @tap="isShow = false" v-show="isShow"></view>
  4. <view class="yealuo-con" :style="inputStyle" @tap='isShow = !isShow'>
  5. <slot name='left'></slot>
  6. <input class="uni-combox__input" :disabled="theDisabled" :placeholder="placeholder" v-model="theValue"
  7. @input="theInput" @focus="theFocus" @blur="theBlur" autocomplete="off" />
  8. <slot name='right' v-if="selectIco">
  9. <svg class="icon" v-if="!isShow"
  10. style="width: 1.5em; height: 1.5em;vertical-align: middle;fill: currentColor;overflow: hidden;"
  11. viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="530">
  12. <path
  13. d="M512 714.666667c-8.533333 0-17.066667-2.133333-23.466667-8.533334l-341.333333-341.333333c-12.8-12.8-12.8-32 0-44.8 12.8-12.8 32-12.8 44.8 0l320 317.866667 317.866667-320c12.8-12.8 32-12.8 44.8 0 12.8 12.8 12.8 32 0 44.8L533.333333 704c-4.266667 8.533333-12.8 10.666667-21.333333 10.666667z"
  14. p-id="531"></path>
  15. </svg>
  16. <svg class="icon" v-else
  17. style="width: 1.5em; height: 1.5em;vertical-align: middle;fill: currentColor;overflow: hidden;"
  18. viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1927">
  19. <path
  20. d="M904.533333 674.133333l-362.666666-362.666666c-17.066667-17.066667-42.666667-17.066667-59.733334 0l-362.666666 362.666666c-17.066667 17.066667-17.066667 42.666667 0 59.733334 17.066667 17.066667 42.666667 17.066667 59.733333 0L512 401.066667l332.8 332.8c8.533333 8.533333 19.2 12.8 29.866667 12.8s21.333333-4.266667 29.866666-12.8c17.066667-17.066667 17.066667-42.666667 0-59.733334z"
  21. p-id="1928"></path>
  22. </svg>
  23. </slot>
  24. </view>
  25. <view class="uni-select__selector" v-show="show" :style="selectStyle">
  26. <view class="uni-popper__arrow"></view>
  27. <scroll-view scroll-y="true" class="uni-select__selector-scroll">
  28. <view class="uni-combox__selector-empty" v-if="filterCandidatesLength === 0">
  29. <text>{{emptyTips}}</text>
  30. </view>
  31. <view class="data">
  32. <radio-group v-if="checkType=='radio'" @change="selectCheckbox">
  33. <view class="select-item" :class="'item-'+overflow" v-for="(item, index) in nowData"
  34. :key="index">
  35. <label class="item-text" :class="{active: theValue==item.value}">
  36. <radio name="name1" checked v-if="theValue==item.value" :value="item.id">
  37. </radio>
  38. <radio name="name1" v-else :value="item.id"></radio>
  39. <text class="select-text">{{item.value}}</text>
  40. </label>
  41. </view>
  42. </radio-group>
  43. <checkbox-group v-else-if="checkType=='checkbox'" @change="selectCheckbox">
  44. <view class="select-item" :class="'item-'+overflow" v-for="(item, index) in nowData"
  45. :key="index">
  46. <label class="item-text" :class="{active: theValue.indexOf(item.value)!=-1 }">
  47. <checkbox name="name1" checked v-if="theValue.indexOf(item.value)!=-1 "
  48. :value="item.id"></checkbox>
  49. <checkbox name="name1" v-else :value="item.id"></checkbox>
  50. <text class="select-text">{{item.value}}</text>
  51. </label>
  52. </view>
  53. </checkbox-group>
  54. <radio-group v-else @change="selectCheckbox">
  55. <view class="select-item" :class="'item-'+overflow" v-for="(item, index) in nowData"
  56. :key="index">
  57. <label class="item-text" :class="{active: theValue==item.value}">
  58. <radio name="name1" style="display: none;" checked v-if="theValue==item.value"
  59. :value="item.id"></radio>
  60. <radio name="name1" style="display: none;" v-else :value="item.id">
  61. </radio>
  62. <text class="select-text">{{item.value}}</text>
  63. </label>
  64. </view>
  65. </radio-group>
  66. </view>
  67. </scroll-view>
  68. <!-- <view class="item-close" @tap="isShow=false">收起</view> -->
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. /**
  74. * v1.0.3
  75. * 最后修改: 2023.03.24
  76. * 创建: 2023.03.24
  77. * Author: 林维增
  78. * contact:2630208719.com
  79. */
  80. let fontUnit = 'upx'
  81. // #ifdef MP-WEIXIN
  82. fontUnit = 'rpx'
  83. // #endif
  84. export default {
  85. name: 'yealuoInputs',
  86. props: {
  87. placeholder: {
  88. type: String,
  89. default: ''
  90. },
  91. //初始化
  92. value: {
  93. type: String,
  94. default: ''
  95. },
  96. checkType: {
  97. type: String,
  98. default: ''
  99. },
  100. itemKey: {
  101. type: String,
  102. default: ''
  103. },
  104. width: {
  105. type: String,
  106. default: '600'
  107. },
  108. disabled: {
  109. type: Boolean,
  110. default: false
  111. },
  112. inputStyle: {
  113. type: String,
  114. default: ''
  115. },
  116. selectStyle: {
  117. type: String,
  118. default: ''
  119. },
  120. overflow: {
  121. type: String,
  122. default: 'auto'
  123. },
  124. tags: {
  125. type: String,
  126. default: ''
  127. },
  128. binData: {
  129. type: Array,
  130. default: ''
  131. },
  132. selectIco: {
  133. type: Boolean,
  134. default: true
  135. },
  136. emptyTips: {
  137. type: String,
  138. default: '无匹配项'
  139. }
  140. },
  141. data() {
  142. return {
  143. odData: this.binData,
  144. nowData: this.binData,
  145. isShow: false,
  146. theValue: this.value,
  147. theDisabled: this.disabled
  148. }
  149. },
  150. watch: {
  151. value(val) {
  152. this.theValue = val;
  153. },
  154. //监听数据变化
  155. nowData: {
  156. handler: function() {
  157. this.nowData = this.binData;
  158. },
  159. deep: true
  160. },
  161. },
  162. computed: {
  163. show() {
  164. return this.isShow
  165. },
  166. filterCandidatesLength() {
  167. return this.binData.length
  168. }
  169. },
  170. methods: {
  171. //获取焦点
  172. theFocus(e) {
  173. this.nowData = this.odData;
  174. },
  175. //失去焦点
  176. theBlur(e) {
  177. this.$emit('blur', e)
  178. },
  179. //获取输入值
  180. theInput(e) {
  181. var val = e.detail.value;
  182. let data = [];
  183. var odData = this.odData;
  184. for (var i = 0; i < odData.length; i++) {
  185. var isHas = false;
  186. if (odData[i].value.indexOf(val) != -1) {
  187. data.push(odData[i])
  188. if (odData[i].value == val) {
  189. isHas = true;
  190. var arr = [];
  191. arr.push(odData[i].value)
  192. this.$emit('getBackVal', arr);
  193. }
  194. }
  195. if (!isHas) {
  196. var arr = [];
  197. arr.push(val)
  198. this.$emit('getBackVal', arr);
  199. }
  200. }
  201. this.nowData = data;
  202. },
  203. //下拉选中
  204. selectCheckbox(e) {
  205. var val = e.detail.value
  206. var str = val;
  207. let list = []
  208. let list2 = []
  209. if (typeof(str) != "string") {
  210. str = ""
  211. val.forEach(item => {
  212. if (item) {
  213. let itenShow = this.binData.find(it => it.id == item)
  214. if (itenShow) {
  215. list2.push(itenShow.value)
  216. }
  217. list.push(item)
  218. }
  219. })
  220. str = list2.join(",")
  221. } else {
  222. let itenShow = this.binData.find(it => it.id == str)
  223. if (itenShow) {
  224. str = itenShow.value
  225. }
  226. this.isShow = false;
  227. }
  228. this.$emit('getBackVal', str)
  229. this.theValue = str;
  230. }
  231. },
  232. }
  233. </script>
  234. <style lang="scss" scoped>
  235. .yealuo-select {
  236. // margin: 20rpx;
  237. max-width: 100%;
  238. position: relative;
  239. border: 1px solid #DCDFE6;
  240. border-radius: 4px;
  241. .yealuo-background {
  242. position: fixed;
  243. top: 0;
  244. left: 0;
  245. width: 750upx;
  246. height: 100%;
  247. }
  248. .yealuo-con {
  249. display: flex;
  250. align-items: center;
  251. justify-content: center;
  252. }
  253. }
  254. .uni-combox__input {
  255. padding: 15rpx;
  256. flex: 1;
  257. font-size: 28rpx;
  258. height: 65rpx;
  259. line-height: 65rpx;
  260. }
  261. .icon {
  262. color: #999;
  263. font-size: 26rpx;
  264. margin-right: 10rpx;
  265. }
  266. .item-close {
  267. padding: 20upx;
  268. text-align: center;
  269. font-size: 32upx;
  270. border-top: 1px solid #f3f3f4;
  271. color: #8F8F94;
  272. }
  273. .uni-select__selector {
  274. /* #ifndef APP-NVUE */
  275. box-sizing: border-box;
  276. /* #endif */
  277. position: absolute;
  278. top: calc(100% + 12px);
  279. left: 0;
  280. width: 100%;
  281. background-color: #FFFFFF;
  282. border: 1px solid #EBEEF5;
  283. border-radius: 6px;
  284. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  285. z-index: 2;
  286. padding: 4px 0;
  287. z-index: 999;
  288. }
  289. .uni-select__selector-scroll {
  290. /* #ifndef APP-NVUE */
  291. max-height: 200px;
  292. box-sizing: border-box;
  293. /* #endif */
  294. padding: 0 20rpx;
  295. .select-item {
  296. width: 100%;
  297. color: #666;
  298. margin: 10rpx 0;
  299. .item-text {
  300. width: 100%;
  301. display: block;
  302. .select-text {
  303. margin-left: 10rpx;
  304. }
  305. }
  306. .active {
  307. font-weight: bold;
  308. }
  309. }
  310. .item-auto {
  311. overflow: auto;
  312. .item-text {
  313. width: max-content;
  314. }
  315. }
  316. .item-hide .item-text {
  317. overflow: hidden;
  318. text-overflow: ellipsis;
  319. white-space: nowrap;
  320. }
  321. }
  322. /* picker 弹出层通用的指示小三角 */
  323. .uni-popper__arrow,
  324. .uni-popper__arrow::after {
  325. position: absolute;
  326. display: block;
  327. width: 0;
  328. height: 0;
  329. border-color: transparent;
  330. border-style: solid;
  331. border-width: 6px;
  332. }
  333. .uni-popper__arrow {
  334. filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.03));
  335. top: -6px;
  336. left: 10%;
  337. margin-right: 3px;
  338. border-top-width: 0;
  339. border-bottom-color: #EBEEF5;
  340. }
  341. .uni-popper__arrow::after {
  342. content: " ";
  343. top: 1px;
  344. margin-left: -6px;
  345. border-top-width: 0;
  346. border-bottom-color: #fff;
  347. }
  348. .uni-combox__selector-empty {
  349. /* #ifndef APP-NVUE */
  350. display: flex;
  351. cursor: pointer;
  352. /* #endif */
  353. line-height: 36px;
  354. font-size: 14px;
  355. text-align: center;
  356. // border-bottom: solid 1px #DDDDDD;
  357. padding: 0px 10px;
  358. }
  359. </style>