targetInfo.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <template>
  2. <view>
  3. <uni-nav-bar fixed :border="false" left-icon="left" title="设备信息" :statusBar="true" @clickLeft="$navBack()" @clickRight="updateUser">
  4. <!-- #ifndef MP-WEIXIN -->
  5. <template v-slot:right>
  6. <view class="add">保存</view>
  7. </template>
  8. <!-- #endif -->
  9. </uni-nav-bar>
  10. <view class="container">
  11. <view class="myinfo">
  12. <view class="myinfo-item">
  13. <view>昵称</view>
  14. <view class="myinfo-itemr" @click="openPop('nickName')">
  15. <text :style="{color: user.nickName ?'#222':'#999'}">{{user.nickName}}</text>
  16. <image class="arrow_black" src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png" mode="aspectFill">
  17. </image>
  18. </view>
  19. </view>
  20. <view class="myinfo-item">
  21. <view>性别</view>
  22. <template v-if="isFamily">
  23. <picker @change="bindPickerChange($event,'sex')" :value="sexIndex" :range="sexArray">
  24. <view class="myinfo-itemr">
  25. <text :style="{color: user.sex == 1 || user.sex == 2 ?'#222':'#999'}">
  26. {{user.sex == 1 ? '男' : user.sex == 2 ? '女' :'未知'}}
  27. </text>
  28. <image class="arrow_black" src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"
  29. mode="aspectFill"></image>
  30. </view>
  31. </picker>
  32. </template>
  33. <view v-else class="myinfo-itemr">
  34. <text :style="{color: user.sex == 1 || user.sex == 2 ?'#222':'#999'}">
  35. {{user.sex == 1 ? '男' : user.sex == 2 ? '女' :'未知'}}
  36. </text>
  37. </view>
  38. </view>
  39. <view class="myinfo-item">
  40. <view>手机号</view>
  41. <template v-if="isFamily">
  42. <view class="myinfo-itemr" @click="openPop('phone')">
  43. <text :style="{color: user.phone ?'#222':'#999'}">{{user.phone || '请填写'}}</text>
  44. <image class="arrow_black" src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"
  45. mode="aspectFill"></image>
  46. </view>
  47. </template>
  48. <view v-else class="myinfo-itemr">
  49. <text :style="{color: user.phone ?'#222':'#999'}">{{user.phone || ''}}</text>
  50. </view>
  51. </view>
  52. <view class="myinfo-item">
  53. <view>生日</view>
  54. <view>
  55. <picker :value="birthday" mode="date" fields="day" @change="birthdayChange">
  56. <view class="myinfo-itemr">
  57. <text :style="{color: user.birthday ?'#222':'#999'}">
  58. {{user.birthday ? user.birthday.substring(0,10) : '请选择'}}
  59. </text>
  60. <image class="arrow_black" src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"
  61. mode="aspectFill"></image>
  62. </view>
  63. </picker>
  64. </view>
  65. </view>
  66. <view class="myinfo-item">
  67. <view>身高</view>
  68. <view class="myinfo-itemr" @click="openPop('height')">
  69. <text :style="{color: user.height ?'#222':'#999'}">{{user.height? user.height + 'cm' : '请填写'}}</text>
  70. <image class="arrow_black" src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"
  71. mode="aspectFill"></image>
  72. </view>
  73. </view>
  74. <view class="myinfo-item">
  75. <view>体重</view>
  76. <view class="myinfo-itemr" @click="openPop('weight')">
  77. <text :style="{color: user.weight ?'#222':'#999'}">{{user.weight? user.weight+'kg' : '请填写'}}</text>
  78. <image class="arrow_black" src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"
  79. mode="aspectFill"></image>
  80. </view>
  81. </view>
  82. </view>
  83. <view class="myinfo-title">目标</view>
  84. <view class="myinfo">
  85. <view class="myinfo-item">
  86. <view>步数</view>
  87. <picker @change="bindPickerChange($event,'targetStep')" :value="stepIndex" :range="stepArray">
  88. <view class="myinfo-itemr">
  89. <text :style="{color: user.targetStep ? '#222':'#999'}">
  90. {{user.targetStep ? user.targetStep + '步' :'请选择'}}
  91. </text>
  92. <image class="arrow_black" src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"
  93. mode="aspectFill"></image>
  94. </view>
  95. </picker>
  96. </view>
  97. <view class="myinfo-item">
  98. <view>卡路里</view>
  99. <picker @change="bindPickerChange($event,'targetCalorie')" :value="kcalIndex" :range="kcalArray">
  100. <view class="myinfo-itemr">
  101. <text :style="{color: user.targetCalorie ? '#222':'#999'}">
  102. {{user.targetCalorie ? user.targetCalorie + '千卡' :'请选择'}}
  103. </text>
  104. <image class="arrow_black" src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"
  105. mode="aspectFill"></image>
  106. </view>
  107. </picker>
  108. </view>
  109. <view class="myinfo-item">
  110. <view>活动小时</view>
  111. <picker @change="bindPickerChange($event,'targetActivity')" :value="activityIndex" :range="hourArray">
  112. <view class="myinfo-itemr">
  113. <text :style="{color: user.targetActivity&& user.targetActivity != 0 ? '#222':'#999'}">
  114. {{user.targetActivity && user.targetActivity != 0 ? user.targetActivity + '小时' :'请选择'}}
  115. </text>
  116. <image class="arrow_black" src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"
  117. mode="aspectFill"></image>
  118. </view>
  119. </picker>
  120. </view>
  121. <view class="myinfo-item">
  122. <view>锻炼时长</view>
  123. <picker mode="multiSelector" @change="bindPickerChange($event,'targetSport')" :value="sportIndex" :range="timeArray">
  124. <view class="myinfo-itemr">
  125. <text :style="{color: user.targetSport&& user.targetSport != 0 ? '#222':'#999'}">
  126. {{user.targetSport && user.targetSport != 0 ? timeArray[0][sportIndex[0]] + timeArray[1][sportIndex[1]] :'请选择'}}
  127. </text>
  128. <image class="arrow_black" src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"
  129. mode="aspectFill"></image>
  130. </view>
  131. </picker>
  132. </view>
  133. </view>
  134. <uni-popup ref="popup" type="bottom">
  135. <view class="popupbox">
  136. <view class="popupbox-head">
  137. <view class="popupbox-cancel" @tap="close">取消</view>
  138. <text class="popupbox-head-title">{{poptitle}}</text>
  139. <view class="popupbox-confirm" @tap="confirm">确定</view>
  140. </view>
  141. <view class="popupbox-body">
  142. <view class="inpubox" v-show="poptitle">
  143. <uni-easyinput :type="type" v-model="inputVal" :trim="true" :inputBorder="false" :primaryColor="'#c0c4cc'"
  144. :placeholderStyle="placeholderStyle" :placeholder="placeholder" :styles="inpuStyle" maxlength="11" />
  145. </view>
  146. </view>
  147. </view>
  148. </uni-popup>
  149. <!-- #ifndef APP-PLUS || H5 -->
  150. <view class="footer-add" @click="handleAdd">保存</view>
  151. <!-- #endif -->
  152. </view>
  153. </view>
  154. </template>
  155. <script>
  156. import simpleScale from "@/pages_watch/components/simpleScale/simpleScale.vue"
  157. import permision from "@/utils/permission.js";
  158. import { editUser,editFamilyUser,getWatchUserInfo } from "@/api/pages_watch/user.js";
  159. import { getInfoByDeviceIds } from "@/api/pages_watch/index.js";
  160. export default {
  161. components: {
  162. simpleScale,
  163. },
  164. data() {
  165. return {
  166. defaultName: '',
  167. selectUserInfo: {},
  168. isFamily: false,
  169. btnLoading: false,
  170. user: {
  171. nickName: "",
  172. sex: undefined,
  173. phone: "",
  174. birthday: null,
  175. targetStep: '',
  176. targetCalorie: '',
  177. targetSport:'',
  178. targetActivity: ''
  179. },
  180. birthday: "",
  181. sexArray: ['男', '女'],
  182. sexIndex: 0,
  183. poptitle: "",
  184. placeholder: "",
  185. inputVal: "",
  186. type: "text",
  187. placeholderStyle: "{font-family: PingFang SC, PingFang SC;font-weight: 400;font-size: 28rpx;color: #CCCCCC;}",
  188. inpuStyle: {
  189. fontFamily: "PingFang SC, PingFang SC",
  190. fontWeight: 400,
  191. fontSize: "28rpx",
  192. color: "#333"
  193. },
  194. stepIndex: 0,
  195. kcalIndex: 0,
  196. sportIndex: [0,0],
  197. activityIndex: 0,
  198. hourArray: ['1小时', '2小时', '3小时', '4小时', '5小时', '6小时', '7小时', '8小时', '9小时', '10小时', '11小时', '12小时', '13小时', '14小时', '15小时', '16小时', '17小时', '18小时', '19小时', '20小时', '21小时', '22小时', '23小时', '24小时'],
  199. timeArray:[['0小时','1小时', '2小时', '3小时', '4小时', '5小时', '6小时', '7小时', '8小时', '9小时', '10小时', '11小时', '12小时', '13小时', '14小时', '15小时', '16小时', '17小时', '18小时', '19小时', '20小时', '21小时', '22小时', '23小时', '24小时'],['00分钟','30分钟']]
  200. }
  201. },
  202. computed: {
  203. stepArray() {
  204. const start = 3000;
  205. const end = 30000;
  206. const step = 1000;
  207. const array = [...Array(Math.ceil((end - start) / step) + 1).keys()].map(i => start + i * step);
  208. return array
  209. },
  210. kcalArray() {
  211. const start = 200;
  212. const end = 1000;
  213. const step = 50;
  214. const array = [...Array(Math.ceil((end - start) / step) + 1).keys()].map(i => start + i * step);
  215. return array
  216. }
  217. },
  218. onLoad(option) {
  219. this.isFamily = option.selectUser != '0'
  220. this.selectUserInfo = option.selectUserInfo ? JSON.parse(option.selectUserInfo) : {}
  221. if (this.$isLogin()) {
  222. const user = uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('userInfo')): {}
  223. this.defaultName = user.nickName
  224. this.getUserInfo();
  225. } else {
  226. this.user = {
  227. nickName: "",
  228. sex: undefined,
  229. phone: "",
  230. birthday: null,
  231. targetStep: '',
  232. targetCalorie: '',
  233. targetSport:'',
  234. targetActivity: ''
  235. }
  236. this.$showLoginPage()
  237. }
  238. },
  239. methods: {
  240. getStepScroll(e) {
  241. this.user.targetStep = e
  242. },
  243. getUserInfo() {
  244. const deviceId = uni.getStorageSync('deviceId') || ''
  245. const param = {
  246. deviceId: deviceId,
  247. isFamily: this.isFamily
  248. }
  249. this.user.nickName = param.isFamily ? this.selectUserInfo.name || '' : this.user.nickName || this.defaultName
  250. getWatchUserInfo(param).then(res => {
  251. if (res.code == 200) {
  252. this.user = res.user ? res.user : {
  253. nickName: "",
  254. sex: undefined,
  255. phone: "",
  256. birthday: null,
  257. targetStep: '',
  258. targetCalorie: '',
  259. targetSport:'',
  260. targetActivity: ''
  261. },
  262. this.user.nickName = param.isFamily ? this.selectUserInfo.name || '' : this.user.nickName || this.defaultName
  263. this.sexIndex = this.user.sex == 2 ? 1 : 0
  264. this.birthday = this.user.birthday ? this.user.birthday.substring(0, 10) : null
  265. this.stepIndex = this.stepArray.findIndex(item=>item == this.user.targetStep) == -1 ? 0 : this.stepArray.findIndex(item=>item == this.user.targetStep)
  266. this.kcalIndex = this.kcalArray.findIndex(item=>item == this.user.targetCalorie) == -1 ? 0 : this.kcalArray.findIndex(item=>item == this.user.targetCalorie)
  267. this.activityIndex = this.hourArray.findIndex(item=>item == this.user.targetActivity+'小时') == -1 ? 0 : this.hourArray.findIndex(item=>item == this.user.targetActivity+'小时')
  268. if(this.user.targetSport) {
  269. const hour = Math.floor(Number(this.user.targetSport || 0) / 60);
  270. const minute = Number(this.user.targetSport || 0) % 60 == 0 ? '00' : Number(this.user.targetSport || 0) % 60;
  271. const one = this.timeArray[0].findIndex(item=>item == hour+'小时') == -1 ? 0 : this.timeArray[0].findIndex(item=>item == hour+'小时')
  272. const two = this.timeArray[1].findIndex(item=>item == minute+'分钟') == -1 ? 0 : this.timeArray[1].findIndex(item=>item == minute+'分钟')
  273. this.sportIndex = [one,two]
  274. }else {
  275. this.sportIndex = [0,1]
  276. }
  277. }
  278. })
  279. },
  280. openPop(type) {
  281. if(type=="nickName") {
  282. this.poptitle = '修改昵称'
  283. this.placeholder = '请输入昵称'
  284. this.type = 'text'
  285. this.inputVal = this.user.nickName
  286. } else if (type=="phone") {
  287. this.poptitle = '修改手机号'
  288. this.placeholder = '请输入手机号'
  289. this.type = 'number'
  290. this.inputVal = this.user.phone
  291. } else if (type=="height") {
  292. this.poptitle = '身高(cm)'
  293. this.placeholder = '请输入身高'
  294. this.type = 'number'
  295. this.inputVal = this.user.height
  296. } else if (type=="weight") {
  297. this.poptitle = '体重(kg)'
  298. this.placeholder = '请输入体重'
  299. this.type = 'number'
  300. this.inputVal = this.user.weight
  301. }
  302. this.$refs.popup.open()
  303. },
  304. confirm() {
  305. if(this.poptitle=="修改昵称") {
  306. if (!this.inputVal.trim()) {
  307. uni.showToast({
  308. title: '请输入昵称',
  309. icon: "none"
  310. })
  311. return
  312. }
  313. this.user.nickName = this.inputVal
  314. } else if (this.poptitle=="修改手机号") {
  315. const reg = /^1[3-9]\d{9}$/;
  316. if (!reg.test(this.inputVal)) {
  317. uni.showToast({
  318. title: '请输入正确的手机号',
  319. icon: "none"
  320. })
  321. return
  322. }
  323. this.user.phone = this.inputVal
  324. } else if (this.poptitle=="身高(cm)") {
  325. const reg = /^[1-9]\d*$/
  326. if(!reg.test(this.inputVal)) {
  327. uni.showToast({
  328. title: "请输入正确的身高",
  329. icon: "none"
  330. })
  331. return
  332. }
  333. this.user.height = this.inputVal
  334. } else if (this.poptitle=="体重(kg)") {
  335. // 判断字符串为数字且保留一位小数
  336. const reg = /^\d+(\.\d{1})?$/
  337. if(!reg.test(this.inputVal) || this.inputVal == 0) {
  338. uni.showToast({
  339. title: "请输入正确的体重",
  340. icon: "none"
  341. })
  342. return
  343. }
  344. this.user.weight = this.inputVal
  345. }
  346. this.$refs.popup.close()
  347. },
  348. close() {
  349. this.$refs.popup.close()
  350. },
  351. bindPickerChange(e,type) {
  352. if(type == 'sex') {
  353. this.sexIndex = e.detail.value
  354. this.user.sex = this.sexIndex == 1 ? 2: 1
  355. }else if(type == 'targetStep') {
  356. this.stepIndex = e.detail.value
  357. this.user.targetStep = this.stepArray[e.detail.value]
  358. }else if(type == 'targetCalorie') {
  359. this.kcalIndex = e.detail.value
  360. this.user.targetCalorie = this.kcalArray[e.detail.value]
  361. } else if(type=='targetSport') {
  362. this.sportIndex = e.detail.value
  363. const hour = this.timeArray[0][e.detail.value[0]].replace('小时','')
  364. const minute = this.timeArray[1][e.detail.value[1]].replace('分钟','')
  365. this.user.targetSport = hour * 60 + Number(minute)
  366. } else if(type=='targetActivity') {
  367. this.activityIndex = e.detail.value
  368. this.user.targetActivity = this.hourArray[e.detail.value].replace('小时','')
  369. }
  370. },
  371. // 生日
  372. birthdayChange(e) {
  373. this.birthday = e.detail.value
  374. this.user.birthday = this.birthday
  375. },
  376. // 修改
  377. updateUser() {
  378. if(this.isFamily) {
  379. const param = {
  380. nickName: this.user.nickName,
  381. deviceId: this.selectUserInfo.deviceId&&this.selectUserInfo.deviceId.length > 0? this.selectUserInfo.deviceId.join(','):'',
  382. sex: this.user.sex,
  383. phone: this.user.phone,
  384. birthday: this.user.birthday ? this.user.birthday.substring(0, 10) + ' 00:00:00' : "",
  385. targetStep: this.user.targetStep||0,
  386. targetCalorie: this.user.targetCalorie||0,
  387. targetSport: this.user.targetSport||0,
  388. targetActivity: this.user.targetActivity||0,
  389. height: this.user.height,
  390. weight: this.user.weight
  391. }
  392. editFamilyUser(param).then(res => {
  393. uni.showToast({
  394. title: res.msg,
  395. icon: "none"
  396. })
  397. if(res.code == 200) {
  398. this.$navBack()
  399. }
  400. })
  401. } else {
  402. const param = {
  403. nickName: this.user.nickName,
  404. birthday: this.user.birthday ? this.user.birthday.substring(0, 10) + ' 00:00:00' : "",
  405. targetStep: this.user.targetStep||0,
  406. targetCalorie: this.user.targetCalorie||0,
  407. targetSport: this.user.targetSport||0,
  408. targetActivity: this.user.targetActivity||0,
  409. height: this.user.height,
  410. weight: this.user.weight
  411. }
  412. editUser(param).then(res => {
  413. uni.showToast({
  414. title: res.msg,
  415. icon: "none"
  416. })
  417. if(res.code == 200) {
  418. this.$navBack()
  419. }
  420. })
  421. }
  422. },
  423. }
  424. }
  425. </script>
  426. <style lang="scss" scoped>
  427. @mixin u-flex($flexD, $alignI, $justifyC) {
  428. display: flex;
  429. flex-direction: $flexD;
  430. align-items: $alignI;
  431. justify-content: $justifyC;
  432. }
  433. .footer-add {
  434. width: 702rpx;
  435. height: 98rpx;
  436. background: #FFFFFF;
  437. border-radius: 16rpx;
  438. font-family: PingFang SC, PingFang SC;
  439. font-weight: 500;
  440. font-size: 32rpx;
  441. color: #FF7700;
  442. line-height: 98rpx;
  443. text-align: center;
  444. margin-top: 24rpx 0;
  445. }
  446. .add {
  447. font-family: PingFang SC, PingFang SC;
  448. font-weight: 400;
  449. font-size: 24rpx;
  450. @include u-flex(row, center, flex-end);
  451. image {
  452. flex-shrink: 0;
  453. width: 48rpx;
  454. height: 48rpx;
  455. margin-right: 6rpx;
  456. }
  457. }
  458. .container {
  459. padding: 24rpx;
  460. .myinfo-title {
  461. margin-bottom: 24rpx;
  462. font-family: PingFang SC, PingFang SC;
  463. font-weight: 500;
  464. font-size: 32rpx;
  465. color: #222;
  466. }
  467. .myinfo {
  468. margin-bottom: 24rpx;
  469. padding: 18rpx 24rpx;
  470. background: #FFFFFF;
  471. border-radius: 16rpx 16rpx 16rpx 16rpx;
  472. font-family: PingFang SC, PingFang SC;
  473. font-weight: 400;
  474. font-size: 30rpx;
  475. color: #757575;
  476. .avatar {
  477. height: 96rpx;
  478. width: 96rpx;
  479. }
  480. &-item {
  481. height: 104rpx;
  482. @include u-flex(row, center, space-between);
  483. display: flex;
  484. align-items: center;
  485. justify-content: space-between;
  486. .arrow_black {
  487. height: 48rpx;
  488. width: 48rpx;
  489. }
  490. }
  491. &-itemr {
  492. @include u-flex(row, center, flex-start);
  493. font-weight: 500;
  494. font-size: 30rpx;
  495. line-height: 36rpx;
  496. position: relative;
  497. }
  498. .wx-head {
  499. position: absolute;
  500. top: 0;
  501. right: 0;
  502. background-color: transparent;
  503. width: 100%;
  504. height: 100%;
  505. &::after {
  506. border: none;
  507. }
  508. }
  509. }
  510. .popupbox {
  511. background-color: #f7f7f7;
  512. font-family: PingFang SC, PingFang SC;
  513. font-weight: 500;
  514. font-size: 28rpx;
  515. color: #333333;
  516. &-head {
  517. padding: 24rpx;
  518. @include u-flex(row, center, space-between);
  519. &-title {
  520. font-size: 30rpx;
  521. }
  522. }
  523. &-cancel {
  524. color: #999;
  525. }
  526. &-confirm {
  527. color: #FF7700;
  528. }
  529. &-body {
  530. min-height: 100rpx;
  531. padding: 24px;
  532. box-sizing: border-box;
  533. }
  534. .inpubox {
  535. background-color: #fff;
  536. }
  537. }
  538. }
  539. </style>