index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 v-model="queryParams.status" placeholder="请选择状态" clearable class="!w-240px">
  22. <el-option
  23. v-for="dict in getIntDictOptions(DICT_TYPE.CRM_PRODUCT_STATUS)"
  24. :key="dict.value"
  25. :label="dict.label"
  26. :value="dict.value"
  27. />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item>
  31. <el-button @click="handleQuery"> <Icon icon="ep:search" class="mr-5px" /> 搜索 </el-button>
  32. <el-button @click="resetQuery"> <Icon icon="ep:refresh" class="mr-5px" /> 重置 </el-button>
  33. <el-button type="primary" @click="openForm('create')" v-hasPermi="['crm:product:create']">
  34. <Icon icon="ep:plus" class="mr-5px" /> 新增
  35. </el-button>
  36. <el-button
  37. type="success"
  38. plain
  39. @click="handleExport"
  40. :loading="exportLoading"
  41. v-hasPermi="['crm:product:export']"
  42. >
  43. <Icon icon="ep:download" class="mr-5px" />
  44. 导出
  45. </el-button>
  46. </el-form-item>
  47. </el-form>
  48. </ContentWrap>
  49. <!-- 列表 -->
  50. <ContentWrap>
  51. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  52. <el-table-column label="产品名称" align="center" prop="name" width="160">
  53. <template #default="scope">
  54. <el-link :underline="false" type="primary" @click="openDetail(scope.row.id)">
  55. {{ scope.row.name }}
  56. </el-link>
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="产品类型" align="center" prop="categoryName" width="160" />
  60. <el-table-column label="产品单位" align="center" prop="unit">
  61. <template #default="scope">
  62. <dict-tag :type="DICT_TYPE.PRODUCT_UNIT" :value="scope.row.unit" />
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="产品编码" align="center" prop="no" />
  66. <el-table-column
  67. label="价格(元)"
  68. align="center"
  69. prop="price"
  70. :formatter="fenToYuanFormat"
  71. width="100"
  72. />
  73. <el-table-column label="产品描述" align="center" prop="description" width="150" />
  74. <el-table-column label="上架状态" align="center" prop="status" width="120">
  75. <template #default="scope">
  76. <dict-tag :type="DICT_TYPE.CRM_PRODUCT_STATUS" :value="scope.row.status" />
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="负责人" align="center" prop="ownerUserName" width="120" />
  80. <el-table-column
  81. label="更新时间"
  82. align="center"
  83. prop="updateTime"
  84. :formatter="dateFormatter"
  85. width="180px"
  86. />
  87. <el-table-column label="创建人" align="center" prop="creatorName" width="120" />
  88. <el-table-column
  89. label="创建时间"
  90. align="center"
  91. prop="createTime"
  92. :formatter="dateFormatter"
  93. width="180px"
  94. />
  95. <el-table-column label="操作" align="center" fixed="right" width="160">
  96. <template #default="scope">
  97. <el-button
  98. link
  99. type="primary"
  100. @click="openForm('update', scope.row.id)"
  101. v-hasPermi="['crm:product:update']"
  102. >
  103. 编辑
  104. </el-button>
  105. <el-button
  106. link
  107. type="danger"
  108. @click="handleDelete(scope.row.id)"
  109. v-hasPermi="['crm:product:delete']"
  110. >
  111. 删除
  112. </el-button>
  113. </template>
  114. </el-table-column>
  115. </el-table>
  116. <!-- 分页 -->
  117. <Pagination
  118. :total="total"
  119. v-model:page="queryParams.pageNo"
  120. v-model:limit="queryParams.pageSize"
  121. @pagination="getList"
  122. />
  123. </ContentWrap>
  124. <!-- 表单弹窗:添加/修改 -->
  125. <ProductForm ref="formRef" @success="getList" />
  126. </template>
  127. <script setup lang="ts">
  128. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  129. import { dateFormatter } from '@/utils/formatTime'
  130. import download from '@/utils/download'
  131. import * as ProductApi from '@/api/crm/product'
  132. import ProductForm from './ProductForm.vue'
  133. import { fenToYuanFormat } from '@/utils/formatter'
  134. defineOptions({ name: 'CrmProduct' })
  135. const message = useMessage() // 消息弹窗
  136. const { t } = useI18n() // 国际化
  137. const loading = ref(true) // 列表的加载中
  138. const total = ref(0) // 列表的总页数
  139. const list = ref([]) // 列表的数据
  140. const queryParams = reactive({
  141. pageNo: 1,
  142. pageSize: 10,
  143. name: undefined,
  144. status: undefined
  145. })
  146. const queryFormRef = ref() // 搜索的表单
  147. const exportLoading = ref(false) // 导出的加载中
  148. /** 查询列表 */
  149. const getList = async () => {
  150. loading.value = true
  151. try {
  152. const data = await ProductApi.getProductPage(queryParams)
  153. list.value = data.list
  154. total.value = data.total
  155. } finally {
  156. loading.value = false
  157. }
  158. }
  159. /** 搜索按钮操作 */
  160. const handleQuery = () => {
  161. queryParams.pageNo = 1
  162. getList()
  163. }
  164. /** 重置按钮操作 */
  165. const resetQuery = () => {
  166. queryFormRef.value.resetFields()
  167. handleQuery()
  168. }
  169. /** 添加/修改操作 */
  170. const formRef = ref()
  171. const openForm = (type: string, id?: number) => {
  172. formRef.value.open(type, id)
  173. }
  174. /** 打开详情 */
  175. const { currentRoute, push } = useRouter()
  176. const openDetail = (id: number) => {
  177. push({ name: 'CrmProductDetail', params: { id } })
  178. }
  179. /** 删除按钮操作 */
  180. const handleDelete = async (id: number) => {
  181. try {
  182. // 删除的二次确认
  183. await message.delConfirm()
  184. // 发起删除
  185. await ProductApi.deleteProduct(id)
  186. message.success(t('common.delSuccess'))
  187. // 刷新列表
  188. await getList()
  189. } catch {}
  190. }
  191. /** 导出按钮操作 */
  192. const handleExport = async () => {
  193. try {
  194. // 导出的二次确认
  195. await message.exportConfirm()
  196. // 发起导出
  197. exportLoading.value = true
  198. const data = await ProductApi.exportProduct(queryParams)
  199. download.excel(data, '产品.xls')
  200. } catch {
  201. } finally {
  202. exportLoading.value = false
  203. }
  204. }
  205. /** 激活时 */
  206. onActivated(() => {
  207. getList()
  208. })
  209. /** 初始化 **/
  210. onMounted(() => {
  211. getList()
  212. })
  213. </script>