myModify.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <div>
  3. <div class="label">
  4. {{ value.name }}
  5. </div>
  6. <cube-textarea
  7. v-model="value.value"
  8. :placeholder="'请输入你的' + value.name"
  9. ></cube-textarea>
  10. <div class="chehui">
  11. <div class="btn" @click="sub()">保&nbsp;存</div>
  12. </div>
  13. <promp-ting
  14. :conents="promptingConent"
  15. :status="promptingStatus"
  16. ></promp-ting>
  17. </div>
  18. </template>
  19. <script>
  20. import PrompTing from "./../views/prompting.vue";
  21. export default {
  22. data() {
  23. return {
  24. loginUser: JSON.parse(localStorage.getItem("loginUser")),
  25. data: "",
  26. value: { type: "", value: "" },
  27. promptingConent: "",
  28. promptingStatus: ""
  29. };
  30. },
  31. methods: {
  32. getAddData() {
  33. switch (this.$route.params.data) {
  34. case "houseNumber":
  35. this.value = {
  36. type: "houseNumber",
  37. name: "详细地址",
  38. value: this.loginUser.houseNumber
  39. };
  40. break;
  41. case "phone":
  42. this.value = {
  43. type: "phone",
  44. name: "联系电话",
  45. value: this.loginUser.phone
  46. };
  47. break;
  48. }
  49. },
  50. sub() {
  51. if (!this.value.value && this.value.type == "phone") {
  52. this.$createDialog({
  53. type: "alert",
  54. title: "保存失败",
  55. content: this.value.name + "不能为空",
  56. icon: "cubeic-wrong"
  57. }).show();
  58. } else {
  59. var that = this;
  60. let url = "",
  61. postData = {};
  62. switch (this.value.type) {
  63. case "houseNumber":
  64. url = "service/user/updHouseNum";
  65. postData = {
  66. reqId: that.loginUser.id,
  67. houseNum: that.value.value
  68. };
  69. break;
  70. case "phone":
  71. url = "service/user/updPhone";
  72. postData = {
  73. reqId: that.loginUser.id,
  74. phone: that.value.value
  75. };
  76. break;
  77. }
  78. this.$http.post(url, postData).then(function(res) {
  79. if (res.status == 200) {
  80. that.promptingConent = "恭喜您,修改" + that.value.name + "成功!";
  81. that.promptingStatus = true;
  82. $("#fade").fadeIn();
  83. setTimeout(function() {
  84. $("#fade").fadeOut();
  85. }, 2000);
  86. that.loginUser[that.value.type] = that.value.value;
  87. var loginUserStr = JSON.stringify(that.loginUser);
  88. localStorage.setItem("loginUser", loginUserStr);
  89. that.dialog = that
  90. .$createDialog({
  91. type: "alert",
  92. title: "修改成功",
  93. content: "点击确定返回我的信息",
  94. icon: "cubeic-right",
  95. onConfirm: (e, promptValue) => {
  96. // that.$router.push({ path: "/main/my" });
  97. that.$router.go(-1);
  98. }
  99. })
  100. .show();
  101. } else {
  102. that.promptingConent = "修改失败,请稍后再试!";
  103. that.promptingStatus = false;
  104. $("#fade").fadeIn();
  105. setTimeout(function() {
  106. $("#fade").fadeOut();
  107. }, 2000);
  108. }
  109. });
  110. }
  111. }
  112. },
  113. created() {
  114. this.getAddData();
  115. },
  116. mounted() {},
  117. components: {
  118. PrompTing
  119. }
  120. };
  121. </script>
  122. <style scoped>
  123. .label {
  124. background-color: rgb(238, 238, 238);
  125. height: 0.6rem;
  126. line-height: 0.6rem;
  127. padding-left: 0.24rem;
  128. font-size: 0.24rem;
  129. color: #666666;
  130. }
  131. .chehui {
  132. height: 1.3rem;
  133. width: 100%;
  134. border-top: 0.01rem rgb(223, 222, 222) solid;
  135. background-color: rgb(248, 248, 248);
  136. position: fixed;
  137. left: 50%;
  138. bottom: 0;
  139. transform: translateX(-50%);
  140. display: flex;
  141. align-items: center;
  142. justify-content: center;
  143. }
  144. .chehui .btn {
  145. width: 90%;
  146. height: 1rem;
  147. background-color: #005395;
  148. border-radius: 10px;
  149. line-height: 1rem;
  150. color: white;
  151. font-size: 0.36rem;
  152. text-align: center;
  153. }
  154. </style>