index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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-item
  71. v-if="userInfo.minMainCardStatus"
  72. labelWidth="auto"
  73. labelAlign="right"
  74. label="服务项目"
  75. prop="remark"
  76. width="120"
  77. >
  78. <uni-data-checkbox multiple v-model="userInfo.serviceProjectId"
  79. :localdata="serviceProjectList"/>
  80. </u-form-item>
  81. </u--form>
  82. </view>
  83. </view>
  84. <view @click="saveUserInfo()" class="sure-btn">
  85. <view class="btn">确认</view>
  86. </view>
  87. </view>
  88. </template>
  89. <script>
  90. export default {
  91. data() {
  92. return {
  93. serviceProjectList: [],
  94. requestStatus: false,
  95. userInfo: {
  96. auth: true,
  97. nickName: '',
  98. facePhoto: '',
  99. blood: '',
  100. remark: '',
  101. id: '',
  102. serviceProjectId:[],
  103. },
  104. genderShow: false,
  105. value1: '2023-12-12',
  106. imgUrl1: '',
  107. rules: []
  108. };
  109. },
  110. mounted() {
  111. },
  112. onShow() {
  113. if (this.userInfo.facePhoto) {
  114. this.getImgUrlByOssId(this.userInfo.facePhoto)
  115. }
  116. },
  117. onLoad(option) {
  118. this.getServiceObjectList()
  119. console.log('++++++++++++++++option+++++++++++++++', option)
  120. if (option.data) {
  121. this.userInfo = JSON.parse(option.data);
  122. if(this.userInfo.authServiceIds){
  123. this.userInfo.serviceProjectId = this.userInfo.authServiceIds.split(',');
  124. }
  125. if (this.userInfo.facePhoto) {
  126. this.getImgUrlByOssId(this.userInfo.facePhoto)
  127. }
  128. }
  129. },
  130. methods: {
  131. //修改数组属性名
  132. changeKey(arr, newName, oldName) {
  133. arr.forEach(item => {
  134. item[newName] = item[oldName]
  135. delete item[oldName]
  136. })
  137. return arr
  138. },
  139. getServiceObjectList() {
  140. this.$api.serviceProjectList().then(res => {
  141. this.serviceProjectList = res.data.data
  142. console.log()
  143. this.changeKey(this.serviceProjectList, 'value', 'id')
  144. this.changeKey(this.serviceProjectList, 'text', 'serviceName')
  145. })
  146. },
  147. getImgUrlByOssId(Id) {
  148. if (Id) {
  149. this.$api.getImage(Id).then(res => {
  150. this.userInfo.facePhotoUrl = res.data.data[0].url.replace(/^http:/, "https:")
  151. this.$set(this.userInfo)
  152. });
  153. }
  154. },
  155. // 保存用户信息
  156. saveUserInfo() {
  157. if (!this.userInfo.nickName) {
  158. uni.showToast({
  159. title: "请填写昵称"
  160. })
  161. return;
  162. }
  163. if (!this.userInfo.blood) {
  164. uni.showToast({
  165. title: "请填写关系"
  166. })
  167. return;
  168. }
  169. if (this.requestStatus) {
  170. return;
  171. }
  172. this.requestStatus = true
  173. this.userInfo.auth = true;
  174. this.userInfo.authServiceIds = this.userInfo.serviceProjectId.join()
  175. this.userInfo.serviceProjectId = this.userInfo.serviceProjectId
  176. if (this.userInfo.opType == '1') { // 绑定
  177. // 保存数据
  178. this.$api.bindServiceObject(this.userInfo).then((res) => {
  179. if (res.data.code === 500) {
  180. uni.showToast({
  181. title: res.data.msg
  182. })
  183. } else {
  184. uni.showToast({
  185. title: "绑定成功"
  186. })
  187. }
  188. // 去服务对象列表页
  189. setTimeout(() => {
  190. this.requestStatus = false
  191. // uni.reLaunch({
  192. // url: '/myPages/ServiceObjectManagement/index',
  193. // })
  194. uni.navigateBack({
  195. delta: 1
  196. });
  197. }, 3000)
  198. }).catch(() => {
  199. this.requestStatus = false
  200. })
  201. } else if (this.userInfo.opType == '2') { // 修改
  202. // 修改数据
  203. this.$api.updateServiceObject(this.userInfo).then((res) => {
  204. uni.showToast({
  205. title: "修改成功"
  206. })
  207. // 去服务对象列表页
  208. setTimeout(() => {
  209. this.requestStatus = false
  210. // uni.redirectTo({
  211. // url: '/myPages/ServiceObjectManagement/index',
  212. // })
  213. uni.navigateBack({
  214. delta: 1
  215. });
  216. }, 3000)
  217. }).catch(() => {
  218. this.requestStatus = false
  219. })
  220. }
  221. },
  222. //头像上传
  223. uploadImg1(imgIndex) {
  224. return //关闭头像上传
  225. let that = this;
  226. uni.chooseImage({
  227. count: 1,
  228. success: (chooseImageRes) => {
  229. const tempFilePaths = chooseImageRes.tempFilePaths;
  230. uni.uploadFile({
  231. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  232. filePath: tempFilePaths[0],
  233. name: 'file',
  234. header: {
  235. 'Authorization': 'Bearer ' + uni.getStorageInfo('accessToken'),
  236. },
  237. success: (uploadFileRes) => {
  238. console.log('uploadFileRes=>', uploadFileRes)
  239. let res = JSON.parse(uploadFileRes.data)
  240. that.userInfo.facePhotoUrl = res.data.url.replace(/^http:/, "https:");
  241. that.userInfo.facePhoto = res.data.ossId
  242. }
  243. });
  244. }
  245. });
  246. }
  247. }
  248. };
  249. </script>
  250. <style lang="scss">
  251. .user-info-wrap {
  252. margin-left: 12px;
  253. margin-right: 12px;
  254. /* 导航菜单 */
  255. .nav-bar {
  256. background: #fff;
  257. border-radius: 10px;
  258. margin-top: 12px;
  259. .cotent-from {
  260. padding-right: 12px;
  261. padding-left: 12px;
  262. }
  263. /* 商店信息 */
  264. .nav-content {
  265. padding-right: 6px;
  266. padding-top: 10px;
  267. padding-bottom: 6px;
  268. .nav-info {
  269. display: flex;
  270. justify-content: space-between;
  271. padding-left: 10px;
  272. align-items: center;
  273. .logo {
  274. width: 12%;
  275. text-align: center;
  276. image {
  277. width: 24px;
  278. height: 24px;
  279. }
  280. }
  281. .nav-desc {
  282. width: 46%;
  283. display: flex;
  284. line-height: 30px;
  285. font-family: PingFangSC-Regular, PingFang SC;
  286. font-weight: 400;
  287. align-items: center;
  288. .custom-input {
  289. font-size: 12px;
  290. }
  291. .nav-name {
  292. width: 60%;
  293. font-size: 14px;
  294. color: #333333;
  295. line-height: 22px;
  296. }
  297. .change-store {
  298. text-align: right;
  299. width: 40%;
  300. font-size: 12px;
  301. color: #333333;
  302. line-height: 22px;
  303. }
  304. }
  305. .arrow-right {
  306. width: 50px;
  307. height: 50px;
  308. display: flex;
  309. justify-content: flex-end;
  310. .head-img {
  311. width: 50px;
  312. height: 50px;
  313. border-radius: 25px;
  314. image {
  315. width: 50px;
  316. height: 50px;
  317. border-radius: 25px;
  318. }
  319. }
  320. .change-store {
  321. font-size: 14px;
  322. color: #999;
  323. line-height: 22px;
  324. }
  325. }
  326. }
  327. }
  328. }
  329. .sure-btn {
  330. margin-top: 20px;
  331. width: 100%;
  332. .btn {
  333. text-align: center;
  334. height: 42px;
  335. background: #FFE05C;
  336. border-radius: 27px;
  337. color: #333333;
  338. line-height: 42px;
  339. margin-top: 12px;
  340. font-size: 14px;
  341. }
  342. }
  343. }
  344. </style>