modelChoose.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <uni-popup class="materials-popup" ref="materialChoosePopRef" type="bottom" :is-mask-click="false"
  3. borderRadius="10px 10px 0 0">
  4. <z-paging class="z-page-popup" ref="paging" :default-page-size="20" style="top: 200px;" 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="6" class="head-cancel align-center justify-start" @click="oncancel">
  11. {{$t('operation.cancel')}}
  12. </uni-col>
  13. <uni-col :span="12" class="head-title justify-center">
  14. {{ $t('ledger.form.model') }}
  15. </uni-col>
  16. </uni-row>
  17. <uni-row class="search-row flex-row justify-between">
  18. <uni-col :span="24">
  19. <uni-easyinput v-model="searchValue" :styles="inputStyles"
  20. :placeholderStyle="placeholderStyle"
  21. :placeholder="`${$t('operation.PleaseInput')}${$t('ledger.brand.labelHint')}`"
  22. @confirm="searchList">
  23. </uni-easyinput>
  24. </uni-col>
  25. </uni-row>
  26. <uni-row :gutter="5" class="table-header flex-row align-center justify-between">
  27. <uni-col :span="6" class="flex-row justify-center">
  28. {{ $t('ledger.model.name') }}
  29. </uni-col>
  30. <uni-col :span="6" class="flex-row justify-center">
  31. {{ $t('ledger.model.standard')}}
  32. </uni-col>
  33. <uni-col :span="6" class="flex-row justify-center">
  34. {{ $t('ledger.brand.status')}}
  35. </uni-col>
  36. <uni-col :span="6" class="flex-row justify-center">
  37. {{ $t('ledger.supplier.time')}}
  38. </uni-col>
  39. </uni-row>
  40. </view>
  41. </template>
  42. <view class="page-table">
  43. <uni-row
  44. :gutter="5"
  45. class="item-row align-center"
  46. :class="{'choosed': selectedItemId === item.id}"
  47. v-for="(item,index) in dataList"
  48. :key="index"
  49. @click="onChoose(item)"
  50. >
  51. <uni-col :span="6" class="item-col flex-row justify-center">
  52. {{ item.name }}
  53. </uni-col>
  54. <uni-col :span="6" class="item-col flex-row justify-center">
  55. {{ item.standard }}
  56. </uni-col>
  57. <uni-col :span="6" class="item-col flex-row justify-center">
  58. {{ getStatusName(item.status) }}
  59. </uni-col>
  60. <uni-col :span="4" class="item-col flex-row justify-center">
  61. {{ item.createTime ? formatDate(item.createTime) : '' }}
  62. </uni-col>
  63. </uni-row>
  64. </view>
  65. </z-paging>
  66. </uni-popup>
  67. </template>
  68. <script setup>
  69. import dayjs from 'dayjs'
  70. import {
  71. computed,
  72. ref,
  73. reactive,
  74. onMounted,
  75. } from 'vue'
  76. import { useI18n } from 'vue-i18n'
  77. import { getDataDictList, getSupplierList } from "@/api";
  78. import { useDataDictStore } from "@/store/modules/dataDict";
  79. import { getDeviceModelList } from "@/api/device";
  80. // 接收父组件传递的参数
  81. const props = defineProps({
  82. selectedItemId: {
  83. type: Number,
  84. default: 0
  85. },
  86. brandId: {
  87. type: Number,
  88. }
  89. })
  90. const getStatusName = (status) => {
  91. if (status === 0) {
  92. return t('ledger.brand.status0')
  93. } else {
  94. return t('ledger.brand.status1')
  95. }
  96. }
  97. const searchValue = ref('')
  98. const placeholderStyle = ref('color:#ADADAD;font-weight:400;font-size:12px')
  99. const inputStyles = reactive({
  100. backgroundColor: '#F5F5F5',
  101. color: '#797979',
  102. })
  103. const paging = ref(null)
  104. // v-model绑定的这个变量不要在分页请求结束中自己赋值,直接使用即可
  105. const dataList = ref([])
  106. const filterList = ref([])
  107. // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可
  108. const queryList = (pageNo, pageSize) => {
  109. // 此处请求仅为演示,请替换为自己项目中的请求
  110. getDeviceModelList({
  111. pageNo,
  112. pageSize,
  113. brand: props.brandId,
  114. name: searchValue.value,
  115. }).then(res => {
  116. // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
  117. res.data.list.forEach(item => {
  118. item.chooseKey = item.id
  119. })
  120. paging.value.complete(res.data.list);
  121. }).catch(res => {
  122. // 如果请求失败写paging.value.complete(false);
  123. // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
  124. // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
  125. paging.value.complete(false);
  126. })
  127. }
  128. const searchList = () => {
  129. paging.value.reload()
  130. }
  131. const formatDate = (time) => {
  132. return dayjs(time).format('YYYY-MM-DD');
  133. }
  134. // ----------------------------------------------
  135. // ---------------------------------------------
  136. const chooseList = ref([])
  137. const chooseIds = computed(() => {
  138. // 返回chooseList的id组成新数组
  139. return chooseList.value.map(c => c.chooseKey)
  140. })
  141. const onChoose = (item) => {
  142. emit('confirm', item)
  143. close()
  144. }
  145. const oncancel = () => {
  146. chooseList.value = []
  147. close()
  148. }
  149. const { t } = useI18n({ useScope: 'global' })
  150. onMounted (() => {})
  151. const materialChoosePopRef = ref(null)
  152. // 打开弹窗
  153. const open = () => {
  154. materialChoosePopRef.value.open()
  155. }
  156. // 关闭弹窗
  157. const close = () => {
  158. materialChoosePopRef.value.close()
  159. }
  160. const emit = defineEmits(['confirm'])
  161. // 提供外部方法
  162. const expose = { open }
  163. defineExpose(expose)
  164. </script>
  165. <style lang="scss" scoped>
  166. @import "@/style/choose-device.scss";
  167. .z-page-popup {
  168. padding: 20px 15px;
  169. box-sizing: border-box;
  170. background: #FFF;
  171. border-radius: 10px 10px 0 0;
  172. }
  173. .page-top {
  174. background: #fff;
  175. padding: 0;
  176. }
  177. .head-row {
  178. margin-bottom: 20px;
  179. font-size: 16px;
  180. line-height: 21px;
  181. color: #A3A3A3;
  182. }
  183. .head-title {
  184. color: #333333;
  185. font-weight: bold;
  186. }
  187. .head-add {
  188. color: #004098;
  189. }
  190. .table-header {
  191. background: #FFF;
  192. border-bottom: 1px solid #CACCCF;
  193. }
  194. .page-table {
  195. padding: 0;
  196. }
  197. .item-col {
  198. font-size: 11px;
  199. }
  200. </style>