editUser.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <view>
  3. <view class="content">
  4. <view class="info-item">
  5. <view class="label">头像</view>
  6. <view class="right">
  7. <u-avatar :src="headImg" size="40" @tap="chooseImage()" ></u-avatar>
  8. <!-- <image class="head" @tap="chooseImage()" :src="headImg" mode=""></image> -->
  9. </view>
  10. </view>
  11. <view class="info-item">
  12. <view class="label">姓名</view>
  13. <view class="right">
  14. <!-- <text class="text">{{nickName}}</text> -->
  15. <input type="text" v-model="nickName" placeholder="请输入姓名" class="input"></text>
  16. </view>
  17. </view>
  18. <view class="info-item">
  19. <view class="label">部门</view>
  20. <view class="right">
  21. <text class="text">{{deptName}}</text>
  22. </view>
  23. </view>
  24. <view class="info-item">
  25. <view class="label">岗位</view>
  26. <view class="right">
  27. <text class="text">{{postNames}}</text>
  28. </view>
  29. </view>
  30. <view class="info-item">
  31. <view class="label">角色</view>
  32. <view class="right">
  33. <text class="text">{{roleNames}}</text>
  34. </view>
  35. </view>
  36. <view class="info-item">
  37. <view class="label">性别</view>
  38. <view class="right">
  39. <picker @change="pickerSex" :value="sex" :range="sexPicker">
  40. <view class="picker">
  41. {{sex>-1?sexPicker[sex]:''}}
  42. </view>
  43. </picker>
  44. </view>
  45. </view>
  46. <view class="info-item">
  47. <view class="label">邮箱</view>
  48. <view class="right">
  49. <input type="text" v-model="email" placeholder="请输入邮箱" class="input"></text>
  50. </view>
  51. </view>
  52. <view class="info-item">
  53. <view class="label">手机号</view>
  54. <view class="right">
  55. <input type="text" v-model="phonenumber" placeholder="请输入手机号" class="input"></text>
  56. </view>
  57. </view>
  58. <view class="info-item">
  59. <view class="label">客服二维码</view>
  60. <view class="right">
  61. <!-- <u-avatar :src="codeimg" size="40" @tap="chooseImages()" :default-url="defaultUrl"></u-avatar> -->
  62. <image class="w90 h90" @tap="chooseImages()" :src="codeimg?codeimg:defaultUrl" mode="aspectFill"></image>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="btn-box">
  67. <view class="sub-btn" @click="submit()">保存修改</view>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. import {setPwd,setHeadImg,setUserInfo,getCompanyUser} from '@/api/user.js';
  73. export default {
  74. data() {
  75. return {
  76. nickName:"",
  77. deptName:"",
  78. postNames:"",
  79. phonenumber:"",
  80. email:"",
  81. sexPicker: ['男', '女','未知'],
  82. sex: 0, // 性别
  83. headImg: this.$store.state.imgpath+'/app/images/detault_head.jpg', // 头像,
  84. headImgUrl:'',
  85. defaultUrl:'https://beiliyo-2025.obs.cn-north-4.myhuaweicloud.com/fs/20250606/1749180611713.png',
  86. codeimg:'',
  87. codeurlimg:'',
  88. roleNames:''
  89. }
  90. },
  91. onLoad() {
  92. this.getCompanyUser();
  93. },
  94. methods: {
  95. bindUser(data){
  96. var that=this;
  97. that.nickName=data.nickName;
  98. that.deptName=data.dept.deptName;
  99. if(data.posts){
  100. that.postNames=data.posts.map(item=>item.postName).join(",")
  101. }
  102. if(data.roles){
  103. this.roleNames=data.roles.map(item=>item.roleName).join(",")
  104. }
  105. // that.posts=data.post;
  106. that.phonenumber=data.phonenumber;
  107. that.email=data.email;
  108. that.sex=data.sex;
  109. if(!that.utils.isEmpty(data.qrCodeWeixin)){
  110. that.codeimg=uni.getStorageSync('requestPath')+data.qrCodeWeixin;
  111. this.codeurlimg=data.qrCodeWeixin;
  112. }
  113. if(!that.utils.isEmpty(data.avatar)){
  114. that.headImg=uni.getStorageSync('requestPath')+data.avatar;
  115. this.headImgUrl=data.avatar;
  116. }
  117. },
  118. getCompanyUser(){
  119. var data = {};
  120. var that=this;
  121. getCompanyUser(data).then(
  122. res => {
  123. that.bindUser(res.user);
  124. },
  125. rej => {}
  126. );
  127. },
  128. // 性别选择
  129. pickerSex(e) {
  130. this.sex = e.detail.value
  131. },
  132. // 选择头像照片
  133. chooseImage() {
  134. uni.chooseImage({
  135. count: 1, //默认9
  136. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  137. sourceType: ['album', 'camera'], //从相册选择
  138. success: (res) => {
  139. //this.headImg = res.tempFilePaths[0]
  140. uni.uploadFile({
  141. url: uni.getStorageSync('requestPath')+'/companyapp/app/common/upload', //仅为示例,非真实的接口地址
  142. filePath: res.tempFilePaths[0],
  143. name: 'file',
  144. formData: {
  145. 'user': 'test' // 上传附带参数
  146. },
  147. success: (uploadFileRes) => {
  148. console.log(uploadFileRes)
  149. // 根据接口具体返回格式 赋值具体对应url
  150. var data=JSON.parse(uploadFileRes.data)
  151. this.headImg=uni.getStorageSync('requestPath')+data.fileName;
  152. this.headImgUrl=data.fileName;
  153. }
  154. });
  155. }
  156. });
  157. },
  158. // 选择头像照片
  159. chooseImages() {
  160. uni.chooseImage({
  161. count: 1, //默认9
  162. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  163. sourceType: ['album', 'camera'], //从相册选择
  164. success: (res) => {
  165. //this.headImg = res.tempFilePaths[0]
  166. uni.uploadFile({
  167. url: uni.getStorageSync('requestPath')+'/companyapp/app/common/upload', //仅为示例,非真实的接口地址
  168. filePath: res.tempFilePaths[0],
  169. name: 'file',
  170. formData: {
  171. 'user': 'test' // 上传附带参数
  172. },
  173. success: (uploadFileRes) => {
  174. console.log(uploadFileRes)
  175. // 根据接口具体返回格式 赋值具体对应url
  176. var data=JSON.parse(uploadFileRes.data)
  177. this.codeimg=uni.getStorageSync('requestPath')+data.fileName;
  178. this.codeurlimg=data.fileName
  179. }
  180. });
  181. }
  182. });
  183. },
  184. // 预览头像
  185. viewImage() {
  186. uni.previewImage({
  187. urls: this.headImg,
  188. current: this.headImg
  189. });
  190. },
  191. submit(){
  192. if (this.utils.isEmpty(this.email)) {
  193. uni.showToast({
  194. title: "请输入邮箱",
  195. icon: 'none',
  196. });
  197. return
  198. }
  199. if (this.utils.isEmpty(this.phonenumber)) {
  200. uni.showToast({
  201. title: "请输入手机号",
  202. icon: 'none',
  203. });
  204. return
  205. }
  206. var data = {mobile:this.phonenumber,email:this.email,
  207. name:this.nickName,
  208. sex:this.sex.toString(),headImg:this.headImgUrl,qrCodeWeixin:this.codeurlimg};
  209. console.log(data);
  210. setUserInfo(data).then(
  211. res => {
  212. if(res.code==200){
  213. uni.showToast({
  214. title: '修改成功',
  215. duration: 2000
  216. });
  217. setTimeout(function() {
  218. uni.navigateBack({
  219. success: () => {
  220. }
  221. })
  222. }, 500);
  223. }
  224. else{
  225. uni.showToast({
  226. title: res.msg,
  227. icon: 'none',
  228. });
  229. }
  230. },
  231. rej => {}
  232. );
  233. }
  234. }
  235. }
  236. </script>
  237. <style scoped lang="scss">
  238. .content{
  239. padding-top: 20rpx;
  240. border-top: 1px solid #F5F6FA;
  241. }
  242. .info-item{
  243. height: 104upx;
  244. background: #FFFFFF;
  245. padding: 0 30upx;
  246. display: flex;
  247. align-items: center;
  248. justify-content: space-between;
  249. border-bottom: 1px solid #F5F6FA;
  250. &:last-child{
  251. border-bottom: none;
  252. }
  253. .label{
  254. font-size: 30upx;
  255. font-family: PingFang SC;
  256. font-weight: 400;
  257. color: #0F1826;
  258. }
  259. .right{
  260. display: flex;
  261. align-items: center;
  262. justify-content: center;
  263. .text{
  264. font-size: 30upx;
  265. font-family: PingFang SC;
  266. font-weight: 400;
  267. color: #0F1826;
  268. }
  269. .image{
  270. margin-left: 10upx;
  271. width: 30upx;
  272. height: 30upx;
  273. }
  274. .input{
  275. text-align: right;
  276. font-size: 30upx;
  277. font-family: PingFang SC;
  278. font-weight: 400;
  279. color: #0F1826;
  280. }
  281. }
  282. .head{
  283. border-radius: 50%;
  284. width: 80upx;
  285. height: 80upx;
  286. }
  287. .arrow{
  288. width: 30upx;
  289. height: 30upx;
  290. }
  291. .text{
  292. font-size: 30upx;
  293. font-family: PingFang SC;
  294. font-weight: 400;
  295. color: #0F1826;
  296. }
  297. .input{
  298. text-align: right;
  299. font-size: 30upx;
  300. font-family: PingFang SC;
  301. font-weight: 400;
  302. color: #0F1826;
  303. }
  304. &.password{
  305. margin-top: 20upx;
  306. .right{
  307. display: flex;
  308. align-items: center;
  309. .text{
  310. font-size: 30upx;
  311. font-family: PingFang SC;
  312. font-weight: 400;
  313. color: #0F1826;
  314. margin-right: 15upx;
  315. }
  316. }
  317. }
  318. }
  319. .btn-box{
  320. margin-top: 15rpx;
  321. height: 120upx;
  322. padding: 0 30upx;
  323. display: flex;
  324. align-items: center;
  325. justify-content: center;
  326. .sub-btn{
  327. width: 100%;
  328. height: 88upx;
  329. line-height: 88upx;
  330. text-align: center;
  331. font-size: 30upx;
  332. font-family: PingFang SC;
  333. font-weight: bold;
  334. color: #FFFFFF;
  335. background: #115296;
  336. border-radius: 44upx;
  337. }
  338. }
  339. </style>