index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <view class="main">
  3. <view class="one">
  4. <upload class='upload' :list="user.logo" name="logo" :count="1" @uplSuc="uplSuc" @uplDel="uplDel">
  5. </upload>
  6. </view>
  7. <view class="two">
  8. <view class="two_1">
  9. <view class="left">真实姓名</view>
  10. <view class="right">
  11. <input v-model="user.name" placeholder="请输入真实姓名" />
  12. <text class="iconfont icon-dayuhao"></text>
  13. </view>
  14. </view>
  15. <view class="two_1">
  16. <view class="left">昵称</view>
  17. <view class="right">
  18. <input v-model="user.nick_name" placeholder="请输入昵称" />
  19. <text class="iconfont icon-dayuhao"></text>
  20. </view>
  21. </view>
  22. <view class="two_1">
  23. <view class="left">性别</view>
  24. <view class="right">
  25. <picker class="picker" mode="selector" :range="genderList" @change="genderChange" range-key="label">
  26. <view>{{gender_name||'请选择性别'}}</view>
  27. </picker>
  28. <text class="iconfont icon-dayuhao"></text>
  29. </view>
  30. </view>
  31. <view class="two_1">
  32. <view class="left">手机号</view>
  33. <view class="right">
  34. <input v-model="user.phone" placeholder="请输入手机号" />
  35. <text class="iconfont icon-dayuhao"></text>
  36. </view>
  37. </view>
  38. <view class="two_1">
  39. <view class="left">生日</view>
  40. <view class="right">
  41. <picker mode="date" :value="user.birthday" :start="startDate" :end="endDate"
  42. @change="bindDateChange">
  43. <view>{{user.birthday||'请选择生日'}}</view>
  44. </picker>
  45. <text class="iconfont icon-dayuhao"></text>
  46. </view>
  47. </view>
  48. <view class="two_1">
  49. <view class="left">所在城市</view>
  50. <view class="right">
  51. <picker class="picker" :value="user.city" mode="selector" :range="cityList" @change="cityChange"
  52. range-key="name">
  53. <view>{{user.city||'请选择所在城市'}}</view>
  54. </picker>
  55. <text class="iconfont icon-dayuhao"></text>
  56. </view>
  57. </view>
  58. </view>
  59. <view class="thr">
  60. <button class="button" type="primary" size="mini" @click="onSubmit()">保存</button>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. import upload from '../../components/upload/index.vue';
  66. export default {
  67. components: {
  68. upload
  69. },
  70. data() {
  71. return {
  72. user: {},
  73. gender_name: '',
  74. // 字典表
  75. genderList: [],
  76. cityList: [],
  77. }
  78. },
  79. onLoad: async function() {
  80. const that = this;
  81. await that.searchOther();
  82. await that.search();
  83. },
  84. onShow: async function(e) {
  85. const that = this;
  86. that.searchToken();
  87. },
  88. methods: {
  89. searchToken() {
  90. const that = this;
  91. try {
  92. const res = uni.getStorageSync('token');
  93. if (res) that.$set(that, `user`, res);
  94. } catch (e) {
  95. uni.showToast({
  96. title: err.errmsg,
  97. icon: 'error',
  98. duration: 2000
  99. });
  100. }
  101. },
  102. // 查询
  103. async search() {
  104. const that = this;
  105. let data = that.genderList.find(i => i.value == that.user.gender);
  106. if (data) that.$set(that, `gender_name`, data.label)
  107. },
  108. // 图片上传
  109. uplSuc(e) {
  110. const that = this;
  111. that.$set(that.user, `logo`, [e.data]);
  112. },
  113. // 图片删除
  114. uplDel(e) {
  115. const that = this;
  116. that.$set(that.user, `logo`, [])
  117. },
  118. // 性别选择
  119. genderChange(e) {
  120. const that = this;
  121. let data = that.genderList.find(i => i.value == e.detail.value);
  122. if (data) {
  123. that.$set(that.user, `gender`, data.value)
  124. that.$set(that, `gender_name`, data.label)
  125. }
  126. },
  127. // 生日选择
  128. bindDateChange: function(e) {
  129. const that = this;
  130. that.$set(that.user, `birthday`, e.detail.value)
  131. },
  132. // 城市选择
  133. cityChange(e) {
  134. const that = this;
  135. let data = that.cityList[e.detail.value];
  136. that.$set(that.user, `city`, data.name)
  137. },
  138. // 保存
  139. async onSubmit() {
  140. const that = this;
  141. const form = that.user;
  142. delete form.gender_name
  143. const res = await that.$api(`/user/${form._id}`, 'POST', form);
  144. if (res.errcode == '0') {
  145. uni.showToast({
  146. title: '维护信息成功',
  147. icon: 'none'
  148. })
  149. let arr = await that.$api(`/user/${form._id}`, 'GET', {})
  150. uni.setStorage({
  151. key: 'token',
  152. data: arr.data,
  153. success: function(res) {
  154. uni.navigateBack({
  155. delta: 1
  156. })
  157. },
  158. fail: function(err) {
  159. console.log(err);
  160. }
  161. })
  162. } else {
  163. uni.showToast({
  164. title: res.errmsg,
  165. icon: 'none'
  166. })
  167. }
  168. },
  169. async searchOther() {
  170. const that = this;
  171. let res;
  172. // 查询类型
  173. res = await that.$api(`/dictData`, 'GET', {
  174. type: 'gender',
  175. is_use: '0',
  176. })
  177. if (res.errcode == '0') that.$set(that, `genderList`, res.data);
  178. let config = that.$config;
  179. that.$set(that, `cityList`, config.china);
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="scss" scoped>
  185. .main {
  186. .one {
  187. display: flex;
  188. justify-content: center;
  189. padding: 2vw;
  190. }
  191. .two {
  192. padding: 2vw;
  193. .two_1 {
  194. display: flex;
  195. justify-content: space-between;
  196. padding: 4vw;
  197. border-bottom: 1px solid var(--f9Color);
  198. font-size: var(--font14Size);
  199. color: var(--f69Color);
  200. .right {
  201. display: flex;
  202. align-items: center;
  203. input {
  204. text-align: right;
  205. padding: 0 1vw;
  206. }
  207. }
  208. }
  209. }
  210. .thr {
  211. text-align: center;
  212. .button {
  213. margin: 2vw 0 0 0;
  214. background-color: var(--f3CColor);
  215. color: var(--mainColor);
  216. font-size: var(--font14Size);
  217. }
  218. }
  219. }
  220. </style>