index.vue 14 KB

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