materSelect.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 in materialList" :key="material.type">
  10. <p class="type-title">
  11. {{ material.type }}
  12. </p>
  13. <view v-for="item in option.filter((item) =>item.type==material.type)" :key="item.label">
  14. <u-cell :title="item.text" @click="onSelect(item)"></u-cell>
  15. </view>
  16. </div>
  17. </u-cell-group>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. data() {
  23. return {
  24. keyword: "",
  25. option: [],
  26. materialList: [],
  27. index: null,
  28. isMultiple: "0",
  29. };
  30. },
  31. onLoad(options) {
  32. this.handleOption(options);
  33. },
  34. methods: {
  35. onSelect(item) {
  36. console.log(item, "========");
  37. let pages = getCurrentPages();
  38. let prevPage = pages[pages.length - 2].$vm.orderForm; //上一个页面
  39. console.log(this.index);
  40. if (this.index && this.index !== null) {
  41. prevPage.batchOrderList[this.index].materialId = ''
  42. prevPage.batchOrderList[this.index].materialName = ''
  43. prevPage.batchOrderList[this.index].kind = ''
  44. prevPage.batchOrderList[this.index].measureUnit = ''
  45. if (item.value) {
  46. prevPage.batchOrderList[this.index].materialId = item.value
  47. prevPage.batchOrderList[this.index].materialName = item.text
  48. prevPage.batchOrderList[this.index].measureUnit = item.measureUnit
  49. }
  50. } else {
  51. prevPage.materialId = ''
  52. prevPage.materialName = ''
  53. prevPage.kind = ''
  54. prevPage.measureUnit = ''
  55. if (item.value) {
  56. prevPage.materialId = item.value
  57. prevPage.materialName = item.text
  58. prevPage.kind = item.kind
  59. prevPage.measureUnit = item.measureUnit
  60. }
  61. }
  62. uni.navigateBack();
  63. },
  64. handleOption(options) {
  65. this.option = JSON.parse(options.option) || [];
  66. this.materialList = this.repeatList(this.option);
  67. this.index = options.index;
  68. console.log(this.materialList, "===========");
  69. },
  70. repeatList(arr) {
  71. const map = new Map();
  72. return arr.filter((item) => !map.has(item.type) && map.set(item.type, 1));
  73. },
  74. },
  75. };
  76. </script>
  77. <style lang="scss" scoped>
  78. .mater-select {
  79. .search-wrap {
  80. padding: 20rpx 30rpx;
  81. background-color: #fff;
  82. }
  83. .type-title {
  84. line-height: 84rpx;
  85. background-color: #f2f2f2;
  86. padding: 0 30rpx;
  87. font-size: 30rpx;
  88. font-weight: bold;
  89. }
  90. }
  91. </style>