index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <u-popup class="jnpf-select" :maskCloseAble="maskCloseAble" mode="bottom" v-model="showPopup"
  3. :safeAreaInsetBottom="safeAreaInsetBottom" @close="close" :height="height" :mask-close-able="false">
  4. <view class="u-select">
  5. <view class="u-select__header" @touchmove.stop.prevent="">
  6. <view class="u-select__header__cancel u-select__header__btn" :style="{ color: cancelColor }"
  7. hover-class="u-hover-class" :hover-stay-time="150" @tap="close()"
  8. style="width: 60rpx;text-align: center;">
  9. <text v-if="cancelBtn">{{cancelText}}</text>
  10. </view>
  11. <view class="u-select__header__title" style="flex: 1;text-align: center;">
  12. {{title}}
  13. </view>
  14. <view class="u-select__header__confirm u-select__header__btn" :style="{ color: confirmColor }"
  15. style="width: 60rpx;text-align: center;" hover-class="u-hover-class" :hover-stay-time="150"
  16. @touchmove.stop="" @tap.stop="handleConfirm()">
  17. <text v-if="confirmBtn">{{confirmText}}</text>
  18. </view>
  19. </view>
  20. <view class="search-box_sticky" v-if=" isFlow || filterable">
  21. <view class="search-box">
  22. <u-search :placeholder="$t('app.apply.pleaseKeyword')" height="72" :show-action="false"
  23. bg-color="#f0f2f6" shape="square" v-model="searchValue">
  24. </u-search>
  25. </view>
  26. </view>
  27. <view class="u-select__body u-select__body__multiple">
  28. <scroll-view :scroll-y="true" style="height: 100%">
  29. <u-checkbox-group v-model="innerValue" v-if="multiple">
  30. <u-checkbox v-model="item.checked" v-for="(item, index) in columnList" :key="index"
  31. :name="item[valueName]">
  32. {{item[labelName]}}
  33. </u-checkbox>
  34. </u-checkbox-group>
  35. <u-radio-group wrap v-model="checkedValue" v-else>
  36. <u-radio @change="radioGroupChange(item,i)" :name="item[valueName]"
  37. v-for="(item,i) in columnList" :key="i">
  38. {{item[labelName]}}
  39. </u-radio>
  40. </u-radio-group>
  41. <view v-if="!columnList.length" class="notData-box u-flex-col">
  42. <view class="u-flex-col notData-inner">
  43. <image :src="icon" class="iconImg"></image>
  44. </view>
  45. <text class="notData-inner-text">{{$t('common.noData')}}</text>
  46. </view>
  47. </scroll-view>
  48. </view>
  49. </view>
  50. </u-popup>
  51. </template>
  52. <script>
  53. import resources from '@/libs/resources.js'
  54. export default {
  55. name: 'JnpfMultSelect',
  56. props: {
  57. list: {
  58. type: Array,
  59. default: () => []
  60. },
  61. height: {
  62. type: [Number, String],
  63. default: ''
  64. },
  65. multiple: {
  66. type: Boolean,
  67. default: false
  68. },
  69. filterable: {
  70. type: Boolean,
  71. default: false
  72. },
  73. cancelBtn: {
  74. type: Boolean,
  75. default: true
  76. },
  77. confirmBtn: {
  78. type: Boolean,
  79. default: true
  80. },
  81. show: {
  82. type: Boolean,
  83. default: false
  84. },
  85. cancelColor: {
  86. type: String,
  87. default: '#606266'
  88. },
  89. confirmColor: {
  90. type: String,
  91. default: '#2979ff'
  92. },
  93. safeAreaInsetBottom: {
  94. type: Boolean,
  95. default: false
  96. },
  97. maskCloseAble: {
  98. type: Boolean,
  99. default: true
  100. },
  101. defaultValue: {
  102. type: Array,
  103. default: () => []
  104. },
  105. labelName: {
  106. type: String,
  107. default: 'fullName'
  108. },
  109. valueName: {
  110. type: String,
  111. default: 'id'
  112. },
  113. title: {
  114. type: String,
  115. default: ''
  116. },
  117. cancelText: {
  118. type: String,
  119. default: '取消'
  120. },
  121. confirmText: {
  122. type: String,
  123. default: '确认'
  124. },
  125. isFlow: {
  126. type: Boolean,
  127. default: false
  128. }
  129. },
  130. data() {
  131. return {
  132. columnData: [],
  133. innerValue: [],
  134. lastSelectIndex: [],
  135. showPopup: false,
  136. checkedValue: '',
  137. searchValue: '',
  138. icon: resources.message.nodata,
  139. }
  140. },
  141. watch: {
  142. show: {
  143. handler(val) {
  144. this.showPopup = val
  145. if (val) setTimeout(() => this.init(), 10);
  146. },
  147. immediate: true,
  148. },
  149. },
  150. computed: {
  151. columnList() {
  152. return this.columnData.filter((o) => (o[this.labelName] && o[this.labelName].match(this.searchValue)))
  153. }
  154. },
  155. methods: {
  156. init() {
  157. this.setColumnData();
  158. this.setDefault();
  159. },
  160. setColumnData() {
  161. this.columnData = this.list.map((o, i) => ({
  162. ...o,
  163. checked: false
  164. }))
  165. },
  166. // 获取默认选中的值
  167. setDefault() {
  168. this.searchValue = ''
  169. this.checkedValue = ''
  170. if (this.multiple) {
  171. this.innerValue = this.defaultValue
  172. outer: for (let i = 0; i < this.innerValue.length; i++) {
  173. inner: for (let j = 0; j < this.columnData.length; j++) {
  174. if (this.innerValue[i] === this.columnData[j][this.valueName]) {
  175. this.columnData[j].checked = true
  176. break inner
  177. }
  178. }
  179. }
  180. } else {
  181. for (let j = 0; j < this.columnData.length; j++) {
  182. if (this.defaultValue[0] === this.columnData[j][this.valueName]) {
  183. this.checkedValue = this.columnData[j][this.valueName]
  184. this.innerValue = this.columnData[j]
  185. }
  186. }
  187. }
  188. },
  189. radioGroupChange(e) {
  190. this.innerValue = [{
  191. ...e,
  192. checked: true
  193. }]
  194. },
  195. handleConfirm() {
  196. if (this.multiple) {
  197. let data = {
  198. indexs: [],
  199. list: [],
  200. label: '',
  201. value: uni.$u.deepClone(this.innerValue)
  202. }
  203. if (!this.isFlow) {
  204. for (let i = 0; i < this.columnData.length; i++) {
  205. const item = this.columnData[i]
  206. if (this.columnData[i].checked) {
  207. data.list.push(uni.$u.deepClone(item))
  208. data.indexs.push(i)
  209. if (!data.label) {
  210. data.label += item[this.labelName]
  211. } else {
  212. data.label += ',' + item[this.labelName]
  213. }
  214. }
  215. }
  216. }
  217. this.$emit('confirm', data);
  218. } else {
  219. if (this.isFlow && !this.innerValue.length) return this.$u.toast("请选择流程");
  220. this.$emit('confirm', this.innerValue);
  221. }
  222. this.close()
  223. },
  224. close() {
  225. this.$emit('close');
  226. },
  227. }
  228. }
  229. </script>
  230. <style scoped lang="scss">
  231. .notData-box {
  232. width: 100%;
  233. height: 100%;
  234. justify-content: center;
  235. align-items: center;
  236. margin-top: -50px;
  237. .notData-inner {
  238. width: 286rpx;
  239. height: 222rpx;
  240. align-items: center;
  241. .iconImg {
  242. width: 100% !important;
  243. height: 100% !important;
  244. }
  245. }
  246. .notData-inner-text {
  247. color: #909399;
  248. }
  249. }
  250. .u-select {
  251. &__header {
  252. display: flex;
  253. flex-direction: row;
  254. align-items: center;
  255. justify-content: space-between;
  256. height: 40px;
  257. padding: 0 20px;
  258. position: relative;
  259. ::after {
  260. content: "";
  261. position: absolute;
  262. border-bottom: 0.5px solid #eaeef1;
  263. transform: scaleY(0.5);
  264. bottom: 0;
  265. right: 0;
  266. left: 0;
  267. }
  268. }
  269. &__body {
  270. width: 100%;
  271. height: 500rpx;
  272. overflow: hidden;
  273. background-color: #fff;
  274. &__picker-view {
  275. height: 100%;
  276. box-sizing: border-box;
  277. &__item {
  278. display: flex;
  279. align-items: center;
  280. justify-content: center;
  281. font-size: 32rpx;
  282. padding: 0 8rpx;
  283. }
  284. }
  285. .u-checkbox-group {
  286. padding: 0 30rpx;
  287. .u-checkbox {
  288. height: 25px;
  289. line-height: 25px;
  290. width: 100% !important;
  291. display: flex;
  292. margin: 6rpx 0;
  293. :deep(uni-text) {
  294. flex: 1;
  295. overflow: hidden;
  296. white-space: nowrap;
  297. text-overflow: ellipsis;
  298. }
  299. }
  300. }
  301. }
  302. }
  303. </style>