index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. if(this.userInfo.serviceProjectId){
  175. this.userInfo.authServiceIds = this.userInfo.serviceProjectId.join()
  176. }
  177. if (this.userInfo.opType == '1') { // 绑定
  178. // 保存数据
  179. this.$api.bindServiceObject(this.userInfo).then((res) => {
  180. if (res.data.code === 500) {
  181. uni.showToast({
  182. title: res.data.msg
  183. })
  184. } else {
  185. uni.showToast({
  186. title: "绑定成功"
  187. })
  188. }
  189. // 去服务对象列表页
  190. setTimeout(() => {
  191. this.requestStatus = false
  192. // uni.reLaunch({
  193. // url: '/myPages/ServiceObjectManagement/index',
  194. // })
  195. uni.navigateBack({
  196. delta: 1
  197. });
  198. }, 3000)
  199. }).catch(() => {
  200. this.requestStatus = false
  201. })
  202. } else if (this.userInfo.opType == '2') { // 修改
  203. // 修改数据
  204. this.$api.updateServiceObject(this.userInfo).then((res) => {
  205. uni.showToast({
  206. title: "修改成功"
  207. })
  208. // 去服务对象列表页
  209. setTimeout(() => {
  210. this.requestStatus = false
  211. // uni.redirectTo({
  212. // url: '/myPages/ServiceObjectManagement/index',
  213. // })
  214. uni.navigateBack({
  215. delta: 1
  216. });
  217. }, 3000)
  218. }).catch(() => {
  219. this.requestStatus = false
  220. })
  221. }
  222. },
  223. //头像上传
  224. uploadImg1(imgIndex) {
  225. return //关闭头像上传
  226. let that = this;
  227. uni.chooseImage({
  228. count: 1,
  229. success: (chooseImageRes) => {
  230. const tempFilePaths = chooseImageRes.tempFilePaths;
  231. uni.uploadFile({
  232. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  233. filePath: tempFilePaths[0],
  234. name: 'file',
  235. header: {
  236. 'Authorization': 'Bearer ' + uni.getStorageInfo('accessToken'),
  237. },
  238. success: (uploadFileRes) => {
  239. console.log('uploadFileRes=>', uploadFileRes)
  240. let res = JSON.parse(uploadFileRes.data)
  241. that.userInfo.facePhotoUrl = res.data.url.replace(/^http:/, "https:");
  242. that.userInfo.facePhoto = res.data.ossId
  243. }
  244. });
  245. }
  246. });
  247. }
  248. }
  249. };
  250. </script>
  251. <style lang="scss">
  252. .user-info-wrap {
  253. margin-left: 12px;
  254. margin-right: 12px;
  255. /* 导航菜单 */
  256. .nav-bar {
  257. background: #fff;
  258. border-radius: 10px;
  259. margin-top: 12px;
  260. .cotent-from {
  261. padding-right: 12px;
  262. padding-left: 12px;
  263. }
  264. /* 商店信息 */
  265. .nav-content {
  266. padding-right: 6px;
  267. padding-top: 10px;
  268. padding-bottom: 6px;
  269. .nav-info {
  270. display: flex;
  271. justify-content: space-between;
  272. padding-left: 10px;
  273. align-items: center;
  274. .logo {
  275. width: 12%;
  276. text-align: center;
  277. image {
  278. width: 24px;
  279. height: 24px;
  280. }
  281. }
  282. .nav-desc {
  283. width: 46%;
  284. display: flex;
  285. line-height: 30px;
  286. font-family: PingFangSC-Regular, PingFang SC;
  287. font-weight: 400;
  288. align-items: center;
  289. .custom-input {
  290. font-size: 12px;
  291. }
  292. .nav-name {
  293. width: 60%;
  294. font-size: 14px;
  295. color: #333333;
  296. line-height: 22px;
  297. }
  298. .change-store {
  299. text-align: right;
  300. width: 40%;
  301. font-size: 12px;
  302. color: #333333;
  303. line-height: 22px;
  304. }
  305. }
  306. .arrow-right {
  307. width: 50px;
  308. height: 50px;
  309. display: flex;
  310. justify-content: flex-end;
  311. .head-img {
  312. width: 50px;
  313. height: 50px;
  314. border-radius: 25px;
  315. image {
  316. width: 50px;
  317. height: 50px;
  318. border-radius: 25px;
  319. }
  320. }
  321. .change-store {
  322. font-size: 14px;
  323. color: #999;
  324. line-height: 22px;
  325. }
  326. }
  327. }
  328. }
  329. }
  330. .sure-btn {
  331. margin-top: 20px;
  332. width: 100%;
  333. .btn {
  334. text-align: center;
  335. height: 42px;
  336. background: #FFE05C;
  337. border-radius: 27px;
  338. color: #333333;
  339. line-height: 42px;
  340. margin-top: 12px;
  341. font-size: 14px;
  342. }
  343. }
  344. }
  345. </style>