index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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) {
  94. res.gender_name
  95. that.$set(that, `user`, res);
  96. }
  97. } catch (e) {
  98. uni.showToast({
  99. title: err.errmsg,
  100. icon: 'error',
  101. duration: 2000
  102. });
  103. }
  104. },
  105. // 查询
  106. async search() {
  107. const that = this;
  108. let data = that.genderList.find(i => i.value == that.user.gender);
  109. if (data) that.$set(that, `gender_name`, data.label)
  110. },
  111. // 图片上传
  112. uplSuc(e) {
  113. const that = this;
  114. that.$set(that.user, `logo`, [e.data]);
  115. },
  116. // 图片删除
  117. uplDel(e) {
  118. const that = this;
  119. that.$set(that.user, `logo`, [])
  120. },
  121. // 性别选择
  122. genderChange(e) {
  123. const that = this;
  124. let data = that.genderList.find(i => i.value == e.detail.value);
  125. if (data) {
  126. that.$set(that.user, `gender`, data.value)
  127. that.$set(that, `gender_name`, data.label)
  128. }
  129. },
  130. // 生日选择
  131. bindDateChange: function(e) {
  132. const that = this;
  133. that.$set(that.user, `birthday`, e.detail.value)
  134. },
  135. // 城市选择
  136. cityChange(e) {
  137. const that = this;
  138. let data = that.cityList[e.detail.value];
  139. that.$set(that.user, `city`, data.name)
  140. },
  141. // 保存
  142. async onSubmit() {
  143. const that = this;
  144. const form = that.user;
  145. delete form.gender_name
  146. const res = await that.$api(`/user/${form._id}`, 'POST', form);
  147. if (res.errcode == '0') {
  148. uni.showToast({
  149. title: '维护信息成功',
  150. icon: 'none'
  151. })
  152. let arr = await that.$api(`/user/${form._id}`, 'GET', {})
  153. uni.setStorage({
  154. key: 'token',
  155. data: arr.data,
  156. success: function(res) {
  157. uni.navigateBack({
  158. delta: 1
  159. })
  160. },
  161. fail: function(err) {
  162. console.log(err);
  163. }
  164. })
  165. } else {
  166. uni.showToast({
  167. title: res.errmsg,
  168. icon: 'none'
  169. })
  170. }
  171. },
  172. async searchOther() {
  173. const that = this;
  174. let res;
  175. // 查询类型
  176. res = await that.$api(`/dictData`, 'GET', {
  177. type: 'gender',
  178. is_use: '0',
  179. })
  180. if (res.errcode == '0') that.$set(that, `genderList`, res.data);
  181. let config = that.$config;
  182. that.$set(that, `cityList`, config.china);
  183. }
  184. }
  185. }
  186. </script>
  187. <style lang="scss" scoped>
  188. .main {
  189. .one {
  190. padding: 2vw;
  191. text-align: center;
  192. }
  193. .two {
  194. padding: 2vw;
  195. .two_1 {
  196. display: flex;
  197. justify-content: space-between;
  198. padding: 4vw;
  199. border-bottom: 1px solid var(--f9Color);
  200. font-size: var(--font14Size);
  201. color: var(--f69Color);
  202. .right {
  203. display: flex;
  204. align-items: center;
  205. input {
  206. text-align: right;
  207. padding: 0 1vw;
  208. }
  209. }
  210. }
  211. }
  212. .thr {
  213. text-align: center;
  214. .button {
  215. margin: 2vw 0 0 0;
  216. background-color: var(--f3CColor);
  217. color: var(--mainColor);
  218. font-size: var(--font14Size);
  219. }
  220. }
  221. }
  222. </style>