points.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view class="container">
  3. <cu-custom id="custom"
  4. bgImage="https://yostest175549.obs.cn-east-2.myhuaweicloud.com:443/202306151686796745663B52544232.png"
  5. :isBack="true">
  6. <block slot="backText">返回</block>
  7. <block slot="content">
  8. {{ title }}
  9. </block>
  10. </cu-custom>
  11. <My_listbox ref="List" @getlist="getList" :empty="empty">
  12. <view :class="[isActive(item[idKey])]" v-for="item in list" :key="item[idKey]" @click="onSelect(item)">
  13. {{ item[showKey] }}
  14. </view>
  15. <view style="height:22vw;" />
  16. </My_listbox>
  17. <view class="but-box">
  18. <view style="width: 75vw;">
  19. <u-button :disabled="!value.length" type="primary" text="确定选择" color="rgba(42,106,242,.8)"
  20. loadingText="执行中..." :loading="loading" @click="submit" />
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. name: "points",
  28. computed: {
  29. isActive() {
  30. return function (id) {
  31. return this.value.some(v => v == id) ? "active item" : "item"
  32. };
  33. }
  34. },
  35. data() {
  36. return {
  37. list: [],
  38. ...this.$Http.route.data.param,
  39. empty: true,
  40. title: '',
  41. idKey: "",
  42. showKey: "",
  43. loading: false,
  44. value: [],
  45. showList: [],
  46. extent: -1,
  47. }
  48. },
  49. onLoad(options) {
  50. let data = this.$Http.route.data;
  51. this.title = '选择' + data.label
  52. this.param = data.param;
  53. this.idKey = data.idKey;
  54. this.showKey = data.showKey;
  55. this.value = data.value.value;
  56. this.showList = data.value.showList;
  57. this.extent = data.extent || -1;
  58. this.getList(true)
  59. },
  60. methods: {
  61. getList(init = false) {
  62. if (this.loading) return;
  63. let param = this.param;
  64. if (init) {
  65. param.content.pageNumber = 1;
  66. param.content.pageSize = param.content.pageSize || 20;
  67. param.content.pageTotal = 1;
  68. };
  69. if (param.content.pageNumber > param.content.pageTotal) return;
  70. this.loading = true;
  71. return this.$Http.basic(param).then(res => {
  72. this.loading = false;
  73. this.$refs.List.setHeight();
  74. console.log("选择列表", res)
  75. if (this.cutoff(res.msg)) return;
  76. this.$refs.List.RefreshToComplete();
  77. this.empty = res.total == 0;
  78. this.list = res.pageNumber == 1 ? res.data : this.list.concat(res.data);
  79. param.content.pageNumber = res.pageNumber + 1;
  80. param.content.pageTotal = res.pageTotal;
  81. })
  82. },
  83. onSelect(item) {
  84. let id = item[this.idKey],
  85. that = this;
  86. if (this.value.some(v => v == id)) {
  87. this.value = this.value.filter(v => v != id)
  88. this.showList = this.showList.filter(v => v[this.showKey] != item[this.showKey])
  89. } else {
  90. if (this.extent == 1) {
  91. uni.showModal({
  92. title: '提示',
  93. content: `是否确定选择"${item[this.showKey]}"`,
  94. success: ({ confirm }) => {
  95. that.value = [id];
  96. that.showList = [item[this.showKey]];
  97. if (confirm) that.submit()
  98. },
  99. })
  100. } else {
  101. if (this.extent != -1 && this.value.length == this.extent) return uni.showToast({
  102. title: '可选数量已上限',
  103. icon: 'none',
  104. duration: 1500,
  105. })
  106. this.value.push(id);
  107. this.showList.push(item[this.showKey])
  108. }
  109. }
  110. },
  111. submit() {
  112. this.$Http.handleAdd({
  113. value: this.value,
  114. showList: this.showList,
  115. })
  116. }
  117. },
  118. onUnload() {
  119. }
  120. }
  121. </script>
  122. <style lang="scss" scoped>
  123. .item {
  124. display: flex;
  125. align-items: center;
  126. justify-content: space-between;
  127. padding: 10px;
  128. box-sizing: border-box;
  129. background: #fff;
  130. width: 355px;
  131. margin: 10px auto;
  132. border-radius: 4px;
  133. }
  134. .active {
  135. background: #0054E1;
  136. color: #fff;
  137. }
  138. .but-box {
  139. position: absolute;
  140. width: 100vw;
  141. bottom: 30px;
  142. display: flex;
  143. justify-content: center;
  144. /deep/ .u-button__text,
  145. /deep/.u-button__loading-text {
  146. font-size: 14px !important;
  147. }
  148. /deep/.u-loading-icon__spinner {
  149. width: 17.25px !important;
  150. height: 17.25px !important;
  151. }
  152. }
  153. </style>