user-skill.vue 9.0 KB

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