userinfo.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <view class="user">
  3. <view class="top">
  4. <view class="left">
  5. <!-- <image @click="chooseImage" v-if="userinfo.headUrl" :src="userinfo.headUrl" mode=""></image> -->
  6. <view class="page-container1-face-image" v-if="userinfo.headUrl" @click="onDiscernHandle">
  7. <u--image :showLoading="true" :src="userinfo.headUrl" width="100rpx" height="100rpx"></u--image>
  8. </view>
  9. <view v-else class="name" @click="onDiscernHandle">
  10. <span>
  11. {{userinfo.realName.slice(-2)}}
  12. </span>
  13. </view>
  14. <view class="txt">
  15. <div>
  16. {{userinfo.realName}}
  17. </div>
  18. <div v-if="userinfo.postName">
  19. {{userinfo.postName}} 岗位
  20. </div>
  21. </view>
  22. </view>
  23. <view class="right">
  24. </view>
  25. </view>
  26. <u-form :model="userinfo" ref="uForm" border-bottom label-width="180rpx">
  27. <view class="main">
  28. <view class="list">
  29. <!-- <u-form-item label="性别:">
  30. {{userinfo.sex}}
  31. </u-form-item>
  32. <u-form-item label="年龄:"> {{userinfo.age}}
  33. </u-form-item> -->
  34. <u-form-item label="手机号:" prop="mobile">
  35. <span v-if="!update">{{userinfo.mobile}}</span>
  36. <u-input v-else border="false" v-model="userinfo.mobile" />
  37. </u-form-item>
  38. <u-form-item label="电子邮箱:" prop="email">
  39. <span v-if="!update">{{userinfo.email}}</span>
  40. <u-input v-else border="false" v-model="userinfo.email" />
  41. </u-form-item>
  42. <!-- <u-form-item label="部门:"> {{userinfo.deptName}}
  43. </u-form-item>
  44. <u-form-item label="岗位:"> {{userinfo.postName}}
  45. </u-form-item> -->
  46. </view>
  47. <!-- <view style="display: flex;justify-content: space-between;padding: 0 30rpx;margin-bottom: 20rpx;">
  48. <view class="">
  49. 默认银行卡
  50. </view>
  51. <view style="text-align: center;color: #3C9CFF;" @click='toBackInfo'>
  52. 银行卡管理
  53. </view>
  54. </view>
  55. <div class="list" v-if='userinfo.bankName'>
  56. <u-form-item label="银行卡:" prop="bankName">
  57. {{userinfo.bankName}}
  58. </u-form-item>
  59. <u-form-item label="银行卡号:" prop="bankCard">
  60. <span>{{userinfo.bankCard}}</span>
  61. </u-form-item>
  62. </div>
  63. <div class="list" v-else style="padding: 0 30rpx">
  64. <span style="color: red;">您当前未添加银行卡,为避免影响工资发放和报销,请及时添加银行卡!</span>
  65. </div> -->
  66. </view>
  67. </u-form>
  68. <u-toast style="display: none;" ref="uToast"></u-toast>
  69. <view class="btns" v-if="!update">
  70. <u-button @click="update=!update" type="primary">编辑</u-button>
  71. </view>
  72. <view class="btns" v-else>
  73. <u-button @click="submit" class="save" type="primary">保存</u-button>
  74. <u-button @click="update=!update">取消</u-button>
  75. </view>
  76. </view>
  77. </template>
  78. <script>
  79. import Config from '@/common/Config.js'
  80. import upload from '../../../../uni_modules/uview-ui/libs/config/props/upload';
  81. export default {
  82. data() {
  83. return {
  84. fileList: [],
  85. update: false,
  86. userinfo: {
  87. realName: ""
  88. },
  89. rules: {
  90. email: [{
  91. required: true,
  92. message: '请输入邮箱',
  93. }],
  94. bankName: [{
  95. required: true,
  96. message: '请输入开户行',
  97. }],
  98. bankCard: [{
  99. required: true,
  100. message: '请输入银行卡号',
  101. }],
  102. }
  103. }
  104. },
  105. onShow() {
  106. this.getinfo()
  107. },
  108. onReady() {
  109. this.$refs.uForm.setRules(this.rules);
  110. },
  111. methods: {
  112. toBackInfo() {
  113. uni.navigateTo({
  114. url: '/pages/main/set/userinfo/backInfo'
  115. })
  116. },
  117. // 选择图片方法
  118. onDiscernHandle() {
  119. let that = this
  120. console.log(1111);
  121. if (this.fileList.length !== 0 && !this.update) {
  122. // 预览图片
  123. uni.previewImage({
  124. urls: [this.userinfo.headUrl],
  125. });
  126. return false;
  127. }
  128. uni.chooseImage({
  129. count: 1, // 选择文件的数量,这里选择一个文件
  130. success: function(res) {
  131. const tempFilePaths = res.tempFilePaths; // 获取选择的文件路径
  132. // 上传文件
  133. uni.uploadFile({
  134. url: `${Config.baseUrl}/sys/oss/uploadAndCreateEnclosure`, // 上传服务器的地址
  135. filePath: tempFilePaths[0], // 要上传的文件路径
  136. name: 'file', // 服务器接收文件的字段名
  137. success: function(uploadRes) {
  138. that.userinfo.headUrl = JSON.parse(uploadRes.data).data[0].src
  139. console.log(JSON.parse(uploadRes.data), that.userinfo);
  140. // 上传成功后的逻辑处理
  141. },
  142. fail: function(err) {
  143. console.log('上传失败', err);
  144. // 上传失败后的逻辑处理
  145. }
  146. });
  147. }
  148. });
  149. },
  150. // 删除图片
  151. deletePic(event) {
  152. this.fileList = [];
  153. this.userinfo.headUrl = ''
  154. },
  155. //获取个人信息
  156. getinfo() {
  157. this.$api.to_http(`/sys/user/info`, "GET").then((res) => {
  158. if (!res.data.data.bankName) {
  159. res.data.data.bankName = '农业银行'
  160. }
  161. this.userinfo = res.data.data
  162. this.fileList[0] = {
  163. url: res.data.data.headUrl
  164. }
  165. })
  166. },
  167. submit() {
  168. this.$refs.uForm.validate(valid => {
  169. if (valid) {
  170. console.log(11);
  171. } else {
  172. console.log('验证失败');
  173. }
  174. });
  175. if (!this.userinfo.email || !this.userinfo.mobile || !this.userinfo.bankName || !this.userinfo.bankCard) {
  176. return uni.$u.toast('请完成必填项')
  177. }
  178. this.$api.to_http(`/sys/user/mobileUpdateInfo`, this.userinfo, "POST").then((res) => {
  179. if (res.data.code != 0) {
  180. return uni.$u.toast(res.data.msg)
  181. }
  182. this.$api.to_http(`/sys/user/updateAvatar`, {
  183. id: this.userinfo.id,
  184. avatar: this.userinfo.headUrl
  185. }, "POST").then((res) => {
  186. if (res.data.code != 0) {
  187. return uni.$u.toast(res.data.msg)
  188. }
  189. uni.setStorageSync('userInfo', this.userinfo)
  190. uni.$u.toast(res.data.msg)
  191. })
  192. })
  193. },
  194. }
  195. }
  196. </script>
  197. <style>
  198. .user .u-form-item {
  199. border-bottom: 1px solid #e1dddd;
  200. padding: 0 30rpx;
  201. }
  202. .user .u-input.u-input--square {
  203. padding: 0 !important;
  204. }
  205. .user .u-upload {
  206. flex: none;
  207. }
  208. </style>
  209. <style scoped lang="less">
  210. .user {
  211. background: #F2F6FF;
  212. position: absolute;
  213. height: 100vh;
  214. width: 100%;
  215. .btns {
  216. margin: 0 auto;
  217. // margin-top: 300rpx;
  218. width: 100%;
  219. padding: 0 50rpx;
  220. box-sizing: border-box;
  221. bottom: 50rpx;
  222. position: absolute;
  223. display: flex;
  224. .save {
  225. margin-right: 40rpx;
  226. }
  227. }
  228. }
  229. .user .top {
  230. background: #fff;
  231. padding: 20rpx 40rpx;
  232. }
  233. .user .top .txt {
  234. margin-left: 20rpx;
  235. }
  236. .name {
  237. background: #39BDFD;
  238. color: #fff;
  239. text-align: center;
  240. border-radius: 50%;
  241. height: 50px;
  242. width: 50px;
  243. span {
  244. line-height: 50px;
  245. display: inline-block;
  246. font-size: 16px;
  247. }
  248. }
  249. .user .top image {
  250. width: 100rpx;
  251. height: 100rpx;
  252. background-color: #999;
  253. border-radius: 16rpx;
  254. }
  255. .user .top .left {
  256. display: flex;
  257. align-items: center;
  258. }
  259. .user .main {
  260. // padding: 0 20rpx;
  261. margin-top: 30rpx;
  262. padding-bottom: 0;
  263. .list {
  264. background: #fff;
  265. margin-bottom: 30rpx;
  266. }
  267. }
  268. .user .main .li {
  269. display: flex;
  270. margin-bottom: 40rpx;
  271. border-bottom: 1px solid #f1f1f1;
  272. padding: 15rpx;
  273. box-sizing: border-box;
  274. font-size: 28rpx
  275. }
  276. .user .main .li:last-child {
  277. border: none;
  278. }
  279. .user .main .li .title {
  280. width: 200rpx;
  281. color: #999;
  282. }
  283. </style>