add-baby.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <view class="user-setting-box">
  3. <!-- #ifndef MP-TOUTIAO -->
  4. <Navbar background-color="transparent" color="#333" title="添加宝宝"></Navbar>
  5. <!-- #endif -->
  6. <view class="bg"></view>
  7. <view class="content">
  8. <view class="baby-top">
  9. <view class="pic-box box">
  10. <view class="label">
  11. <view class="upload-pic-box" @click="chooseImg">
  12. <image class="avatar" :src="form.avatar" mode="aspectFill"></image>
  13. <view class="camera-box">
  14. <IconText class="icon" :code="`\ue8a9`" size="14" color="#fff"></IconText>
  15. </view>
  16. </view>
  17. </view>
  18. <view class="tip">点击上传宝宝头像</view>
  19. </view>
  20. <view class="name-box box">
  21. <view class="label">
  22. 宝宝昵称
  23. </view>
  24. <input v-model="form.nickname" type="text" class="input" placeholder="此处输入宝宝昵称"/>
  25. </view>
  26. <view class="gender-box box">
  27. <view class="label"></view>
  28. <view class="gender-select">
  29. <view class="item" @click="handleSelectGender(0)">
  30. <IconText class="icon" :code="`\ue842`" v-if="!form.gender" size="12" color="#6B95FF"></IconText>
  31. <IconText class="icon" :code="`\ue84e`" size="12" color="#999" v-else></IconText>
  32. 小孩
  33. </view>
  34. <view class="item" @click="handleSelectGender(1)">
  35. <IconText class="icon" :code="`\ue842`" v-if="form.gender === 1" size="12" color="#6B95FF"></IconText>
  36. <IconText class="icon" :code="`\ue84e`" size="12" color="#999" v-else></IconText>
  37. 小王子
  38. </view>
  39. <view class="item" @click="handleSelectGender(2)">
  40. <IconText class="icon" :code="`\ue842`" v-if="form.gender === 2" size="12" color="#6B95FF"></IconText>
  41. <IconText class="icon" :code="`\ue84e`" size="12" color="#999" v-else></IconText>
  42. 小公主
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="info-box top-border-radius top10">
  48. <view class="label">出生体重</view>
  49. <view class="right">
  50. <input v-model="form.birthWeight" type="text" class="input" placeholder="此处输入体重"/>
  51. </view>
  52. </view>
  53. <view class="info-box">
  54. <view class="label">出生日期</view>
  55. <view class="right">
  56. <!-- <uni-datetime-picker v-model="form.birthday" :border="false" type="date" class="date"/> -->
  57. <uni-datetime-picker v-model="form.birthday" :border="false" type="date" class="date-box">
  58. <view class="date">
  59. {{form.birthday || '请选择日期'}}
  60. <IconText :code="`\ue88e`" class="icon" size="12" color="#C6C5CB"></IconText>
  61. </view>
  62. </uni-datetime-picker>
  63. </view>
  64. </view>
  65. <view class="info-box" v-if="type !== 'register'">
  66. <view class="label">是否过敏</view>
  67. <view class="right">
  68. <switch @change="changeAllergy" :checked="form.allergy === 1" style="transform:scale(0.7)"/>
  69. </view>
  70. </view>
  71. <view class="info-box bottom-border-radius" v-if="type !== 'register'">
  72. <view class="label">宝宝体质</view>
  73. <view class="right">
  74. <input v-model="form.constitution" type="text" class="input" placeholder="此处输入宝宝体质"/>
  75. </view>
  76. </view>
  77. <view class="info-box">
  78. <view class="label">喂养方式</view>
  79. <view class="right">
  80. <picker @change="changeFeedMode" :value="feedModeIndex" :range="feedModeList" range-key="name">
  81. <view class="date">
  82. {{feedModeList[feedModeIndex].name || '请选择'}}
  83. <IconText :code="`\ue88e`" class="icon" size="12" color="#C6C5CB"></IconText>
  84. </view>
  85. </picker>
  86. </view>
  87. </view>
  88. <view class="info-box bottom-border-radius">
  89. <view class="label">选择奶粉</view>
  90. <view class="right select-milk-powder">
  91. <input v-model="form.constitution" type="text" class="input" placeholder="此处输入奶粉名称"/>
  92. <view class="btn">选择</view>
  93. </view>
  94. </view>
  95. <view class="info-box top-border-radius bottom-border-radius top10">
  96. <view class="label">所在家庭</view>
  97. <view class="right">
  98. <picker @change="changeFamily" :value="familyIndex" :range="familyList" range-key="name">
  99. <view class="date">
  100. {{familyList[familyIndex].name || '请选择'}}
  101. <IconText :code="`\ue88e`" class="icon" size="12" color="#C6C5CB"></IconText>
  102. </view>
  103. </picker>
  104. </view>
  105. </view>
  106. </view>
  107. <view class="fixed-bottom" >
  108. <view class="btn" @click="deleteBabyModal" v-if="bid">删除</view>
  109. <view class="solid-btn" @click="handleConfirm">保存</view>
  110. </view>
  111. <ShowModal ref="deletePopup" title="提示" @submit="deleteBaby" leftBtnText="取消" content="确认后宝宝数据将清空,是否确认删除?" btnText="确认" />
  112. </view>
  113. </template>
  114. <script lang="ts">
  115. import {
  116. Component,
  117. Mixins
  118. } from 'vue-property-decorator';
  119. import loginMixin from '@/common/mixins/loginMixin.ts';
  120. // import {
  121. // namespace
  122. // } from 'vuex-class';
  123. // const baseModule = namespace('base');
  124. @Component({
  125. filters: {
  126. phoneFormat(val : any) {
  127. if (!+val) return '';
  128. let arr = val.split("");
  129. let pre = arr.slice(0, 3).join("");
  130. let next = arr.reverse().slice(0, 4).reverse().join("");
  131. return pre + "****" + next;
  132. },
  133. uidFormat(val : any) {
  134. if (!val) return '';
  135. let str = val + '';
  136. let length = 6 - str.length;
  137. for (let i = 0; i < length; i++) {
  138. str = '0' + str;
  139. }
  140. return 'QY' + str;
  141. }
  142. }
  143. })
  144. export default class UserSetting extends Mixins(loginMixin) {
  145. // @baseModule.Getter('_userInfo') _userInfo: any;
  146. gender: any = 1;
  147. constitutionList: any = [];
  148. familyList: any = []
  149. form: any = {
  150. avatar: '',
  151. nickname: '',
  152. gender: 0,
  153. birthday: '',
  154. birthWeight: null,
  155. allergy: 2,
  156. constitution: '',
  157. fId: null,
  158. };
  159. constitutionIndex: any = null;
  160. familyIndex: any = null;
  161. bid: any = null;
  162. type: any = '';
  163. feedModeList: any = [
  164. {
  165. name: '母乳',
  166. value: 1
  167. },
  168. {
  169. name: '配方奶',
  170. value: 2
  171. },
  172. {
  173. name: '混合',
  174. value: 3
  175. }
  176. ];
  177. feedModeIndex: any = null;
  178. onShow() {
  179. }
  180. onLoad(){
  181. this.type = this.$Route.query.type;
  182. if (this.$Route.query.bid) {
  183. this.bid = +this.$Route.query.bid;
  184. this.getBabyInfo();
  185. }
  186. }
  187. updatePhone() {
  188. // uni.showToast({
  189. // title: '请联系后台客服修改手机号',
  190. // icon: 'none'
  191. // })
  192. }
  193. getBabyInfo(){
  194. uni.showLoading({
  195. title: '加载中',
  196. });
  197. this.$http.get({
  198. url: this.$api.getBabyInfo,
  199. data: {
  200. bid: this.bid
  201. }
  202. }).then((res: any) => {
  203. for(let key in this.form){
  204. this.form[key] = res[key];
  205. }
  206. uni.hideLoading();
  207. })
  208. }
  209. changeFeedMode(e: any){
  210. this.feedModeIndex = e.detail.value;
  211. this.form.feedMode = this.feedModeList[e.detail.value].value;
  212. }
  213. getCode() {
  214. return new Promise((resolve : any, reject : any) => {
  215. uni.login({
  216. provider: 'weixin',
  217. success: (eve) => {
  218. resolve(eve);
  219. },
  220. fail: (err) => {
  221. console.log(err);
  222. reject();
  223. }
  224. });
  225. })
  226. }
  227. handleSelectGender(gender: any){
  228. this.form.gender = gender;
  229. }
  230. chooseImg() {
  231. uni.chooseImage({
  232. count: 1, //默认9
  233. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  234. success: (res) => {
  235. const tempFilePaths : any = res.tempFilePaths;
  236. uni.showLoading({
  237. title: '上传中...'
  238. });
  239. this.$http
  240. .upPic({
  241. filePath: res.tempFilePaths[0]
  242. })
  243. .then((res : any) => {
  244. uni.hideLoading();
  245. this.form.avatar = res;
  246. })
  247. .catch((err : any) => {
  248. uni.hideLoading();
  249. console.log(err);
  250. });
  251. }
  252. });
  253. }
  254. changeConstitution(e: any){
  255. console.log(e);
  256. this.constitutionIndex = e.detail.value;
  257. this.form.constitution = this.constitutionList[e.detail.value];
  258. }
  259. changeFamily(e: any){
  260. this.familyIndex = e.detail.value;
  261. this.form.fId = this.familyList[e.detail.value].id;
  262. }
  263. changeAllergy(e: any){
  264. console.log(e)
  265. this.form.allergy = e.detail.value ? 1 : 2;
  266. }
  267. deleteBabyModal(){
  268. (this.$refs.deletePopup as any).open();
  269. }
  270. deleteBaby(){
  271. uni.showLoading({
  272. title: '加载中',
  273. });
  274. this.$http.delete({
  275. url: this.$api.deleteBaby,
  276. data: {
  277. bid: this.bid
  278. }
  279. }).then((res: any) => {
  280. this.$Router.back(1);
  281. uni.hideLoading();
  282. })
  283. }
  284. handleConfirm(){
  285. console.log(this.form);
  286. uni.showLoading({
  287. title: '加载中',
  288. });
  289. let url : string = 'addBaby';
  290. let method : string = 'post';
  291. let data: any = {
  292. ...this.form,
  293. birthWeight: +this.form.birthWeight
  294. };
  295. if (this.bid) {
  296. url = 'updateBaby';
  297. method = 'put';
  298. data.bid = this.bid;
  299. }
  300. this.$http[method]({
  301. url: this.$api[url],
  302. data: data
  303. }).then((res: any) => {
  304. this.$Router.back(1);
  305. uni.hideLoading();
  306. })
  307. }
  308. }
  309. </script>
  310. <style lang="scss" scoped>
  311. page{
  312. background: #f5f5f5;
  313. }
  314. .user-setting-box {
  315. // background: #F5F5F5;
  316. height: 100vh;
  317. @include flex-y(flex-start);
  318. .bg{
  319. width: 100%;
  320. height: vw(300);
  321. background: linear-gradient(162.34deg, rgba(232, 237, 255, 1) 0%, rgba(244, 230, 255, 1) 47.75%, rgba(247, 242, 255, 1) 82.84%, rgba(251, 246, 252, 1) 100%);
  322. position: absolute;
  323. top: 0;
  324. z-index: -1;
  325. }
  326. .content {
  327. width: 100%;
  328. flex: 1;
  329. // padding: 0 vw(10);
  330. box-sizing: border-box;
  331. @include flex-y(flex-start);
  332. .baby-top{
  333. width: vw(355);
  334. background: #fff;
  335. margin-top: vw(60);
  336. border-radius: vw(10);
  337. .box{
  338. padding-left: vw(20);
  339. padding-right: vw(10);
  340. @include flex-x(flex-start);
  341. .label{
  342. width: vw(110);
  343. @include word-vw(14, #333);
  344. @include flex-x(flex-start);
  345. }
  346. }
  347. .pic-box{
  348. height: vw(60);
  349. .label{
  350. height: 100%;
  351. position: relative;
  352. }
  353. .upload-pic-box{
  354. @include wh(88, 88);
  355. border-radius: vw(44);
  356. border: vw(2) solid #fff;
  357. box-shadow: 0px 6px 16px rgba(44, 0, 242, 0.16);
  358. background: #E3E3E3;
  359. position: absolute;
  360. bottom: vw(10);
  361. // overflow: hidden;
  362. .avatar{
  363. @include wh(88, 88);
  364. border-radius: vw(44);
  365. }
  366. .camera-box{
  367. @include wh(24, 24);
  368. border-radius: vw(12);
  369. background: #333;
  370. @include flex-x(center);
  371. position: absolute;
  372. bottom: vw(3);
  373. right: vw(3);
  374. }
  375. }
  376. .tip{
  377. @include word-vw(14, #ccc);
  378. }
  379. }
  380. .name-box{
  381. height: vw(60);
  382. .input{
  383. flex: 1;
  384. height: vw(40);
  385. background: #F6F6F6;
  386. border-radius: vw(5);
  387. text-align: center;
  388. font-size: vw(14);
  389. }
  390. }
  391. .gender-box{
  392. height: vw(44);
  393. .gender-select{
  394. @include flex-x(flex-start);
  395. @include word-vw(14, #333);
  396. .item{
  397. @include flex-x(flex-start);
  398. margin-right: vw(12);
  399. .icon{
  400. margin-right: vw(3);
  401. }
  402. }
  403. }
  404. }
  405. }
  406. .info-box{
  407. width: vw(355);
  408. height: vw(56);
  409. background: #fff;
  410. @include flex-x();
  411. padding-left: vw(20);
  412. padding-right: vw(10);
  413. box-sizing: border-box;
  414. @include word-vw(14, #333);
  415. margin-top: vw(1);
  416. &.top10{
  417. margin-top: vw(10);
  418. }
  419. &.top-border-radius{
  420. border-top-right-radius: vw(10);
  421. border-top-left-radius: vw(10);
  422. }
  423. &.bottom-border-radius{
  424. border-bottom-right-radius: vw(10);
  425. border-bottom-left-radius: vw(10);
  426. }
  427. .right{
  428. width: vw(210);
  429. @include flex-x(flex-end);
  430. .input{
  431. width: 100%;
  432. height: vw(40);
  433. border-radius: vw(5);
  434. background: #F6F6F6;
  435. text-align: center;
  436. font-size: vw(14);
  437. }
  438. /deep/.uni-date{
  439. @include flex-x(flex-end);
  440. }
  441. .date{
  442. width: vw(100);
  443. @include flex-x(flex-end);
  444. .icon{
  445. margin-left: vw(3);
  446. }
  447. }
  448. &.select-milk-powder{
  449. background: #F6F6F6;
  450. .input{
  451. flex: 1;
  452. margin-right: vw(10);
  453. }
  454. .btn{
  455. @include wh(56, 30);
  456. border-radius: vw(3);
  457. background: #5283FF;
  458. @include word-vw(12, #fff);
  459. @include flex-x(center);
  460. margin-right: vw(5);
  461. }
  462. }
  463. }
  464. }
  465. }
  466. .fixed-bottom {
  467. height: vw(60);
  468. width: 100%;
  469. // background: #fff;
  470. @include flex-x(center);
  471. padding: 0 vw(15);
  472. box-sizing: border-box;
  473. .btn{
  474. @include solid-btn(125, 50, #787878);
  475. border-radius: vw(25);
  476. margin-right: vw(15);
  477. background: #fff;
  478. }
  479. .solid-btn {
  480. background: $bk-color;
  481. @include solid-btn(345, 50, #333);
  482. border-radius: vw(25);
  483. @include word-vw(14, #fff);
  484. flex: 1;
  485. }
  486. }
  487. }
  488. </style>