index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <a-card :bordered="false" style="margin-bottom: 10px" class="mb-2">
  3. <a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
  4. <a-row :gutter="24">
  5. <a-col :span="6">
  6. <a-form-item label="货品编码" name="goodsCode">
  7. <a-input v-model:value="searchFormState.goodsCode" placeholder="查询货品编码" allow-clear />
  8. </a-form-item>
  9. </a-col>
  10. <a-col :span="6">
  11. <a-form-item label="货品名称" name="goodsName">
  12. <a-input v-model:value="searchFormState.goodsName" placeholder="查询货品名称" allow-clear />
  13. </a-form-item>
  14. </a-col>
  15. <a-col :span="6">
  16. <a-button type="primary" @click="tableRef.refresh()">查询</a-button>
  17. <a-button style="margin: 0 8px" @click="reset">重置</a-button>
  18. <a-button type="primary" @click="formRef.onOpen()" v-if="hasPerm('goodsAdd')">
  19. <template #icon><plus-outlined /></template>
  20. 新增
  21. </a-button>
  22. </a-col>
  23. </a-row>
  24. </a-form>
  25. </a-card>
  26. <a-card :bordered="false">
  27. <s-table
  28. ref="tableRef"
  29. :columns="columns"
  30. :data="loadData"
  31. bordered
  32. :row-key="(record) => record.id"
  33. >
  34. <template #bodyCell="{ column, record, index }">
  35. <template v-if="column.dataIndex === 'serial'">
  36. {{ index + 1 }}
  37. </template>
  38. <template v-if="column.dataIndex === 'action'">
  39. <a-space>
  40. <a @click="formRef.onOpen(record)" v-if="hasPerm('goodsEdit')">编辑</a>
  41. <a-divider type="vertical" v-if="hasPerm(['goodsEdit', 'goodsDelete'], 'and')" />
  42. <a-button type="link" danger size="small" v-if="hasPerm('goodsDelete')" @click="deleteConfig(record)">删除</a-button>
  43. </a-space>
  44. </template>
  45. </template>
  46. </s-table>
  47. </a-card>
  48. <Form ref="formRef" @successful="tableRef.refresh()" />
  49. </template>
  50. <script setup name="goods">
  51. import { cloneDeep } from 'lodash-es'
  52. import Form from './form.vue'
  53. import goodsApi from '@/api/biz/goodsApi'
  54. import {ExclamationCircleOutlined} from '@ant-design/icons-vue';
  55. import {Modal} from 'ant-design-vue';
  56. import {createVNode} from 'vue';
  57. const searchFormState = ref({})
  58. const searchFormRef = ref()
  59. const tableRef = ref()
  60. const formRef = ref()
  61. const submitLoading = ref(false)
  62. const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
  63. const columns = [
  64. {
  65. title: '序号',
  66. width: 50,
  67. dataIndex: 'serial',
  68. align:'center'
  69. },
  70. {
  71. title: '货品编码',
  72. width: 180,
  73. dataIndex: 'goodsCode',
  74. align:'center'
  75. },
  76. {
  77. title: '货品名称',
  78. dataIndex: 'goodsName',
  79. align:'center'
  80. },
  81. {
  82. title: '货品规格',
  83. width: 180,
  84. dataIndex: 'goodsModel',
  85. align:'center'
  86. },
  87. ]
  88. // 操作栏通过权限判断是否显示
  89. columns.push({
  90. title: '操作',
  91. dataIndex: 'action',
  92. align: 'center',
  93. width: 250
  94. })
  95. const selectedRowKeys = ref([])
  96. // 列表选择配置
  97. const options = {
  98. // columns数字类型字段加入 needTotal: true 可以勾选自动算账
  99. alert: {
  100. show: true,
  101. clear: () => {
  102. selectedRowKeys.value = ref([])
  103. }
  104. },
  105. rowSelection: {
  106. onChange: (selectedRowKey, selectedRows) => {
  107. selectedRowKeys.value = selectedRowKey
  108. }
  109. }
  110. }
  111. const loadData = (parameter) => {
  112. const searchFormParam = cloneDeep(searchFormState.value)
  113. return goodsApi.goodsPage(Object.assign(parameter, searchFormParam)).then((data) => {
  114. return data
  115. })
  116. }
  117. // 重置
  118. const reset = () => {
  119. searchFormRef.value.resetFields()
  120. tableRef.value.refresh(true)
  121. }
  122. // 删除
  123. const deleteConfig = (record) => {
  124. Modal.confirm({
  125. title: '确定删除该数据吗?',
  126. icon: createVNode(ExclamationCircleOutlined),
  127. content: '',
  128. onOk() {
  129. submitLoading.value = true
  130. let params = [
  131. {
  132. id: record.id
  133. }
  134. ]
  135. goodsApi
  136. .goodsDelete(params)
  137. .then(() => {
  138. tableRef.value.refresh(true)
  139. })
  140. .finally(() => {
  141. submitLoading.value = false
  142. })
  143. },
  144. onCancel() {}
  145. })
  146. }
  147. </script>