multiple.vue 6.3 KB

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