index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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="标签名称" prop="productLabelName">
  8. <el-input v-model="queryParams.productLabelName" placeholder="请输入标签名称" clearable @keyup.enter="handleQuery" />
  9. </el-form-item>
  10. <el-form-item>
  11. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  12. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  13. </el-form-item>
  14. </el-form>
  15. </el-card>
  16. </div>
  17. </transition>
  18. <el-card shadow="never">
  19. <template #header>
  20. <el-row :gutter="10" class="mb8">
  21. <el-col :span="1.5">
  22. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['product:lable:add']">新增</el-button>
  23. </el-col>
  24. <el-col :span="1.5">
  25. <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['product:lable:edit']">修改</el-button>
  26. </el-col>
  27. <el-col :span="1.5">
  28. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['product:lable:remove']">删除</el-button>
  29. </el-col>
  30. <!-- <el-col :span="1.5">
  31. <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['product:lable:export']">导出</el-button>
  32. </el-col> -->
  33. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  34. </el-row>
  35. </template>
  36. <el-table v-loading="loading" border :data="lableList" @selection-change="handleSelectionChange">
  37. <el-table-column type="selection" width="55" align="center" />
  38. <el-table-column label="标签名称" align="center" prop="productLabelName" />
  39. <el-table-column label="产品数量" align="center" prop="productQuantity" />
  40. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  41. <template #default="scope">
  42. <el-tooltip content="修改" placement="top">
  43. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['product:lable:edit']"></el-button>
  44. </el-tooltip>
  45. <el-tooltip content="删除" placement="top">
  46. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['product:lable:remove']"></el-button>
  47. </el-tooltip>
  48. </template>
  49. </el-table-column>
  50. </el-table>
  51. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  52. </el-card>
  53. <!-- 添加或修改产品标签信息(注意:名疑似拼写错误,应为 product_label)对话框 -->
  54. <el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
  55. <el-form ref="lableFormRef" :model="form" :rules="rules" label-width="80px">
  56. <el-form-item label="标签名称" prop="productLabelName">
  57. <el-input v-model="form.productLabelName" placeholder="请输入标签名称" />
  58. </el-form-item>
  59. </el-form>
  60. <template #footer>
  61. <div class="dialog-footer">
  62. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  63. <el-button @click="cancel">取 消</el-button>
  64. </div>
  65. </template>
  66. </el-dialog>
  67. </div>
  68. </template>
  69. <script setup name="Lable" lang="ts">
  70. import { listLable, getLable, delLable, addLable, updateLable } from '@/api/pmsProduct/lable';
  71. import { LableVO, LableQuery, LableForm } from '@/api/pmsProduct/lable/types';
  72. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  73. const lableList = ref<LableVO[]>([]);
  74. const buttonLoading = ref(false);
  75. const loading = ref(true);
  76. const showSearch = ref(true);
  77. const ids = ref<Array<string | number>>([]);
  78. const single = ref(true);
  79. const multiple = ref(true);
  80. const total = ref(0);
  81. const queryFormRef = ref<ElFormInstance>();
  82. const lableFormRef = ref<ElFormInstance>();
  83. const dialog = reactive<DialogOption>({
  84. visible: false,
  85. title: ''
  86. });
  87. const initFormData: LableForm = {
  88. id: undefined,
  89. productLabelName: undefined,
  90. }
  91. const data = reactive<PageData<LableForm, LableQuery>>({
  92. form: {...initFormData},
  93. queryParams: {
  94. pageNum: 1,
  95. pageSize: 10,
  96. productLabelName: undefined,
  97. params: {
  98. }
  99. },
  100. rules: {
  101. productLabelName: [
  102. { required: true, message: "标签名称不能为空", trigger: "blur" }
  103. ],
  104. }
  105. });
  106. const { queryParams, form, rules } = toRefs(data);
  107. /** 查询产品标签信息(注意:名疑似拼写错误,应为 product_label)列表 */
  108. const getList = async () => {
  109. loading.value = true;
  110. const res = await listLable(queryParams.value);
  111. lableList.value = res.rows;
  112. total.value = res.total;
  113. loading.value = false;
  114. }
  115. /** 取消按钮 */
  116. const cancel = () => {
  117. reset();
  118. dialog.visible = false;
  119. }
  120. /** 表单重置 */
  121. const reset = () => {
  122. form.value = {...initFormData};
  123. lableFormRef.value?.resetFields();
  124. }
  125. /** 搜索按钮操作 */
  126. const handleQuery = () => {
  127. queryParams.value.pageNum = 1;
  128. getList();
  129. }
  130. /** 重置按钮操作 */
  131. const resetQuery = () => {
  132. queryFormRef.value?.resetFields();
  133. handleQuery();
  134. }
  135. /** 多选框选中数据 */
  136. const handleSelectionChange = (selection: LableVO[]) => {
  137. ids.value = selection.map(item => item.id);
  138. single.value = selection.length != 1;
  139. multiple.value = !selection.length;
  140. }
  141. /** 新增按钮操作 */
  142. const handleAdd = () => {
  143. reset();
  144. dialog.visible = true;
  145. dialog.title = "新增商品标签";
  146. }
  147. /** 修改按钮操作 */
  148. const handleUpdate = async (row?: LableVO) => {
  149. reset();
  150. const _id = row?.id || ids.value[0]
  151. const res = await getLable(_id);
  152. Object.assign(form.value, res.data);
  153. dialog.visible = true;
  154. dialog.title = "编辑商品标签";
  155. }
  156. /** 提交按钮 */
  157. const submitForm = () => {
  158. lableFormRef.value?.validate(async (valid: boolean) => {
  159. if (valid) {
  160. buttonLoading.value = true;
  161. if (form.value.id) {
  162. await updateLable(form.value).finally(() => buttonLoading.value = false);
  163. } else {
  164. await addLable(form.value).finally(() => buttonLoading.value = false);
  165. }
  166. proxy?.$modal.msgSuccess("操作成功");
  167. dialog.visible = false;
  168. await getList();
  169. }
  170. });
  171. }
  172. /** 删除按钮操作 */
  173. const handleDelete = async (row?: LableVO) => {
  174. const _ids = row?.id || ids.value;
  175. await proxy?.$modal.confirm('是否确认删除选中的标签?').finally(() => loading.value = false);
  176. await delLable(_ids);
  177. proxy?.$modal.msgSuccess("删除成功");
  178. await getList();
  179. }
  180. /** 导出按钮操作 */
  181. const handleExport = () => {
  182. proxy?.download('product/lable/export', {
  183. ...queryParams.value
  184. }, `lable_${new Date().getTime()}.xlsx`)
  185. }
  186. onMounted(() => {
  187. getList();
  188. });
  189. </script>