userInfo-change.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class="container">
  3. <view>
  4. <!-- 头部标题和副标题 -->
  5. <view class="header">
  6. <view class="mar-b-16">
  7. <text class="title">请补全个人资料</text>
  8. </view>
  9. </view>
  10. </view>
  11. <!-- 头像与昵称 -->
  12. <view>
  13. <!-- <u-upload :fileList="fileList" @afterRead="afterRead" @delete="deletePic" name="1" :maxCount="1"> -->
  14. <button open-type="chooseAvatar" @chooseavatar="onChooseAvatar" class="avatarButton">
  15. <image class="avatar" :src="user.avatar||'../../static/images/avatar-upload.png'" mode="aspectFill">
  16. </image>
  17. <view class="font28">
  18. 点击授权头像
  19. </view>
  20. </button>
  21. <!-- </u-upload> -->
  22. </view>
  23. <view class=" inputBg ">
  24. <input class="" v-model="user.name" type="nickname" placeholder="请填写名称(建议用真实名字)" />
  25. </view>
  26. <view class=" inputBg ">
  27. <input class="" v-model="user.phone" placeholder="请填写手机号" />
  28. </view>
  29. <view class=" inputBg ">
  30. <view class="flex-items flex-sp-between" @click="change">
  31. <view>
  32. <text class="font30" v-if="user.deptName">
  33. {{user.deptName}}
  34. </text>
  35. <text class="font30 font-gray2" v-else>
  36. 请选择部门
  37. </text>
  38. </view>
  39. <view>
  40. <uni-icons @click="change" color="#8f9499" type="right" size="20"></uni-icons>
  41. </view>
  42. </view>
  43. <u-picker :show="show" :columns="deptList" @cancel="cancel" @confirm="confirm"
  44. keyName="deptName"></u-picker>
  45. </view>
  46. <button class="saveBtn" :class="user.name&&user.phone!=''&&user.deptId!=''?'btnColorSelect':'btnColor'"
  47. type="primary" @click="next">保存</button>
  48. </view>
  49. </template>
  50. <script>
  51. import {
  52. memberDetail
  53. } from '../../config/api';
  54. import store from "@/store";
  55. import {
  56. UPLOAD_URL
  57. } from '../../common/config.js'
  58. export default {
  59. data() {
  60. return {
  61. show: false,
  62. deptList: [
  63. ],
  64. user: {
  65. name: "",
  66. phone: "",
  67. avatar: "",
  68. },
  69. fileList: [],
  70. token: "",
  71. };
  72. },
  73. created() {
  74. this.token = store.state.vuex_user.access_token
  75. this.user = store.state.vuex_user
  76. this.user.deptId = ""
  77. console.log(this.user)
  78. },
  79. onLoad() {
  80. // this.getList()
  81. },
  82. methods: {
  83. confirm(item) {
  84. console.log(item)
  85. this.user.deptId = item.value[0].id
  86. this.user.deptName = item.value[0].deptName
  87. this.show = false
  88. },
  89. cancel() {
  90. this.show = false
  91. },
  92. change() {
  93. this.show = true
  94. },
  95. onChooseAvatar(e) {
  96. console.log(e)
  97. this.uploadFilePromise(e.detail.avatarUrl).then((res) => {
  98. console.log(res)
  99. this.user.avatar = res.data.link
  100. })
  101. this.$forceUpdate()
  102. },
  103. getUserDetail() {
  104. this.bladeUserGetUserDetail().then((res) => {
  105. this.user = res.data
  106. })
  107. },
  108. getList() {
  109. getDeptList().then((res) => {
  110. let list = []
  111. list = res.data
  112. this.deptList.push(list)
  113. console.log(this.deptList)
  114. })
  115. },
  116. async afterRead(event) {
  117. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  118. let lists = [].concat(event.file)
  119. let fileListLen = this.fileList.length
  120. for (let i = 0; i < lists.length; i++) {
  121. const result = await this.uploadFilePromise(lists[i].thumb)
  122. this.user.avatar = result.data.link
  123. }
  124. },
  125. uploadFilePromise(url) {
  126. return new Promise((resolve, reject) => {
  127. let a = uni.uploadFile({
  128. url: UPLOAD_URL,
  129. filePath: url,
  130. header: {
  131. "Blade-Auth": this.token
  132. },
  133. name: 'file',
  134. formData: {
  135. user: 'test'
  136. },
  137. success: (res) => {
  138. resolve(JSON.parse(res.data))
  139. }
  140. });
  141. })
  142. },
  143. // 删除图片
  144. deletePic(event) {
  145. this.fileList.splice(event.index, 1)
  146. },
  147. next() {
  148. console.log(this.user)
  149. if (this.user.name == "") {
  150. return uni.$u.toast('请填写名称');
  151. }
  152. if (this.user.phone == "") {
  153. return uni.$u.toast('请填写手机号码');
  154. }
  155. if (this.user.deptId == "") {
  156. return uni.$u.toast('请选择部门');
  157. }
  158. updateUser(this.user).then((res) => {
  159. this.$Router.replaceAll({
  160. name: 'my'
  161. });
  162. })
  163. },
  164. }
  165. };
  166. </script>
  167. <style scoped>
  168. .saveBtn {
  169. margin-top: 50rpx;
  170. width: 700rpx;
  171. margin-left: 25rpx;
  172. border-radius: 10rpx;
  173. background-color: #659bf2;
  174. }
  175. button::after {
  176. border: none;
  177. }
  178. .btnColorSelect {
  179. background-color: #659bf2;
  180. }
  181. .btnColor {
  182. background-color: #e5e5e5;
  183. }
  184. .inputBg {
  185. background-color: #f3f3f3;
  186. width: 700rpx;
  187. margin-left: 25rpx;
  188. margin-top: 50rpx;
  189. border-radius: 20rpx;
  190. border: none;
  191. font-size: 30rpx;
  192. padding: 20rpx;
  193. position: relative;
  194. }
  195. .container {
  196. min-height: 100vh;
  197. background-color: #FFFFFF;
  198. }
  199. .header {
  200. text-align: center;
  201. margin-bottom: 20px;
  202. padding-top: 30rpx;
  203. }
  204. .title {
  205. font-size: 24px;
  206. font-weight: bold;
  207. }
  208. .subtitle {
  209. font-size: 16px;
  210. color: #666;
  211. }
  212. .avatarButton {
  213. background: transparent;
  214. border: none;
  215. }
  216. .avatar {
  217. width: 150rpx;
  218. height: 150rpx;
  219. border-radius: 50%;
  220. /* border: 1px solid #ababab; */
  221. }
  222. button::after {
  223. border: none;
  224. }
  225. </style>