editUser.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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"/>
  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"/>
  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"/>
  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 {setUserInfo,getCompanyUser} from './api/manageCompany.js';
  73. import { premissionCheck } from "@/js_sdk/wa-permission/permission.js"
  74. export default {
  75. data() {
  76. return {
  77. nickName:"",
  78. deptName:"",
  79. postNames:"",
  80. phonenumber:"",
  81. email:"",
  82. sexPicker: ['男', '女','未知'],
  83. sex: 0, // 性别
  84. headImg: this.$store.getters.imgpath+'/app/images/detault_head.jpg', // 头像,
  85. headImgUrl:'',
  86. defaultUrl:'https://beiliyo-2025.obs.cn-north-4.myhuaweicloud.com/fs/20250606/1749180611713.png',
  87. codeimg:'',
  88. codeurlimg:'',
  89. roleNames:''
  90. }
  91. },
  92. onLoad() {
  93. this.getCompanyUser();
  94. },
  95. methods: {
  96. bindUser(data){
  97. var that=this;
  98. that.nickName=data.nickName;
  99. that.deptName=data.dept.deptName;
  100. if(data.posts){
  101. that.postNames=data.posts.map(item=>item.postName).join(",")
  102. }
  103. if(data.roles){
  104. this.roleNames=data.roles.map(item=>item.roleName).join(",")
  105. }
  106. // that.posts=data.post;
  107. that.phonenumber=data.phonenumber;
  108. that.email=data.email;
  109. that.sex=data.sex;
  110. if (data.qrCodeWeixin && data.qrCodeWeixin.trim() !== '') {
  111. that.codeimg = uni.getStorageSync('requestPath') + data.qrCodeWeixin;
  112. this.codeurlimg = data.qrCodeWeixin;
  113. }
  114. if (data.avatar && data.avatar.trim() !== '') {
  115. that.headImg = data.avatar;
  116. this.headImgUrl = data.avatar;
  117. }
  118. },
  119. getCompanyUser(){
  120. var data = {};
  121. var that=this;
  122. getCompanyUser(data).then(
  123. res => {
  124. that.bindUser(res.user);
  125. },
  126. rej => {}
  127. );
  128. },
  129. // 性别选择
  130. pickerSex(e) {
  131. this.sex = e.detail.value
  132. },
  133. // 选择头像照片
  134. async chooseImage() {
  135. // #ifdef APP-PLUS
  136. if(!plus.runtime.isAgreePrivacy()) {
  137. uni.showToast({title: "请同意隐私政策",icon: "none"});
  138. return;
  139. }
  140. uni.showActionSheet({
  141. itemList: ['拍摄','从相册选择'],
  142. success: (res)=>{
  143. if(res.tapIndex==0) { //拍摄
  144. this.chooseImageAction("CAMERA","camera");
  145. } else if(res.tapIndex==1) { //从相册选择
  146. this.chooseImageAction("EXTERNAL_STORAGE","album");
  147. }
  148. }
  149. });
  150. // #endif
  151. },
  152. async chooseImageAction(premission,sizeType){
  153. let result = await premissionCheck(premission);
  154. if(result == 1) {
  155. uni.chooseImage({
  156. count: 1, //默认9
  157. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  158. sourceType: [sizeType], //从相册选择
  159. success: (res) => {
  160. //this.headImg = res.tempFilePaths[0]
  161. uni.uploadFile({
  162. url: uni.getStorageSync('requestPath')+'/app/common/uploadOSS', //仅为示例,非真实的接口地址
  163. filePath: res.tempFilePaths[0],
  164. name: 'file',
  165. formData: {
  166. 'user': 'test' // 上传附带参数
  167. },
  168. success: (uploadFileRes) => {
  169. var data=JSON.parse(uploadFileRes.data)
  170. this.headImg=data.url
  171. this.headImgUrl=data.url
  172. }
  173. });
  174. }
  175. });
  176. }
  177. },
  178. // 选择头像照片
  179. async chooseImages() {
  180. // #ifdef APP-PLUS
  181. if(!plus.runtime.isAgreePrivacy()) {
  182. uni.showToast({title: "请同意隐私政策",icon: "none"});
  183. return;
  184. }
  185. uni.showActionSheet({
  186. itemList: ['拍摄','从相册选择'],
  187. success: (res)=>{
  188. if(res.tapIndex==0) { //拍摄
  189. this.chooseImagesAction("CAMERA","camera");
  190. } else if(res.tapIndex==1) { //从相册选择
  191. this.chooseImagesAction("EXTERNAL_STORAGE","album");
  192. }
  193. }
  194. });
  195. // #endif
  196. },
  197. async chooseImagesAction(premission,sizeType){
  198. let result = await premissionCheck(premission);
  199. if(result == 1) {
  200. uni.chooseImage({
  201. count: 1, //默认9
  202. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  203. sourceType: [sizeType], //从相册选择
  204. success: (res) => {
  205. //this.headImg = res.tempFilePaths[0]
  206. uni.uploadFile({
  207. url: uni.getStorageSync('requestPath')+'/companyapp/app/common/upload', //仅为示例,非真实的接口地址
  208. filePath: res.tempFilePaths[0],
  209. name: 'file',
  210. formData: {
  211. 'user': 'test' // 上传附带参数
  212. },
  213. success: (uploadFileRes) => {
  214. var data=JSON.parse(uploadFileRes.data)
  215. this.codeimg=uni.getStorageSync('requestPath')+data.fileName;
  216. this.codeurlimg=data.fileName
  217. }
  218. });
  219. }
  220. });
  221. }
  222. },
  223. // 预览头像
  224. viewImage() {
  225. uni.previewImage({
  226. urls: this.headImg,
  227. current: this.headImg
  228. });
  229. },
  230. submit(){
  231. if (!this.email || this.email.trim() === '') {
  232. uni.showToast({
  233. title: "请输入邮箱",
  234. icon: 'none',
  235. });
  236. return;
  237. }
  238. if (!this.phonenumber || this.phonenumber.trim() === '') {
  239. uni.showToast({
  240. title: "请输入手机号",
  241. icon: 'none',
  242. });
  243. return;
  244. }
  245. var data = {mobile:this.phonenumber,email:this.email,
  246. name:this.nickName,
  247. sex:this.sex.toString(),headImg:this.headImgUrl,qrCodeWeixin:this.codeurlimg};
  248. console.log(data);
  249. setUserInfo(data).then(
  250. res => {
  251. if(res.code==200){
  252. uni.showToast({
  253. title: '修改成功',
  254. duration: 2000
  255. });
  256. setTimeout(function() {
  257. uni.navigateBack({
  258. success: () => {
  259. }
  260. })
  261. }, 500);
  262. }
  263. else{
  264. uni.showToast({
  265. title: res.msg,
  266. icon: 'none',
  267. });
  268. }
  269. },
  270. rej => {}
  271. );
  272. }
  273. }
  274. }
  275. </script>
  276. <style scoped lang="scss">
  277. .content{
  278. padding-top: 20rpx;
  279. border-top: 1px solid #F5F6FA;
  280. }
  281. .info-item{
  282. height: 104upx;
  283. background: #FFFFFF;
  284. padding: 0 30upx;
  285. display: flex;
  286. align-items: center;
  287. justify-content: space-between;
  288. border-bottom: 1px solid #F5F6FA;
  289. &:last-child{
  290. border-bottom: none;
  291. }
  292. .label{
  293. font-size: 30upx;
  294. font-family: PingFang SC;
  295. font-weight: 400;
  296. color: #0F1826;
  297. }
  298. .right{
  299. display: flex;
  300. align-items: center;
  301. justify-content: center;
  302. .text{
  303. font-size: 30upx;
  304. font-family: PingFang SC;
  305. font-weight: 400;
  306. color: #0F1826;
  307. }
  308. .image{
  309. margin-left: 10upx;
  310. width: 30upx;
  311. height: 30upx;
  312. }
  313. .input{
  314. text-align: right;
  315. font-size: 30upx;
  316. font-family: PingFang SC;
  317. font-weight: 400;
  318. color: #0F1826;
  319. }
  320. }
  321. .head{
  322. border-radius: 50%;
  323. width: 80upx;
  324. height: 80upx;
  325. }
  326. .arrow{
  327. width: 30upx;
  328. height: 30upx;
  329. }
  330. .text{
  331. font-size: 30upx;
  332. font-family: PingFang SC;
  333. font-weight: 400;
  334. color: #0F1826;
  335. }
  336. .input{
  337. text-align: right;
  338. font-size: 30upx;
  339. font-family: PingFang SC;
  340. font-weight: 400;
  341. color: #0F1826;
  342. }
  343. &.password{
  344. margin-top: 20upx;
  345. .right{
  346. display: flex;
  347. align-items: center;
  348. .text{
  349. font-size: 30upx;
  350. font-family: PingFang SC;
  351. font-weight: 400;
  352. color: #0F1826;
  353. margin-right: 15upx;
  354. }
  355. }
  356. }
  357. }
  358. .btn-box{
  359. margin-top: 15rpx;
  360. height: 120upx;
  361. padding: 0 30upx;
  362. display: flex;
  363. align-items: center;
  364. justify-content: center;
  365. .sub-btn{
  366. width: 100%;
  367. height: 88upx;
  368. line-height: 88upx;
  369. text-align: center;
  370. font-size: 30upx;
  371. font-family: PingFang SC;
  372. font-weight: bold;
  373. color: #FFFFFF;
  374. background: #115296;
  375. border-radius: 44upx;
  376. }
  377. }
  378. </style>