edituser.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <!--
  2. * @Author: your name
  3. * @Date: 2020-10-22 18:26:27
  4. * @LastEditTime: 2020-11-26 08:14:05
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: \vue-manage-system-master\src\views\system\users\popups\AddOrEdit.vue
  8. -->
  9. <template>
  10. <div class="alert-body__main_content">
  11. <zz-form :cols="formCols" :data="formData" :rules="formRules" :errors="formErrors" labelWidth="110" ref="form">
  12. <el-input slot="password" type="password" clearable v-model="formData.password"></el-input>
  13. <el-input slot="passwordOK" type="password" clearable 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-select slot="roleId" v-model="formData.roleId">
  18. <el-option v-for="(item, index) in allRoleId" :key="index" :label="item.roleName" :value="item.id">{{
  19. item.roleName
  20. }}</el-option>
  21. </el-select>
  22. <el-select slot="userType" v-model="formData.userType">
  23. <el-option v-for="(item, index) in allUserType" :key="index" :label="item.dictValue" :value="item.id">{{
  24. item.dictValue
  25. }}</el-option>
  26. </el-select>
  27. <select-tree
  28. :props="defaultProps"
  29. slot="companyOrgId"
  30. class="new-select-tree"
  31. selectTreeTitle="组织机构"
  32. width="320"
  33. treeWidth="320"
  34. :options="organListCompany"
  35. @selected="selectedcompanyOrgId"
  36. v-model="formData.companyOrgId"
  37. :labelModel="formData.companyOrgName"
  38. />
  39. <select-tree
  40. :props="defaultProps"
  41. slot="deptOrgId"
  42. class="new-select-tree"
  43. selectTreeTitle="组织机构"
  44. width="320"
  45. treeWidth="320"
  46. :options="organListdepartment"
  47. @selected="selecteddeptOrgId"
  48. v-model="formData.deptOrgId"
  49. />
  50. <div class="imgdis-div" slot="companylogo" v-show="formData.photo">
  51. <i class="el-icon-delete" @click="delformphoto"></i>
  52. <img :src="envConfig.baseImgApi + formData.photo" alt="" width="60" height="60" style="object-fit: cover" />
  53. <!-- <div class="tips"><img style="width:12px;height:12px;vertical-align: middle;" src="@assets/img/icon-warning.png"/><span>支持jpg,jpeg,gif,png,bmp格式的图片</span></div> -->
  54. </div>
  55. <el-upload
  56. v-show="!formData.photo"
  57. :headers="token"
  58. ref="uploaduserlogo"
  59. class="mini-upload"
  60. slot="companylogo"
  61. limit="1"
  62. action="/sc-user-center/user/addUserPhoto"
  63. list-type="picture-card"
  64. :on-success="uploadsuccess"
  65. :auto-upload="true"
  66. name="avatarfile"
  67. >
  68. <i slot="default" class="el-icon-plus"></i>
  69. <div slot="file" slot-scope="{ file }">
  70. <img class="el-upload-list__item-thumbnail" :src="file.url" alt="" />
  71. <span class="el-upload-list__item-actions">
  72. <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleRemove(file)">
  73. <i class="el-icon-delete"></i>
  74. </span>
  75. </span>
  76. </div>
  77. <div class="tips">
  78. <img style="width: 12px; height: 12px; vertical-align: middle" src="@assets/img/icon-warning.png" /><span
  79. >支持jpg,jpeg,gif,png,bmp格式的图片</span
  80. >
  81. </div>
  82. </el-upload>
  83. <el-dialog :visible.sync="dialogVisible">
  84. <img width="100%" :src="dialogImageUrl" alt="" />
  85. </el-dialog>
  86. </zz-form>
  87. </div>
  88. </template>
  89. <script>
  90. import envConfig from '@/config';
  91. // import SelectTree from '@/components/common/SelectTree.vue';
  92. export default {
  93. props: ['params'],
  94. components: {
  95. // SelectTree
  96. },
  97. data() {
  98. var validatePassContrast = (rule, value, callback) => {
  99. if (value == '' || value == null) {
  100. callback(new Error('请输入密码'));
  101. } else {
  102. if (this.formData.password !== value) {
  103. callback(new Error('两次密码不一致'));
  104. }
  105. callback();
  106. }
  107. };
  108. var validatePass = (rule, value, callback) => {
  109. if (value == '' || value == null) {
  110. callback(new Error('请输入密码'));
  111. } else {
  112. if (value.length < 6) {
  113. callback(new Error('密码位数不得少于6位'));
  114. }
  115. callback();
  116. }
  117. };
  118. return {
  119. token: {
  120. [localStorage.getItem('SC_token') && 'Authorization']: 'Bearer ' + localStorage.getItem('SC_token')
  121. },
  122. envConfig: envConfig,
  123. organList: [
  124. {
  125. id: 1,
  126. tenantId: 'string123',
  127. orgName: '公司',
  128. parentOrgId: 0,
  129. orgs: [{ id: 2, tenantId: 'string123', orgName: '部门', parentOrgId: 1, orgs: null, display: true }],
  130. display: true
  131. }
  132. ],
  133. organListCompany: [],
  134. organListdepartment: [],
  135. phoneNumber: '',
  136. defaultProps: {
  137. value: 'id', // 唯一标识
  138. label: 'orgName', // 标签显示
  139. children: 'orgs' // 子级
  140. },
  141. formData: {
  142. companyOrgId: '',
  143. companyOrgName: '',
  144. createBy: '',
  145. dateCreate: '',
  146. dateUpdate: '',
  147. deptOrgId: '',
  148. deptOrgName: '',
  149. email: '',
  150. enableState: '',
  151. id: '',
  152. phone: '',
  153. photo: '',
  154. remark: '',
  155. roleId: '',
  156. status: '',
  157. tenantId: '',
  158. updateBy: '',
  159. userGroupId: '',
  160. userTags: '',
  161. userType: '',
  162. username: '',
  163. password: '**********',
  164. passwordOK: '**********'
  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. allUserType: [],
  181. formCols: [
  182. [
  183. {
  184. label: '用户名',
  185. prop: 'username',
  186. input: true
  187. },
  188. {
  189. label: '手机号码',
  190. prop: 'phone',
  191. input: true
  192. },
  193. {
  194. label: '密码',
  195. prop: 'password',
  196. slot: 'password'
  197. },
  198. {
  199. label: '确认密码',
  200. prop: 'passwordOK',
  201. slot: 'passwordOK'
  202. },
  203. {
  204. label: '头像',
  205. prop: 'photo',
  206. slot: 'companylogo'
  207. },
  208. {
  209. label: '邮箱',
  210. prop: 'email',
  211. input: true
  212. },
  213. {
  214. label: '备注',
  215. prop: 'remark',
  216. input: true
  217. }
  218. ]
  219. ],
  220. formRules: {
  221. companyOrgId: [this.$valid.selectRequired('所属公司')],
  222. username: [this.$valid.inputRequired('用户名')],
  223. password: [{ required: true, validator: validatePass, trigger: 'blur' }],
  224. passwordOK: [{ required: true, validator: validatePassContrast, trigger: 'blur' }],
  225. phone: [this.$valid.patternPhone()],
  226. enableState: [this.$valid.inputRequired('状态')]
  227. },
  228. formErrors: {}
  229. };
  230. },
  231. methods: {
  232. delformphoto() {
  233. this.formData.photo = '';
  234. this.$refs.uploaduserlogo.clearFiles();
  235. },
  236. getselectAll() {},
  237. submit() {
  238. new Promise((resolve) => {
  239. this.$refs.form.validate(resolve);
  240. }).then(() => {
  241. var loading = this.$loading();
  242. var posturl = '/sc-user-center/user/updateUserById';
  243. if (this.formData.password === '**********' || this.formData.passwordOK === '**********') {
  244. delete this.formData.password;
  245. delete this.formData.passwordOK;
  246. }
  247. this.$http
  248. .post(posturl, this.formData)
  249. .then(({ status, data, msg }) => {
  250. debugger;
  251. loading.close();
  252. if (0 == status) {
  253. this.$message.success(msg);
  254. if (this.phoneNumber !== this.formData.phone) {
  255. this.$alert('你的手机号已变更,需重新登录', '提示', {
  256. confirmButtonText: '确定',
  257. showClose: false
  258. }).then(() => {
  259. window.open(`${envConfig.loginUrl}`, '_self');
  260. window.relogin = false;
  261. localStorage.removeItem('SC_token');
  262. return;
  263. });
  264. } else {
  265. this.params.callback && this.params.callback();
  266. this.$emit('close');
  267. if (this.$route.path === '/userInfo') {
  268. this.$router.go(0);
  269. }
  270. }
  271. } else {
  272. this.$message.error(msg);
  273. }
  274. })
  275. .catch((err) => {
  276. loading.close();
  277. });
  278. });
  279. },
  280. handleRemove(file) {
  281. this.$refs.uploaduserlogo.clearFiles();
  282. },
  283. uploadsuccess(response, file, fileList) {
  284. if (0 === response.status) {
  285. this.formData.photo = response.data;
  286. }
  287. }
  288. },
  289. created() {
  290. this.getselectAll();
  291. this.phoneNumber = this.params.data.phone;
  292. let val = Object.assign(this.formData, this.params.data);
  293. this.formData = val;
  294. this.$set(this.formData, 'password', '**********');
  295. this.organList = this.params.organList ? this.params.organList : this.organList;
  296. this.organListCompany = this.params.organListCompany ? this.params.organListCompany : this.organListCompany;
  297. this.organListdepartment = this.params.organListdepartment ? this.params.organListdepartment : this.organListdepartment;
  298. this.allRoleId = this.params.allRoleId ? this.params.allRoleId : this.allRoleId;
  299. this.allUserType = this.params.allUserType ? this.params.allUserType : this.allUserType;
  300. }
  301. };
  302. </script>
  303. <style lang='scss' scoped>
  304. </style>
  305. <style lang="scss">
  306. .mini-upload .el-upload-list--picture-card .el-upload-list__item {
  307. width: 60px;
  308. height: 60px;
  309. }
  310. .mini-upload .el-upload--picture-card {
  311. width: 60px;
  312. height: 60px;
  313. line-height: 60px;
  314. font-size: 14px;
  315. }
  316. .mini-upload .el-upload--picture-card i {
  317. font-size: 20px;
  318. }
  319. .imgdis-div {
  320. width: 60px;
  321. height: 60px;
  322. position: relative;
  323. }
  324. .imgdis-div i {
  325. display: none;
  326. position: absolute;
  327. top: 50%;
  328. left: 50%;
  329. transform: translate(-50%, -50%);
  330. }
  331. // .imgdis-div .notice{
  332. // display: contents;
  333. // font-size: 12px;
  334. // }
  335. .imgdis-div:hover i {
  336. display: block;
  337. }
  338. // .imgdis-div .tips{
  339. // position: absolute;
  340. // font-size: 0.12px;
  341. // font-family: MicrosoftYaHei;
  342. // color: #7D7F87;
  343. // top: 10px;
  344. // right: -261px;
  345. // }
  346. .el-upload .tips {
  347. position: absolute;
  348. top: 0;
  349. right: 0;
  350. font-size: 12px;
  351. color: #7d7f87;
  352. // font-size: 12px;
  353. // span{
  354. // position: absolute;
  355. // font-size: 12px;
  356. // font-family: MicrosoftYaHei;
  357. // color: #7D7F87;
  358. // top: 0px;
  359. // right: 0px;
  360. // }
  361. }
  362. </style>