edit-skill.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <div class="mainContentBox">
  3. <avue-form
  4. ref="formRef"
  5. v-model:search="search"
  6. v-model="form"
  7. :data="data2"
  8. :option="option2"
  9. />
  10. <avue-crud
  11. ref="crudRef"
  12. v-model="form"
  13. :data="data"
  14. :option="option"
  15. @row-save="createRow"
  16. @row-update="updateRow"
  17. @row-del="deleteRow"
  18. >
  19. <template #menu-left="{ size }">
  20. <el-button type="primary" icon="el-icon-plus" circle @click="addSkill"
  21. /></template>
  22. </avue-crud>
  23. <CommonTable
  24. ref="ctableRef"
  25. tableTitle="员工选择"
  26. tableType="USERS"
  27. @selected-sure="onSelectedFinish"
  28. />
  29. <div class="detail-footer">
  30. <el-button type="primary" @click="onHandle"> 确定 </el-button>
  31. <el-button @click="cancelWindow">取消</el-button>
  32. </div>
  33. </div>
  34. </template>
  35. <script setup>
  36. import { ref, getCurrentInstance } from "vue";
  37. import { useCrud } from "@/hooks/userCrud";
  38. import { useCommonStoreHook, useDictionaryStore } from "@/store";
  39. import dictDataUtil from "@/common/configs/dictDataUtil";
  40. const { isShowTable, tableType } = toRefs(useCommonStoreHook());
  41. import {
  42. getPostSkill,
  43. addEmployeeSkill,
  44. getSkillDetail,
  45. } from "@/api/system/skill";
  46. // 数据字典相关
  47. const { dicts } = useDictionaryStore();
  48. const test = () => {
  49. isShowTable.value = true;
  50. tableType.value = tableType.value == 1 ? 2 : 1;
  51. };
  52. const data3 = ref([]);
  53. const data2 = ref(null);
  54. // 传入一个url,后面不带/
  55. const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  56. useCrud({
  57. src: "/api/v1/sys/skillScore",
  58. dataListUrl: "/api/v1/sys/skillScore/list",
  59. });
  60. const {
  61. dataList,
  62. createRow,
  63. updateRow,
  64. deleteRow,
  65. searchChange,
  66. dataNoPageList,
  67. } = Methords; //增删改查
  68. const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
  69. const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具
  70. // checkBtnPerm(ButtonPermKeys.PLAN.BTNS.order_add) :permission="permission"
  71. // const permission = reactive({
  72. // delBtn: checkPerm(buttonPermission.PLAN.BTNS.order_del),
  73. // addBtn: checkPerm(buttonPermission.PLAN.BTNS.order_add),
  74. // editBtn: checkPerm(buttonPermission.PLAN.BTNS.order_edit),
  75. // menu: true,
  76. // });
  77. const option2 = ref(null);
  78. const ctableRef = ref(null); //crudRef.value 获取avue-crud对象
  79. const router = useRouter();
  80. onMounted(() => {
  81. // console.log("crudRef", crudRef)
  82. getSkillDetail(props.skillId).then((data) => {
  83. form.value = data.data;
  84. });
  85. search.value.employeeSkillId = props.skillId;
  86. dataList();
  87. });
  88. const skillChange = (row) => {
  89. if (
  90. skillValue.value !== undefined &&
  91. skillValue.value !== null &&
  92. skillValue.value !== ""
  93. ) {
  94. data.value[row.$index].skillDictValue = skillValue.value;
  95. }
  96. };
  97. const cancelWindow = () => {
  98. props.editDialog.visible = false;
  99. };
  100. const addSkill = () => {
  101. const bom = ref({
  102. $cellEdit: true,
  103. });
  104. data.value.push(bom.value);
  105. };
  106. const employeeSkill = ref({});
  107. const onHandle = () => {
  108. console.info("dddd", data);
  109. if (
  110. form.value.userId === null ||
  111. form.value.userId === undefined ||
  112. form.value.userId === ""
  113. ) {
  114. ElMessage({
  115. message: "未选择打分用户",
  116. type: "error",
  117. });
  118. return false;
  119. }
  120. if (
  121. form.value.postId === null ||
  122. form.value.postId === undefined ||
  123. form.value.postId === ""
  124. ) {
  125. ElMessage({
  126. message: "未选择岗位",
  127. type: "error",
  128. });
  129. return false;
  130. }
  131. if (data.value.length === 0) {
  132. ElMessage({
  133. message: "没有要保存的打分项",
  134. type: "error",
  135. });
  136. return false;
  137. }
  138. if (data.value.length > 0) {
  139. for (let i = 0; i < data.value.length; i++) {
  140. if (
  141. data.value[i].skillDictValue === undefined ||
  142. data.value[i].skillDictValue === null ||
  143. data.value[i].skillDictValue === ""
  144. ) {
  145. ElMessage({
  146. message: "第" + (i + 1) + "项没有选择技能",
  147. type: "error",
  148. });
  149. return false;
  150. }
  151. if (
  152. data.value[i].score === undefined ||
  153. data.value[i].score === null ||
  154. data.value[i].score === ""
  155. ) {
  156. ElMessage({
  157. message: "第" + (i + 1) + "项没有打分",
  158. type: "error",
  159. });
  160. return false;
  161. }
  162. }
  163. }
  164. employeeSkill.value.userId = form.value.userId;
  165. employeeSkill.value.postId = form.value.postId;
  166. employeeSkill.value.skillList = Array.from(data.value);
  167. employeeSkill.value.id = form.value.id;
  168. addEmployeeSkill(employeeSkill.value).then((data) => {
  169. if (data.code === "200") {
  170. ElMessage({
  171. message: data.msg,
  172. type: "success",
  173. });
  174. props.editDialog.visible = false;
  175. } else {
  176. ElMessage({
  177. message: data.msg,
  178. type: "error",
  179. });
  180. }
  181. });
  182. };
  183. // 设置表格列或者其他自定义的option
  184. option2.value = {
  185. selection: true,
  186. submitBtn: false,
  187. clearAbleBtn: false,
  188. emptyBtn: false,
  189. column: [
  190. {
  191. label: "id",
  192. prop: "id",
  193. width: 130,
  194. overHidden: true,
  195. search: true,
  196. filterable: true,
  197. width: 100,
  198. overHidden: true,
  199. disabled: false,
  200. display: false,
  201. },
  202. {
  203. label: "用户id",
  204. prop: "userId",
  205. width: 130,
  206. overHidden: true,
  207. search: true,
  208. filterable: true,
  209. disabled: true,
  210. display: false,
  211. },
  212. {
  213. label: "用户名",
  214. prop: "userName",
  215. width: 140,
  216. overHidden: true,
  217. search: true,
  218. rules: [
  219. {
  220. required: true,
  221. search: true,
  222. message: "请选择员工姓名",
  223. trigger: "blur",
  224. },
  225. ],
  226. click: ({ value, column }) => {
  227. ctableRef.value.startSelect();
  228. },
  229. },
  230. /* {
  231. label: "所属机构",
  232. prop: "institution",
  233. width: 130,
  234. overHidden: true,
  235. search: true,
  236. filterable: true,
  237. },*/
  238. {
  239. label: "员工编号",
  240. prop: "employeeCode",
  241. search: true,
  242. disabled: true,
  243. },
  244. {
  245. label: "岗位",
  246. prop: "postName",
  247. search: true,
  248. filterable: true,
  249. overHidden: true,
  250. disabled: true,
  251. dicUrl: dictDataUtil.post_list_url,
  252. dicMethod: "post",
  253. change: ({ value, column }) => {
  254. if (value !== undefined) {
  255. props.postId = value;
  256. skillValue.value = null;
  257. optionSkill.value = null;
  258. dataNoPageList();
  259. }
  260. },
  261. props: { label: "postName", value: "id" },
  262. },
  263. { label: "所属机构", prop: "deptName", overHidden: true, disabled: true },
  264. ],
  265. };
  266. const postIdValue = ref({});
  267. const props = defineProps({
  268. editDialog: {
  269. type: Object,
  270. default: () => {
  271. return {};
  272. },
  273. },
  274. skillId: {
  275. type: String,
  276. default: () => {
  277. return "0";
  278. },
  279. },
  280. postId: {
  281. type: Number,
  282. default: () => {
  283. return "0";
  284. },
  285. },
  286. });
  287. const postIdSkill = ref({});
  288. // 设置表格列或者其他自定义的option
  289. option.value = Object.assign(option.value, {
  290. selection: false,
  291. addBtn: false,
  292. viewBtn: false,
  293. editBtn: false,
  294. saveBtn: false,
  295. cellBtn: true,
  296. column: [
  297. {
  298. label: "技能",
  299. prop: "skillDictValue",
  300. align: "center",
  301. headerAlign: "center",
  302. span: 24,
  303. cell: true,
  304. type: "select",
  305. dicUrl:
  306. import.meta.env.VITE_APP_BASE_API +
  307. "/api/v1/sys/postSkill/list/" +
  308. props.postId,
  309. props: {
  310. label: "skillDictLabel", // 下拉菜单显示的字段
  311. value: "skillDictValue", // 下拉菜单值的字段
  312. },
  313. change: (row) => {
  314. console.log(row);
  315. data.value.forEach((item, index) => {
  316. console.log("aaa", index);
  317. console.log("bbbb", item);
  318. if (item.skillDictValue == row.value && index != row.index) {
  319. row.row.skillDictValue = "";
  320. row.value = "";
  321. console.log("ccc", row);
  322. ElMessage({
  323. message: item.$skillDictValue + " 打分项重复",
  324. type: "error",
  325. });
  326. }
  327. });
  328. },
  329. },
  330. {
  331. label: "分数",
  332. prop: "score",
  333. align: "center",
  334. headerAlign: "center",
  335. cell: true,
  336. type: "number",
  337. precision: 2,
  338. max: 100,
  339. min: 0,
  340. span: 24,
  341. },
  342. ],
  343. });
  344. const onSelectedFinish = (selectedValue) => {
  345. form.value.userId = selectedValue.id;
  346. form.value.userName = selectedValue.userName;
  347. form.value.deptName = selectedValue.deptName;
  348. form.value.employeeCode = selectedValue.employeeCode;
  349. //form.value.institution = selectedValue.institution;
  350. };
  351. const skillValue = ref(null);
  352. const optionSkill = ref([]);
  353. const getPostSkills = () => {
  354. if (
  355. postIdValue.value === undefined ||
  356. postIdValue.value === null ||
  357. postIdValue.value === ""
  358. ) {
  359. ElMessage({
  360. message: "未选择岗位",
  361. type: "error",
  362. });
  363. return false;
  364. }
  365. getPostSkill(postIdValue.value).then((data) => {
  366. optionSkill.value = Array.from(data.data);
  367. });
  368. };
  369. </script>
  370. <style type="text/css">
  371. .title-detail {
  372. width: 30%;
  373. height: 50px;
  374. line-height: 50px;
  375. margin: 25px 20px 25px 0;
  376. float: left;
  377. }
  378. .detail {
  379. margin: 0 auto;
  380. width: 100%;
  381. }
  382. .avue-crud {
  383. float: left;
  384. }
  385. .detail-footer {
  386. float: right;
  387. margin-top: 15px;
  388. }
  389. .el-select__selection {
  390. width: 150px;
  391. }
  392. </style>