brandChoose.vue 6.2 KB

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