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

info.vue 6.5KB

1ヶ月前
4週間前
4週間前
4週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
4週間前
1ヶ月前
4週間前
4週間前
4週間前
1ヶ月前
1ヶ月前
4週間前
4週間前
4週間前
4週間前
4週間前
4週間前
4週間前
4週間前
1ヶ月前
4週間前
1ヶ月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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" :closeOnClickOverlay="true" :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' }">{{actionText}}</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. action: '',
  94. }
  95. },
  96. onReady() {
  97. //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
  98. this.$refs.uForm.setRules(this.rules)
  99. this.$refs.datetimePicker.setFormatter(this.formatter)
  100. },
  101. computed: {
  102. themeColor() {
  103. return this.$themeColor
  104. },
  105. bgthemeColor() {
  106. return '#333'
  107. },
  108. avatarSrc() {
  109. return this.$store.state.user.userInfo.avatarSrc || require('../../static/tabbar/user_default.png')
  110. },
  111. minDate() {
  112. const now = new Date();
  113. const minDate = new Date(now.getFullYear() - 50, now.getMonth(), now.getDate());
  114. return minDate
  115. },
  116. maxDate() {
  117. const now1 = new Date();
  118. const maxDate = new Date(now1.getFullYear() - 10, now1.getMonth(), now1.getDate());
  119. return maxDate.getTime()
  120. },
  121. actionText() {
  122. return this.action === 'update' ? '修改资料': '创建用户'
  123. },
  124. userInfo() {
  125. return this.$store.state.user.userInfo
  126. },
  127. },
  128. onLoad(props) {
  129. if(props) {
  130. this.action = props.action;
  131. if(props.action === 'update' && this.userInfo) {
  132. this.form = {... this.userInfo}
  133. this.pickerDate = new Date(this.userInfo.date)
  134. /* this.form.date = new Date(this.userInfo.date).getTime() */
  135. }
  136. console.log("this.action", this.action);
  137. }
  138. },
  139. methods: {
  140. formatter(type, value) {
  141. if (type === 'year') {
  142. return `${value}年`
  143. }
  144. if (type === 'month') {
  145. return `${value}月`
  146. }
  147. if (type === 'day') {
  148. return `${value}日`
  149. }
  150. return value
  151. },
  152. onSubmit() {
  153. console.log("this.form", this.form);
  154. let that = this;
  155. this.$refs.uForm.validate().then( async valid => {
  156. if(valid) {
  157. uni.showLoading({
  158. title: that.action === 'update' ? '修改中': '创建中',
  159. mask: true,
  160. })
  161. setTimeout(() => {
  162. // 缓存到本地
  163. that.$store.commit('SET_USERINFO', that.form);
  164. that.$store.commit('saveAll');
  165. uni.showToast({
  166. title: that.action === 'update' ? '修改成功' : "创建成功",
  167. icon: 'success'
  168. });
  169. }, 1000)
  170. setTimeout(() => {
  171. uni.switchTab({
  172. url: '/pages/index/index',
  173. })
  174. }, 2000)
  175. }
  176. }).catch(errors => {
  177. console.log("errors", errors);
  178. })
  179. },
  180. selectClickGender(e) {
  181. console.log("e", e);
  182. this.form.gender = e.name;
  183. this.showGender = false
  184. },
  185. onConfirmDate(date) {
  186. console.log("date", date);
  187. this.form.date = this.$util.formateDate('yyyy-mm-dd', date.value);
  188. this.showDate = false;
  189. },
  190. onCancelDate() {
  191. this.showDate = false;
  192. }
  193. }
  194. }
  195. </script>
  196. <style lang="scss">
  197. .info {
  198. position: relative;
  199. height: 100vh;
  200. width: 100vw;
  201. overflow: hidden;
  202. .main {
  203. padding: 40rpx;
  204. .avatar {
  205. width: 100%;
  206. display: flex;
  207. justify-content: center;
  208. align-items: center;
  209. padding: 20rpx 0;
  210. }
  211. .form-box {
  212. .u-form-item {
  213. padding: 0 20rpx;
  214. border-radius: 50rpx;
  215. border: 1rpx solid $uni-text-color-grey;
  216. margin: 20rpx 0;
  217. }
  218. .u-form-item__body__left {
  219. height: 80rpx !important;
  220. width: 10rpx !important;
  221. .u-form-item__body__left__content__required {
  222. left: -10rpx !important;
  223. top: -10rpx !important;
  224. }
  225. }
  226. .u-form-item__body__right__message {
  227. margin-left: 20rpx !important;
  228. }
  229. }
  230. .action-box {
  231. width: 100%;
  232. position: fixed;
  233. bottom: 30rpx;
  234. left: 0;
  235. .btn-box {
  236. padding: 0 40rpx;
  237. margin-top: 20rpx;
  238. display: flex;
  239. justify-content: center;
  240. align-items: center;
  241. text {
  242. font-size: 36rpx;
  243. }
  244. .black {
  245. color: $uni-text-color;
  246. }
  247. .gray {
  248. color: $uni-text-color-grey;
  249. }
  250. }
  251. }
  252. }
  253. }
  254. </style>