index.vue 6.5 KB

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