device.vue 5.2 KB

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