choose.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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" 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.supplier') }}
  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.supplier.nameHint')}`"
  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="5" class="flex-row justify-center">
  28. {{ $t('ledger.supplier.name') }}
  29. </uni-col>
  30. <uni-col :span="7" class="flex-row justify-center">
  31. {{ $t('ledger.supplier.code')}}
  32. </uni-col>
  33. <uni-col :span="4" class="flex-row justify-center">
  34. {{ $t('ledger.supplier.type')}}
  35. </uni-col>
  36. <uni-col :span="4" class="flex-row justify-center">
  37. {{ $t('ledger.supplier.status')}}
  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="5" class="item-col flex-row justify-center">
  55. {{ item.name }}
  56. </uni-col>
  57. <uni-col :span="7" class="item-col flex-row justify-center">
  58. {{ item.code }}
  59. </uni-col>
  60. <uni-col :span="4" class="item-col flex-row justify-center">
  61. {{ getSupplierTypeName(item.classification) }}
  62. </uni-col>
  63. <uni-col :span="4" class="item-col flex-row justify-center">
  64. {{ getStatusName(item.status) }}
  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 { 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 getSupplierTypeName = (code) => {
  93. for (const item of supplierTypeList.value) {
  94. if (item.value === code) {
  95. return item.label
  96. }
  97. }
  98. }
  99. const getStatusName = (status) => {
  100. if (status === 1) {
  101. return t('ledger.supplier.status1')
  102. } else if (status === 2) {
  103. return t('ledger.supplier.status2')
  104. } else {
  105. return t('ledger.supplier.status3')
  106. }
  107. }
  108. const searchValue = ref('')
  109. const placeholderStyle = ref('color:#ADADAD;font-weight:400;font-size:12px')
  110. const inputStyles = reactive({
  111. backgroundColor: '#F5F5F5',
  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. getSupplierList({
  121. pageNo,
  122. pageSize:20,
  123. name: searchValue.value
  124. }).then(res => {
  125. // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
  126. res.data.list.forEach(item => {
  127. item.chooseKey = item.id
  128. })
  129. paging.value.complete(res.data.list);
  130. }).catch(res => {
  131. // 如果请求失败写paging.value.complete(false);
  132. // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
  133. // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
  134. paging.value.complete(false);
  135. })
  136. }
  137. const searchList = () => {
  138. paging.value.reload()
  139. }
  140. const formatDate = (time) => {
  141. return dayjs(time).format('YYYY-MM-DD');
  142. }
  143. // ----------------------------------------------
  144. // ---------------------------------------------
  145. const chooseList = ref([])
  146. const chooseIds = computed(() => {
  147. // 返回chooseList的id组成新数组
  148. return chooseList.value.map(c => c.chooseKey)
  149. })
  150. const onChoose = (item) => {
  151. emit('confirm', item)
  152. close()
  153. }
  154. const oncancel = () => {
  155. chooseList.value = []
  156. close()
  157. }
  158. const { t } = useI18n({ useScope: 'global' })
  159. const supplierTypeList = ref([])
  160. const { getDataDictList } = useDataDictStore()
  161. onMounted (() => {
  162. supplierTypeList.value = getDataDictList('supplier_classification')
  163. })
  164. const materialChoosePopRef = ref(null)
  165. // 打开弹窗
  166. const open = () => {
  167. materialChoosePopRef.value.open()
  168. }
  169. // 关闭弹窗
  170. const close = () => {
  171. materialChoosePopRef.value.close()
  172. }
  173. const emit = defineEmits(['confirm'])
  174. // 提供外部方法
  175. const expose = { open }
  176. defineExpose(expose)
  177. </script>
  178. <style lang="scss" scoped>
  179. @import "@/style/choose-device.scss";
  180. .z-page-popup {
  181. padding: 20px 15px;
  182. box-sizing: border-box;
  183. background: #FFF;
  184. border-radius: 10px 10px 0 0;
  185. }
  186. .page-top {
  187. background: #fff;
  188. padding: 0;
  189. }
  190. .head-row {
  191. margin-bottom: 20px;
  192. font-size: 16px;
  193. line-height: 21px;
  194. color: #A3A3A3;
  195. }
  196. .head-title {
  197. color: #333333;
  198. font-weight: bold;
  199. }
  200. .head-add {
  201. color: #004098;
  202. }
  203. .table-header {
  204. background: #FFF;
  205. border-bottom: 1px solid #CACCCF;
  206. }
  207. .page-table {
  208. padding: 0;
  209. }
  210. .item-col {
  211. font-size: 11px;
  212. }
  213. </style>