index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template>
  2. <div class="m-right-block">
  3. <div class="right-block-bd tc">
  4. <el-row style="margin: 0 auto;">
  5. <el-col :span="8">
  6. <div style="margin: 10px auto;">
  7. <img :src="userInfo.headImg" :onerror="errorImg" class="setting-img" @click="showImg(userInfo.headImg)">
  8. <do-upload @onFinish="setHeadImg" placeholder="上传头像"> </do-upload>
  9. </div>
  10. <div style="margin: 10px auto;">
  11. <img :src="userInfo.cardImg" :onerror="errorImg" class="setting-img" @click="showImg(userInfo.cardImg)">
  12. <do-upload @onFinish="setCardImg" placeholder="身份证正面"> </do-upload>
  13. <span style="color: red;text-align: center;margin-top: 10px;">必须本人身份证</span>
  14. </div>
  15. </el-col>
  16. <el-col :span="8">
  17. <el-form ref="elForm" :inline="false" style="width: 500px;margin: 0 auto;" label-width='160px' label-position="center">
  18. <el-form-item label="详细地址" class="mt30" prop="address">
  19. <el-input placeholder="详细地址" v-model="userInfo.address " class="pass-input">
  20. </el-input>
  21. </el-form-item>
  22. <el-form-item label="邮政编码" class="mt30" prop="postalCode">
  23. <el-input placeholder="邮政编码" v-model="userInfo.postalCode " class="pass-input">
  24. </el-input>
  25. </el-form-item>
  26. <el-form-item label="工作年限" class="mt30" prop="years">
  27. <el-input placeholder="工作年限" v-model="userInfo.years " class="pass-input">
  28. </el-input>
  29. </el-form-item>
  30. <el-form-item label="工作单位" class="mt30" prop="company">
  31. <el-input placeholder="工作单位" v-model="userInfo.company " class="pass-input">
  32. </el-input>
  33. </el-form-item>
  34. <el-form-item label="最高学历" class="mt30" prop="oldPass">
  35. <el-input placeholder="最高学历" v-model="userInfo.education " class="pass-input">
  36. </el-input>
  37. </el-form-item>
  38. <el-form-item label="" label-width='0' class="mt30" prop="rePass">
  39. <el-button type="primary" @click="saveMoreInfo()">
  40. 确认修改
  41. </el-button>
  42. <el-button type="warning" @click="passwdDialog=true">修改密码</el-button>
  43. <el-button type="danger" @click="openPhoneDialog()">修改手机</el-button>
  44. </el-form-item>
  45. </el-form>
  46. </el-col>
  47. </el-row>
  48. <el-dialog :visible.sync="passwdDialog" title="修改密码" center :close-on-click-modal="false"
  49. :modal-append-to-body="false" :append-to-body="true" :show-close="false">
  50. <el-form ref="passForm" :inline="false" :model="passForm" :rules="passRules" class="mt50">
  51. <el-form-item label="输入旧密码" label-width='150px' class="mt30" prop="oldPass">
  52. <el-input placeholder="输入旧密码" v-model="passForm.oldPass " class="pass-input" type="password" show-password
  53. auto-complete="new-password">
  54. </el-input>
  55. </el-form-item>
  56. <el-form-item label="输入新密码" label-width='150px' class="mt30" prop="newPass">
  57. <el-input placeholder="输入新密码" v-model="passForm.newPass" class="pass-input" type="password" show-password
  58. auto-complete="new-password">
  59. </el-input>
  60. </el-form-item>
  61. <el-form-item label="确认新密码" label-width='150px' class="mt30" prop="rePass">
  62. <el-input placeholder="确认新密码" v-model="passForm.rePass" class="pass-input" type="password" show-password
  63. auto-complete="new-password">
  64. </el-input>
  65. </el-form-item>
  66. <el-form-item label="" label-width='150px' class="mt30" prop="rePass">
  67. <el-button type="primary" @click="passwdDialog=false">
  68. 取消修改
  69. </el-button>
  70. <el-button type="warning" @click="doSavePassword()">
  71. 确认修改
  72. </el-button>
  73. </el-form-item>
  74. </el-form>
  75. </el-dialog>
  76. <el-dialog :visible.sync="phoneDialog" title="修改手机" center :close-on-click-modal="false"
  77. :modal-append-to-body="false" :append-to-body="true" :show-close="false">
  78. <el-form ref="phoneForm" :inline="false" :model="phoneForm" :rules="phoneRules" class="mt50">
  79. <el-form-item label="用户身份证" label-width='150px' class="mt30" prop="cardId">
  80. <el-input placeholder="输入用户身份证" v-model="phoneForm.cardId " style="width: 300px;" :maxlength="18" disabled />
  81. </el-form-item>
  82. <el-form-item label="用户的姓名" label-width='150px' class="mt30" prop="nickname">
  83. <el-input placeholder="输入姓名" v-model="phoneForm.nickname " style="width: 300px;" :maxlength="11">
  84. </el-input>
  85. </el-form-item>
  86. <el-form-item label="输入新手机" label-width='150px' class="mt30" prop="phone">
  87. <el-input placeholder="输入新手机" v-model="phoneForm.phone " style="width: 300px;" :maxlength="11"
  88. show-word-limit>
  89. </el-input>
  90. </el-form-item>
  91. <el-form-item label="短信检验码" label-width='150px' class="mt30" prop="code">
  92. <el-input placeholder="输入短信检验码" v-model="phoneForm.code" style="width: 180px;" :maxlength="6"
  93. show-word-limit>
  94. </el-input>
  95. <el-button style="width: 120px;" type="info" v-if="phoneForm.phone.length!=11" disabled>获取检验码</el-button>
  96. <el-button style="width: 120px;" type="primary" v-else-if="!count" @click="getCode()">获取检验码</el-button>
  97. <el-button style="width: 120px;" type="info" disabled v-else>剩余时间{{count}} s</el-button>
  98. </el-form-item>
  99. <el-form-item label="" label-width='150px' class="mt30" prop="code">
  100. <span style="color: red;">注意:必须本人实名认证</span>
  101. </el-form-item>
  102. <el-form-item label="" label-width='150px' class="mt30" prop="rePass">
  103. <el-button type="primary" @click="phoneDialog=false">
  104. 取消修改
  105. </el-button>
  106. <el-button type="warning" @click="doSavePhone()">
  107. 确认修改
  108. </el-button>
  109. </el-form-item>
  110. </el-form>
  111. </el-dialog>
  112. </div>
  113. <el-dialog append-to-body close-on-click-modal :visible.sync="visible" :width="width">
  114. <img :src="imgUrl" @load="onLoad" alt="" />
  115. </el-dialog>
  116. </div>
  117. </div>
  118. </template>
  119. <script>
  120. import {
  121. httpServer
  122. } from "@/components/httpServer/httpServer.js";
  123. import UploadImage from "@/components/upload/index.vue";
  124. import ImgView from '@/components/upload/imgView.vue';
  125. import DoUpload from '@/components/upload/index.vue'
  126. import rules from "@/utils/rules.js";
  127. import {
  128. mapGetters,
  129. mapActions
  130. } from "vuex";
  131. export default {
  132. data() {
  133. var validatePass2 = (rule, value, callback) => {
  134. if (value === "") {
  135. callback(new Error("请再次输入密码"));
  136. } else if (value !== this.passForm.newPass) {
  137. callback(new Error("两次输入密码不一致!"));
  138. } else {
  139. callback();
  140. }
  141. };
  142. return {
  143. show: 1,
  144. width: "",
  145. visible: false,
  146. timer: false,
  147. count: 0,
  148. imgUrl: '',
  149. passForm: {
  150. oldPass: '',
  151. newPass: '',
  152. rePass: '',
  153. },
  154. passwdDialog: false,
  155. phoneDialog: false,
  156. passRules: {
  157. oldPass: rules.defaultFun("请输入密码"),
  158. newPass: rules.passwordItem,
  159. rePass: [{
  160. required: true,
  161. validator: validatePass2,
  162. trigger: "blur"
  163. }, ],
  164. },
  165. phoneForm: {
  166. cardId:'',
  167. nickname:'',
  168. phone: '',
  169. code: ''
  170. },
  171. phoneRules: {
  172. phone: rules.defaultFun("请输入新手机"),
  173. code: rules.defaultFun("请输入短信校验码")
  174. },
  175. errorImg: 'this.src="' + require('../../../assets/images/no-data_hash5abcd2ef62.png') + '"'
  176. }
  177. },
  178. computed: {
  179. ...mapGetters("user", ["userInfo"])
  180. },
  181. components: {
  182. DoUpload,
  183. UploadImage,
  184. ImgView
  185. },
  186. methods: {
  187. ...mapActions("user", ["saveBaseInfo"]),
  188. isPhone() {
  189. let phone = this.userInfo.phone;
  190. return !phone || /^1[0-9]{10}$/.test(phone)
  191. },
  192. checkPhone() {
  193. let phone = this.phoneForm.phone;
  194. if (!/^1[3456789]\d{9}$/.test(phone)) {
  195. this.$message.error("请填写正确的手机号");
  196. return false;
  197. }
  198. return true
  199. },
  200. showImg(url) {
  201. this.imgUrl = url;
  202. this.visible = true;
  203. },
  204. setHeadImg(imgUrl) {
  205. console.log('setHeadImg', imgUrl)
  206. this.userInfo.headImg = imgUrl;
  207. },
  208. setCardImg(url) {
  209. httpServer("User.addCardImg", {
  210. url
  211. }).then(res => {
  212. if (res.code == 200) {
  213. this.userInfo.cardImg = res.url;
  214. this.userInfo.nickname = res.nickname
  215. this.userInfo.address = res.address;
  216. this.saveBaseInfo(this.userInfo)
  217. }
  218. })
  219. },
  220. setCardBackImg(url) {
  221. httpServer("User.addCardBackImg", {
  222. url
  223. }).then(res => {
  224. if (res.code == 200) {
  225. this.userInfo.cardBackImg = url;
  226. this.saveBaseInfo(this.userInfo)
  227. }
  228. })
  229. },
  230. setGraduateImg(url) {
  231. httpServer("User.addGraduateImg", {
  232. url
  233. }).then(res => {
  234. if (res.code == 200) {
  235. this.userInfo.graduateImg = url;
  236. this.saveBaseInfo(this.userInfo);
  237. }
  238. })
  239. },
  240. identify() {
  241. httpServer("User.identify", {}).then(res => {
  242. if (res.code == 200) {
  243. this.userInfo.identify = 1;
  244. this.saveBaseInfo(this.userInfo)
  245. this.$message.success("实名认证成功")
  246. }
  247. })
  248. },
  249. doSaveBaseInfo() {
  250. let param = {
  251. headImg: this.userInfo.headImg,
  252. gender: this.userInfo.gender,
  253. }
  254. httpServer("User.saveBaseInfo", param).then(res => {
  255. if (res.code == 200) {
  256. this.$message.success("保存成功")
  257. }
  258. })
  259. },
  260. openPhoneDialog(){
  261. this.phoneForm.phone = ''
  262. this.phoneForm.code = ''
  263. this.phoneForm.cardId = this.userInfo.cardId
  264. this.phoneForm.nickname = this.userInfo.nickname
  265. this.phoneDialog = true
  266. },
  267. doSavePhone() {
  268. let {
  269. phone,
  270. code
  271. } = this.phoneForm;
  272. this.$refs["phoneForm"].validate((valid) => {
  273. if (!valid) return;
  274. let param = {
  275. phone: phone,
  276. code: code
  277. }
  278. httpServer("User.ChangePhone", param).then(res => {
  279. if (res.code == 200) {
  280. this.userInfo.phone = phone;
  281. this.phoneDialog = false
  282. this.$message.success("修改手机成功");
  283. this.saveBaseInfo(this.userInfo);
  284. }
  285. })
  286. })
  287. },
  288. getCode() {
  289. if (!this.checkPhone()) return;
  290. let phone = this.phoneForm.phone
  291. this.startTimer()
  292. let type = "changePhone"
  293. httpServer("Auth.getCode", {
  294. phone,
  295. type
  296. }).then(res => {
  297. if (res.code == 200) {
  298. this.$message.successMsg("发送成功", 1)
  299. this.startTimer()
  300. }
  301. })
  302. },
  303. startTimer() {
  304. const TIME_COUNT = 60; //更改倒计时时间
  305. if (this.timer) clearInterval(this.timer);
  306. this.count = TIME_COUNT;
  307. this.timer = setInterval(() => {
  308. if (this.count > 0) {
  309. this.count--;
  310. } else {
  311. clearInterval(this.timer); // 清除定时器
  312. this.timer = null;
  313. this.count = 0;
  314. }
  315. }, 1000)
  316. },
  317. doSavePassword() {
  318. let {
  319. oldPass,
  320. newPass
  321. } = this.passForm;
  322. console.log({
  323. oldPass,
  324. newPass
  325. })
  326. this.$refs["passForm"].validate((valid) => {
  327. console.log(" valid")
  328. if (!valid) return;
  329. let param = {
  330. oldPass: this.$md5(oldPass),
  331. newPass: this.$md5(newPass)
  332. }
  333. httpServer("User.ResetPass", param).then(res => {
  334. if (res.code == 200) {
  335. this.passForm = {
  336. oldPass: '',
  337. newPass: '',
  338. rePass: ''
  339. };
  340. this.passwdDialog = false
  341. this.$message.success("密码修改成功")
  342. }
  343. })
  344. })
  345. },
  346. onLoad(e) {
  347. const img = e.target;
  348. let width = 0;
  349. if (img.fileSize > 0 || (img.width > 1 && img.height > 1)) {
  350. width = img.width + 40;
  351. }
  352. this.width = width + "px";
  353. console.log(this.width)
  354. },
  355. saveMoreInfo() {
  356. let param = {
  357. education: this.userInfo.education,
  358. address: this.userInfo.address,
  359. years: +this.userInfo.years,
  360. company: this.userInfo.company,
  361. address: this.userInfo.address,
  362. education: this.userInfo.education,
  363. postalCode: this.userInfo.postalCode,
  364. }
  365. httpServer("User.saveMoreInfo", param).then(res => {
  366. if (res.code == 200) {
  367. this.$message.success("编辑成功")
  368. }
  369. })
  370. }
  371. }
  372. }
  373. </script>
  374. <style>
  375. @import url("./index.css");
  376. @import url("../../../assets/css/m-account.css");
  377. .pass-input {
  378. width: 296px;
  379. }
  380. .confirm {
  381. width: 296px;
  382. }
  383. </style>