index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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="no">
  21. <el-input
  22. v-model="queryParams.no"
  23. placeholder="请输入产品编码"
  24. clearable
  25. @keyup.enter="handleQuery"
  26. class="!w-240px"
  27. />
  28. </el-form-item>
  29. <el-form-item label="状态" prop="status">
  30. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable class="!w-240px">
  31. <el-option
  32. v-for="dict in getBoolDictOptions(DICT_TYPE.CRM_PRODUCT_STATUS)"
  33. :key="dict.value"
  34. :label="dict.label"
  35. :value="dict.value"
  36. />
  37. </el-select>
  38. </el-form-item>
  39. <el-form-item label="产品分类" prop="categoryId">
  40. <el-input
  41. v-model="queryParams.categoryId"
  42. placeholder="请选择产品分类"
  43. clearable
  44. @keyup.enter="handleQuery"
  45. class="!w-240px"
  46. />
  47. </el-form-item>
  48. <el-form-item label="创建时间" prop="createTime">
  49. <el-date-picker
  50. v-model="queryParams.createTime"
  51. value-format="YYYY-MM-DD HH:mm:ss"
  52. type="daterange"
  53. start-placeholder="开始日期"
  54. end-placeholder="结束日期"
  55. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  56. class="!w-240px"
  57. />
  58. </el-form-item>
  59. <el-form-item>
  60. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  61. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  62. <el-button type="primary" @click="openForm('create')" v-hasPermi="['crm:product:create']">
  63. <Icon icon="ep:plus" class="mr-5px" /> 新增
  64. </el-button>
  65. <el-button
  66. type="success"
  67. plain
  68. @click="handleExport"
  69. :loading="exportLoading"
  70. v-hasPermi="['crm:product:export']"
  71. >
  72. <Icon icon="ep:download" class="mr-5px" /> 导出
  73. </el-button>
  74. </el-form-item>
  75. </el-form>
  76. </ContentWrap>
  77. <!-- 列表 -->
  78. <ContentWrap>
  79. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  80. <!--<el-table-column label="主键id" align="center" prop="id" />-->
  81. <el-table-column label="产品名称" align="center" prop="name" />
  82. <el-table-column label="产品编码" align="center" prop="no" />
  83. <el-table-column label="单位" align="center" prop="unit">
  84. <template #default="scope">
  85. <dict-tag :type="DICT_TYPE.PRODUCT_UNIT" :value="scope.row.unit" />
  86. </template>
  87. </el-table-column>
  88. <el-table-column label="价格" align="center" prop="price">
  89. <template #default="{ row }">
  90. {{ fenToYuan(row.price) }}
  91. </template>
  92. </el-table-column>
  93. <el-table-column label="状态" align="center" prop="status">
  94. <template #default="scope">
  95. <dict-tag :type="DICT_TYPE.CRM_PRODUCT_STATUS" :value="scope.row.status" />
  96. </template>
  97. </el-table-column>
  98. <el-table-column label="产品分类" align="center" prop="categoryId">
  99. <template #default="{ row }">
  100. <span>{{ productCategoryList?.find((c) => c.id === row.categoryId)?.name }}</span>
  101. </template>
  102. </el-table-column>
  103. <el-table-column label="产品描述" align="center" prop="description" />
  104. <el-table-column label="负责人" align="center" prop="ownerUserId">
  105. <template #default="{ row }">
  106. <span>{{ userList?.find((c) => c.id === row.ownerUserId)?.nickname }}</span>
  107. </template>
  108. </el-table-column>
  109. <el-table-column
  110. label="创建时间"
  111. align="center"
  112. prop="createTime"
  113. :formatter="dateFormatter"
  114. width="180px"
  115. />
  116. <el-table-column label="操作" align="center" width="160">
  117. <template #default="scope">
  118. <el-button
  119. v-hasPermi="['crm:product:query']"
  120. link
  121. type="primary"
  122. @click="openDetail(scope.row)"
  123. >
  124. 详情
  125. </el-button>
  126. <el-button
  127. link
  128. type="primary"
  129. @click="openForm('update', scope.row.id)"
  130. v-hasPermi="['crm:product:update']"
  131. >
  132. 编辑
  133. </el-button>
  134. <el-button
  135. link
  136. type="danger"
  137. @click="handleDelete(scope.row.id)"
  138. v-hasPermi="['crm:product:delete']"
  139. >
  140. 删除
  141. </el-button>
  142. </template>
  143. </el-table-column>
  144. </el-table>
  145. <!-- 分页 -->
  146. <Pagination
  147. :total="total"
  148. v-model:page="queryParams.pageNo"
  149. v-model:limit="queryParams.pageSize"
  150. @pagination="getList"
  151. />
  152. </ContentWrap>
  153. <!-- 表单弹窗:添加/修改 -->
  154. <ProductForm ref="formRef" @success="getList" />
  155. <!-- 表单弹窗:详情 -->
  156. <ProductDetail ref="detailRef" @success="getList" />
  157. </template>
  158. <script setup lang="ts">
  159. import { DICT_TYPE, getBoolDictOptions } from '@/utils/dict'
  160. import { dateFormatter } from '@/utils/formatTime'
  161. import download from '@/utils/download'
  162. import * as ProductApi from '@/api/crm/product'
  163. import ProductForm from './ProductForm.vue'
  164. import ProductDetail from './ProductDetail.vue'
  165. import { fenToYuan } from '@/utils'
  166. import * as ProductCategoryApi from '@/api/crm/productCategory'
  167. import { getSimpleUserList, UserVO } from '@/api/system/user'
  168. defineOptions({ name: 'CrmProduct' })
  169. const message = useMessage() // 消息弹窗
  170. const { t } = useI18n() // 国际化
  171. const loading = ref(true) // 列表的加载中
  172. const total = ref(0) // 列表的总页数
  173. const list = ref([]) // 列表的数据
  174. const queryParams = reactive({
  175. pageNo: 1,
  176. pageSize: 10,
  177. name: null,
  178. no: null,
  179. unit: null,
  180. price: null,
  181. status: null,
  182. categoryId: null,
  183. description: null,
  184. ownerUserId: null,
  185. createTime: []
  186. })
  187. const queryFormRef = ref() // 搜索的表单
  188. const exportLoading = ref(false) // 导出的加载中
  189. /** 查询列表 */
  190. const getList = async () => {
  191. loading.value = true
  192. try {
  193. const data = await ProductApi.getProductPage(queryParams)
  194. list.value = data.list
  195. total.value = data.total
  196. } finally {
  197. loading.value = false
  198. }
  199. }
  200. /** 搜索按钮操作 */
  201. const handleQuery = () => {
  202. queryParams.pageNo = 1
  203. getList()
  204. }
  205. /** 重置按钮操作 */
  206. const resetQuery = () => {
  207. queryFormRef.value.resetFields()
  208. handleQuery()
  209. }
  210. /** 添加/修改操作 */
  211. const formRef = ref()
  212. const openForm = (type: string, id?: number) => {
  213. formRef.value.open(type, id)
  214. }
  215. /** 详情操作 */
  216. const detailRef = ref()
  217. const openDetail = (data: ProductApi.ProductVO) => {
  218. detailRef.value.open(data)
  219. }
  220. /** 删除按钮操作 */
  221. const handleDelete = async (id: number) => {
  222. try {
  223. // 删除的二次确认
  224. await message.delConfirm()
  225. // 发起删除
  226. await ProductApi.deleteProduct(id)
  227. message.success(t('common.delSuccess'))
  228. // 刷新列表
  229. await getList()
  230. } catch {}
  231. }
  232. /** 导出按钮操作 */
  233. const handleExport = async () => {
  234. try {
  235. // 导出的二次确认
  236. await message.exportConfirm()
  237. // 发起导出
  238. exportLoading.value = true
  239. const data = await ProductApi.exportProduct(queryParams)
  240. download.excel(data, '产品.xls')
  241. } catch {
  242. } finally {
  243. exportLoading.value = false
  244. }
  245. }
  246. const productCategoryList = ref([]) // 产品分类树
  247. const userList = ref<UserVO[]>([]) // 系统用户
  248. /** 初始化 **/
  249. onMounted(async () => {
  250. await getList()
  251. productCategoryList.value = await ProductCategoryApi.getProductCategoryList({})
  252. userList.value = await getSimpleUserList()
  253. })
  254. </script>