index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // 单据中使用商品表
  2. <template>
  3. <div>
  4. <a-button type="primary" @click="showModel" :disabled="disabled">添加商品</a-button>
  5. <a-drawer
  6. title="商品"
  7. :closable="false"
  8. v-model:open="visible"
  9. width="80%"
  10. :get-container="!fullscreen"
  11. @close="onClose"
  12. >
  13. <template #extra>
  14. <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
  15. <a-button type="primary" @click="onOK">添加</a-button>
  16. </template>
  17. <a-input class="search-panel" v-model:value="search" placeholder="搜索内容" @keyup.enter="searchData" allowClear></a-input>
  18. <a-table
  19. :loading="loading"
  20. class="ant-table-striped"
  21. :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange,onSelect:onSelect,onSelectAll:onSelectAll,fixed:true }"
  22. :rowKey="props.rowKey?props.rowKey:'itemid'"
  23. :columns="props.columns ? propsColumns:columns"
  24. :data-source="data"
  25. :scroll="{x:'max-content'}"
  26. :pagination="{showSizeChanger:true,defaultPageSize:20,current:props.param.content.pageNumber,total:total}"
  27. @change="onChange"
  28. size="small"
  29. :row-class-name="(_record, index) => (index % 2 === 1 ? 'table-striped' : null)">
  30. <template #headerCell="{ column }">
  31. <div style="min-width:100px;" v-if="column.filter == 1 || column.filter == 2">
  32. <a-input v-model:value="column.value" :placeholder="column.title" @pressEnter="listData(column.dataIndex,column.value)"></a-input>
  33. </div>
  34. <span v-else style="display:inline-block;padding:0 10px;">{{column.title}}</span>
  35. </template>
  36. <template #bodyCell="{ column, record }">
  37. <template v-if="column.dataIndex === 'price'">
  38. {{utils.formatAmount(record.price?record.price:record.marketprice)}}
  39. </template>
  40. <template v-if="column.fn" >
  41. <div style="pointer-events: none;">{{column.fn(column.fn?record:'')}}</div>
  42. </template>
  43. <slot name="tb_cell" :data="{column, record}"></slot>
  44. </template>
  45. </a-table>
  46. </a-drawer>
  47. </div>
  48. </template>
  49. <script setup>
  50. import {defineEmits,ref,defineProps,onMounted,toRefs,defineExpose } from 'vue';
  51. import utils from '@/utils/utils'
  52. import Api from '@/api/api'
  53. import { useRouter } from "vue-router";
  54. import { useBaseStore } from '@/stores/modules/base'
  55. import { storeToRefs } from 'pinia'
  56. const base = useBaseStore()
  57. let { tableRecord,fullscreen } = storeToRefs(base)
  58. const router = useRouter()
  59. const props = defineProps({
  60. columns:Array,
  61. param: Object,
  62. disabled:Boolean,
  63. loading:Boolean,
  64. tableid:Number,
  65. rowKey:String
  66. })
  67. const propsColumns = ref(props.columns)
  68. const visible = ref(false)
  69. const search = ref('')
  70. const data = ref([])
  71. const selectedRowKeys = ref([])
  72. const selectRows = ref([])
  73. const total = ref(0)
  74. const emit = defineEmits(['onSelectChange'])
  75. const columns = [
  76. {
  77. title:'行号',
  78. dataIndex:'rowindex',
  79. width:90,
  80. },
  81. {
  82. title:'商品名称',
  83. dataIndex:'itemname',
  84. width:180,
  85. },
  86. {
  87. title:'商品编号',
  88. dataIndex:'itemno',
  89. width:180,
  90. },
  91. {
  92. title:'单价',
  93. dataIndex:'price',
  94. width:180,
  95. },
  96. {
  97. title:'商品标签',
  98. dataIndex:'delistingstatus',
  99. width:180,
  100. },
  101. {
  102. title:'包装数量',
  103. dataIndex:'packageqty',
  104. width:180,
  105. },
  106. {
  107. title:'数量',
  108. dataIndex:'qty',
  109. width:90,
  110. },
  111. ]
  112. const onClose = ()=>{
  113. visible.value = false
  114. props.param.content.pageNumber = 1
  115. props.param.content.where.condition = ''
  116. search.value = ''
  117. reloadSelect()
  118. }
  119. const showModel = ()=>{
  120. visible.value = true
  121. reloadSelect()
  122. listData()
  123. }
  124. const onSelectChange = (changableRowKeys, selectedRows)=>{
  125. selectedRowKeys.value = changableRowKeys
  126. }
  127. const onSelectAll = (selected, selectedRows, changeRows)=>{
  128. tableRecord.value = selectedRows
  129. }
  130. const onOK = (changableRowKeys, selectedRows)=>{
  131. emit('onSelectChange',tableRecord.value)
  132. // visible.value = false
  133. reloadSelect()
  134. }
  135. const onChange = (pagination, filters, sorter, { currentDataSource })=>{
  136. selectedRowKeys.value = tableRecord.value.map(e=>e.itemid)
  137. props.param.content.pageNumber = pagination.current
  138. props.param.content.pageSize = pagination.pageSize
  139. listData()
  140. }
  141. const listData = async (dataIndex,value)=> {
  142. props.param.content.where.tablefilter = {}
  143. propsColumns.value.forEach((e)=>{
  144. e.value?props.param.content.where.tablefilter[e.dataIndex] = e.value:''
  145. })
  146. props.param.content.tableid = props.tableid
  147. const res = await Api.requested(props.param)
  148. res.data.forEach(element => {
  149. element.qty = element.qty ? element.qty:element.orderminqty
  150. });
  151. data.value = res.data
  152. total.value = res.total
  153. }
  154. const onSelect = async (record, selected, selectedRows, nativeEvent)=>{
  155. if (!selected) {
  156. tableRecord.value = tableRecord.value.filter(e=>e.itemid !== record.itemid)
  157. } else {
  158. tableRecord.value.push(record)
  159. }
  160. }
  161. const searchData = ()=>{
  162. props.param.content.where.condition = search.value
  163. props.param.content.pageNumber = 1
  164. listData()
  165. }
  166. const reloadSelect = () =>{
  167. selectedRowKeys.value = []
  168. tableRecord.value = []
  169. }
  170. defineExpose({
  171. visible,
  172. listData
  173. })
  174. onMounted(()=>{
  175. // listData()
  176. })
  177. </script>
  178. <style scoped>
  179. .search-panel{
  180. width: 300px;
  181. margin-bottom:10px;
  182. }
  183. .ant-table-striped :deep td{
  184. font-size: 12px;
  185. }
  186. </style>