index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <div class="p-2">
  3. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  4. <div v-show="showSearch" class="mb-[10px]">
  5. <el-card shadow="hover">
  6. <el-form ref="queryFormRef" :model="queryParams" :inline="true">
  7. <el-form-item label="产品id" prop="productId">
  8. <el-input v-model="queryParams.productId" placeholder="请输入产品id" clearable @keyup.enter="handleQuery" />
  9. </el-form-item>
  10. <el-form-item label="分类编号" prop="categoryId">
  11. <el-input v-model="queryParams.categoryId" placeholder="请输入分类编号" clearable @keyup.enter="handleQuery" />
  12. </el-form-item>
  13. <el-form-item label="属性列表" prop="attributesList">
  14. <el-input v-model="queryParams.attributesList" placeholder="请输入属性列表" clearable @keyup.enter="handleQuery" />
  15. </el-form-item>
  16. <el-form-item label="平台标识" prop="platformCode">
  17. <el-input v-model="queryParams.platformCode" placeholder="请输入平台标识" clearable @keyup.enter="handleQuery" />
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  21. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  22. </el-form-item>
  23. </el-form>
  24. </el-card>
  25. </div>
  26. </transition>
  27. <el-card shadow="never">
  28. <template #header>
  29. <el-row :gutter="10" class="mb8">
  30. <el-col :span="1.5">
  31. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['product:classification:add']">新增</el-button>
  32. </el-col>
  33. <el-col :span="1.5">
  34. <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['product:classification:edit']">修改</el-button>
  35. </el-col>
  36. <el-col :span="1.5">
  37. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['product:classification:remove']">删除</el-button>
  38. </el-col>
  39. <el-col :span="1.5">
  40. <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['product:classification:export']">导出</el-button>
  41. </el-col>
  42. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  43. </el-row>
  44. </template>
  45. <el-table v-loading="loading" border :data="classificationList" @selection-change="handleSelectionChange">
  46. <el-table-column type="selection" width="55" align="center" />
  47. <el-table-column label="主键ID" align="center" prop="id" v-if="true" />
  48. <el-table-column label="产品id" align="center" prop="productId" />
  49. <el-table-column label="分类编号" align="center" prop="categoryId" />
  50. <el-table-column label="属性列表" align="center" prop="attributesList" />
  51. <el-table-column label="备注" align="center" prop="remark" />
  52. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  53. <template #default="scope">
  54. <el-tooltip content="修改" placement="top">
  55. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['product:classification:edit']"></el-button>
  56. </el-tooltip>
  57. <el-tooltip content="删除" placement="top">
  58. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['product:classification:remove']"></el-button>
  59. </el-tooltip>
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  64. </el-card>
  65. <!-- 添加或修改产品属性关联对话框 -->
  66. <el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
  67. <el-form ref="classificationFormRef" :model="form" :rules="rules" label-width="80px">
  68. <el-form-item label="产品id" prop="productId">
  69. <el-input v-model="form.productId" placeholder="请输入产品id" />
  70. </el-form-item>
  71. <el-form-item label="分类编号" prop="categoryId">
  72. <el-input v-model="form.categoryId" placeholder="请输入分类编号" />
  73. </el-form-item>
  74. <el-form-item label="属性列表" prop="attributesList">
  75. <el-input v-model="form.attributesList" type="textarea" placeholder="请输入内容" />
  76. </el-form-item>
  77. <el-form-item label="备注" prop="remark">
  78. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  79. </el-form-item>
  80. </el-form>
  81. <template #footer>
  82. <div class="dialog-footer">
  83. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  84. <el-button @click="cancel">取 消</el-button>
  85. </div>
  86. </template>
  87. </el-dialog>
  88. </div>
  89. </template>
  90. <script setup name="Classification" lang="ts">
  91. import { listClassification, getClassification, delClassification, addClassification, updateClassification } from '@/api/pmsProduct/classification';
  92. import { ClassificationVO, ClassificationQuery, ClassificationForm } from '@/api/pmsProduct/classification/types';
  93. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  94. const classificationList = ref<ClassificationVO[]>([]);
  95. const buttonLoading = ref(false);
  96. const loading = ref(true);
  97. const showSearch = ref(true);
  98. const ids = ref<Array<string | number>>([]);
  99. const single = ref(true);
  100. const multiple = ref(true);
  101. const total = ref(0);
  102. const queryFormRef = ref<ElFormInstance>();
  103. const classificationFormRef = ref<ElFormInstance>();
  104. const dialog = reactive<DialogOption>({
  105. visible: false,
  106. title: ''
  107. });
  108. const initFormData: ClassificationForm = {
  109. id: undefined,
  110. productId: undefined,
  111. categoryId: undefined,
  112. attributesList: undefined,
  113. remark: undefined,
  114. }
  115. const data = reactive<PageData<ClassificationForm, ClassificationQuery>>({
  116. form: {...initFormData},
  117. queryParams: {
  118. pageNum: 1,
  119. pageSize: 10,
  120. productId: undefined,
  121. categoryId: undefined,
  122. attributesList: undefined,
  123. platformCode: undefined,
  124. params: {
  125. }
  126. },
  127. rules: {
  128. productId: [
  129. { required: true, message: "产品id不能为空", trigger: "blur" }
  130. ],
  131. categoryId: [
  132. { required: true, message: "分类编号不能为空", trigger: "blur" }
  133. ],
  134. attributesList: [
  135. { required: true, message: "属性列表不能为空", trigger: "blur" }
  136. ],
  137. remark: [
  138. { required: true, message: "备注不能为空", trigger: "blur" }
  139. ],
  140. }
  141. });
  142. const { queryParams, form, rules } = toRefs(data);
  143. /** 查询产品属性关联列表 */
  144. const getList = async () => {
  145. loading.value = true;
  146. const res = await listClassification(queryParams.value);
  147. classificationList.value = res.rows;
  148. total.value = res.total;
  149. loading.value = false;
  150. }
  151. /** 取消按钮 */
  152. const cancel = () => {
  153. reset();
  154. dialog.visible = false;
  155. }
  156. /** 表单重置 */
  157. const reset = () => {
  158. form.value = {...initFormData};
  159. classificationFormRef.value?.resetFields();
  160. }
  161. /** 搜索按钮操作 */
  162. const handleQuery = () => {
  163. queryParams.value.pageNum = 1;
  164. getList();
  165. }
  166. /** 重置按钮操作 */
  167. const resetQuery = () => {
  168. queryFormRef.value?.resetFields();
  169. handleQuery();
  170. }
  171. /** 多选框选中数据 */
  172. const handleSelectionChange = (selection: ClassificationVO[]) => {
  173. ids.value = selection.map(item => item.id);
  174. single.value = selection.length != 1;
  175. multiple.value = !selection.length;
  176. }
  177. /** 新增按钮操作 */
  178. const handleAdd = () => {
  179. reset();
  180. dialog.visible = true;
  181. dialog.title = "添加产品属性关联";
  182. }
  183. /** 修改按钮操作 */
  184. const handleUpdate = async (row?: ClassificationVO) => {
  185. reset();
  186. const _id = row?.id || ids.value[0]
  187. const res = await getClassification(_id);
  188. Object.assign(form.value, res.data);
  189. dialog.visible = true;
  190. dialog.title = "修改产品属性关联";
  191. }
  192. /** 提交按钮 */
  193. const submitForm = () => {
  194. classificationFormRef.value?.validate(async (valid: boolean) => {
  195. if (valid) {
  196. buttonLoading.value = true;
  197. if (form.value.id) {
  198. await updateClassification(form.value).finally(() => buttonLoading.value = false);
  199. } else {
  200. await addClassification(form.value).finally(() => buttonLoading.value = false);
  201. }
  202. proxy?.$modal.msgSuccess("操作成功");
  203. dialog.visible = false;
  204. await getList();
  205. }
  206. });
  207. }
  208. /** 删除按钮操作 */
  209. const handleDelete = async (row?: ClassificationVO) => {
  210. const _ids = row?.id || ids.value;
  211. await proxy?.$modal.confirm('是否确认删除产品属性关联编号为"' + _ids + '"的数据项?').finally(() => loading.value = false);
  212. await delClassification(_ids);
  213. proxy?.$modal.msgSuccess("删除成功");
  214. await getList();
  215. }
  216. /** 导出按钮操作 */
  217. const handleExport = () => {
  218. proxy?.download('product/classification/export', {
  219. ...queryParams.value
  220. }, `classification_${new Date().getTime()}.xlsx`)
  221. }
  222. onMounted(() => {
  223. getList();
  224. });
  225. </script>