index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <view class="user-info-wrap">
  3. <view class="nav-bar">
  4. <view class="nav-content">
  5. <view class="nav-info">
  6. <view class="nav-desc">
  7. <view class="nav-name">
  8. <view class="">头像</view>
  9. </view>
  10. </view>
  11. <view @click="uploadImg1(1)" class="arrow-right">
  12. <view class="head-img">
  13. <image :src="userInfo.facePhotoUrl || '/static/me/ud4.png'" mode="aspectFill"></image>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. <view class="custom-line"></view>
  19. <view class="cotent-from">
  20. <u--form
  21. labelPosition="left"
  22. :model="userInfo"
  23. :rules="rules"
  24. ref="form1"
  25. >
  26. <u-form-item
  27. label="昵称"
  28. prop="nickName"
  29. labelWidth="auto"
  30. labelAlign="right"
  31. >
  32. <u--input
  33. v-model="userInfo.nickName"
  34. placeholder="请输入昵称"
  35. border="bottom"
  36. maxlength="20"
  37. type="text"
  38. ></u--input>
  39. </u-form-item>
  40. <u-form-item
  41. labelWidth="auto"
  42. labelAlign="right"
  43. label="关系"
  44. prop="blood"
  45. width="120"
  46. >
  47. <u--input
  48. maxlength="20"
  49. v-model="userInfo.blood"
  50. placeholder="请输入关系"
  51. border="bottom"
  52. type="text"
  53. ></u--input>
  54. </u-form-item>
  55. <u-form-item
  56. labelWidth="auto"
  57. labelAlign="right"
  58. label="备注"
  59. prop="remark"
  60. width="120"
  61. >
  62. <u--input
  63. maxlength="20"
  64. v-model="userInfo.remark"
  65. placeholder="请输入备注"
  66. border="bottom"
  67. type="text"
  68. ></u--input>
  69. </u-form-item>
  70. </u--form>
  71. </view>
  72. </view>
  73. <view @click="saveUserInfo()" class="sure-btn">
  74. <view class="btn">确认</view>
  75. </view>
  76. </view>
  77. </template>
  78. <script>
  79. export default {
  80. data() {
  81. return {
  82. requestStatus:false,
  83. userInfo: {
  84. auth: true,
  85. nickName: '',
  86. facePhoto: '',
  87. blood: '',
  88. remark: '',
  89. id: ''
  90. },
  91. genderShow: false,
  92. value1: '2023-12-12',
  93. imgUrl1: '',
  94. rules:[]
  95. };
  96. },
  97. mounted() {
  98. },
  99. onShow(){
  100. if (this.userInfo.facePhoto){
  101. this.getImgUrlByOssId(this.userInfo.facePhoto)
  102. }
  103. },
  104. onLoad(option) {
  105. console.log('++++++++++++++++option+++++++++++++++',option)
  106. if(option.data){
  107. this.userInfo = JSON.parse(option.data);
  108. if (this.userInfo.facePhoto){
  109. this.getImgUrlByOssId(this.userInfo.facePhoto)
  110. }
  111. }
  112. },
  113. methods: {
  114. getImgUrlByOssId(Id){
  115. if (Id) {
  116. this.$api.getImage(Id).then(res=>{
  117. this.userInfo.facePhotoUrl = res.data.data[0].url.replace(/^http:/, "https:")
  118. this.$set(this.userInfo)
  119. });
  120. }
  121. },
  122. // 保存用户信息
  123. saveUserInfo(){
  124. if(!this.userInfo.nickName){
  125. uni.showToast({
  126. title: "请填写昵称"
  127. })
  128. return;
  129. }
  130. if(!this.userInfo.blood){
  131. uni.showToast({
  132. title: "请填写关系"
  133. })
  134. return;
  135. }
  136. if(this.requestStatus){
  137. return;
  138. }
  139. this.requestStatus=true
  140. this.userInfo.auth = true;
  141. if(this.userInfo.opType == '1'){ // 绑定
  142. // 保存数据
  143. this.$api.bindServiceObject(this.userInfo).then((res)=>{
  144. if (res.data.code === 500){
  145. uni.showToast({
  146. title: res.data.msg
  147. })
  148. }else {
  149. uni.showToast({
  150. title: "绑定成功"
  151. })
  152. }
  153. // 去服务对象列表页
  154. setTimeout(()=>{
  155. this.requestStatus=false
  156. // uni.reLaunch({
  157. // url: '/myPages/ServiceObjectManagement/index',
  158. // })
  159. uni.navigateBack({
  160. delta: 1
  161. });
  162. },3000)
  163. }).catch(()=>{
  164. this.requestStatus=false
  165. })
  166. }else if(this.userInfo.opType == '2'){ // 修改
  167. // 修改数据
  168. this.$api.updateServiceObject(this.userInfo).then((res)=>{
  169. uni.showToast({
  170. title: "修改成功"
  171. })
  172. // 去服务对象列表页
  173. setTimeout(()=>{
  174. this.requestStatus=false
  175. // uni.redirectTo({
  176. // url: '/myPages/ServiceObjectManagement/index',
  177. // })
  178. uni.navigateBack({
  179. delta: 1
  180. });
  181. },3000)
  182. }).catch(()=>{
  183. this.requestStatus=false
  184. })
  185. }
  186. },
  187. //头像上传
  188. uploadImg1(imgIndex) {
  189. return //关闭头像上传
  190. let that = this;
  191. uni.chooseImage({
  192. count: 1,
  193. success: (chooseImageRes) => {
  194. const tempFilePaths = chooseImageRes.tempFilePaths;
  195. uni.uploadFile({
  196. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  197. filePath: tempFilePaths[0],
  198. name: 'file',
  199. header: {
  200. 'Authorization': 'Bearer ' + uni.getStorageInfo('accessToken'),
  201. },
  202. success: (uploadFileRes) => {
  203. console.log('uploadFileRes=>',uploadFileRes)
  204. let res = JSON.parse(uploadFileRes.data)
  205. that.userInfo.facePhotoUrl = res.data.url.replace(/^http:/, "https:");
  206. that.userInfo.facePhoto = res.data.ossId
  207. }
  208. });
  209. }
  210. });
  211. }
  212. }
  213. };
  214. </script>
  215. <style lang="scss">
  216. .user-info-wrap{
  217. margin-left: 12px;
  218. margin-right: 12px;
  219. /* 导航菜单 */
  220. .nav-bar{
  221. background: #fff;
  222. border-radius: 10px;
  223. margin-top: 12px;
  224. .cotent-from{
  225. padding-right: 12px;
  226. padding-left: 12px;
  227. }
  228. /* 商店信息 */
  229. .nav-content{
  230. padding-right: 6px;
  231. padding-top: 10px;
  232. padding-bottom: 6px;
  233. .nav-info{
  234. display: flex;
  235. justify-content: space-between;
  236. padding-left: 10px;
  237. align-items: center;
  238. .logo {
  239. width: 12%;
  240. text-align: center;
  241. image{
  242. width: 24px;
  243. height: 24px;
  244. }
  245. }
  246. .nav-desc{
  247. width: 46%;
  248. display: flex;
  249. line-height: 30px;
  250. font-family: PingFangSC-Regular, PingFang SC;
  251. font-weight: 400;
  252. align-items: center;
  253. .custom-input{
  254. font-size: 12px;
  255. }
  256. .nav-name{
  257. width: 60%;
  258. font-size: 14px;
  259. color: #333333;
  260. line-height: 22px;
  261. }
  262. .change-store{
  263. text-align: right;
  264. width: 40%;
  265. font-size: 12px;
  266. color: #333333;
  267. line-height: 22px;
  268. }
  269. }
  270. .arrow-right{
  271. width: 50px;
  272. height: 50px;
  273. display: flex;
  274. justify-content: flex-end;
  275. .head-img {
  276. width: 50px;
  277. height: 50px;
  278. border-radius: 25px;
  279. image{
  280. width: 50px;
  281. height: 50px;
  282. border-radius: 25px;
  283. }
  284. }
  285. .change-store{
  286. font-size: 14px;
  287. color: #999;
  288. line-height: 22px;
  289. }
  290. }
  291. }
  292. }
  293. }
  294. .sure-btn{
  295. margin-top: 20px;
  296. width: 100%;
  297. .btn{
  298. text-align: center;
  299. height: 42px;
  300. background: #FFE05C;
  301. border-radius: 27px;
  302. color: #333333;
  303. line-height: 42px;
  304. margin-top: 12px;
  305. font-size: 14px;
  306. }
  307. }
  308. }
  309. </style>