index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <div class="quality-project-container layout-pd">
  3. <el-card shadow="never">
  4. <el-form :model="state.queryParams" ref="ruleFormRef" inline @submit.native.prevent>
  5. <el-form-item label="质检项名称" prop="Name">
  6. <el-input v-model="state.queryParams.Name" placeholder="请输入质检项目名称" clearable @keyup.enter="handleQuery" class="keyword-input" />
  7. </el-form-item>
  8. <el-form-item label="质检项分组" prop="GroupingName">
  9. <el-select v-model="state.queryParams.GroupingName" placeholder="请选择质检项目分组" @change="handleQuery">
  10. <el-option v-for="item in qualityItemGrouping" :value="item.dicDataValue" :key="item.dicDataValue" :label="item.dicDataName" />
  11. </el-select>
  12. </el-form-item>
  13. <el-form-item>
  14. <el-button type="primary" @click="handleQuery" :loading="state.loading"> <SvgIcon name="ele-Search" class="mr5" />查询 </el-button>
  15. <el-button @click="resetQuery(ruleFormRef)" v-waves class="default-button"> <SvgIcon name="ele-Refresh" class="mr5" />重置 </el-button>
  16. </el-form-item>
  17. </el-form>
  18. </el-card>
  19. <el-card shadow="never">
  20. <ProTable
  21. ref="proTableRef"
  22. :columns="columns"
  23. :data="state.tableData"
  24. @updateTable="queryList"
  25. :loading="state.loading"
  26. :total="state.total"
  27. v-model:page-index="state.queryParams.PageIndex"
  28. v-model:page-size="state.queryParams.PageSize"
  29. >
  30. <!-- 表格 header 按钮 -->
  31. <template #tableHeader="scope">
  32. <el-button type="primary" @click="onProjectAdd" v-waves v-auth="'quality:project:add'">
  33. <SvgIcon name="ele-Plus" class="mr5" />新增
  34. </el-button>
  35. <el-button type="primary" @click="onProjectDelete" v-waves v-auth="'quality:project:delete'" :disabled="!scope.isSelected">
  36. <SvgIcon name="ele-Delete" class="mr5" />删除
  37. </el-button>
  38. </template>
  39. <template #type="{ row }">
  40. {{ row.isIntelligent === 1 ? '是' : '否' }}
  41. </template>
  42. <!-- 表格操作 -->
  43. <template #operation="{ row }">
  44. <el-button link type="primary" @click="onProjectEdit(row)" v-auth="'quality:project:edit'" title="编辑质检项目"> 编辑 </el-button>
  45. </template>
  46. </ProTable>
  47. </el-card>
  48. <!-- 质检项目新增 -->
  49. <project-add ref="projectAddRef" @updateList="queryList" :qualityItemGrouping="qualityItemGrouping" />
  50. <!-- 质检项目编辑 -->
  51. <project-edit ref="projectEditRef" @updateList="queryList" :qualityItemGrouping="qualityItemGrouping" />
  52. </div>
  53. </template>
  54. <script lang="tsx" setup name="qualityProject">
  55. import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
  56. import { ElMessage, ElMessageBox, FormInstance } from 'element-plus';
  57. import { formatDate } from '@/utils/formatTime';
  58. import { auth } from '@/utils/authFunction';
  59. import { projectBaseData, projectDelete, projectList, projectUpdate } from '@/api/quality/project';
  60. // 引入组件
  61. const ProjectAdd = defineAsyncComponent(() => import('@/views/quality/project/components/Project-add.vue')); // 质检项目新增
  62. const ProjectEdit = defineAsyncComponent(() => import('@/views/quality/project/components/Project-edit.vue')); // 质检项目编辑
  63. const proTableRef = ref<RefType>(); // 表格ref
  64. // 表格配置项
  65. const columns = ref<any[]>([
  66. { type: 'selection', fixed: 'left', width: 55,align: 'center' },
  67. { prop: 'name', label: '质检项名称' },
  68. { prop: 'describe', label: '质检项描述', width: 130 },
  69. { prop: 'groupingName', label: '质检项分组' },
  70. { prop: 'type', label: '是否智能质检' },
  71. { prop: 'grade', label: '分值(分)' },
  72. {
  73. prop: 'isEnable',
  74. label: '是否启用',
  75. render: (scope) => {
  76. return (
  77. <>
  78. {auth('quality:project:edit') ? (
  79. <el-switch
  80. model-value={scope.row.isEnable}
  81. active-text="启用"
  82. inactive-text="禁用"
  83. active-value={1}
  84. inactive-value={0}
  85. onClick={() => changeIsEnable(scope.row)}
  86. inline-prompt
  87. />
  88. ) : (
  89. <span>{scope.row.isEnable === 1 ? '启用' : '禁用'}</span>
  90. )}
  91. </>
  92. );
  93. },
  94. },
  95. { prop: 'creatorName', label: '创建人' },
  96. {
  97. prop: 'creationTime',
  98. label: '创建时间',
  99. width: 170,
  100. render: (scope) => {
  101. return <span>{formatDate(scope.row.creationTime, 'YYYY-mm-dd HH:MM:SS')}</span>;
  102. },
  103. },
  104. { prop: 'lastModificationName', label: '更新人' },
  105. {
  106. prop: 'lastModificationTime',
  107. label: '更新时间',
  108. width: 170,
  109. render: (scope) => {
  110. return <span>{formatDate(scope.row.lastModificationTime, 'YYYY-mm-dd HH:MM:SS')}</span>;
  111. },
  112. },
  113. { prop: 'operation', label: '操作', fixed: 'right', width: 120, align: 'center' },
  114. ]);
  115. // 定义变量内容
  116. const state = reactive({
  117. loading: false, // 加载状态
  118. queryParams: {
  119. // 查询参数
  120. PageIndex: 1,
  121. PageSize: 10,
  122. GroupingName: null,
  123. Type: null,
  124. Name: null,
  125. },
  126. total: 0, // 总条数
  127. tableData: [], // 表格数据
  128. });
  129. const ruleFormRef = ref<RefType>(null); // 表单ref
  130. const qualityItemGrouping = ref<EmptyArrayType>([]); // 质检项目分组
  131. const getBaseData = async () => {
  132. try {
  133. const res = await projectBaseData();
  134. qualityItemGrouping.value = res.result?.qualityItemGrouping ?? [];
  135. } catch (error) {
  136. console.log(error);
  137. }
  138. };
  139. // 手动查询,将页码设置为1
  140. const handleQuery = () => {
  141. state.queryParams.PageIndex = 1;
  142. queryList();
  143. };
  144. // 获取参数列表
  145. const queryList = () => {
  146. state.loading = true;
  147. projectList(state.queryParams)
  148. .then((res) => {
  149. state.loading = false;
  150. state.tableData = res.result.items ?? [];
  151. state.total = res.result.total ?? 0;
  152. })
  153. .finally(() => {
  154. state.loading = false;
  155. });
  156. };
  157. // 重置表单
  158. const resetQuery = (formEl: FormInstance | undefined) => {
  159. if (!formEl) return;
  160. formEl.resetFields();
  161. queryList();
  162. };
  163. // 新增质检项目
  164. const projectAddRef = ref<RefType>();
  165. const onProjectAdd = () => {
  166. projectAddRef.value.openDialog();
  167. };
  168. // 编辑质检项目
  169. const projectEditRef = ref<RefType>();
  170. const onProjectEdit = (row: any) => {
  171. projectEditRef.value.openDialog(row);
  172. };
  173. // 删除质检项目
  174. const onProjectDelete = () => {
  175. const names = proTableRef.value.selectedList.map((item: any) => item.name).join('、');
  176. const ids = proTableRef.value.selectedList.map((item: any) => item.id);
  177. ElMessageBox.confirm(`您确定要删除:【${names}】质检项目,是否继续?`, '提示', {
  178. confirmButtonText: '确认',
  179. cancelButtonText: '取消',
  180. type: 'warning',
  181. draggable: true,
  182. cancelButtonClass: 'default-button',
  183. autofocus: false,
  184. })
  185. .then(() => {
  186. projectDelete({ ids }).then(() => {
  187. ElMessage.success('操作成功');
  188. queryList();
  189. });
  190. })
  191. .catch(() => {});
  192. };
  193. // 修改是否启用
  194. const changeIsEnable = (row: any) => {
  195. ElMessageBox.confirm(`您确定要${row.isEnable === 1 ? '禁用' : '启用'}:【${row.name}】质检项,是否继续?`, '提示', {
  196. confirmButtonText: '确认',
  197. cancelButtonText: '取消',
  198. type: 'warning',
  199. draggable: true,
  200. cancelButtonClass: 'default-button',
  201. autofocus: false,
  202. })
  203. .then(() => {
  204. const isEnable = row.isEnable === 1 ? 0 : 1;
  205. const request = {
  206. ...row,
  207. isEnable: isEnable,
  208. };
  209. projectUpdate(request)
  210. .then(() => {
  211. ElMessage.success('操作成功');
  212. queryList();
  213. })
  214. .catch(() => {
  215. queryList();
  216. });
  217. })
  218. .catch(() => {
  219. queryList();
  220. });
  221. };
  222. // 页面加载时
  223. onMounted(() => {
  224. getBaseData();
  225. queryList();
  226. });
  227. </script>
  228. <style lang="scss" scoped>
  229. .quality-project-container {
  230. }
  231. </style>