康巴易测肤/伤疤uniapp小程序类
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

info.vue 5.9KB

1ヶ月前
4週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
4週間前
4週間前
1ヶ月前
4週間前
4週間前
4週間前
1ヶ月前
4週間前
1ヶ月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <view class="info">
  3. <view class="main">
  4. <view class="avatar">
  5. <u-avatar :src="avatarSrc" size="70"></u-avatar>
  6. </view>
  7. <view class="form-box">
  8. <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm">
  9. <u-form-item required prop="name" borderBottom>
  10. <u--input v-model="form.name" type="text" maxlength="15" border placeholder="请输入昵称"></u--input>
  11. </u-form-item>
  12. <u-form-item required prop="gender" borderBottom @click="showGender = true;">
  13. <u--input v-model="form.gender" disabled disabledColor="#ffffff" placeholder="请选择性别"
  14. border></u--input>
  15. <u-icon slot="right" name="arrow-right"></u-icon>
  16. </u-form-item>
  17. <u-form-item required labelWidth="80" prop="date" borderBottom @click="showDate = true">
  18. <u--input v-model="form.date" disabled disabledColor="#ffffff" placeholder="请选择出生日期"
  19. border></u--input>
  20. <u-icon slot="right" name="arrow-right"></u-icon>
  21. </u-form-item>
  22. <u-form-item borderBottom>
  23. <u-input v-model="form.height" border placeholder="请输入身高" type="number" maxlength="3"></u-input>
  24. </u-form-item>
  25. <u-form-item borderBottom>
  26. <u--input v-model="form.weight" border placeholder="请输入体重" type="number"
  27. maxlength="3"></u--input>
  28. </u-form-item>
  29. </u--form>
  30. </view>
  31. <!-- 性别弹窗 -->
  32. <u-action-sheet :actions="genderList" @select="selectClickGender" :show="showGender"></u-action-sheet>
  33. <!-- 出生日期弹窗 -->
  34. <u-datetime-picker ref="datetimePicker" :show="showDate" v-model="pickerDate" mode="date" :minDate="minDate"
  35. :maxDate="maxDate" confirmColor="#E19F4B" @confirm="onConfirmDate" @cancel="onCancelDate"
  36. :formatter="formatter"></u-datetime-picker>
  37. <view class="action-box">
  38. <view class="btn-box">
  39. <u-button @click="onSubmit()" shape="circle" :color="bgthemeColor" type="info" size="large">
  40. <text :style="{ color: themeColor, fontSize: '32rpx', fontWeight: 'bold' }">创建用户</text>
  41. </u-button>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. export default {
  49. data() {
  50. return {
  51. checked: true,
  52. showDate: false,
  53. showGender: false,
  54. pickerDate: Number(new Date()),
  55. form: {
  56. name: '',
  57. gender: '',
  58. date: '',
  59. height: '',
  60. weight: ''
  61. },
  62. genderList: [
  63. {
  64. name: '男',
  65. subname: "",
  66. color: '#000',
  67. fontSize: '16',
  68. },
  69. {
  70. name: '女',
  71. subname: "",
  72. color: '#000',
  73. fontSize: '16'
  74. },
  75. ],
  76. rules: {
  77. name: [{
  78. required: true,
  79. message: '请输入昵称',
  80. trigger: ['blur', 'change']
  81. }],
  82. gender: [{
  83. required: true,
  84. message: '请选择性别',
  85. trigger: ['blur', 'change']
  86. }],
  87. date: [{
  88. required: true,
  89. message: '请选择出生日期',
  90. trigger: ['blur', 'change']
  91. }],
  92. }
  93. }
  94. },
  95. onReady() {
  96. //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
  97. this.$refs.uForm.setRules(this.rules)
  98. this.$refs.datetimePicker.setFormatter(this.formatter)
  99. },
  100. computed: {
  101. themeColor() {
  102. return this.$themeColor
  103. },
  104. bgthemeColor() {
  105. return '#333'
  106. },
  107. avatarSrc() {
  108. return this.$store.state.user.userInfo.avatarSrc || require('../../static/tabbar/user_default.png')
  109. },
  110. minDate() {
  111. const now = new Date();
  112. const minDate = new Date(now.getFullYear() - 50, now.getMonth(), now.getDate());
  113. return minDate
  114. },
  115. maxDate() {
  116. const now1 = new Date();
  117. const maxDate = new Date(now1.getFullYear() - 10, now1.getMonth(), now1.getDate());
  118. return maxDate.getTime()
  119. },
  120. },
  121. methods: {
  122. formatter(type, value) {
  123. if (type === 'year') {
  124. return `${value}年`
  125. }
  126. if (type === 'month') {
  127. return `${value}月`
  128. }
  129. if (type === 'day') {
  130. return `${value}日`
  131. }
  132. return value
  133. },
  134. onSubmit() {
  135. console.log("this.form", this.form);
  136. let that = this;
  137. this.$refs.uForm.validate().then( async valid => {
  138. if(valid) {
  139. uni.showLoading({
  140. title: '创建中',
  141. mask: true,
  142. })
  143. setTimeout(() => {
  144. // 缓存到本地
  145. that.$store.commit('SET_USERINFO',that.form);
  146. that.$store.commit('saveAll');
  147. uni.showToast({
  148. title: "创建成功",
  149. icon: 'success'
  150. });
  151. uni.switchTab({
  152. url: '/pages/index/index',
  153. })
  154. },1500)
  155. }
  156. }).catch(errors => {
  157. console.log("errors", errors);
  158. })
  159. },
  160. selectClickGender(e) {
  161. console.log("e", e);
  162. this.form.gender = e.name;
  163. this.showGender = false
  164. },
  165. onConfirmDate(date) {
  166. console.log("date", date);
  167. this.form.date = this.$util.formateDate('yyyy-mm-dd', date.value);
  168. this.showDate = false;
  169. },
  170. onCancelDate() {
  171. this.showDate = false;
  172. }
  173. }
  174. }
  175. </script>
  176. <style lang="scss">
  177. .info {
  178. position: relative;
  179. height: 100vh;
  180. width: 100vw;
  181. overflow: hidden;
  182. .main {
  183. padding: 40rpx;
  184. .avatar {
  185. width: 100%;
  186. display: flex;
  187. justify-content: center;
  188. align-items: center;
  189. padding: 20rpx 0;
  190. }
  191. .form-box {
  192. .u-form-item {
  193. padding: 0 20rpx;
  194. border-radius: 50rpx;
  195. border: 1rpx solid $uni-text-color-grey;
  196. margin: 20rpx 0;
  197. }
  198. .u-form-item__body__left {
  199. height: 80rpx !important;
  200. width: 10rpx !important;
  201. .u-form-item__body__left__content__required {
  202. left: -10rpx !important;
  203. top: -10rpx !important;
  204. }
  205. }
  206. .u-form-item__body__right__message {
  207. margin-left: 20rpx !important;
  208. }
  209. }
  210. .action-box {
  211. width: 100%;
  212. position: fixed;
  213. bottom: 30rpx;
  214. left: 0;
  215. .btn-box {
  216. padding: 0 40rpx;
  217. margin-top: 20rpx;
  218. display: flex;
  219. justify-content: center;
  220. align-items: center;
  221. text {
  222. font-size: 36rpx;
  223. }
  224. .black {
  225. color: $uni-text-color;
  226. }
  227. .gray {
  228. color: $uni-text-color-grey;
  229. }
  230. }
  231. }
  232. }
  233. }
  234. </style>