index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <ContentWrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="单位名字" prop="name">
  12. <el-input
  13. v-model="queryParams.name"
  14. placeholder="请输入单位名字"
  15. clearable
  16. @keyup.enter="handleQuery"
  17. class="!w-240px"
  18. />
  19. </el-form-item>
  20. <el-form-item label="单位状态" prop="status">
  21. <el-select
  22. v-model="queryParams.status"
  23. placeholder="请选择单位状态"
  24. clearable
  25. class="!w-240px"
  26. >
  27. <el-option label="请选择字典生成" value="" />
  28. </el-select>
  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-unit: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-unit: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="id" />
  68. <el-table-column label="单位名字" align="center" prop="name" />
  69. <el-table-column label="单位状态" align="center" prop="status" />
  70. <el-table-column
  71. label="创建时间"
  72. align="center"
  73. prop="createTime"
  74. :formatter="dateFormatter"
  75. width="180px"
  76. />
  77. <el-table-column label="操作" align="center">
  78. <template #default="scope">
  79. <el-button
  80. link
  81. type="primary"
  82. @click="openForm('update', scope.row.id)"
  83. v-hasPermi="['erp:product-unit:update']"
  84. >
  85. 编辑
  86. </el-button>
  87. <el-button
  88. link
  89. type="danger"
  90. @click="handleDelete(scope.row.id)"
  91. v-hasPermi="['erp:product-unit:delete']"
  92. >
  93. 删除
  94. </el-button>
  95. </template>
  96. </el-table-column>
  97. </el-table>
  98. <!-- 分页 -->
  99. <Pagination
  100. :total="total"
  101. v-model:page="queryParams.pageNo"
  102. v-model:limit="queryParams.pageSize"
  103. @pagination="getList"
  104. />
  105. </ContentWrap>
  106. <!-- 表单弹窗:添加/修改 -->
  107. <ProductUnitForm ref="formRef" @success="getList" />
  108. </template>
  109. <script setup lang="ts">
  110. import { dateFormatter } from '@/utils/formatTime'
  111. import download from '@/utils/download'
  112. import { ProductUnitApi, ProductUnitVO } from '@/api/erp/product/unit'
  113. import ProductUnitForm from './ProductUnitForm.vue'
  114. /** ERP 产品单位列表 */
  115. defineOptions({ name: 'ErpProductUnit' })
  116. const message = useMessage() // 消息弹窗
  117. const { t } = useI18n() // 国际化
  118. const loading = ref(true) // 列表的加载中
  119. const list = ref<ProductUnitVO[]>([]) // 列表的数据
  120. // 列表的总页数
  121. const total = ref(0)
  122. const queryParams = reactive({
  123. pageNo: 1,
  124. pageSize: 10,
  125. name: undefined,
  126. status: undefined,
  127. createTime: []
  128. })
  129. const queryFormRef = ref() // 搜索的表单
  130. const exportLoading = ref(false) // 导出的加载中
  131. /** 查询列表 */
  132. const getList = async () => {
  133. loading.value = true
  134. try {
  135. const data = await ProductUnitApi.getProductUnitPage(queryParams)
  136. list.value = data.list
  137. total.value = data.total
  138. } finally {
  139. loading.value = false
  140. }
  141. }
  142. /** 搜索按钮操作 */
  143. const handleQuery = () => {
  144. queryParams.pageNo = 1
  145. getList()
  146. }
  147. /** 重置按钮操作 */
  148. const resetQuery = () => {
  149. queryFormRef.value.resetFields()
  150. handleQuery()
  151. }
  152. /** 添加/修改操作 */
  153. const formRef = ref()
  154. const openForm = (type: string, id?: number) => {
  155. formRef.value.open(type, id)
  156. }
  157. /** 删除按钮操作 */
  158. const handleDelete = async (id: number) => {
  159. try {
  160. // 删除的二次确认
  161. await message.delConfirm()
  162. // 发起删除
  163. await ProductUnitApi.deleteProductUnit(id)
  164. message.success(t('common.delSuccess'))
  165. // 刷新列表
  166. await getList()
  167. } catch {}
  168. }
  169. /** 导出按钮操作 */
  170. const handleExport = async () => {
  171. try {
  172. // 导出的二次确认
  173. await message.exportConfirm()
  174. // 发起导出
  175. exportLoading.value = true
  176. const data = await ProductUnitApi.exportProductUnit(queryParams)
  177. download.excel(data, 'ERP 产品单位.xls')
  178. } catch {
  179. } finally {
  180. exportLoading.value = false
  181. }
  182. }
  183. /** 初始化 **/
  184. onMounted(() => {
  185. getList()
  186. })
  187. </script>