index.vue 5.8 KB

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