newAdd.vue 14 KB

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