AddOrEditUserInfo.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <!--
  2. * @Author: your name
  3. * @Date: 2020-10-22 18:26:27
  4. * @LastEditTime: 2021-05-21 13:31:31
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: \WEB\userCenter\src\views\system\users\popups\AddOrEditUserInfo.vue
  8. -->
  9. <template>
  10. <div class="alert-body__main_content">
  11. <zz-form :cols="formCols" :data="formData" :rules="formRules" :errors="formErrors" labelWidth="120" ref="form">
  12. <el-input slot="password" type="password" v-model="formData.password"></el-input>
  13. <el-input slot="passwordOK" type="password" v-model="formData.passwordOK"></el-input>
  14. <el-select slot="status" v-model="formData.enableState">
  15. <el-option v-for="(item, index) in allStatus" :key="index" :label="item.label" :value="item.id">{{ item.label }}</el-option>
  16. </el-select>
  17. <el-input slot="roleId" v-if="noAllRoleId" v-model="formData.roleName" disabled></el-input>
  18. <el-select v-else slot="roleId" v-model="formData.roleId">
  19. <el-option
  20. v-show="item.roleState"
  21. v-for="(item, index) in allRoleId"
  22. :key="index"
  23. :label="item.roleName"
  24. :value="item.id"
  25. >{{ item.roleName }}</el-option
  26. >
  27. </el-select>
  28. <el-select slot="userType" v-model="formData.userType">
  29. <el-option v-for="(item, index) in allUserType" :key="index" :label="item.dictValue" :value="item.dictCode">{{
  30. item.dictValue
  31. }}</el-option>
  32. </el-select>
  33. <select-tree
  34. :props="defaultProps"
  35. slot="companyOrgId"
  36. class="new-select-tree"
  37. selectTreeTitle="组织机构"
  38. width="320"
  39. treeWidth="320"
  40. :options="organListCompany"
  41. @selected="selectedcompanyOrgId"
  42. v-model="formData.companyOrgId"
  43. :labelModel="formData.companyOrgName"
  44. />
  45. <select-tree
  46. :props="defaultProps"
  47. slot="deptOrgId"
  48. class="new-select-tree"
  49. selectTreeTitle="组织机构"
  50. width="320"
  51. treeWidth="320"
  52. :options="organListdepartment"
  53. @selected="selecteddeptOrgId"
  54. v-model="formData.deptOrgId"
  55. />
  56. <div class="imgdis-div" slot="companylogo" v-show="formData.photo">
  57. <i class="el-icon-delete" @click="delformphoto"></i>
  58. <img :src="envConfig.baseImgApi + formData.photo" alt="" width="60" height="60" />
  59. </div>
  60. <el-upload
  61. v-show="!formData.photo"
  62. :headers="token"
  63. ref="uploaduserlogo"
  64. class="mini-upload"
  65. slot="companylogo"
  66. limit="1"
  67. action="/sc-user-center/user/addUserPhoto"
  68. list-type="picture-card"
  69. :on-success="uploadsuccess"
  70. :auto-upload="true"
  71. name="avatarfile"
  72. >
  73. <i slot="default" class="el-icon-plus"></i>
  74. <div slot="file" slot-scope="{ file }">
  75. <img class="el-upload-list__item-thumbnail" :src="file.url" alt="" />
  76. <span class="el-upload-list__item-actions">
  77. <!-- <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
  78. <i class="el-icon-zoom-in"></i>
  79. </span> -->
  80. <!-- <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleDownload(file)">
  81. <i class="el-icon-download"></i>
  82. </span> -->
  83. <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleRemove(file)">
  84. <i class="el-icon-delete"></i>
  85. </span>
  86. </span>
  87. </div>
  88. </el-upload>
  89. <el-dialog :visible.sync="dialogVisible">
  90. <img width="100%" :src="dialogImageUrl" alt="" />
  91. </el-dialog>
  92. </zz-form>
  93. </div>
  94. </template>
  95. <script>
  96. import envConfig from '@/config';
  97. // import SelectTree from '@/components/common/SelectTree.vue';
  98. export default {
  99. props: ['params'],
  100. components: {
  101. // SelectTree
  102. },
  103. data() {
  104. var validatePassContrast = (rule, value, callback) => {
  105. if (value == '' || value == null) {
  106. callback(new Error('请输入密码'));
  107. } else {
  108. if (this.formData.password !== value) {
  109. callback(new Error('两次密码不一致'));
  110. }
  111. callback();
  112. }
  113. };
  114. var validatePass = (rule, value, callback) => {
  115. if (value == '' || value == null) {
  116. callback(new Error('请输入密码'));
  117. } else {
  118. if (value.length < 6) {
  119. callback(new Error('密码位数不得少于6位'));
  120. }
  121. callback();
  122. }
  123. };
  124. return {
  125. token: {
  126. [localStorage.getItem('SC_token') && 'Authorization']: 'Bearer ' + localStorage.getItem('SC_token')
  127. },
  128. isLoginUser: false,
  129. envConfig: envConfig,
  130. organList: [
  131. {
  132. id: 1,
  133. tenantId: 'string123',
  134. orgName: '公司',
  135. parentOrgId: 0,
  136. orgs: [{ id: 2, tenantId: 'string123', orgName: '部门', parentOrgId: 1, orgs: null, display: true }],
  137. display: true
  138. }
  139. ],
  140. organListCompany: [],
  141. organListdepartment: [],
  142. defaultProps: {
  143. value: 'id', // 唯一标识
  144. label: 'orgName', // 标签显示
  145. children: 'orgs' // 子级
  146. },
  147. formData: {
  148. companyOrgId: '',
  149. companyOrgName: '',
  150. deptOrgId: '',
  151. deptOrgName: '',
  152. email: '',
  153. enableState: '1',
  154. id: '',
  155. phone: '',
  156. password: '',
  157. passwordOK: '',
  158. photo: '',
  159. remark: '',
  160. roleId: '',
  161. status: '',
  162. tenantId: '',
  163. userType: '',
  164. username: ''
  165. },
  166. dialogImageUrl: '',
  167. dialogVisible: false,
  168. disabled: false,
  169. allStatus: [
  170. {
  171. id: '0',
  172. label: '停用'
  173. },
  174. {
  175. id: '1',
  176. label: '启用'
  177. }
  178. ],
  179. allRoleId: [],
  180. noAllRoleId: false,
  181. noIdInAllRoleId: false,
  182. allUserType: [],
  183. formCols: [
  184. [
  185. {
  186. label: '所属公司',
  187. prop: 'companyOrgId',
  188. slot: 'companyOrgId'
  189. },
  190. {
  191. label: '所属部门',
  192. prop: 'deptOrgId',
  193. slot: 'deptOrgId'
  194. },
  195. {
  196. label: '用户名',
  197. prop: 'username',
  198. input: true
  199. },
  200. {
  201. label: '手机号码',
  202. prop: 'phone',
  203. input: true
  204. },
  205. {
  206. label: '密码',
  207. prop: 'password',
  208. slot: 'password'
  209. },
  210. {
  211. label: '确认密码',
  212. prop: 'passwordOK',
  213. slot: 'passwordOK'
  214. },
  215. {
  216. label: '状态',
  217. prop: 'enableState',
  218. slot: 'status'
  219. },
  220. {
  221. label: '角色',
  222. prop: 'roleId',
  223. slot: 'roleId'
  224. },
  225. {
  226. label: '头像',
  227. prop: 'photo',
  228. slot: 'companylogo'
  229. },
  230. {
  231. label: '邮箱',
  232. prop: 'email',
  233. input: true
  234. },
  235. {
  236. label: '用户类型',
  237. prop: 'userType',
  238. slot: 'userType'
  239. },
  240. {
  241. label: '备注',
  242. prop: 'remark',
  243. input: true
  244. }
  245. ]
  246. ],
  247. formColsEdit: [
  248. [
  249. {
  250. label: '用户名',
  251. prop: 'username',
  252. input: true
  253. },
  254. {
  255. label: '手机号码',
  256. prop: 'phone',
  257. input: true
  258. },
  259. {
  260. label: '密码',
  261. prop: 'password',
  262. slot: 'password'
  263. },
  264. {
  265. label: '确认密码',
  266. prop: 'passwordOK',
  267. slot: 'passwordOK'
  268. },
  269. {
  270. label: '头像',
  271. prop: 'photo',
  272. slot: 'companylogo'
  273. },
  274. {
  275. label: '邮箱',
  276. prop: 'email',
  277. input: true
  278. },
  279. {
  280. label: '备注',
  281. prop: 'remark',
  282. input: true
  283. }
  284. ]
  285. ],
  286. formRules: {
  287. companyOrgId: [this.$valid.selectRequired('所属公司')],
  288. // deptOrgId: [this.$valid.selectRequired('所属部门')],
  289. username: [this.$valid.inputRequired('用户名')],
  290. phone: [this.$valid.patternPhone()],
  291. password: [{ required: true, validator: validatePass, trigger: 'blur' }],
  292. passwordOK: [{ required: true, validator: validatePassContrast, trigger: 'blur' }],
  293. enableState: [this.$valid.inputRequired('状态')],
  294. userType: [this.$valid.selectRequired('用户类型')]
  295. },
  296. formErrors: {}
  297. };
  298. },
  299. watch: {
  300. 'formData.passwordOK'(val) {
  301. if (this.formData.password !== val) {
  302. }
  303. }
  304. },
  305. methods: {
  306. delformphoto() {
  307. this.formData.photo = '';
  308. this.$refs.uploaduserlogo.clearFiles();
  309. },
  310. getselectAll() {},
  311. submit() {
  312. new Promise((resolve) => {
  313. this.$refs.form.validate(resolve);
  314. }).then(() => {
  315. var loading = this.$loading();
  316. var posturl = '';
  317. let frData = JSON.parse(JSON.stringify(this.formData));
  318. if (this.params.todo === 'edit') {
  319. posturl = '/user/updateUserById';
  320. if (frData.password === '**********' || frData.passwordOK === '**********') {
  321. delete frData.password;
  322. delete frData.passwordOK;
  323. }
  324. } else {
  325. posturl = '/user/addUser';
  326. }
  327. this.$http
  328. .post(posturl, frData)
  329. .then(({ status, data, msg }) => {
  330. loading.close();
  331. if (0 == status) {
  332. if (this.isLoginUser) {
  333. this.$store.commit('setcCruUserInfo', this.formData);
  334. }
  335. this.$message.success(msg);
  336. this.params.callback && this.params.callback();
  337. this.$emit('close');
  338. } else {
  339. this.$message.error(msg);
  340. }
  341. })
  342. .catch((err) => {
  343. loading.close();
  344. });
  345. });
  346. },
  347. handleRemove(file) {
  348. this.$refs.uploaduserlogo.clearFiles();
  349. },
  350. uploadsuccess(response, file, fileList) {
  351. if (0 === response.status) {
  352. this.formData.photo = response.data;
  353. }
  354. },
  355. selectedcompanyOrgId(e) {
  356. this.formData.deptOrgId = '';
  357. this.formData.deptOrgName = '';
  358. // 获取 部门树e
  359. this.$http.postForm('/org/getOrgUserTree', { orgType: 'department', id: e }).then(({ status, data, msg }) => {
  360. if (status === 0) {
  361. // console.log(data);
  362. this.organListdepartment = data ? data : [];
  363. }
  364. });
  365. }
  366. },
  367. created() {
  368. this.getselectAll();
  369. this.formData = JSON.stringify(this.params.data) !== '{}' ? this.params.data : this.formData;
  370. if (this.params.todo === 'edit') {
  371. this.$set(this.formData, 'password', '**********');
  372. this.$set(this.formData, 'passwordOK', '**********');
  373. }
  374. this.organList = this.params.organList ? this.params.organList : this.organList;
  375. this.organListCompany = this.params.organListCompany ? this.params.organListCompany : this.organListCompany;
  376. this.organListdepartment = this.params.organListdepartment ? this.params.organListdepartment : this.organListdepartment;
  377. this.allRoleId = this.params.allRoleId ? this.params.allRoleId : this.allRoleId;
  378. this.allUserType = this.params.allUserType ? this.params.allUserType : this.allUserType;
  379. this.isLoginUser = this.formData.id == this.$store.getters['getCruUserInfo'].id ? true : false;
  380. if (this.isLoginUser) {
  381. this.formCols = this.formColsEdit;
  382. }
  383. if (this.allRoleId.length === 0) {
  384. this.noAllRoleId = true;
  385. } else {
  386. // console.log(this.allRoleId);
  387. this.noIdInAllRoleId = this.allRoleId.every((v, i) => {
  388. return v.id !== this.formData.roleId;
  389. });
  390. // console.log(this.noIdInAllRoleId);
  391. if (this.noIdInAllRoleId) {
  392. this.allRoleId.push({
  393. id: this.formData.roleId,
  394. roleName: this.formData.roleName
  395. });
  396. }
  397. }
  398. }
  399. };
  400. </script>
  401. <style lang='scss' scoped>
  402. </style>
  403. <style lang="scss">
  404. .mini-upload .el-upload-list--picture-card .el-upload-list__item {
  405. width: 60px;
  406. height: 60px;
  407. }
  408. .mini-upload .el-upload--picture-card {
  409. width: 60px;
  410. height: 60px;
  411. line-height: 60px;
  412. font-size: 14px;
  413. }
  414. .mini-upload .el-upload--picture-card i {
  415. font-size: 20px;
  416. }
  417. .imgdis-div {
  418. width: 60px;
  419. height: 60px;
  420. position: relative;
  421. }
  422. .imgdis-div i {
  423. display: none;
  424. position: absolute;
  425. top: 50%;
  426. left: 50%;
  427. transform: translate(-50%, -50%);
  428. }
  429. .imgdis-div:hover i {
  430. display: block;
  431. }
  432. </style>