AddOrEditUserInfo.vue 16 KB

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