materMultipleSelect.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view class="mater-select">
  3. <!-- <u-sticky>
  4. <view class="search-wrap">
  5. <u-search placeholder="关键词搜索" :showAction="false" v-model="keyword"></u-search>
  6. </view>
  7. </u-sticky> -->
  8. <u-cell-group>
  9. <div v-for="(material,index) in materialList" :key="index">
  10. <p class="type-title">
  11. {{ material.type }}
  12. </p>
  13. <view v-for="(item,iindex) in option.filter((item) =>item.type==material.type)" :key="iindex">
  14. <u-cell :title="item.text" @click="onSelect(item)">
  15. <u-switch slot="right-icon" disabled activeColor="#5ac725" v-model="item.isSelect"></u-switch>
  16. </u-cell>
  17. </view>
  18. </div>
  19. </u-cell-group>
  20. <view class="bind-btn-wrap">
  21. <button class="bind-btn" @click="onSubmitClick()">{{ $t('base.common.submit') }}
  22. </button>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. data() {
  29. return {
  30. keyword: "",
  31. option: [],
  32. materialList: [],
  33. index: null,
  34. isMultiple: "0",
  35. selectMaterList: [],
  36. };
  37. },
  38. onLoad(options) {
  39. this.handleOption(options);
  40. },
  41. methods: {
  42. onSubmitClick() {
  43. if (this.selectMaterList && this.selectMaterList.length > 0) {
  44. let pages = getCurrentPages();
  45. let prevPage = pages[pages.length - 2].$vm.materialList = this.selectMaterList; //重点$vm
  46. uni.navigateBack();
  47. }
  48. },
  49. onSelect(mater) {
  50. console.log(mater, "========");
  51. let index = this.option.findIndex(function(item) {
  52. return mater.value === item.value;
  53. });
  54. let selectedIndex = this.selectMaterList.findIndex(function(item) {
  55. return mater.value === item.value;
  56. });
  57. let isSelect = false
  58. if (mater.isSelect != 1) {
  59. isSelect = true
  60. }
  61. if (index > -1) {
  62. if (selectedIndex > -1) {
  63. this.selectMaterList.splice(selectedIndex, 1)
  64. } else {
  65. this.selectMaterList.push({
  66. ...mater
  67. })
  68. }
  69. this.option[index].isSelect = isSelect
  70. }
  71. this.$forceUpdate()
  72. },
  73. handleOption(options) {
  74. this.option = JSON.parse(options.option) || [];
  75. this.materialList = this.repeatList(this.option);
  76. var selectedOption = JSON.parse(options.selectedOption) || [];
  77. console.log("系统物料信息,已选择物料,", this.option, selectedOption);
  78. if (selectedOption) {
  79. selectedOption.forEach(mater => {
  80. this.selectMaterList.push({
  81. ...mater
  82. })
  83. let selectedIndex = this.option.findIndex(function(p) {
  84. return p.value === mater.value;
  85. });
  86. if (selectedIndex > -1) {
  87. this.$set(this.option[selectedIndex], "isSelect", true);
  88. }
  89. })
  90. }
  91. },
  92. repeatList(arr) {
  93. const map = new Map();
  94. return arr.filter((item) => !map.has(item.type) && map.set(item.type, 1));
  95. },
  96. },
  97. };
  98. </script>
  99. <style lang="scss" scoped>
  100. .mater-select {
  101. padding-bottom: 154rpx;
  102. .search-wrap {
  103. padding: 20rpx 30rpx;
  104. background-color: #fff;
  105. }
  106. .type-title {
  107. line-height: 84rpx;
  108. background-color: #f2f2f2;
  109. padding: 0 30rpx;
  110. font-size: 30rpx;
  111. font-weight: bold;
  112. }
  113. .bind-btn-wrap{
  114. width: calc(100% - 48rpx);
  115. padding: 32rpx 24rpx;
  116. position: fixed;
  117. bottom: 0;
  118. background-color: #fff;
  119. }
  120. }
  121. </style>