index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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.CRM_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="erpPriceTableColumnFormatter"
  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. import { erpPriceTableColumnFormatter } from '@/utils'
  135. defineOptions({ name: 'CrmProduct' })
  136. const message = useMessage() // 消息弹窗
  137. const { t } = useI18n() // 国际化
  138. const loading = ref(true) // 列表的加载中
  139. const total = ref(0) // 列表的总页数
  140. const list = ref([]) // 列表的数据
  141. const queryParams = reactive({
  142. pageNo: 1,
  143. pageSize: 10,
  144. name: undefined,
  145. status: undefined
  146. })
  147. const queryFormRef = ref() // 搜索的表单
  148. const exportLoading = ref(false) // 导出的加载中
  149. /** 查询列表 */
  150. const getList = async () => {
  151. loading.value = true
  152. try {
  153. const data = await ProductApi.getProductPage(queryParams)
  154. list.value = data.list
  155. total.value = data.total
  156. } finally {
  157. loading.value = false
  158. }
  159. }
  160. /** 搜索按钮操作 */
  161. const handleQuery = () => {
  162. queryParams.pageNo = 1
  163. getList()
  164. }
  165. /** 重置按钮操作 */
  166. const resetQuery = () => {
  167. queryFormRef.value.resetFields()
  168. handleQuery()
  169. }
  170. /** 添加/修改操作 */
  171. const formRef = ref()
  172. const openForm = (type: string, id?: number) => {
  173. formRef.value.open(type, id)
  174. }
  175. /** 打开详情 */
  176. const { currentRoute, push } = useRouter()
  177. const openDetail = (id: number) => {
  178. push({ name: 'CrmProductDetail', params: { id } })
  179. }
  180. /** 删除按钮操作 */
  181. const handleDelete = async (id: number) => {
  182. try {
  183. // 删除的二次确认
  184. await message.delConfirm()
  185. // 发起删除
  186. await ProductApi.deleteProduct(id)
  187. message.success(t('common.delSuccess'))
  188. // 刷新列表
  189. await getList()
  190. } catch {}
  191. }
  192. /** 导出按钮操作 */
  193. const handleExport = async () => {
  194. try {
  195. // 导出的二次确认
  196. await message.exportConfirm()
  197. // 发起导出
  198. exportLoading.value = true
  199. const data = await ProductApi.exportProduct(queryParams)
  200. download.excel(data, '产品.xls')
  201. } catch {
  202. } finally {
  203. exportLoading.value = false
  204. }
  205. }
  206. /** 激活时 */
  207. onActivated(() => {
  208. getList()
  209. })
  210. /** 初始化 **/
  211. onMounted(() => {
  212. getList()
  213. })
  214. </script>