平安校园
 
 
 
 
 
 

217 lines
6.6 KiB

  1. <!--
  2. * @Description: 服装库管理
  3. * @Author: syy
  4. * @Date: 2024-7-18
  5. -->
  6. <template>
  7. <div class="main-box">
  8. <!-- :request-api="userManageClothApi.getList" -->
  9. <TreeFilter
  10. :key="treeKey"
  11. ref="treeFilter"
  12. label="clothSetName"
  13. id="clothSetId"
  14. width="300px"
  15. :show-all="false"
  16. :isData="true"
  17. :data="treeData"
  18. :default-value="clothSetId"
  19. @change="changeTreeFilter"
  20. >
  21. <template v-slot:header>
  22. <s-button suffix="服装库" @click="addClass(FormOptEnum.ADD)" style="margin-bottom: 15px" />
  23. </template>
  24. <template v-slot:label="{ row }">
  25. <span class="custom-tree-node">
  26. <span>{{ row.node.label }}</span>
  27. <span v-if="row.node.label != '全部'">
  28. <a @click.stop="addClass(FormOptEnum.EDIT, row.node.data)">
  29. <el-icon><Edit /></el-icon>
  30. </a>
  31. <a style="margin-left: 8px" @click.stop="addDelete(row.node.data.clothSetId, '删除服装库')">
  32. <el-icon><Delete /></el-icon>
  33. </a>
  34. </span>
  35. </span>
  36. </template>
  37. </TreeFilter>
  38. <div class="table-box">
  39. <ProTable ref="proTable" title="服装库管理" :columns="columns" rowKey="clothId" :data="tableData.clothes">
  40. <!-- 表格 header 按钮 -->
  41. <template #tableHeader="scope">
  42. <s-button suffix="服装" @click="onOpen(FormOptEnum.ADD, { clothSetId: clothSetId }, treeData)" />
  43. <s-button
  44. type="danger"
  45. :opt="FormOptEnum.DELETE"
  46. plain
  47. suffix="服装"
  48. :disabled="!scope.isSelected"
  49. @click="onDelete(scope.selectedListIds, '删除所选服装')"
  50. />
  51. </template>
  52. <!-- 表格操作栏 -->
  53. <template #operation="scope">
  54. <el-space>
  55. <s-button link :opt="FormOptEnum.DELETE" @click="onDelete([scope.row.clothId], `删除服装`)" />
  56. </el-space>
  57. </template>
  58. </ProTable>
  59. </div>
  60. <!-- 人员新增/编辑表单 -->
  61. <Form ref="formRef"></Form>
  62. <!-- 班级新增/编辑表单 -->
  63. <Form1 ref="formRefC" />
  64. <!-- 预览头像 -->
  65. <el-dialog v-model="visible" title="查看头像" width="830px" :before-close="handleClose">
  66. <div style="display: flex; align-items: center; justify-content: center">
  67. <img style="max-width: 100%; max-height: 600px" class="detailpic" :src="faceUrl" alt="" />
  68. </div>
  69. <template #footer>
  70. <div class="dialog-footer">
  71. <el-button @click="visible = false">关闭</el-button>
  72. </div>
  73. </template>
  74. </el-dialog>
  75. </div>
  76. </template>
  77. <script setup lang="tsx" name="SysUserClothing">
  78. import { userManageClothApi,userClothButtonCode,SysUserCloth } from "@/api";
  79. import { useHandleData } from "@/hooks/useHandleData";
  80. import { FormOptEnum } from "@/enums";
  81. import Form from "./components/form/index.vue";
  82. import Form1 from "./components/form1/index.vue";
  83. import { ColumnProps, ProTableInstance } from "@/components/ProTable/interface";
  84. import TreeFilter from "@/components/TreeFilter/index.vue";
  85. import { useUserStore } from "@/stores/modules";
  86. // 获取 ProTable 元素,调用其获取刷新数据方法(还能获取到当前查询参数,方便导出携带参数)
  87. const faceUrl = ref('');
  88. const visible = ref(false); //是否显示人员表单
  89. const proTable = ref<ProTableInstance>();
  90. const treeFilter = ref<any>({});
  91. const treeKey = ref(1234);
  92. const userStore = useUserStore();
  93. const { accessToken } = userStore;
  94. const tableData = ref<any>([])
  95. // 初始化数据
  96. const treeData = ref<any>([]);
  97. // 表格配置项
  98. const columns: ColumnProps<SysUserCloth.list>[] = [
  99. { type: "selection", fixed: "left", width: 50 },
  100. {
  101. prop: "clothUrl",
  102. label: "服装图",
  103. render: scope => {
  104. return (
  105. <img src={scope.row.clothUrl} onClick={() => viewHeadImage(scope)} style='width:50px;height:50px' alt=''/>
  106. );
  107. }
  108. },
  109. { prop: "operation", label: "操作", width: 250, fixed: "right" }
  110. ];
  111. const viewHeadImage = (scope: any) => {
  112. faceUrl.value = scope.row.clothUrl;
  113. visible.value = true
  114. };
  115. const handleClose = () => {
  116. visible.value = false;
  117. };
  118. // 人员表单引用
  119. const formRef = ref<InstanceType<typeof Form> | null>(null);
  120. // 班级表单引用
  121. const formRefC = ref<InstanceType<typeof Form1> | null>(null);
  122. /**
  123. * 打开服装表单
  124. * @param opt 操作类型
  125. * @param record 记录
  126. */
  127. function onOpen(opt: FormOptEnum, record: {},treeAllData:any) {
  128. formRef.value?.onOpen({ opt: opt, record: record,treeAllData:treeAllData, successful: RefreshTable });
  129. }
  130. /**
  131. * 打开服装库表单
  132. * @param opt 操作类型
  133. * @param record 记录
  134. */
  135. function addClass(opt: FormOptEnum, record: {} | SysUserCloth.list = {}) {
  136. formRefC.value?.onOpen({ opt: opt, record: JSON.parse(JSON.stringify(record)), successful: RefreshTree });
  137. }
  138. /**
  139. * 服装库删除
  140. * @param ids id数组
  141. */
  142. async function addDelete(clothSetId: string[],msg: string) {
  143. // 二次确认 => 请求api => 刷新表格
  144. await useHandleData(userManageClothApi.deleteClothDataBaseD, { clothSetId }, msg);
  145. RefreshTree('delete'); //刷新表格
  146. }
  147. /**
  148. * 服装删除
  149. * @param ids id数组
  150. */
  151. async function onDelete(ids: string[], msg: string) {
  152. // 二次确认 => 请求api => 刷新表格
  153. await useHandleData(userManageClothApi.delete, {clothId: ids.join(","), clothSetId:tableData.value.clothSetId}, msg);
  154. RefreshTable(); //刷新表格
  155. }
  156. // 刷新表格
  157. const RefreshTable = () => {
  158. getList(clothSetId.value)
  159. }
  160. // 刷新表格+树
  161. const RefreshTree = async(type='') => {
  162. if(type == 'delete'){clothSetId.value = ''}
  163. treeKey.value = Math.random();
  164. await getTree(); //刷新树形筛选器
  165. await getList(clothSetId.value)
  166. }
  167. /** 服装库切换切换 */
  168. const clothSetId = ref<number | string>()
  169. function changeTreeFilter(val: number | string) {
  170. clothSetId.value = val
  171. proTable.value!.pageable.pageNum = 1;
  172. getList(val)
  173. }
  174. // 获取列表
  175. const getList = (clothSetId:any)=>{
  176. if(!clothSetId) return false
  177. userManageClothApi.page({clothSetId:clothSetId}).then((resp:any)=>{
  178. if(resp.code == 200){
  179. tableData.value = resp.data
  180. }
  181. })
  182. }
  183. const getTree =async ()=>{
  184. const { data }:any = await userManageClothApi.getList({});
  185. treeData.value = data;
  186. // showTree.value = true
  187. if(!clothSetId.value){
  188. clothSetId.value = data[0].clothSetId.toString()
  189. }
  190. }
  191. onMounted(async () => {
  192. await getTree()
  193. getList(clothSetId.value)
  194. })
  195. </script>
  196. <style scoped lang="scss">
  197. .table-box {
  198. width: 100%;
  199. height: 100%;
  200. }
  201. .custom-tree-node {
  202. display: flex;
  203. flex: 1;
  204. align-items: center;
  205. justify-content: space-between;
  206. padding-right: 8px;
  207. font-size: 14px;
  208. }
  209. </style>