multiple.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <uni-popup
  3. class="device-popup"
  4. ref="deviceChoosePopRef"
  5. type="bottom"
  6. :is-mask-click="false"
  7. borderRadius="10px 10px 0 0"
  8. >
  9. <z-paging
  10. class="page-nopadding z-page-popup"
  11. ref="paging"
  12. style="top: 100px"
  13. :default-page-size="15"
  14. v-model="dataList"
  15. @query="queryList"
  16. >
  17. <!-- z-paging默认铺满全屏,此时页面所有view都应放在z-paging标签内,否则会被盖住 -->
  18. <!-- 需要固定在页面顶部的view请通过slot="top"插入,包括自定义的导航栏 -->
  19. <template #top>
  20. <view class="page-top">
  21. <uni-row class="head-row">
  22. <uni-col :span="22" class="head-title justify-center">
  23. {{ $t("device.selectDevice") }}
  24. </uni-col>
  25. <uni-col
  26. :span="2"
  27. class="head-cancel align-center justify-end"
  28. @click="oncancel"
  29. >
  30. <uni-icons type="closeempty" color="#333"></uni-icons>
  31. </uni-col>
  32. </uni-row>
  33. <view
  34. class="choice-row flex-row flex-wrap align-center justify-start"
  35. >
  36. <view
  37. class="choice-item align-center justify-center"
  38. v-for="item in chooseList"
  39. @click="onChooseDel(item)"
  40. >
  41. {{ item.deviceName }}
  42. <uni-icons
  43. class="choice-close-icon"
  44. type="closeempty"
  45. color="#fff"
  46. ></uni-icons>
  47. </view>
  48. </view>
  49. <uni-row class="search-row flex-rowc justify-between">
  50. <uni-col :span="18">
  51. <uni-easyinput
  52. v-model="searchValue"
  53. :styles="inputStyles"
  54. :placeholderStyle="placeholderStyle"
  55. :placeholder="`${$t('operation.PleaseInput')}`"
  56. >
  57. </uni-easyinput>
  58. </uni-col>
  59. <uni-col :span="6" class="flex-row justify-end">
  60. <button
  61. class="mini-btn"
  62. type="primary"
  63. size="mini"
  64. @click="searchList"
  65. >
  66. {{ $t("operation.search") }}
  67. </button>
  68. </uni-col>
  69. </uni-row>
  70. <uni-row
  71. :gutter="2"
  72. class="table-header flex-row align-center justify-between"
  73. >
  74. <uni-col :span="6" class="flex-row justify-center">
  75. {{ $t("device.deviceName") }}
  76. </uni-col>
  77. <uni-col :span="6" class="flex-row justify-center">
  78. {{ $t("device.assetCode") }}
  79. </uni-col>
  80. <uni-col :span="6" class="flex-row justify-center">
  81. {{ $t("device.department") }}
  82. </uni-col>
  83. <uni-col :span="6" class="flex-row justify-center">
  84. {{ $t("operation.createTime") }}
  85. </uni-col>
  86. </uni-row>
  87. </view>
  88. </template>
  89. <view class="page-table">
  90. <view class="table-content">
  91. <uni-row
  92. :gutter="2"
  93. class="item-row align-center"
  94. :class="{
  95. choosed: chooseIds.includes(item.id),
  96. 'no-boms': item.hasSetMaintenanceBom === false,
  97. }"
  98. v-for="(item, index) in dataList"
  99. :key="index"
  100. @click="onChoose(item)"
  101. >
  102. <uni-col :span="6" class="item-col flex-row justify-start">
  103. {{ item.deviceName }}
  104. </uni-col>
  105. <uni-col :span="6" class="item-col flex-row justify-center">
  106. {{ item.deviceCode }}
  107. </uni-col>
  108. <uni-col :span="6" class="item-col flex-row justify-center">
  109. {{ item.deptName }}
  110. </uni-col>
  111. <uni-col :span="6" class="item-col flex-row justify-end">
  112. {{ item.createTime ? formatDate(item.createTime) : "" }}
  113. </uni-col>
  114. </uni-row>
  115. </view>
  116. </view>
  117. <template #bottom>
  118. <button style="border-radius: 0" type="primary" @click="onSubmit">
  119. {{ $t("operation.submit") }}
  120. </button>
  121. </template>
  122. </z-paging>
  123. </uni-popup>
  124. </template>
  125. <script setup>
  126. import { ref, reactive, computed } from "vue";
  127. import dayjs from "dayjs";
  128. import { devicePage } from "@/api/device";
  129. const searchValue = ref("");
  130. const placeholderStyle = ref("color:#797979;font-weight:500;font-size:16px");
  131. const inputStyles = reactive({
  132. backgroundColor: "#FFFFFF",
  133. color: "#797979",
  134. });
  135. const paging = ref(null);
  136. // v-model绑定的这个变量不要在分页请求结束中自己赋值,直接使用即可
  137. const dataList = ref([]);
  138. // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可
  139. const queryList = (pageNo, pageSize) => {
  140. // 此处请求仅为演示,请替换为自己项目中的请求
  141. devicePage({
  142. pageNo,
  143. pageSize,
  144. commonParam: searchValue.value,
  145. })
  146. .then((res) => {
  147. // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
  148. paging.value.complete(res.data.list);
  149. })
  150. .catch((res) => {
  151. // 如果请求失败写paging.value.complete(false);
  152. // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
  153. // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
  154. paging.value.complete(false);
  155. });
  156. };
  157. const searchList = () => {
  158. paging.value.reload();
  159. };
  160. const formatDate = (time) => {
  161. return dayjs(time).format("YYYY-MM-DD");
  162. };
  163. // ----------------------------------------------
  164. const deviceChoosePopRef = ref(null);
  165. const open = () => {
  166. deviceChoosePopRef.value.open();
  167. };
  168. const close = () => {
  169. deviceChoosePopRef.value.close();
  170. };
  171. // 提供外部方法
  172. const expose = {
  173. open,
  174. };
  175. defineExpose(expose);
  176. const emit = defineEmits(["multiple-devide-submit"]);
  177. // ---------------------------------------------
  178. const chooseList = ref([]);
  179. const chooseIds = computed(() => {
  180. // 返回chooseList的id组成新数组
  181. return chooseList.value.map((c) => c.id);
  182. });
  183. const onChoose = (item) => {
  184. // 判断当前点击的设备是否存在于chooseList中,
  185. // 若存在,则从chooseList中删除,否则添加到chooseList中
  186. // 若不存在则添加
  187. const index = chooseList.value.findIndex((v) => v.id === item.id);
  188. if (index > -1) {
  189. // chooseList.value.splice(index, 1)
  190. } else {
  191. chooseList.value.push(item);
  192. }
  193. };
  194. const onChooseDel = (item) => {
  195. // 判断当前点击的设备是否存在于chooseList中,
  196. // 若存在,则从chooseList中删除,否则添加到chooseList中
  197. const index = chooseList.value.findIndex((v) => v.id === item.id);
  198. if (index > -1) {
  199. chooseList.value.splice(index, 1);
  200. }
  201. };
  202. const oncancel = () => {
  203. chooseList.value = [];
  204. close();
  205. };
  206. const onSubmit = () => {
  207. emit("multiple-devide-submit", chooseList.value);
  208. chooseList.value = [];
  209. close();
  210. // uni.$emit('multiple-devide-submit', chooseList.value)
  211. // uni.navigateBack()
  212. };
  213. </script>
  214. <style lang="scss" scoped>
  215. @import "@/style/choose-device.scss";
  216. .no-boms {
  217. background-color: #f2f6fc;
  218. }
  219. </style>