newAdd.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <script setup lang="ts">
  2. defineOptions({
  3. name: "evaluateNewAdd"
  4. });
  5. import { ref, reactive, onMounted } from "vue";
  6. import one from "@/assets/svg/2.svg";
  7. import two from "@/assets/svg/1.svg";
  8. import one1 from "@/assets/svg/2-2.svg";
  9. import two2 from "@/assets/svg/1-1.svg";
  10. import { useRouter, useRoute } from "vue-router";
  11. import { Edit } from "@element-plus/icons-vue";
  12. import { ElMessageBox, ElMessage } from "element-plus";
  13. import {
  14. postAddDimension,
  15. getDimensionRemove,
  16. getQuotaByDimensionId
  17. } from "@/api/dimension";
  18. import editMould from "./editMould.vue";
  19. import { delQuota } from "@/api/indexDefine";
  20. import settingIndexDrawer from "./settingIndexDrawer.vue";
  21. import { postAddTemplate, getInfo, getListBy } from "@/api/templateInfo";
  22. import importIndex from "./importIndex.vue";
  23. import { useNav } from "@/layout/hooks/useNav";
  24. const { toggleSideBar } = useNav();
  25. const router = useRouter();
  26. const route = useRoute();
  27. const formRef = ref();
  28. const active = ref(0);
  29. const editDrawer = ref();
  30. const editDrawerShow = ref(false);
  31. const titleShow = ref(false);
  32. // 指标设置
  33. const settingIndexDrawerRef = ref();
  34. const settingIndexDrawerShow = ref(false);
  35. // 导入指标
  36. const importIndexRef = ref();
  37. const importIndexShow = ref(false);
  38. const handleSelect = index => {
  39. // console.log(index);
  40. active.value = index;
  41. };
  42. const tepName = ref();
  43. onMounted(() => {
  44. if (route.query.tpName) {
  45. tepNameForm.tpName = route.query.tpName;
  46. tepNameForm.id = route.query.id;
  47. }
  48. });
  49. const tableData = ref([]);
  50. const tepNameForm = reactive({
  51. tpName: "",
  52. id: ""
  53. });
  54. // 新建模板
  55. const postAddTemplateApi = async () => {
  56. const res = await postAddTemplate({ ...tepNameForm });
  57. Object.assign(tepNameForm, {
  58. tpName: "",
  59. id: ""
  60. });
  61. if (res.code === 200) {
  62. ElMessage({
  63. message: "创建成功",
  64. type: "success"
  65. });
  66. tepNameForm.tpName = res.data.tpName;
  67. tepNameForm.id = res.data.id;
  68. titleShow.value = true;
  69. } else {
  70. ElMessage.error(res.msg);
  71. }
  72. };
  73. // 考核维度卡片
  74. const eaxmCard = ref([]);
  75. // 获取维度
  76. const getListByApi = async () => {
  77. console.log(tepNameForm.id);
  78. const { code, data, msg } = await getListBy(tepNameForm.id);
  79. Object.assign(tepNameForm, {
  80. tpName: "",
  81. id: ""
  82. });
  83. if (code === 200) {
  84. titleShow.value = true;
  85. eaxmCard.value = data;
  86. eaxmCard.value.forEach(item => {
  87. initializeTableData(item);
  88. });
  89. } else {
  90. ElMessage.error(msg);
  91. }
  92. };
  93. // 获取指标信息
  94. const paramsIndex = reactive({
  95. id: "",
  96. tpId: "",
  97. dimId: ""
  98. });
  99. const getQuotaByDimensionIdApi = async id => {
  100. paramsIndex.dimId = id;
  101. const { code, data, msg } = await getQuotaByDimensionId(paramsIndex);
  102. if (code === 200) {
  103. return data;
  104. } else {
  105. ElMessage.error(msg);
  106. return [];
  107. }
  108. };
  109. const initializeTableData = async item => {
  110. item.tableData = await getQuotaByDimensionIdApi(item.id);
  111. };
  112. const amountTo = itemList => {
  113. let num = 0;
  114. if (itemList) {
  115. itemList.forEach(item => {
  116. num = num + item.weight;
  117. });
  118. return num;
  119. }
  120. };
  121. const addDimension = reactive({
  122. list: [
  123. {
  124. id: "",
  125. dimName: "",
  126. dimWeight: "",
  127. mode: ""
  128. }
  129. ],
  130. dimName: "",
  131. dimWeight: "",
  132. mode: "",
  133. showIndicRemark: "",
  134. showScoreRule: "",
  135. showDatasource: "",
  136. showTargetValue: "",
  137. showFinalValue: "",
  138. showChallengeValue: "",
  139. showStartValue: "",
  140. remark: ""
  141. });
  142. // 创建考核维度
  143. const createAdd = () => {
  144. editDrawer.value.open(tepNameForm, "新建");
  145. };
  146. const backChange = () => {
  147. toggleSideBar();
  148. router.back();
  149. };
  150. const save = () => {
  151. formRef.value.validate(valid => {
  152. if (valid) {
  153. if (tepNameForm.id) {
  154. getListByApi();
  155. } else {
  156. postAddTemplateApi();
  157. }
  158. }
  159. });
  160. if (titleShow.value) {
  161. router.back();
  162. }
  163. };
  164. const deleteRow = row => {
  165. console.log(row);
  166. ElMessageBox.confirm(
  167. "指标删除后不可恢复,请谨慎操作!",
  168. "确定删除该指标吗?",
  169. {
  170. confirmButtonText: "确认",
  171. cancelButtonText: "取消",
  172. type: "warning"
  173. }
  174. )
  175. .then(async () => {
  176. const { code, msg } = await delQuota(row.id);
  177. if (code === 200) {
  178. ElMessage({
  179. type: "success",
  180. message: "删除成功"
  181. });
  182. initializeTableData(row.dimId);
  183. } else {
  184. ElMessage.error(msg);
  185. }
  186. })
  187. .catch(() => {
  188. ElMessage({
  189. type: "info",
  190. message: "用户取消"
  191. });
  192. });
  193. };
  194. // 编辑
  195. const editPen = item => {
  196. editDrawer.value.open(item, "编辑");
  197. };
  198. // 删除考核维度
  199. const deletePen = index => {
  200. ElMessageBox.confirm(
  201. "该维度删除后不可恢复,请谨慎操作!",
  202. "确定删除考核维度",
  203. {
  204. confirmButtonText: "确认",
  205. cancelButtonText: "取消",
  206. type: "warning"
  207. }
  208. )
  209. .then(async () => {
  210. // eaxmCard.value.splice(index, 1);
  211. const { code, msg } = await getDimensionRemove(index);
  212. if (code === 200) {
  213. getListByApi();
  214. ElMessage({
  215. type: "success",
  216. message: "删除成功"
  217. });
  218. } else {
  219. ElMessage.error(msg);
  220. }
  221. })
  222. .catch(() => {
  223. ElMessage({
  224. type: "info",
  225. message: "用户取消"
  226. });
  227. });
  228. };
  229. const settingIndex = row => {
  230. console.log(row);
  231. settingIndexDrawerRef.value.open();
  232. };
  233. const importIndexDialog = row => {
  234. importIndexRef.value.open(row);
  235. };
  236. </script>
  237. <template>
  238. <div class="w-[100%]">
  239. <!-- 导入指标 -->
  240. <importIndex ref="importIndexRef" v-model="importIndexShow" />
  241. <!-- 指标设置 -->
  242. <settingIndexDrawer
  243. ref="settingIndexDrawerRef"
  244. v-model:drawerValue="settingIndexDrawerShow"
  245. />
  246. <!-- 新增、编辑模块 -->
  247. <editMould
  248. ref="editDrawer"
  249. v-model:drawerValue="editDrawerShow"
  250. @handClick="getListByApi"
  251. />
  252. <div class="w-[100%] flex justify-evenly">
  253. <div class="left-box">
  254. <el-text class="cursor-pointer" @click="backChange"
  255. ><el-icon><ArrowLeft /></el-icon>返回</el-text
  256. >
  257. </div>
  258. <div class="center-box">
  259. <div
  260. style="max-width: 220px"
  261. class="m-auto flex justify-between items-center"
  262. >
  263. <div
  264. :class="{ 'step-success': !titleShow, 'step-error': titleShow }"
  265. class="w-[100px] flex justify-center items-center"
  266. >
  267. <one v-if="titleShow" /><two2 v-else />基础信息
  268. </div>
  269. <div
  270. :class="{ 'step-success': titleShow, 'step-error': !titleShow }"
  271. class="w-[100px] flex justify-center items-center"
  272. >
  273. <two v-if="titleShow" /><one1 v-else />考核指标
  274. </div>
  275. </div>
  276. </div>
  277. <div class="right-box">
  278. <el-button type="primary" class="mr-2" @click="save()">保存</el-button>
  279. </div>
  280. </div>
  281. <div class="mt-2">
  282. <div v-if="!titleShow" class="w-[40%] m-auto mt-10">
  283. <el-form
  284. ref="formRef"
  285. :model="tepNameForm"
  286. label-width="auto"
  287. style="max-width: 600px"
  288. >
  289. <el-form-item
  290. prop="tpName"
  291. label="模板名称"
  292. :rules="[
  293. {
  294. required: true,
  295. message: '请输入模板名称',
  296. trigger: 'blur'
  297. }
  298. ]"
  299. >
  300. <el-input
  301. v-model="tepNameForm.tpName"
  302. placeholder="最多输入100字"
  303. />
  304. </el-form-item>
  305. </el-form>
  306. </div>
  307. <div v-else class="w-[90%] m-auto mt-4">
  308. <div class="relative h-10">
  309. <el-button class="float-right" type="primary" plain @click="createAdd"
  310. >创建考核维度</el-button
  311. >
  312. </div>
  313. <el-card v-for="(item, index) in eaxmCard" :key="index" class="mb-3">
  314. <!-- {{ getQuotaByDimensionIdApi(item.id) }} -->
  315. <template #header>
  316. <div class="card-header">
  317. <span>{{ item.dimName }}({{ item.dimWeight }}%)</span>
  318. <div class="float-right mr-7">
  319. <el-icon class="mr-3" @click="editPen(item)"
  320. ><EditPen
  321. /></el-icon>
  322. <el-icon @click="deletePen(item.id)"
  323. ><Delete class="text-red-500"
  324. /></el-icon>
  325. </div>
  326. </div>
  327. </template>
  328. <el-table :data="item.tableData" style="width: 100%" max-height="250">
  329. <el-table-column fixed prop="name" label="指标名称" />
  330. <el-table-column
  331. v-if="item.showIndicRemark"
  332. prop="remark"
  333. label="指标说明"
  334. width="120"
  335. />
  336. <el-table-column
  337. v-if="item.showScoreRule"
  338. prop="scoreRule"
  339. label="评价标准"
  340. width="300"
  341. />
  342. <el-table-column
  343. v-if="item.showDatasource"
  344. prop="stshowDatasourceate"
  345. label="数据来源"
  346. width="120"
  347. />
  348. <el-table-column
  349. v-if="item.mode"
  350. prop="weight"
  351. label="权重"
  352. width="120"
  353. />
  354. <el-table-column
  355. v-if="item.showTargetValue"
  356. prop="targetValue"
  357. label="目标值"
  358. width="120"
  359. />
  360. <el-table-column
  361. v-if="item.showFinalValue"
  362. prop="finalValue"
  363. label="完成值"
  364. width="120"
  365. />
  366. <el-table-column
  367. v-if="item.showChallengeValue"
  368. prop="challengeValue"
  369. label="挑战值"
  370. width="120"
  371. />
  372. <el-table-column
  373. v-if="item.showStartValue"
  374. prop="startValue"
  375. label="门槛值"
  376. width="120"
  377. />
  378. <el-table-column fixed="right" label="操作">
  379. <template #default="{ row }">
  380. <el-icon class="mr-3" @click="settingIndex(row)"
  381. ><Setting
  382. /></el-icon>
  383. <el-icon @click="deleteRow(row)">
  384. <Delete class="text-red-500" />
  385. </el-icon>
  386. </template>
  387. </el-table-column>
  388. </el-table>
  389. <template #footer>
  390. <el-button type="primary" link class="mr-4"> 添加指标 </el-button>
  391. <el-button type="primary" link @click="importIndexDialog(item)">
  392. 导入指标
  393. </el-button>
  394. <span class="float-right num"
  395. >指标权重合计:{{ amountTo(item.tableData) }}</span
  396. >
  397. </template>
  398. </el-card>
  399. </div>
  400. </div>
  401. </div>
  402. </template>
  403. <style lang="scss" scoped>
  404. .left-box {
  405. display: flex;
  406. flex: 0 0 5%;
  407. align-items: center;
  408. margin: auto;
  409. text-align: center;
  410. // justify-content: center;
  411. }
  412. .center-box {
  413. flex: 0 0 70%;
  414. }
  415. .right-box {
  416. display: flex;
  417. flex: 0 0 5%;
  418. align-items: center;
  419. justify-content: center;
  420. margin: auto;
  421. }
  422. .step-success {
  423. height: 24px;
  424. padding-bottom: 5px;
  425. font-size: 16px;
  426. // font-family: PingFangSC-SNaNpxibold;
  427. font-weight: 600;
  428. line-height: 24px;
  429. color: black;
  430. color: #000000e6;
  431. border-bottom: 2px solid #022bbd;
  432. }
  433. .step-error {
  434. height: 24px;
  435. padding-bottom: 5px;
  436. font-size: 16px;
  437. // font-family: PingFangSC-SNaNpxibold;
  438. font-weight: 600;
  439. line-height: 24px;
  440. color: #0006;
  441. letter-spacing: 0;
  442. }
  443. .num {
  444. font-size: 14px;
  445. // font-family: PingFangSC-Regular;
  446. font-weight: 400;
  447. line-height: 22px;
  448. color: #0009;
  449. letter-spacing: 0;
  450. }
  451. </style>