useredit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <template>
  2. <view class="user-page">
  3. <u-navbar
  4. title="编辑资料"
  5. :safeAreaInsetTop="true"
  6. :fixed="true"
  7. :placeholder="true"
  8. height="50px"
  9. bgColor="transparent"
  10. titleStyle="fw600 fs-18"
  11. leftIconColor="#303133"
  12. @leftClick="goBack"
  13. >
  14. <view class="u-nav-slot" slot="left">
  15. <u-icon name="arrow-left" size="20" color="#303133"></u-icon>
  16. </view>
  17. </u-navbar>
  18. <view class="user-page-content">
  19. <view class="edit-card">
  20. <view class="edit-row">
  21. <view class="edit-icon-box">
  22. <u-icon name="account-fill" size="14" color="#ffffff"></u-icon>
  23. </view>
  24. <text class="edit-label">姓名</text>
  25. <input
  26. class="edit-input"
  27. placeholder="请输入姓名"
  28. placeholder-style="color: #b9c6da;"
  29. name="input"
  30. v-model="myFormData.realname"
  31. />
  32. </view>
  33. <view class="edit-divider"></view>
  34. <view class="edit-row">
  35. <view class="edit-icon-box">
  36. <u-icon name="account" size="14" color="#ffffff"></u-icon>
  37. </view>
  38. <text class="edit-label">用户名</text>
  39. <input
  40. class="edit-input edit-input-disabled"
  41. placeholder="用户名"
  42. placeholder-style="color: #b9c6da;"
  43. name="input"
  44. v-model="myFormData.username"
  45. disabled
  46. />
  47. </view>
  48. <view class="edit-divider"></view>
  49. <view class="edit-row">
  50. <view class="edit-icon-box">
  51. <u-icon name="photo-fill" size="14" color="#ffffff"></u-icon>
  52. </view>
  53. <text class="edit-label">头像</text>
  54. <view class="avatar-area">
  55. <view
  56. class="avatar-item"
  57. v-for="(item, index) in imgList"
  58. :key="index"
  59. @tap="ViewImage"
  60. :data-url="imgList[index]"
  61. >
  62. <image
  63. class="avatar-img"
  64. :src="imgList[index]"
  65. mode="aspectFill"
  66. ></image>
  67. <view class="avatar-del" @tap.stop="DelImg" :data-index="index">
  68. <u-icon name="close" size="10" color="#ffffff"></u-icon>
  69. </view>
  70. </view>
  71. <view
  72. class="avatar-add"
  73. @tap="ChooseImage"
  74. v-if="imgList.length < 1"
  75. >
  76. <u-icon name="camera-fill" size="18" color="#0065f8"></u-icon>
  77. </view>
  78. </view>
  79. </view>
  80. <view class="edit-divider"></view>
  81. <view class="edit-row">
  82. <view class="edit-icon-box">
  83. <u-icon
  84. :name="switchC ? 'man' : 'woman'"
  85. size="14"
  86. color="#ffffff"
  87. ></u-icon>
  88. </view>
  89. <text class="edit-label">性别</text>
  90. <view class="edit-control">
  91. <view
  92. class="sex-btn"
  93. :class="switchC ? 'action-btn-primary' : 'action-btn-outline'"
  94. @click="SwitchC(true)"
  95. >
  96. <text class="action-btn-text">男</text>
  97. </view>
  98. <view
  99. class="sex-btn"
  100. :class="!switchC ? 'action-btn-primary' : 'action-btn-outline'"
  101. @click="SwitchC(false)"
  102. >
  103. <text class="action-btn-text">女</text>
  104. </view>
  105. </view>
  106. </view>
  107. <view class="edit-divider"></view>
  108. <view class="edit-row">
  109. <view class="edit-icon-box">
  110. <u-icon name="phone-fill" size="14" color="#ffffff"></u-icon>
  111. </view>
  112. <text class="edit-label">手机号码</text>
  113. <input
  114. class="edit-input"
  115. placeholder="输入手机号码"
  116. placeholder-style="color: #b9c6da;"
  117. name="input"
  118. v-model="myFormData.phone"
  119. />
  120. <view class="edit-capsule">
  121. <text class="edit-capsule-code">+86</text>
  122. <text class="edit-capsule-region">中国大陆</text>
  123. </view>
  124. </view>
  125. <view class="edit-divider"></view>
  126. <view class="edit-row">
  127. <view class="edit-icon-box">
  128. <u-icon name="email-fill" size="14" color="#ffffff"></u-icon>
  129. </view>
  130. <text class="edit-label">邮箱</text>
  131. <input
  132. class="edit-input"
  133. placeholder="输入邮箱"
  134. placeholder-style="color: #b9c6da;"
  135. name="input"
  136. v-model="myFormData.email"
  137. />
  138. </view>
  139. </view>
  140. <view class="submit-area">
  141. <view
  142. class="action-btn action-btn-primary submit-btn"
  143. @click="onSubmit"
  144. >
  145. <text class="action-btn-text">提交</text>
  146. </view>
  147. </view>
  148. </view>
  149. </view>
  150. </template>
  151. <script>
  152. export default {
  153. data() {
  154. return {
  155. index: -1,
  156. switchC: true,
  157. imgList: [],
  158. uploadUrl: "/sys/common/upload",
  159. myFormData: {
  160. avatar: "",
  161. realname: "",
  162. username: "",
  163. sex: 1,
  164. birthday: "",
  165. orgCode: "",
  166. workNo: "",
  167. phone: "",
  168. email: "",
  169. id: "",
  170. },
  171. };
  172. },
  173. onLoad: function (option) {
  174. console.log("this.$Route.query", this.$Route.query);
  175. let query = this.$Route.query;
  176. if (query) {
  177. this.myFormData = query;
  178. if (this.myFormData.sex == "女") {
  179. this.switchC = false;
  180. } else if (this.myFormData.sex == "男") {
  181. this.switchC = true;
  182. }
  183. if (this.myFormData.avatar) {
  184. this.imgList = [this.myFormData.avatar];
  185. }
  186. if (!this.myFormData.birthday) {
  187. this.myFormData.birthday = "无";
  188. }
  189. if (this.myFormData.identity == "普通成员") {
  190. this.myFormData.identity = 1;
  191. } else if (this.myFormData.identity == "上级") {
  192. this.myFormData.identity = 2;
  193. }
  194. if (this.myFormData.status == "正常") {
  195. this.myFormData.status = 1;
  196. } else if (this.myFormData.status == "冻结") {
  197. this.myFormData.status = 2;
  198. }
  199. this.Avatar = this.myFormData.avatar;
  200. Object.keys(this.myFormData).map((key) => {
  201. if (this.myFormData[key] == "无") {
  202. this.myFormData[key] = "";
  203. }
  204. });
  205. console.log("this.myFormData", this.myFormData);
  206. }
  207. },
  208. methods: {
  209. onSubmit() {
  210. let myForm = this.myFormData;
  211. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  212. let checkEmail =
  213. /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
  214. console.log("myForm", myForm);
  215. if (!myForm.phone || myForm.phone.length == 0) {
  216. this.$tip.alert("请输入手机号");
  217. return false;
  218. }
  219. if (!checkPhone.test(myForm.phone)) {
  220. this.$tip.alert("请输入正确的手机号");
  221. return false;
  222. }
  223. if (!checkEmail.test(myForm.email)) {
  224. this.$tip.alert("请输入正确的邮箱地址");
  225. return false;
  226. }
  227. this.myFormData.id = this.$store.getters.userid;
  228. if (this.switchC) {
  229. this.myFormData.sex = 1;
  230. } else {
  231. this.myFormData.sex = 2;
  232. }
  233. console.log("myform", this.myFormData);
  234. this.$tip.loading();
  235. this.$http
  236. .put("/sys/user/appEdit", this.myFormData)
  237. .then((res) => {
  238. console.log(res);
  239. this.$tip.loaded();
  240. if (res.data.success) {
  241. this.$tip.toast("提交成功");
  242. this.$Router.replace({ name: "userdetail" });
  243. /* uni.navigateTo({
  244. url: '/pages/user/userdetail'
  245. }) */
  246. }
  247. })
  248. .catch(() => {
  249. this.$tip.loaded();
  250. this.$tip.error("提交失败");
  251. });
  252. },
  253. DateChange(e) {
  254. this.myFormData.birthday = e.detail.value;
  255. },
  256. //左上角返回键:返回上一页
  257. goBack() {
  258. uni.navigateBack({
  259. delta: 1,
  260. });
  261. },
  262. SwitchC(value) {
  263. this.switchC = value;
  264. },
  265. ChooseImage() {
  266. var that = this;
  267. uni.chooseImage({
  268. count: 4, //默认9
  269. sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
  270. sourceType: ["album"], //从相册选择
  271. success: (res) => {
  272. that.$http
  273. .upload(that.$config.apiUrl + that.uploadUrl, {
  274. filePath: res.tempFilePaths[0],
  275. name: "file",
  276. })
  277. .then((res) => {
  278. that.myFormData.avatar = res.data.message;
  279. })
  280. .catch((err) => {
  281. that.$tip.error(err.data.message);
  282. });
  283. this.imgList = res.tempFilePaths;
  284. },
  285. });
  286. },
  287. ViewImage(e) {
  288. uni.previewImage({
  289. urls: this.imgList,
  290. current: e.currentTarget.dataset.url,
  291. });
  292. },
  293. DelImg(e) {
  294. uni.showModal({
  295. title: "召唤师",
  296. content: "确定要删除这段回忆吗?",
  297. cancelText: "再看看",
  298. confirmText: "再见",
  299. success: (res) => {
  300. if (res.confirm) {
  301. this.imgList.splice(e.currentTarget.dataset.index, 1);
  302. }
  303. },
  304. });
  305. },
  306. },
  307. };
  308. </script>
  309. <style lang="scss" scoped>
  310. .user-page {
  311. min-height: 100vh;
  312. background: linear-gradient(180deg, #c8d8f8 0%, #eef4fd 320rpx, #f4f7fd 100%);
  313. }
  314. .user-page-content {
  315. padding-left: 24rpx;
  316. padding-right: 24rpx;
  317. padding-bottom: 40rpx;
  318. box-sizing: border-box;
  319. }
  320. .edit-card {
  321. background: #ffffff;
  322. border: 1rpx solid #e8effc;
  323. border-radius: 16rpx;
  324. padding: 0 24rpx;
  325. box-shadow: 0 4rpx 16rpx rgba(43, 124, 255, 0.08);
  326. }
  327. .edit-row {
  328. display: flex;
  329. flex-direction: row;
  330. align-items: center;
  331. min-height: 112rpx;
  332. padding: 20rpx 0;
  333. }
  334. .edit-divider {
  335. height: 1rpx;
  336. background: #eef0f4;
  337. }
  338. .edit-icon-box {
  339. display: flex;
  340. align-items: center;
  341. justify-content: center;
  342. width: 56rpx;
  343. height: 56rpx;
  344. border-radius: 12rpx;
  345. background: linear-gradient(135deg, #80b4ff, #347df3);
  346. box-sizing: border-box;
  347. flex-shrink: 0;
  348. margin-right: 20rpx;
  349. }
  350. .edit-label {
  351. flex-shrink: 0;
  352. width: 150rpx;
  353. font-size: 24rpx;
  354. color: #000;
  355. line-height: 1.4;
  356. }
  357. .edit-input {
  358. flex: 1;
  359. min-width: 0;
  360. height: 56rpx;
  361. padding: 0 16rpx;
  362. box-sizing: border-box;
  363. font-size: 24rpx;
  364. color: #000;
  365. background: #ffffff;
  366. border: 1rpx solid #2572ff;
  367. border-radius: 8rpx;
  368. }
  369. .edit-input-disabled {
  370. color: #9aa4b2;
  371. background: #f5f7fb;
  372. border-color: #d7e0ee;
  373. }
  374. .edit-control {
  375. flex: 1;
  376. display: flex;
  377. flex-direction: row;
  378. align-items: center;
  379. justify-content: flex-end;
  380. }
  381. .sex-btn {
  382. width: 96rpx;
  383. height: 56rpx;
  384. border-radius: 8rpx;
  385. display: flex;
  386. align-items: center;
  387. justify-content: center;
  388. box-sizing: border-box;
  389. }
  390. .sex-btn + .sex-btn {
  391. margin-left: 12rpx;
  392. }
  393. .edit-capsule {
  394. flex-shrink: 0;
  395. display: flex;
  396. flex-direction: row;
  397. align-items: center;
  398. margin-left: 12rpx;
  399. border: 1rpx solid #0065f8;
  400. border-radius: 8rpx;
  401. overflow: hidden;
  402. }
  403. .edit-capsule-code {
  404. height: 56rpx;
  405. padding: 0 12rpx;
  406. line-height: 56rpx;
  407. font-size: 22rpx;
  408. color: #ffffff;
  409. background: #0065f8;
  410. }
  411. .edit-capsule-region {
  412. height: 56rpx;
  413. padding: 0 12rpx;
  414. line-height: 56rpx;
  415. font-size: 22rpx;
  416. color: #0065f8;
  417. background: #ffffff;
  418. }
  419. .avatar-area {
  420. flex: 1;
  421. display: flex;
  422. flex-direction: row;
  423. align-items: center;
  424. justify-content: flex-end;
  425. }
  426. .avatar-item {
  427. position: relative;
  428. width: 96rpx;
  429. height: 96rpx;
  430. margin-left: 16rpx;
  431. }
  432. .avatar-img {
  433. width: 96rpx;
  434. height: 96rpx;
  435. border-radius: 12rpx;
  436. border: 1rpx solid #e8effc;
  437. }
  438. .avatar-del {
  439. position: absolute;
  440. top: -10rpx;
  441. right: -10rpx;
  442. width: 32rpx;
  443. height: 32rpx;
  444. border-radius: 16rpx;
  445. background: #ff3b30;
  446. display: flex;
  447. align-items: center;
  448. justify-content: center;
  449. }
  450. .avatar-add {
  451. width: 96rpx;
  452. height: 96rpx;
  453. border-radius: 12rpx;
  454. border: 1rpx dashed #2b7cff;
  455. background: rgba(43, 124, 255, 0.06);
  456. display: flex;
  457. align-items: center;
  458. justify-content: center;
  459. }
  460. .submit-area {
  461. margin-top: 32rpx;
  462. }
  463. .action-btn {
  464. display: flex;
  465. align-items: center;
  466. justify-content: center;
  467. box-sizing: border-box;
  468. }
  469. .action-btn-text {
  470. font-size: 24rpx;
  471. font-weight: 500;
  472. line-height: 1;
  473. }
  474. .action-btn-primary {
  475. background: #0065f8;
  476. }
  477. .action-btn-primary .action-btn-text {
  478. color: #ffffff;
  479. }
  480. .action-btn-outline {
  481. background: #ffffff;
  482. border: 1rpx solid #0065f8;
  483. }
  484. .action-btn-outline .action-btn-text {
  485. color: #0065f8;
  486. }
  487. .submit-btn {
  488. height: 84rpx;
  489. border-radius: 12rpx;
  490. }
  491. .submit-btn .action-btn-text {
  492. font-size: 28rpx;
  493. font-weight: 600;
  494. }
  495. </style>