userInfo.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div class="page-box">
  3. <el-card class="title">
  4. 用户详情-<span v-if="detail && detail.id">{{ detail.id }}</span>
  5. </el-card>
  6. <br />
  7. <el-card class="el-input" v-if="detail && detail.id">
  8. <el-form ref="detail" :model="detail" label-width="80px">
  9. <el-form-item label="邮箱">
  10. <div>{{ detail.email }}</div>
  11. </el-form-item>
  12. <el-form-item label="用户昵称">
  13. <el-input type="text" v-model="detail.name"></el-input>
  14. </el-form-item>
  15. <el-form-item label="是否患病">
  16. <el-switch v-model="detail.isSick"></el-switch>
  17. <div v-if="detail.isSick">
  18. <el-tag
  19. v-for="tag in detail.sick"
  20. :key="tag"
  21. closable
  22. style="margin-right: 5px; margin-bottom: 5px"
  23. @close="handleTagClose(tag)"
  24. >
  25. {{ tag }}
  26. </el-tag>
  27. <span v-if="inputVisible">
  28. <el-input
  29. class="input-new-tag"
  30. v-model="inputValue"
  31. ref="saveTagInput"
  32. size="small"
  33. @keyup.enter.native="handleInputConfirm"
  34. @blur="handleInputConfirm"
  35. />
  36. <el-button @click="inputVisible = false">取消</el-button>
  37. </span>
  38. <el-button
  39. v-else
  40. class="button-new-tag"
  41. size="small"
  42. @click="showInput"
  43. >+ 添加</el-button
  44. >
  45. </div>
  46. </el-form-item>
  47. <el-form-item label="性别">
  48. <el-select v-model="detail.sex" placeholder="请选择">
  49. <el-option
  50. v-for="item in sexOptions"
  51. :key="item.value"
  52. :label="item.label"
  53. :value="item.value"
  54. >
  55. </el-option>
  56. </el-select>
  57. </el-form-item>
  58. <el-form-item label="年龄">
  59. <el-input v-model="detail.age" placeholder="请输入内容"></el-input>
  60. </el-form-item>
  61. <el-form-item>
  62. <el-button type="primary" @click="onSubmit">保存</el-button>
  63. <el-button @click="toHome">取消</el-button>
  64. </el-form-item>
  65. </el-form>
  66. <div class="del-user"><span @click="deleteUser">退出登陆</span></div>
  67. </el-card>
  68. </div>
  69. </template>
  70. <script>
  71. import { userInfo, userUpdate } from "@/api";
  72. export default {
  73. data() {
  74. return {
  75. detail: {},
  76. sexOptions: [
  77. {
  78. value: "woman",
  79. label: "女",
  80. },
  81. {
  82. value: "man",
  83. label: "男",
  84. },
  85. {
  86. value: "other",
  87. label: "保密",
  88. },
  89. ],
  90. inputVisible: false,
  91. inputValue: "",
  92. };
  93. },
  94. mounted() {
  95. this.pageInit();
  96. },
  97. methods: {
  98. async onSubmit() {
  99. const params = {
  100. ...this.detail,
  101. };
  102. // if (this.inputValue) {
  103. // params.isSick = true;
  104. // }
  105. if (!this.detail.isSick) {
  106. this.detail.sick = [];
  107. }
  108. console.log(110, this.detail.isSick);
  109. const res = await userUpdate(params);
  110. if (res.data) {
  111. window.location.reload();
  112. }
  113. },
  114. async pageInit() {
  115. const token = localStorage.getItem("token");
  116. const res = await userInfo({ token });
  117. this.detail = res.data;
  118. console.log(117, this.detail);
  119. if (this.detail.isSick && this.detail.isSick === true) {
  120. // this.inputValue = this.detail.sick;
  121. }
  122. this.$set(this.detail, "isSick", this.detail.isSick === true);
  123. },
  124. toHome(query) {
  125. console.log(101);
  126. this.$router.replace({
  127. name: "home",
  128. query,
  129. });
  130. },
  131. deleteUser() {
  132. this.$alert("退出前用户之后无法使用订单信息!", "提示", {
  133. confirmButtonText: "确定",
  134. callback: (action) => {
  135. this.$message({
  136. type: "info",
  137. message: `删除成功!`,
  138. });
  139. localStorage.clear();
  140. this.toHome({
  141. type: "reload",
  142. });
  143. },
  144. });
  145. },
  146. handleTagClose(tag) {
  147. console.log(tag);
  148. const sick = this.detail.sick.filter((name) => name !== tag);
  149. this.detail.sick = this.detail = {
  150. ...this.detail,
  151. sick: [...sick],
  152. };
  153. },
  154. showInput() {
  155. this.inputVisible = true;
  156. const detail = {
  157. ...this.detail,
  158. // sick: [],
  159. };
  160. if (detail?.sick) {
  161. detail.sick = [];
  162. }
  163. this.detail = { ...detail };
  164. this.$nextTick((_) => {
  165. this.$refs.saveTagInput.$refs.input.focus();
  166. });
  167. },
  168. handleInputConfirm() {
  169. const sick = new Set([...(this.detail?.sick || []), this.inputValue]);
  170. this.detail.sick = this.detail = {
  171. ...this.detail,
  172. sick: [...sick],
  173. };
  174. },
  175. },
  176. };
  177. </script>
  178. <style lang="less" scoped>
  179. .page-box {
  180. padding: 24px;
  181. .title {
  182. }
  183. .del-user {
  184. text-align: right;
  185. span {
  186. background-color: rgba(255, 0, 0, 0.29);
  187. color: red;
  188. padding: 1px 3px;
  189. font-size: 10px;
  190. cursor: pointer;
  191. }
  192. }
  193. .el-tag + .el-tag {
  194. margin-left: 10px;
  195. }
  196. .button-new-tag {
  197. margin-left: 10px;
  198. height: 32px;
  199. line-height: 30px;
  200. padding-top: 0;
  201. padding-bottom: 0;
  202. }
  203. .input-new-tag {
  204. width: 90px;
  205. margin-left: 10px;
  206. vertical-align: bottom;
  207. }
  208. }
  209. </style>