family_info.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <view>
  3. <view class="top-back"></view>
  4. <view class="content">
  5. <view class="margin-top" >
  6. <uv-gap height="10" ></uv-gap>
  7. <!-- <p style="font-size: 25px;">个人信息</p> -->
  8. <uv-divider class="head-text" :text="title" textSize="26" textColor="#000"></uv-divider>
  9. <uv-gap height="10" ></uv-gap>
  10. <view class="margin-top"><!-- 昵称 -->
  11. <view class="title">昵称</view>
  12. <uv-gap height="10" ></uv-gap>
  13. <view class="flex justify-between">
  14. <input maxlength=20 type="text" style="width: 60%;" v-model="family.name"
  15. placeholder-style="color: #cccccc; font-size: 24px; font-weight: 100;" placeholder="请输入昵称"
  16. @click="$content_check.checkLogin" :disabled="$content_check.isDisabled"
  17. @blur="inputBindBlur('name')"
  18. />
  19. <image src="@/static/img/user.png" style="background-color: #fff;width: 15vw;height: 15vw;margin: 0 30px 5px;"></image>
  20. </view>
  21. </view>
  22. <uv-divider customStyle="margin: 0 0"></uv-divider>
  23. <uv-gap height="20" ></uv-gap>
  24. <view style="margin-bottom: -20upx;"><!-- 关系 -->
  25. <view class="title">关系</view>
  26. <uv-gap height="10" ></uv-gap>
  27. <view class="flex justify-between">
  28. <input maxlength=10 type="text" style="width: 60%;" v-model="family.relationship"
  29. placeholder-style="color: #cccccc; font-size: 24px; font-weight: 100;" placeholder="请输入成员关系"
  30. @click="$content_check.checkLogin" :disabled="$content_check.isDisabled"
  31. @blur="inputBindBlur('relationship')"
  32. />
  33. <image src="@/static/img/family.png" style="background-color: #fff;width: 15vw;height: 15vw;margin: 0 30px 15px;"></image>
  34. </view>
  35. </view>
  36. <uv-divider customStyle="margin: 0 0"></uv-divider>
  37. <uv-gap height="20" ></uv-gap>
  38. <view><!-- 性别 -->
  39. <view>
  40. <view class="title">性别</view>
  41. <uv-gap height="10" ></uv-gap>
  42. <view class="flex justify-between">
  43. <input placeholder="请选择性别" disabled="disabled" style="width: 60%;" name="input" v-model="gender" placeholder-style="color: #cccccc; font-size: 24px; font-weight: 100;" @click="changegender"></input>
  44. <image @click="confirm({'indexs': [0]})" src="@/static/img/man.png" style="background-color: #fff;width: 15vw;height: 15vw;"></image>
  45. <image @click="confirm({'indexs': [1]})" src="@/static/img/woman.png" style="background-color: #fff;width: 15vw;height: 15vw;"></image>
  46. </view>
  47. </view>
  48. <uv-picker ref="picker" :columns="columns" @confirm="confirm"></uv-picker>
  49. </view>
  50. <uv-divider customStyle="margin: 0 0"></uv-divider>
  51. <uv-gap height="20" ></uv-gap>
  52. <view style="margin-bottom: -20upx;"><!-- 年龄 -->
  53. <view class="title">年龄</view>
  54. <uv-gap height="10" ></uv-gap>
  55. <input maxlength=3 type="number" v-model="family.age" placeholder-style="color: #cccccc; font-size: 24px; font-weight: 100;" placeholder="请输入年龄" />
  56. </view>
  57. <uv-divider customStyle="margin: 0 0"></uv-divider>
  58. <uv-gap height="10" ></uv-gap>
  59. </view>
  60. <uv-modal width=260 ref="modal" title="请将信息填写完整" @confirm="confirm"></uv-modal>
  61. </view>
  62. <uv-button @click="update()" customStyle="position: fixed; bottom: 40px;width: calc(100vw - 60px);margin: 0 30px" shape="circle" size="large" color="#1678ff">{{button_text}}</uv-button>
  63. </view>
  64. </template>
  65. <script>
  66. export default {
  67. onLoad(options) {
  68. // 获取传递的对象参数,使用decodeURIComponent解码,并转为对象
  69. if ('id' in options) {
  70. let id = JSON.parse(decodeURIComponent(options.id));
  71. this.family.id = id;
  72. this.family = uni.getStorageSync("family_list")[id];
  73. this.gender = this.family.gender === 0 ? '男' : '女';
  74. }
  75. else{
  76. let title = '新增成员';
  77. let button_text = '新增';
  78. uni.setNavigationBarTitle({title});
  79. this.title = title;
  80. this.button_text = button_text;
  81. let family_list = uni.getStorageSync('family_list');
  82. if(!family_list || Object.keys(family_list).length == 0) this.family.id = 1;
  83. else{
  84. let keys = Object.keys(family_list);
  85. this.family.id = Number(keys[keys.length - 1]) + 1;
  86. }
  87. }
  88. },
  89. data() {
  90. return {
  91. title: '成员资料',
  92. button_text: '保存',
  93. family:{
  94. id: null,
  95. name: '',
  96. relationship: '',
  97. gender: '',
  98. age: '',
  99. },
  100. gender: '',
  101. columns: [['男','女']],
  102. }
  103. },
  104. methods: {
  105. inputBindBlur(type){
  106. this.$content_check.textCheck(this.family[type], this, 'family.' + type);
  107. },
  108. changegender() {
  109. this.$refs.picker.open();
  110. },
  111. confirm(e) {
  112. this.family.gender = e['indexs'][0];
  113. this.gender = this.family.gender === 0 ? '男' : '女';
  114. },
  115. async update(){
  116. if(this.family.name.length == 0){
  117. console.log("用户名无效");
  118. uni.showToast({duration:1500,icon:"none",title: '请输入用户名'});
  119. return ;
  120. }
  121. //用户名必须由1到20个字符组成,并且只能包含字母、数字、汉字。
  122. const regex = /^[a-zA-Z0-9\u4e00-\u9fa5]{1,20}$/;
  123. const isValid = regex.test(this.family.name);
  124. if (!isValid) {
  125. console.log("用户名无效");
  126. uni.showToast({duration:1500,icon:"none",title: '用户名只能包含字母和数字'});
  127. return ;
  128. }
  129. console.log("用户名有效");
  130. let isCheck = await this.$content_check.textCheck(this.family.name, this, 'family.name');
  131. console.log('isCheck: ',isCheck);
  132. if(isCheck !== true) return ;
  133. isCheck = await this.$content_check.textCheck(this.family.relationship, this, 'family.relationship');
  134. console.log('isCheck: ',isCheck);
  135. if(isCheck !== true) return ;
  136. let family_list = uni.getStorageSync('family_list');
  137. if(!family_list || Object.keys(family_list).length == 0) family_list = {};
  138. family_list[this.family.id] = this.family;
  139. console.log('family_list: ',family_list);
  140. uni.setStorageSync('family_list', family_list);
  141. uni.showToast({duration:1000,icon:'success',title: '保存成功 !'});
  142. setTimeout(() => uni.navigateBack(), 1300);
  143. }
  144. }
  145. }
  146. </script>
  147. <style>
  148. page {
  149. height: 100vh;
  150. }
  151. .top-back{
  152. height: 30px;
  153. background-color: #1678ff;
  154. color: #fff;
  155. margin-bottom: -40px;
  156. }
  157. .head-text{
  158. letter-spacing: 5px;
  159. font-weight: 600;
  160. }
  161. .title{
  162. letter-spacing: 2px;
  163. color: #8c92ad;
  164. font-size: 18px;
  165. }
  166. input {
  167. letter-spacing: 1px;
  168. width: 100%;
  169. height: 8vh;
  170. padding-bottom: 5px;
  171. font-size: 24px;
  172. font-weight: 600;
  173. font-weight: 400;
  174. color: #000;
  175. outline: none; /* 移除聚焦时的默认边框 */
  176. }
  177. .content {
  178. padding: 0 35px;
  179. border-radius: 25px;
  180. border: none;
  181. background-color: #ffffff;
  182. }
  183. .content image:active {
  184. transform: translateY(2px) translateX(2px);
  185. }
  186. </style>