addPersonnel.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <!-- 添加人员信息 -->
  3. <div class="addWagonLoad">
  4. <PageTitle>返回</PageTitle>
  5. <div class="form-box" style="margin-right: 10rem">
  6. <dil-form :formId="325" v-model="form1" ref="from1"></dil-form>
  7. </div>
  8. <div class="department">
  9. <div class="department2">
  10. <span>二级部门:</span>
  11. <el-select v-model="value1" placeholder="请选择" @change="onchange1">
  12. <el-option
  13. v-for="(item,i) in options1"
  14. :key="i"
  15. :label="item.label"
  16. :value="item.value"
  17. >
  18. </el-option>
  19. </el-select>
  20. </div>
  21. <div class="department3">
  22. <span>三级部门:</span>
  23. <el-select v-model="value2" placeholder="请选择" @change="onchange2">
  24. <el-option
  25. v-for="(item,i) in options2"
  26. :key="i"
  27. :label="item.label"
  28. :value="item.value"
  29. >
  30. </el-option>
  31. </el-select>
  32. </div>
  33. </div>
  34. <div>
  35. <div class="role">
  36. <span>赋权角色:</span>
  37. <el-select v-model="value3" placeholder="请选择">
  38. <el-option
  39. v-for="(item,i) in options3"
  40. :key="i"
  41. :label="item.roleName"
  42. :value="item.roleId"
  43. >
  44. </el-option>
  45. </el-select>
  46. </div>
  47. </div>
  48. <div class="button-box">
  49. <el-button @click="cancel">取消</el-button>
  50. <el-button type="primary" @click="makeSure">确定</el-button>
  51. </div>
  52. </div>
  53. </template>
  54. <script>
  55. import PageTitle from "@/components/Page/Title";
  56. import { getCookie } from "@/utils/util.js";
  57. export default {
  58. components: { PageTitle },
  59. data() {
  60. return {
  61. form1: {},
  62. value: undefined,
  63. //新增用户的SSO主键
  64. personnelSsoId:'',
  65. //token
  66. token: null,
  67. //二级部门
  68. options1:[],
  69. //选中的二级部门名称
  70. value1:'',
  71. //选中的二级部门机构ID和机构编码
  72. map1:[],
  73. // 三级部门
  74. options2:[],
  75. // 选中的三级部门名称
  76. value2:'',
  77. //选中的三级部门机构ID和机构编码
  78. map2:[],
  79. // 角色
  80. options3:[],
  81. // 选中的角色名称
  82. value3:'',
  83. // 选中的角色ID
  84. roleId:''
  85. };
  86. },
  87. created(){
  88. this.token = getCookie("accessToken");
  89. },
  90. mounted() {
  91. //初始化二级机构和角色
  92. this.initialization();
  93. },
  94. methods: {
  95. initialization(){
  96. //初始化选择二级机构
  97. this.axios.get('/api/v1/rms/getSecondShipper').then((res)=>{
  98. this.options1 = res.data.data;
  99. })
  100. //初始化角色
  101. const formData = new FormData();
  102. this.$store.dispatch('system/rolesManage/list',formData)
  103. .then((res)=>{
  104. var roleList = [];
  105. roleList=res.data;
  106. roleList.forEach((item,i)=>{
  107. if(item.roleId!='superadmin'){
  108. this.options3.push(item);
  109. }
  110. })
  111. // this.options3 = res.data;
  112. })
  113. },
  114. onchange1(val){
  115. // 查询选中的二级机构下的三级机构
  116. this.value2 = '';
  117. this.axios.get('/api/v1/rms/getThirdShipper?shipperId='+val).then((res)=>{
  118. this.options2 = res.data.data;
  119. })
  120. //获取二级部门的机构ID和机构编码
  121. this.axios.post('/api/v1/rms/getShipperMap?shipperId='+val).then((res)=>{
  122. this.map1 = res.data.data;
  123. })
  124. },
  125. onchange2(val){
  126. //获取三级部门的机构ID和机构编码
  127. this.axios.post('/api/v1/rms/getShipperMap?shipperId='+val).then((res)=>{
  128. this.map2 = res.data.data;
  129. })
  130. },
  131. //确定人员新增
  132. makeSure() {
  133. //初始化用户信息
  134. let userInfo = {};
  135. //该用户没有三级部门
  136. if(this.options2.length==0){
  137. userInfo = {
  138. userName : this.form1.personnelName,
  139. userCode : this.form1.personnelJobNumber,
  140. orgCode : this.map1.shipperOrgCode,
  141. orgName : this.value1,
  142. orgId : this.map1.shipperSsoId,
  143. // mobile : '13500000011',
  144. // email : '123456789@qq.com',
  145. groupId : '506514577756917769',
  146. companyId : '713710108567277568'
  147. }
  148. //该用户有三级部门
  149. }else{
  150. userInfo = {
  151. userName : this.form1.personnelName,
  152. userCode : this.form1.personnelJobNumber,
  153. orgCode : this.map2.shipperOrgCode,
  154. orgName : this.value1,
  155. orgId : this.map2.shipperSsoId,
  156. // mobile : '13500000011',
  157. // email : '123456789@qq.com',
  158. groupId : '506514577756917769',
  159. companyId : '713710108567277568'
  160. }
  161. }
  162. //先新增SSO中的用户
  163. const formData = new FormData();
  164. Object.keys(userInfo).forEach((key) => {
  165. formData.append(key, userInfo[key]);
  166. });
  167. //新增用户
  168. this.$store.dispatch('system/usersManage/addUser',formData)
  169. .then((res)=>{
  170. //再新增RMS_PERSONNEL表信息
  171. let rmsPersonnel = {
  172. personnelJobNumber : this.form1.personnelJobNumber,
  173. personnelPost : this.form1.personnelPost,
  174. personnelName : this.form1.personnelName,
  175. personnelDepartmentId : this.form1.shipperId,
  176. // personnelWorkshopid : this.form1.personnelWorkshopid,
  177. personnelShifts : this.form1.personnelShifts,
  178. personnelTeam : this.form1.personnelTeam,
  179. personnelSsoId : res.data.userId
  180. }
  181. if(
  182. RmsPersonnel.personnelJobNumber ==null ||
  183. RmsPersonnel.personnelName ==null ||
  184. RmsPersonnel.personnelPost ==null ||
  185. // RmsPersonnel.personnelWorkshopid==null ||
  186. RmsPersonnel.personnelShifts==null ||
  187. RmsPersonnel.departmentId==null ||
  188. RmsPersonnel.personnelTeam==null ||
  189. userInfo.orgName==null ||
  190. userInfo.orgCode==null ||
  191. userInfo.orgId==null ||
  192. this.value3==null
  193. )this.$message.error("存在空值!");
  194. else
  195. this.axios.post('/api/v1/rms/addPersonnel',rmsPersonnel)
  196. .then((res)=>{
  197. if (res.data.code == 200) {
  198. this.$message({
  199. type: "success",
  200. message: "新增成功!",
  201. });
  202. // this.$refs.table.refreshData();
  203. } else {
  204. this.$message.error("新增失败,可能存在重复!");
  205. }
  206. // this.$refs['table'].resetField();
  207. })
  208. //最后新增角色赋权表
  209. this.axios.post('pass/v1/sysuserroles/addUserroles?userId='
  210. +res.data.userId+'&userCode='+this.form1.personnelJobNumber+'&roleId='+this.value3)
  211. .then((res)=>{
  212. this.$router.go(-1);
  213. })
  214. });
  215. //最后新增角色赋权表
  216. // let RmsPersonnel={
  217. // personnelId:this.form1.personnelId,
  218. // personnelJobNumber: this.form1.personnelJobNumber,
  219. // personnelName: this.form1.personnelName,
  220. // personnelPost: this.form1.personnelPost,
  221. // personnelWorkshopid: this.form1.personnelWorkshopid,
  222. // personnelShifts: this.form1.personnelShifts,
  223. // personnelTeam:this.form1.personnelTeam,
  224. // departmentId: this.form1.shipperId
  225. // };
  226. // if(
  227. // RmsPersonnel.personnelJobNumber ==null ||
  228. // RmsPersonnel.personnelName ==null ||
  229. // RmsPersonnel.personnelPost ==null ||
  230. // RmsPersonnel.personnelWorkshopid==null ||
  231. // RmsPersonnel.personnelShifts==null ||
  232. // RmsPersonnel.departmentId==null ||
  233. // RmsPersonnel.personnelTeam==null
  234. // )this.$message.error("存在空值!");
  235. // else
  236. // this.axios
  237. // .post(
  238. // "/api/v1/rms/insertPersonnel",
  239. // RmsPersonnel
  240. // )
  241. // .then((res) => {
  242. // if (res.data.code == 200) {
  243. // this.$message({
  244. // type: "success",
  245. // message: "新增成功!",
  246. // });
  247. // // this.$refs.table.refreshData();
  248. // this.$router.go(-1);
  249. // } else {
  250. // this.$message.error("新增失败,可能存在重复!");
  251. // }
  252. // this.$refs['table'].resetField();
  253. // });
  254. },
  255. // 取消
  256. cancel() {
  257. this.$router.go(-1);
  258. },
  259. },
  260. };
  261. </script>
  262. <style lang='scss' >
  263. .button-box{
  264. display: flex;
  265. justify-content: center;
  266. margin-top: 2rem;
  267. .el-button{
  268. width: 80px;
  269. margin-right: 10px;
  270. }
  271. }
  272. .form-box{
  273. display: flex;
  274. justify-content: center;
  275. .el-form-item{
  276. display: flex;
  277. justify-content: center;
  278. .el-form-item__label{
  279. display: flex;
  280. align-items: center;
  281. }
  282. .el-form-item__content{
  283. .el-input{
  284. .el-input__inner{
  285. width: 250px;
  286. }
  287. }
  288. }
  289. }
  290. }
  291. .department{
  292. display: flex;
  293. justify-content: center;
  294. .department3{
  295. margin-left: 2rem;
  296. }
  297. }
  298. .role{
  299. display: flex;
  300. justify-content: center;
  301. margin-top: 2rem;
  302. }
  303. </style>