index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 getBoolDictOptions(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. </el-button>
  45. </el-form-item>
  46. </el-form>
  47. </ContentWrap>
  48. <!-- 列表 -->
  49. <ContentWrap>
  50. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  51. <!--<el-table-column label="主键id" align="center" prop="id" />-->
  52. <el-table-column label="产品名称" align="center" prop="name" />
  53. <el-table-column label="产品编码" align="center" prop="no" />
  54. <el-table-column label="单位" align="center" prop="unit">
  55. <template #default="scope">
  56. <dict-tag :type="DICT_TYPE.PRODUCT_UNIT" :value="scope.row.unit" />
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="价格" align="center" prop="price">
  60. <template #default="{ row }">
  61. {{ fenToYuan(row.price) }}
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="状态" align="center" prop="status">
  65. <template #default="scope">
  66. <dict-tag :type="DICT_TYPE.CRM_PRODUCT_STATUS" :value="scope.row.status" />
  67. </template>
  68. </el-table-column>
  69. <el-table-column label="产品分类" align="center" prop="categoryId">
  70. <template #default="{ row }">
  71. <span>{{ productCategoryList?.find((c) => c.id === row.categoryId)?.name }}</span>
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="产品描述" align="center" prop="description" />
  75. <el-table-column label="负责人" align="center" prop="ownerUserId">
  76. <template #default="{ row }">
  77. <span>{{ userList?.find((c) => c.id === row.ownerUserId)?.nickname }}</span>
  78. </template>
  79. </el-table-column>
  80. <el-table-column
  81. label="创建时间"
  82. align="center"
  83. prop="createTime"
  84. :formatter="dateFormatter"
  85. width="180px"
  86. />
  87. <el-table-column label="操作" align="center" width="160">
  88. <template #default="scope">
  89. <el-button
  90. v-hasPermi="['crm:product:query']"
  91. link
  92. type="primary"
  93. @click="openDetail(scope.row)"
  94. >
  95. 详情
  96. </el-button>
  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. <!-- 表单弹窗:详情 -->
  127. <ProductDetail ref="detailRef" @success="getList" />
  128. </template>
  129. <script setup lang="ts">
  130. import { DICT_TYPE, getBoolDictOptions } from '@/utils/dict'
  131. import { dateFormatter } from '@/utils/formatTime'
  132. import download from '@/utils/download'
  133. import * as ProductApi from '@/api/crm/product'
  134. import ProductForm from './ProductForm.vue'
  135. import ProductDetail from './ProductDetail.vue'
  136. import { fenToYuan } from '@/utils'
  137. import * as ProductCategoryApi from '@/api/crm/product/productCategory'
  138. import { getSimpleUserList, UserVO } from '@/api/system/user'
  139. defineOptions({ name: 'CrmProduct' })
  140. const message = useMessage() // 消息弹窗
  141. const { t } = useI18n() // 国际化
  142. const loading = ref(true) // 列表的加载中
  143. const total = ref(0) // 列表的总页数
  144. const list = ref([]) // 列表的数据
  145. const queryParams = reactive({
  146. pageNo: 1,
  147. pageSize: 10,
  148. name: null,
  149. no: null,
  150. unit: null,
  151. price: null,
  152. status: null,
  153. categoryId: null,
  154. description: null,
  155. ownerUserId: null,
  156. createTime: []
  157. })
  158. const queryFormRef = ref() // 搜索的表单
  159. const exportLoading = ref(false) // 导出的加载中
  160. /** 查询列表 */
  161. const getList = async () => {
  162. loading.value = true
  163. try {
  164. const data = await ProductApi.getProductPage(queryParams)
  165. list.value = data.list
  166. total.value = data.total
  167. } finally {
  168. loading.value = false
  169. }
  170. }
  171. /** 搜索按钮操作 */
  172. const handleQuery = () => {
  173. queryParams.pageNo = 1
  174. getList()
  175. }
  176. /** 重置按钮操作 */
  177. const resetQuery = () => {
  178. queryFormRef.value.resetFields()
  179. handleQuery()
  180. }
  181. /** 添加/修改操作 */
  182. const formRef = ref()
  183. const openForm = (type: string, id?: number) => {
  184. formRef.value.open(type, id)
  185. }
  186. /** 详情操作 */
  187. const detailRef = ref()
  188. const openDetail = (data: ProductApi.ProductVO) => {
  189. detailRef.value.open(data)
  190. }
  191. /** 删除按钮操作 */
  192. const handleDelete = async (id: number) => {
  193. try {
  194. // 删除的二次确认
  195. await message.delConfirm()
  196. // 发起删除
  197. await ProductApi.deleteProduct(id)
  198. message.success(t('common.delSuccess'))
  199. // 刷新列表
  200. await getList()
  201. } catch {}
  202. }
  203. /** 导出按钮操作 */
  204. const handleExport = async () => {
  205. try {
  206. // 导出的二次确认
  207. await message.exportConfirm()
  208. // 发起导出
  209. exportLoading.value = true
  210. const data = await ProductApi.exportProduct(queryParams)
  211. download.excel(data, '产品.xls')
  212. } catch {
  213. } finally {
  214. exportLoading.value = false
  215. }
  216. }
  217. const productCategoryList = ref([]) // 产品分类树
  218. const userList = ref<UserVO[]>([]) // 系统用户
  219. /** 初始化 **/
  220. onMounted(async () => {
  221. await getList()
  222. productCategoryList.value = await ProductCategoryApi.getProductCategoryList({})
  223. userList.value = await getSimpleUserList()
  224. })
  225. </script>