single.vue 6.6 KB

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