index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <!-- ERP 产品列表 -->
  2. <template>
  3. <ContentWrap>
  4. <!-- 搜索工作栏 -->
  5. <el-form
  6. class="-mb-15px"
  7. :model="queryParams"
  8. ref="queryFormRef"
  9. :inline="true"
  10. label-width="68px"
  11. >
  12. <el-form-item label="名称" prop="name">
  13. <el-input
  14. v-model="queryParams.name"
  15. placeholder="请输入名称"
  16. clearable
  17. @keyup.enter="handleQuery"
  18. class="!w-240px"
  19. />
  20. </el-form-item>
  21. <el-form-item label="分类" prop="categoryId">
  22. <el-tree-select
  23. v-model="queryParams.categoryId"
  24. :data="categoryList"
  25. :props="defaultProps"
  26. check-strictly
  27. default-expand-all
  28. placeholder="请输入分类"
  29. class="!w-240px"
  30. />
  31. </el-form-item>
  32. <el-form-item>
  33. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  34. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  35. <el-button
  36. type="primary"
  37. plain
  38. @click="openForm('create')"
  39. v-hasPermi="['erp:product:create']"
  40. >
  41. <Icon icon="ep:plus" class="mr-5px" /> 新增
  42. </el-button>
  43. <el-button
  44. type="success"
  45. plain
  46. @click="handleExport"
  47. :loading="exportLoading"
  48. v-hasPermi="['erp:product:export']"
  49. >
  50. <Icon icon="ep:download" class="mr-5px" /> 导出
  51. </el-button>
  52. </el-form-item>
  53. </el-form>
  54. </ContentWrap>
  55. <!-- 列表 -->
  56. <ContentWrap>
  57. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  58. <el-table-column label="条码" align="center" prop="barCode" />
  59. <el-table-column label="名称" align="center" prop="name" />
  60. <el-table-column label="规格" align="center" prop="standard" />
  61. <el-table-column label="分类" align="center" prop="categoryName" />
  62. <el-table-column label="单位" align="center" prop="unitName" />
  63. <el-table-column label="采购价格" align="center" prop="purchasePrice" />
  64. <el-table-column label="销售价格" align="center" prop="salePrice" />
  65. <el-table-column label="最低价格" align="center" prop="minPrice" />
  66. <el-table-column label="状态" align="center" prop="status">
  67. <template #default="scope">
  68. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  69. </template>
  70. </el-table-column>
  71. <el-table-column
  72. label="创建时间"
  73. align="center"
  74. prop="createTime"
  75. :formatter="dateFormatter"
  76. width="180px"
  77. />
  78. <el-table-column label="操作" align="center" width="110">
  79. <template #default="scope">
  80. <el-button
  81. link
  82. type="primary"
  83. @click="openForm('update', scope.row.id)"
  84. v-hasPermi="['erp:product:update']"
  85. >
  86. 编辑
  87. </el-button>
  88. <el-button
  89. link
  90. type="danger"
  91. @click="handleDelete(scope.row.id)"
  92. v-hasPermi="['erp:product:delete']"
  93. >
  94. 删除
  95. </el-button>
  96. </template>
  97. </el-table-column>
  98. </el-table>
  99. <!-- 分页 -->
  100. <Pagination
  101. :total="total"
  102. v-model:page="queryParams.pageNo"
  103. v-model:limit="queryParams.pageSize"
  104. @pagination="getList"
  105. />
  106. </ContentWrap>
  107. <!-- 表单弹窗:添加/修改 -->
  108. <ProductForm ref="formRef" @success="getList" />
  109. </template>
  110. <script setup lang="ts">
  111. import { dateFormatter } from '@/utils/formatTime'
  112. import download from '@/utils/download'
  113. import { ProductApi, ProductVO } from '@/api/erp/product'
  114. import { ProductCategoryApi, ProductCategoryVO } from '@/api/erp/product/category'
  115. import ProductForm from './ProductForm.vue'
  116. import { DICT_TYPE } from '@/utils/dict'
  117. import { defaultProps, handleTree } from '@/utils/tree'
  118. /** ERP 产品列表 */
  119. defineOptions({ name: 'ErpProduct' })
  120. const message = useMessage() // 消息弹窗
  121. const { t } = useI18n() // 国际化
  122. const loading = ref(true) // 列表的加载中
  123. const list = ref<ProductVO[]>([]) // 列表的数据
  124. const total = ref(0) // 列表的总页数
  125. const queryParams = reactive({
  126. pageNo: 1,
  127. pageSize: 10,
  128. name: undefined,
  129. categoryId: undefined
  130. })
  131. const queryFormRef = ref() // 搜索的表单
  132. const exportLoading = ref(false) // 导出的加载中
  133. const categoryList = ref<ProductCategoryVO[]>([]) // 产品分类列表
  134. /** 查询列表 */
  135. const getList = async () => {
  136. loading.value = true
  137. try {
  138. const data = await ProductApi.getProductPage(queryParams)
  139. list.value = data.list
  140. total.value = data.total
  141. } finally {
  142. loading.value = false
  143. }
  144. }
  145. /** 搜索按钮操作 */
  146. const handleQuery = () => {
  147. queryParams.pageNo = 1
  148. getList()
  149. }
  150. /** 重置按钮操作 */
  151. const resetQuery = () => {
  152. queryFormRef.value.resetFields()
  153. handleQuery()
  154. }
  155. /** 添加/修改操作 */
  156. const formRef = ref()
  157. const openForm = (type: string, id?: number) => {
  158. formRef.value.open(type, id)
  159. }
  160. /** 删除按钮操作 */
  161. const handleDelete = async (id: number) => {
  162. try {
  163. // 删除的二次确认
  164. await message.delConfirm()
  165. // 发起删除
  166. await ProductApi.deleteProduct(id)
  167. message.success(t('common.delSuccess'))
  168. // 刷新列表
  169. await getList()
  170. } catch {}
  171. }
  172. /** 导出按钮操作 */
  173. const handleExport = async () => {
  174. try {
  175. // 导出的二次确认
  176. await message.exportConfirm()
  177. // 发起导出
  178. exportLoading.value = true
  179. const data = await ProductApi.exportProduct(queryParams)
  180. download.excel(data, '产品.xls')
  181. } catch {
  182. } finally {
  183. exportLoading.value = false
  184. }
  185. }
  186. /** 初始化 **/
  187. onMounted(async () => {
  188. await getList()
  189. // 产品分类
  190. const categoryData = await ProductCategoryApi.getProductCategorySimpleList()
  191. categoryList.value = handleTree(categoryData, 'id', 'parentId')
  192. })
  193. </script>