index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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/u4.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. userInfo: {
  83. auth: true,
  84. nickName: '',
  85. facePhoto: '',
  86. blood: '',
  87. remark: '',
  88. id: ''
  89. },
  90. genderShow: false,
  91. value1: '2023-12-12',
  92. imgUrl1: '',
  93. rules:[]
  94. };
  95. },
  96. mounted() {
  97. },
  98. onShow(){
  99. if (this.userInfo.facePhoto){
  100. this.getImgUrlByOssId(this.userInfo.facePhoto)
  101. }
  102. },
  103. onLoad(option) {
  104. console.log('++++++++++++++++option+++++++++++++++',option)
  105. if(option.data){
  106. this.userInfo = JSON.parse(option.data);
  107. if (this.userInfo.facePhoto){
  108. this.getImgUrlByOssId(this.userInfo.facePhoto)
  109. }
  110. }
  111. },
  112. methods: {
  113. getImgUrlByOssId(Id){
  114. if (Id) {
  115. this.$api.getImage(Id).then(res=>{
  116. this.userInfo.facePhotoUrl = res.data.data[0].url.replace(/^http:/, "https:")
  117. this.$set(this.userInfo)
  118. });
  119. }
  120. },
  121. // 保存用户信息
  122. saveUserInfo(){
  123. if(!this.userInfo.nickName){
  124. uni.showToast({
  125. title: "请填写昵称"
  126. })
  127. return;
  128. }
  129. if(!this.userInfo.blood){
  130. uni.showToast({
  131. title: "请填写关系"
  132. })
  133. return;
  134. }
  135. this.userInfo.auth = true;
  136. if(this.userInfo.opType == '1'){ // 绑定
  137. // 保存数据
  138. this.$api.bindServiceObject(this.userInfo).then((res)=>{
  139. if (res.data.code === 500){
  140. uni.showToast({
  141. title: res.data.msg
  142. })
  143. }else {
  144. uni.showToast({
  145. title: "绑定成功"
  146. })
  147. }
  148. // 去服务对象列表页
  149. setTimeout(()=>{
  150. uni.redirectTo({
  151. url: '/myPages/ServiceObjectManagement/index',
  152. })
  153. },3000)
  154. })
  155. }else if(this.userInfo.opType == '2'){ // 修改
  156. // 修改数据
  157. this.$api.updateServiceObject(this.userInfo).then((res)=>{
  158. uni.showToast({
  159. title: "修改成功"
  160. })
  161. // 去服务对象列表页
  162. setTimeout(()=>{
  163. uni.redirectTo({
  164. url: '/myPages/ServiceObjectManagement/index',
  165. })
  166. },3000)
  167. })
  168. }
  169. },
  170. //头像上传
  171. uploadImg1(imgIndex) {
  172. return //关闭头像上传
  173. let that = this;
  174. uni.chooseImage({
  175. count: 1,
  176. success: (chooseImageRes) => {
  177. const tempFilePaths = chooseImageRes.tempFilePaths;
  178. uni.uploadFile({
  179. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  180. filePath: tempFilePaths[0],
  181. name: 'file',
  182. header: {
  183. 'Authorization': 'Bearer ' + uni.getStorageInfo('accessToken'),
  184. },
  185. success: (uploadFileRes) => {
  186. console.log('uploadFileRes=>',uploadFileRes)
  187. let res = JSON.parse(uploadFileRes.data)
  188. that.userInfo.facePhotoUrl = res.data.url.replace(/^http:/, "https:");
  189. that.userInfo.facePhoto = res.data.ossId
  190. }
  191. });
  192. }
  193. });
  194. }
  195. }
  196. };
  197. </script>
  198. <style lang="scss">
  199. .user-info-wrap{
  200. margin-left: 12px;
  201. margin-right: 12px;
  202. /* 导航菜单 */
  203. .nav-bar{
  204. background: #fff;
  205. border-radius: 10px;
  206. margin-top: 12px;
  207. .cotent-from{
  208. padding-right: 12px;
  209. padding-left: 12px;
  210. }
  211. /* 商店信息 */
  212. .nav-content{
  213. padding-right: 6px;
  214. padding-top: 10px;
  215. padding-bottom: 6px;
  216. .nav-info{
  217. display: flex;
  218. justify-content: space-between;
  219. padding-left: 10px;
  220. align-items: center;
  221. .logo {
  222. width: 12%;
  223. text-align: center;
  224. image{
  225. width: 24px;
  226. height: 24px;
  227. }
  228. }
  229. .nav-desc{
  230. width: 46%;
  231. display: flex;
  232. line-height: 30px;
  233. font-family: PingFangSC-Regular, PingFang SC;
  234. font-weight: 400;
  235. align-items: center;
  236. .custom-input{
  237. font-size: 12px;
  238. }
  239. .nav-name{
  240. width: 60%;
  241. font-size: 14px;
  242. color: #333333;
  243. line-height: 22px;
  244. }
  245. .change-store{
  246. text-align: right;
  247. width: 40%;
  248. font-size: 12px;
  249. color: #333333;
  250. line-height: 22px;
  251. }
  252. }
  253. .arrow-right{
  254. width: 50px;
  255. height: 50px;
  256. display: flex;
  257. justify-content: flex-end;
  258. .head-img {
  259. width: 50px;
  260. height: 50px;
  261. border-radius: 25px;
  262. image{
  263. width: 50px;
  264. height: 50px;
  265. border-radius: 25px;
  266. }
  267. }
  268. .change-store{
  269. font-size: 14px;
  270. color: #999;
  271. line-height: 22px;
  272. }
  273. }
  274. }
  275. }
  276. }
  277. .sure-btn{
  278. margin-top: 20px;
  279. width: 100%;
  280. .btn{
  281. text-align: center;
  282. height: 42px;
  283. background: #FFE05C;
  284. border-radius: 27px;
  285. color: #333333;
  286. line-height: 42px;
  287. margin-top: 12px;
  288. font-size: 14px;
  289. }
  290. }
  291. }
  292. </style>