multiple.vue 6.4 KB

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