perfectInfo.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. <template>
  2. <view class="container">
  3. <uni-nav-bar id="nav-bar" status-bar="true" @clickLeft="onBack" :title="pageTitle" color="#000000" fixed="true"
  4. :border="false">
  5. <!-- <view slot="left">
  6. <view class=" flex align-center margin-left">
  7. <image class="p-left-arrow" src="../../../static/p-left-arrow.png"></image>
  8. </view>
  9. </view> -->
  10. <view slot="right">
  11. <text class="text-df text-purple margin-right-sm" @tap="onSkip">跳过</text>
  12. </view>
  13. </uni-nav-bar>
  14. <view style="height:6px ;width: 100%; background-color: #f2eff2;"></view>
  15. <!-- 手机端登录,获取验证码 -->
  16. <view class="input-container" style="margin: 32px 102rpx 0 68rpx;">
  17. <view class="make-text-bPurple text-bold margin-bottom" style="font-size: 20px;">完善资料</view>
  18. <view class="text-16px text-gray">请完善您的个人资料,以便于更好的统计数据……</view>
  19. </view>
  20. <view class="input-container" style="margin: 32px 102rpx 0 68rpx;">
  21. <view class="text-bold margin-bottom text-16px">你的性别</view>
  22. <view class="flex justify-start">
  23. <view class="flex justify-between align-center" style="height: 38px;" @tap="onGender(0)">
  24. <image style="width: 38rpx;height: 38rpx;" :src="gender==0?'/static/radio-on.png':'/static/radio-off.png'"></image>
  25. <view class="text-16px margin-left">男</view>
  26. </view>
  27. <view class="flex justify-between align-center" style="height: 38px;margin-left: 143rpx;" @tap="onGender(1)">
  28. <image style="width: 38rpx;height: 38rpx;" :src="gender==1?'/static/radio-on.png':'/static/radio-off.png'"></image>
  29. <view class="text-16px margin-left">女</view>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="input-container" style="margin: 32px 102rpx 0 68rpx;">
  34. <view class="text-bold margin-bottom text-16px">您所在的省份/城市</view>
  35. <view class="flex justify-start align-center" style="margin: 68rpx 0;">
  36. <image style="width: 38rpx;height: 38rpx;" src="../../../static/locationIcon.png"></image>
  37. <view class="text-16px margin-left">{{city.label}}</view>
  38. <view style="margin-left: 10rpx;" @tap="showModal" data-target="showPickerModal" data-type="city">
  39. <image style="width: 38rpx;height: 38rpx;" src="../../../static/locationMore.png"></image>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="flex justify-between perf-bottom-container">
  44. <view class="flex justify-center align-center">
  45. <!-- <image style="width: 10px;height: 10px; margin-left: 38rpx;" src="/static/asterisk.png"></image> -->
  46. <view class="text-grey padding-sm margin-name text-width flex">生日</view>
  47. <view class="text-bold">{{sBirthday}} </view>
  48. </view>
  49. <view class="right-container" @tap="showModal" data-target="showPickerModal" data-type="birthday">
  50. <text class="text-grey text-sm" style="margin: 0 24rpx;">请选择</text>
  51. <view class="only-arrow"></view>
  52. </view>
  53. </view>
  54. <view class="flex justify-between perf-bottom-container">
  55. <view class="flex justify-center align-center">
  56. <!-- <image style="width: 10px;height: 10px; margin-left: 38rpx;" src="/static/asterisk.png"></image> -->
  57. <view class="text-grey padding-sm margin-name text-width flex">身高</view>
  58. <view class="text-bold">{{height}}cm </view>
  59. </view>
  60. <view class="right-container" @tap="showModal" data-target="showPickerModal" data-type="height">
  61. <text class="text-grey text-sm" style="margin: 0 24rpx;">请选择</text>
  62. <view class="only-arrow"></view>
  63. </view>
  64. </view>
  65. <view class="flex justify-between perf-bottom-container">
  66. <view class="flex justify-center align-center">
  67. <!-- <image style="width: 10px;height: 10px; margin-left: 38rpx;" src="/static/asterisk.png"></image> -->
  68. <view class="text-grey padding-sm margin-name text-width flex">体重</view>
  69. <view class="text-bold">{{weight}}kg </view>
  70. </view>
  71. <view class="right-container" @tap="showModal" data-target="showPickerModal" data-type="weight">
  72. <text class="text-grey text-sm" style="margin: 0 24rpx;">请选择</text>
  73. <view class="only-arrow"></view>
  74. </view>
  75. </view>
  76. <view class="btn-row">
  77. <view class="btn-confirm" @tap="onPerfectConfirm">确认绑定</view>
  78. </view>
  79. <view class="cu-modal bottom-modal" :class="modalName=='showPickerModal'?'show':''" @touchmove.stop.prevent="moveHandle">
  80. <view class="cu-dialog" style="border-top-right-radius: 20rpx; border-top-left-radius: 20rpx;">
  81. <myPicker v-if="modalName == 'showPickerModal' ? true:false" :pickerObj="pickerObj" @confirmEvent="onPickerConfirm"
  82. @cancelEvent="hideModal">
  83. </myPicker>
  84. </view>
  85. </view>
  86. </view>
  87. </template>
  88. <script>
  89. import myPicker from '@/components/slambb-picker/slambb-picker.vue';
  90. import pickerData from '@/components/slambb-picker/picker.js';
  91. import config from '@/common/config.js';
  92. import reqUtil from "@/util/util-js/requstUtil.js";
  93. import date from "@/util/util-js/date.js";
  94. import {
  95. mapState
  96. } from 'vuex'
  97. export default {
  98. components: {
  99. myPicker
  100. },
  101. data() {
  102. return {
  103. account: '',
  104. pageTitle: "完善资料",
  105. sBirthday: '',
  106. modalName: null,
  107. //选择器对象
  108. pickerObj: {
  109. pickerLeftList: pickerData.getWeightList().leftList,
  110. pickerRightList: pickerData.getWeightList().rightList,
  111. pickerType: "doubleItem",
  112. pickerUnit: "斤",
  113. pickerTitle: "记体重",
  114. defaultValue: 0
  115. },
  116. bLoading: false,
  117. //是否可以更新
  118. bCanUpdate: false,
  119. }
  120. },
  121. computed: mapState(['bNewUser','height', 'weight', 'birthday', 'city', 'gender', 'userName']),
  122. onLoad() {
  123. let s = this.birthday.replace(/-/g, "/");
  124. var dateTemp = new Date(s);
  125. this.sBirthday = date.formatDate(dateTemp);
  126. if (this.bNewUser) {
  127. this.$store.state.bNewGuide = true;
  128. }
  129. },
  130. methods: {
  131. onBack() {
  132. uni.navigateBack({
  133. delta: 1
  134. })
  135. },
  136. showModal(e) {
  137. this.pikerType = e.currentTarget.dataset.type
  138. switch (this.pikerType) {
  139. case "weight":
  140. this.$set(this.pickerObj, 'pickerLeftList', pickerData.getWeightList().leftList);
  141. this.$set(this.pickerObj, 'pickerRightList', pickerData.getWeightList().rightList);
  142. this.$set(this.pickerObj, 'pickerType', "doubleItem");
  143. this.$set(this.pickerObj, 'pickerUnit', "公斤");
  144. this.$set(this.pickerObj, 'pickerTitle', "记体重");
  145. this.$set(this.pickerObj, 'defaultValue', this.weight);
  146. this.$set(this.pickerObj, 'showInput', true);
  147. break;
  148. case "height":
  149. this.pickerObj = {};
  150. this.$set(this.pickerObj, 'pickerLeftList', pickerData.getHeightList().leftList);
  151. // pickerData.getHeightList().rightList
  152. this.$set(this.pickerObj, 'pickerRightList', []);
  153. this.$set(this.pickerObj, 'pickerType', "singleItem");
  154. this.$set(this.pickerObj, 'pickerUnit', "厘米");
  155. this.$set(this.pickerObj, 'pickerTitle', "记身高");
  156. this.$set(this.pickerObj, 'defaultValue', this.height);
  157. this.$set(this.pickerObj, 'showInput', true);
  158. break;
  159. case "birthday":
  160. this.pickerObj = {};
  161. this.$set(this.pickerObj, 'pickerType', "dateItem");
  162. this.$set(this.pickerObj, 'pickerTitle', "记生日");
  163. this.$set(this.pickerObj, 'showInput', false);
  164. break;
  165. case "gender":
  166. this.pickerObj = {};
  167. this.$set(this.pickerObj, 'pickerLeftList', pickerData.getGenderList().genderList);
  168. this.$set(this.pickerObj, 'pickerRightList', []);
  169. this.$set(this.pickerObj, 'pickerType', "singleItem");
  170. this.$set(this.pickerObj, 'pickerTitle', "性别");
  171. this.$set(this.pickerObj, 'defaultValue', "男");
  172. this.$set(this.pickerObj, 'showInput', false);
  173. break;
  174. case "city":
  175. this.pickerObj = {};
  176. this.$set(this.pickerObj, 'pickerType', "city");
  177. this.$set(this.pickerObj, 'pickerTitle', "省市区");
  178. this.$set(this.pickerObj, 'defaultValue', this.city.value);
  179. this.$set(this.pickerObj, 'showInput', false);
  180. break;
  181. }
  182. this.modalName = e.currentTarget.dataset.target
  183. },
  184. hideModal(e) {
  185. this.modalName = null
  186. },
  187. moveHandle() {
  188. return;
  189. },
  190. onPickerConfirm(data) {
  191. console.log(data);
  192. switch (this.pikerType) {
  193. case "weight":
  194. if (data.value != this.weight) {
  195. this.bCanUpdate = true;
  196. this.$store.state.weight = data.value;
  197. }
  198. break;
  199. case "height":
  200. if (data.value != this.height) {
  201. this.bCanUpdate = true;
  202. this.$store.state.height = data.value;
  203. }
  204. break;
  205. case "birthday":
  206. this.bCanUpdate = true;
  207. let nDate = new Date();
  208. nDate.setFullYear(data.value[0], data.value[1] - 1, data.value[2]);
  209. this.sBirthday = date.formatDate(nDate);
  210. this.$store.state.birthday = date.formatTime(nDate);
  211. break;
  212. case "gender":
  213. if (data.value != this.gender) {
  214. this.bCanUpdate = true;
  215. this.$store.state.gender = data.value;
  216. }
  217. break;
  218. case "city":
  219. if (data.value.cityCode != this.cityCode) {
  220. this.bCanUpdate = true;
  221. this.$store.state.city = data.value;
  222. }
  223. break;
  224. }
  225. this.hideModal();
  226. },
  227. onGender(value) {
  228. // console.log(value);
  229. this.$store.state.gender = value;
  230. },
  231. /**
  232. * 由于性别和生日是有默认值,所以不用检测
  233. */
  234. onCheck() {
  235. if (this.height == 0) {
  236. uni.showToast({
  237. title: "请选择身高",
  238. icon: "none"
  239. })
  240. return false;
  241. } else
  242. if (this.weight == 0) {
  243. uni.showToast({
  244. title: "请选择体重",
  245. icon: "none"
  246. })
  247. return false;
  248. }
  249. return true;
  250. },
  251. onPerfectConfirm() {
  252. let that = this;
  253. if (!that.onCheck()) {
  254. console.log("onCheck false")
  255. return;
  256. }
  257. uni.showToast({
  258. title: "",
  259. icon: "loading",
  260. mask: true,
  261. duration: 10000
  262. })
  263. if (that.bLoading) return;
  264. that.bLoading = true;
  265. let data = {
  266. "username": this.userName,
  267. "birthday": this.birthday,
  268. "gender": this.gender,
  269. "cityCode": this.city.cityCode,
  270. "weight": this.weight,
  271. "height": this.height,
  272. //微信注册时候,更新一次到fitness
  273. "bAddWeightInfo":true
  274. }
  275. reqUtil.requestData(config.URL.USERINFOADD, data, "POST").then(res => {
  276. console.log('requestData USERINFOADD =====', res);
  277. uni.hideToast();
  278. that.bLoading = false;
  279. if (res.code == 0) {
  280. uni.showToast({
  281. title: "更新成功",
  282. mask: true,
  283. duration: 1000
  284. })
  285. // that.bCanUpdate = false;
  286. setTimeout(() => {
  287. that.$store.state.bNewUser = false;
  288. // uni.redirectTo({
  289. // url: "../../personal-page/personal/personal"
  290. // })
  291. uni.redirectTo({
  292. url:'../firstPlan/firstPlan'
  293. })
  294. }, 1000);
  295. }
  296. },
  297. e => {
  298. console.log(e);
  299. that.bLoading = false;
  300. uni.showModal({
  301. title: '错误',
  302. content: '更新数据失败,是否重新更新?',
  303. confirmText: '是的',
  304. success: (res) => {
  305. if (res.confirm) {
  306. that.onPerfectConfirm();
  307. }
  308. }
  309. })
  310. });
  311. },
  312. //跳过
  313. onSkip(){
  314. let that = this;
  315. uni.showToast({
  316. title: "",
  317. icon: "loading",
  318. mask: true,
  319. duration: 10000
  320. })
  321. if (that.bLoading) return;
  322. that.bLoading = true;
  323. let data = {
  324. "username": this.userName,
  325. "birthday": this.birthday,
  326. "gender": this.gender,
  327. "cityCode": this.city.cityCode,
  328. "weight": this.weight,
  329. "height": this.height,
  330. //微信注册时候,更新一次到fitness
  331. "bAddWeightInfo":true
  332. }
  333. reqUtil.requestData(config.URL.USERINFOADD, data, "POST").then(res => {
  334. console.log('requestData USERINFOADD =====', res);
  335. uni.hideToast();
  336. that.bLoading = false;
  337. if (res.code == 0) {
  338. uni.showToast({
  339. title: "",
  340. icon:"loading",
  341. mask: true,
  342. duration: 1000
  343. })
  344. // that.bCanUpdate = false;
  345. setTimeout(() => {
  346. that.$store.state.bNewUser = false;
  347. // uni.redirectTo({
  348. // url: "../../personal-page/personal/personal"
  349. // })
  350. uni.redirectTo({
  351. url:'../firstPlan/firstPlan'
  352. })
  353. }, 1000);
  354. }
  355. },
  356. e => {
  357. console.log(e);
  358. that.bLoading = false;
  359. uni.showModal({
  360. title: '错误',
  361. content: '更新数据失败,是否重新更新?',
  362. confirmText: '是的',
  363. success: (res) => {
  364. if (res.confirm) {
  365. that.onPerfectConfirm();
  366. }
  367. }
  368. })
  369. });
  370. }
  371. }
  372. }
  373. </script>
  374. <style>
  375. .btn-row {
  376. display: flex;
  377. justify-content: center;
  378. align-items: center;
  379. margin: 102rpx 0;
  380. }
  381. .container {
  382. position: absolute;
  383. top: 0;
  384. bottom: 0;
  385. left: 0;
  386. right: 0;
  387. background-color: #FFFFFF;
  388. }
  389. .input-container {
  390. /* border-bottom: 1rpx solid #e7e9eb; */
  391. }
  392. .btn-confirm {
  393. width: 636rpx;
  394. height: 102rpx;
  395. background-color: rgba(151, 151, 255, 1);
  396. border-radius: 10px;
  397. display: flex;
  398. justify-content: center;
  399. align-items: center;
  400. font-size: 17px;
  401. color: #FFFFFF;
  402. }
  403. .right-container {
  404. display: flex;
  405. flex-direction: row;
  406. justify-content: center;
  407. align-items: center;
  408. position: relative;
  409. }
  410. .perf-bottom-container {
  411. border: 1rpx solid #EEEEEE;
  412. border-radius: 10px;
  413. height: 50px;
  414. margin: 19rpx 41rpx 0 41rpx;
  415. }
  416. </style>