compnaySelect.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <template>
  2. <view class="select-container" @touchmove.stop.prevent>
  3. <view class="mask" :class="activeClass ? 'mask-show' : ''" @tap="onCancel(true)"></view>
  4. <view class="select-box" :class="activeClass ? 'select-box-show' : ''">
  5. <div style="height: 900rpx">
  6. <div style="display: flex">
  7. <uni-easyinput type="text" class="searchinput" v-model="formData.qymc" placeholder="输入关联企业名称(模糊查询)"
  8. style="height: 70rpx" />
  9. <van-button class="searchbutton" style="height: 70rpx" type="primary"
  10. @click="getCompaynList()">搜索</van-button>
  11. </div>
  12. <div class="chooseCompanyTags">
  13. <scroll-view class="body" @scrolltolower="scrolltolower" scroll-y="true"
  14. style="position: absolute; z-index: 1000">
  15. <div v-for="(item, index) in companyList" :key="index" class="selectlist">
  16. <div class="title_2">
  17. {{ item.label }}
  18. </div>
  19. <div v-if="!item.isSelected" class="title_1" @click="chosseTags(item, index)">
  20. <uni-icons type="plusempty" size="30rpx"></uni-icons>
  21. </div>
  22. </div>
  23. </scroll-view>
  24. </div>
  25. </div>
  26. <view class="btn-view">
  27. <button class="btn" @click="openTagsDialog()" style="
  28. border-top-left-radius: 5rem;
  29. border-bottom-left-radius: 5rem;
  30. background: white;
  31. color: #1d18bc;
  32. border: 1px solid;
  33. ">
  34. 已选择({{ isSelectedList.length }})<van-icon name="arrow-down" />
  35. </button>
  36. <button style="
  37. border-radius: 0;
  38. border: 1px solid #1d18bc;
  39. border-top-right-radius: 5rem;
  40. border-bottom-right-radius: 5rem;
  41. " class="btn" @click="updown()">
  42. 确认提交
  43. </button>
  44. </view>
  45. </view>
  46. <is-selected-tags ref="isSelectedTags" :isSelectedList="isSelectedList" @clearAll="clearAll" @updown="updown"
  47. @spiliceIsSelectedList="spiliceIsSelectedList" />
  48. </view>
  49. </template>
  50. <!-- 多选组件 -->
  51. <script>
  52. import isSelectedTags from "./isSelectedTags.vue";
  53. export default {
  54. data() {
  55. return {
  56. isSelectedList: [],
  57. companyList: [],
  58. isSelectList: [],
  59. formData: {},
  60. show: false, //是否显示
  61. activeClass: true, //激活样式状态
  62. selectedArr: [], //选择对照列表
  63. selectedArrOld: [], //选择对照列表上一次的数据
  64. };
  65. },
  66. components: {
  67. isSelectedTags,
  68. },
  69. onShow() {
  70. this.show = this.value;
  71. },
  72. methods: {
  73. async updown() {
  74. console.log(this.isSelectedList);
  75. this.$emit("confirm", this.isSelectedList);
  76. this.show = false;
  77. this.emit('colseSelectPage')
  78. },
  79. clearAll() {
  80. this.isSelectedList = [];
  81. this.companyList.forEach((e) => {
  82. e.isSelected = false;
  83. this.$forceUpdate();
  84. });
  85. },
  86. spiliceIsSelectedList(item, index) {
  87. this.isSelectedList.splice(index, 1);
  88. let changeIndex = this.companyList.findIndex(
  89. (e) => e.tagCategoryId == item.tagCategoryId
  90. );
  91. this.companyList[changeIndex].isSelected = false;
  92. this.$forceUpdate();
  93. },
  94. chosseTags(item, index) {
  95. let filterIndex = this.isSelectedList.findIndex(
  96. (e) => e.value == item.value
  97. );
  98. if (filterIndex != -1) {
  99. this.$showToast("该标签与已选择标签重复");
  100. return;
  101. }
  102. if (item.isEffective == 1) {
  103. this.openChooseTimeDialog(item, index);
  104. } else {
  105. this.isSelectedList.push(this.companyList[index]);
  106. this.companyList[index].isSelected = true;
  107. this.companyList = [...this.companyList];
  108. }
  109. },
  110. openTagsDialog() {
  111. this.$refs.isSelectedTags.onOpen([]);
  112. },
  113. getAllList(data) {
  114. console.log(data)
  115. this.companyList = [...this.companyList, ...data];
  116. },
  117. getCompaynList() {
  118. this.companyList = []
  119. this.$emit('clearCompaynList')
  120. console.log(this.companyList);
  121. console.log(this.selectedArr);
  122. this.$emit("getCompanyAll", this.formData.qymc);
  123. },
  124. scrolltolower(e) {
  125. console.log(e)
  126. this.$emit('addPageNum')
  127. },
  128. // 设置默认选中通用办法
  129. setItemActiveState() {
  130. if (this.companyList.length && this.defaultSelected.length) {
  131. this.companyList.forEach((item, i) => {
  132. for (let n = 0; n < this.defaultSelected.length; n++) {
  133. if (
  134. !item.disabled &&
  135. item[this.valueName] === this.defaultSelected[n]
  136. ) {
  137. this.selectedArr.splice(i, 1, true);
  138. break;
  139. }
  140. }
  141. });
  142. }
  143. },
  144. /**
  145. * 选择事件
  146. * @index {Number} 点击下标
  147. */
  148. onSelected(index) {
  149. if (this.companyList[index].disabled) return;
  150. console.log(this.companyList[index]);
  151. if (!this.companyList[index].isSelect) {
  152. this.isSelectList.push(this.companyList[index].value);
  153. this.companyList[index].isSelect = true;
  154. } else {
  155. let deleteIndex = this.isSelectList.findIndex(
  156. (e) => e.value == this.companyList[index].value
  157. );
  158. this.isSelectList.splice(deleteIndex, 1);
  159. this.companyList[index].isSelect = false;
  160. }
  161. this.$forceUpdate();
  162. this.companyList = [...this.companyList];
  163. // let index2Active = this.selectedArr[index];
  164. // this.selectedArr.splice(index, 1, !index2Active);
  165. },
  166. // 取消事件
  167. onCancel(isMask) {
  168. if (!isMask || this.maskCloseAble) {
  169. this.show = false;
  170. this.selectedArr = JSON.parse(JSON.stringify(this.selectedArrOld));
  171. } else {
  172. return;
  173. }
  174. this.$emit("cancel");
  175. },
  176. // 返回去除了disabled状态后的对照列表
  177. returnWipeDisabledList() {
  178. let arr = [];
  179. this.selectedArr.forEach((el, index) => {
  180. if (!this.companyList[index].disabled) arr.push(el);
  181. });
  182. return arr;
  183. },
  184. // 全选/非全选事件
  185. onAllToggle() {
  186. let wipeDisabledList = this.returnWipeDisabledList();
  187. // 如果去除了disabled的对照列表有false的数据,代表未全选
  188. if (wipeDisabledList.includes(false)) {
  189. this.selectedArr.forEach((el, index) => {
  190. if (!this.companyList[index].disabled)
  191. this.selectedArr.splice(index, 1, true);
  192. });
  193. } else {
  194. this.selectedArr.forEach((el, index) => {
  195. if (!this.companyList[index].disabled)
  196. el = this.selectedArr.splice(index, 1, false);
  197. });
  198. }
  199. },
  200. // 确定事件
  201. onConfirm() {
  202. this.show = false;
  203. let selectedData = [];
  204. this.companyList.forEach((e, index) => {
  205. if (e.isSelect) {
  206. selectedData.push(this.companyList[index]);
  207. }
  208. });
  209. if (this.mode === "multiple") {
  210. this.$emit("confirm", selectedData);
  211. } else {
  212. let backData = selectedData[0] || {};
  213. this.$emit("confirm", backData);
  214. }
  215. },
  216. },
  217. computed: {
  218. // 返回是否全选
  219. isAll() {
  220. let wipeDisabledList = this.returnWipeDisabledList();
  221. if (!wipeDisabledList.length) return false;
  222. return !wipeDisabledList.includes(false);
  223. },
  224. },
  225. props: {
  226. // 双向绑定
  227. value: {
  228. type: Boolean,
  229. default: false,
  230. },
  231. // 取消按钮文字
  232. cancelText: {
  233. type: String,
  234. default: "取消",
  235. },
  236. // 确认按钮文字
  237. confirmText: {
  238. type: String,
  239. default: "确认",
  240. },
  241. // label对应的key名称
  242. labelName: {
  243. type: String,
  244. default: "label",
  245. },
  246. // value对应的key名称
  247. valueName: {
  248. type: String,
  249. default: "value",
  250. },
  251. // 是否允许点击遮罩层关闭
  252. maskCloseAble: {
  253. type: Boolean,
  254. default: true,
  255. },
  256. // 是否显示全选
  257. allShow: {
  258. type: Boolean,
  259. default: true,
  260. },
  261. // 模式
  262. mode: {
  263. type: String,
  264. default: "multiple",
  265. },
  266. // 默认选中值
  267. defaultSelected: {
  268. type: Array,
  269. default: function () {
  270. return [];
  271. },
  272. },
  273. // 数据源
  274. // data: {
  275. // type: Array,
  276. // required: true,
  277. // default: () => {
  278. // return [];
  279. // },
  280. // },
  281. },
  282. watch: {
  283. async value(newVal) {
  284. console.log(newVal)
  285. this.show = newVal;
  286. this.activeClass = newVal;
  287. if (newVal) {
  288. this.selectedArrOld = JSON.parse(JSON.stringify(this.selectedArr));
  289. }
  290. },
  291. show(newVal) {
  292. this.$emit("input", newVal);
  293. this.$emit("change", newVal);
  294. },
  295. defaultSelected: {
  296. handler() {
  297. this.setItemActiveState();
  298. },
  299. deep: true,
  300. immediate: true,
  301. },
  302. },
  303. };
  304. </script>
  305. <style lang="scss">
  306. .searchbutton {
  307. button {
  308. height: 69rpx;
  309. line-height: 69rpx;
  310. }
  311. }
  312. .searchinput {
  313. .uni-easyinput__content-input {
  314. height: 70rpx;
  315. }
  316. }
  317. .btn-view {
  318. width: 100%;
  319. height: 100rpx;
  320. padding: 20rpx 10%;
  321. background-color: #ffffff;
  322. position: fixed;
  323. bottom: 0;
  324. left: 0;
  325. z-index: 1000;
  326. button {
  327. &::after {
  328. border: none;
  329. }
  330. }
  331. }
  332. </style>
  333. <style lang="scss" scoped>
  334. .selectlist {
  335. border-bottom: 2rpx solid #cccccc;
  336. display: flex;
  337. align-items: center;
  338. justify-content: space-between;
  339. }
  340. .chooseCompanyTags {
  341. .title_1 {
  342. font-size: 28rpx;
  343. font-weight: 500;
  344. color: #333333;
  345. text-align: right;
  346. height: 64rpx;
  347. line-height: 64rpx;
  348. }
  349. .title_2 {
  350. font-size: 26rpx;
  351. font-weight: 500;
  352. color: #777777;
  353. height: 64rpx;
  354. line-height: 64rpx;
  355. text-align: left;
  356. }
  357. .title_3 {
  358. margin-bottom: 12rpx;
  359. font-size: 26rpx;
  360. font-weight: 500;
  361. color: #777777;
  362. }
  363. .cell_1 {
  364. float: left;
  365. width: 10%;
  366. }
  367. .checkbox {
  368. border: 1px solid #cccccc;
  369. border-radius: 4rpx 4rpx 4rpx 4rpx;
  370. height: 30rpx;
  371. width: 30rpx;
  372. }
  373. .cell_2 {
  374. float: left;
  375. width: 90%;
  376. img {
  377. height: 60rpx;
  378. width: 60rpx;
  379. float: right;
  380. margin: 96rpx 0rpx 94rpx 0;
  381. }
  382. }
  383. .btn {
  384. width: 40%;
  385. height: 90rpx;
  386. background: #1d18bc;
  387. line-height: 90rpx;
  388. color: white;
  389. float: left;
  390. }
  391. .jichuback {
  392. width: calc(100% - 64rpx);
  393. margin: 32rpx;
  394. background: white;
  395. border-bottom: 2rpx solid #cccccc;
  396. }
  397. .tags_type {
  398. width: calc(100% - 64rpx);
  399. margin: 16rpx;
  400. }
  401. }
  402. .btn-view {
  403. width: 100%;
  404. height: 100rpx;
  405. padding: 20rpx 10%;
  406. background-color: #ffffff;
  407. position: fixed;
  408. bottom: 0;
  409. left: 0;
  410. z-index: 1000;
  411. }
  412. .btn {
  413. width: 40%;
  414. height: 90rpx;
  415. background: #1d18bc;
  416. line-height: 90rpx;
  417. color: white;
  418. float: left;
  419. }
  420. .select-container {
  421. width: 100vw;
  422. height: 100vh;
  423. position: fixed;
  424. left: 0;
  425. top: 0;
  426. z-index: 999;
  427. $paddingLR: 18rpx;
  428. .mask {
  429. width: 100%;
  430. height: 100%;
  431. background-color: $uni-bg-color-mask;
  432. opacity: 0;
  433. transition: opacity 0.3s;
  434. &.mask-show {
  435. opacity: 1;
  436. }
  437. }
  438. // 选择器内容区域
  439. .select-box {
  440. width: 100%;
  441. position: absolute;
  442. bottom: 0;
  443. left: 0;
  444. transform: translate3d(0px, 100%, 0px);
  445. background-color: $uni-bg-color;
  446. transition: all 0.3s;
  447. &.select-box-show {
  448. transform: translateZ(0);
  449. }
  450. .header {
  451. display: flex;
  452. box-sizing: border-box;
  453. width: 100%;
  454. justify-content: space-between;
  455. border-bottom: 1px solid $uni-border-color;
  456. line-height: 76rpx;
  457. font-size: 30rpx;
  458. padding: 0 $paddingLR;
  459. .cancel {
  460. color: $uni-text-color-grey;
  461. }
  462. .all {
  463. .all-active {
  464. &::after {
  465. display: inline-block;
  466. content: "✔";
  467. padding-left: 8rpx;
  468. }
  469. }
  470. }
  471. .confirm {
  472. color: $uni-color-primary;
  473. }
  474. }
  475. .body-warp {
  476. width: 100%;
  477. height: 30vh;
  478. box-sizing: border-box;
  479. padding: 20rpx $paddingLR;
  480. }
  481. .body {
  482. width: 96%;
  483. height: 70%;
  484. overflow-y: auto;
  485. padding: 2%;
  486. .empty-tips {
  487. margin-top: 25%;
  488. text-align: center;
  489. font-size: 26rpx;
  490. color: $uni-color-error;
  491. }
  492. }
  493. }
  494. }
  495. </style>