index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. {{basicInfo.name}}
  5. </view>
  6. <view class="two">
  7. <uni-forms ref="form" :model="form" :rules="rules" label-width="auto">
  8. <uni-forms-item name="account">
  9. <uni-easyinput v-model="form.account" placeholder="请输入登录账号" />
  10. </uni-forms-item>
  11. <uni-forms-item name="password">
  12. <uni-easyinput type="password" v-model="form.password" placeholder="请输入登录密码" />
  13. </uni-forms-item>
  14. <uni-forms-item name="phone">
  15. <uni-easyinput v-model="form.phone" placeholder="请输入联系电话" />
  16. </uni-forms-item>
  17. <uni-forms-item name="nick_name">
  18. <uni-easyinput v-model="form.nick_name" placeholder="请输入账号昵称" />
  19. </uni-forms-item>
  20. <uni-forms-item name="gender">
  21. <uni-data-checkbox v-model="form.gender" :localdata="genderList"
  22. :map="{text:'label',value:'value'}" />
  23. </uni-forms-item>
  24. <uni-forms-item name="logo_url">
  25. <upload :list="form.logo_url" name="logo_url" :count="1" @uplSuc="uplSuc" @uplDel="uplDel"></upload>
  26. </uni-forms-item>
  27. </uni-forms>
  28. <view class="agree">
  29. <checkbox-group @change="changeAgree">
  30. <label>
  31. <checkbox :checked="agree" />
  32. <text @tap.stop="toAgree()">我已阅读并同意“用户协议”和“隐私政策”</text>
  33. </label>
  34. </checkbox-group>
  35. </view>
  36. <view class="btn">
  37. <button size="mini" @tap="toSubmit('form')">提交注册</button>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import upload from "@/components/upload/index.vue";
  44. export default {
  45. components: {
  46. upload,
  47. },
  48. data() {
  49. return {
  50. // 基本信息
  51. basicInfo: {},
  52. form: {
  53. logo_url: [],
  54. },
  55. // 校验规则
  56. rules: {
  57. account: {
  58. rules: [{
  59. required: true,
  60. errorMessage: '请输入登录账号'
  61. }]
  62. },
  63. password: {
  64. rules: [{
  65. required: true,
  66. errorMessage: '请输入登录密码'
  67. }]
  68. },
  69. phone: {
  70. rules: [{
  71. required: true,
  72. errorMessage: '请输入联系电话'
  73. }]
  74. },
  75. },
  76. // 用戶协议
  77. agree: true,
  78. // 性别
  79. genderList: []
  80. };
  81. },
  82. onLoad() {
  83. },
  84. onShow() {
  85. const that = this;
  86. that.searchBasic();
  87. that.searchOther();
  88. },
  89. methods: {
  90. searchBasic() {
  91. const that = this;
  92. uni.getStorage({
  93. key: 'basicInfo',
  94. success: (res) => {
  95. let data = res.data
  96. that.$set(that, `basicInfo`, data);
  97. }
  98. })
  99. },
  100. // 图片上传
  101. uplSuc(e) {
  102. const that = this;
  103. that.$set(that.form, `${e.name}`, [...that.form[e.name], e.data]);
  104. },
  105. // 图片删除
  106. uplDel(e) {
  107. const that = this;
  108. let data = that.form[e.name];
  109. let arr = data.filter((i, index) => index != e.data.index);
  110. that.$set(that.form, `${e.name}`, arr);
  111. },
  112. // 提交注册
  113. toSubmit(ref) {
  114. const that = this;
  115. let agree = that.agree;
  116. that.$refs[ref].validate().then(async parmas => {
  117. if (agree) {
  118. let res = await that.$api('user', 'POST', parmas)
  119. if (res.errcode == '0') {
  120. if (res.errcode == '0') {
  121. uni.showToast({
  122. title: '账号注册成功',
  123. icon: 'none'
  124. })
  125. uni.redirectTo({
  126. url: '/pagesAccount/login/index'
  127. })
  128. }
  129. } else {
  130. uni.showToast({
  131. title: res.errmsg,
  132. icon: 'none'
  133. })
  134. }
  135. } else {
  136. uni.showToast({
  137. title: '请阅读并同意用户协议和隐私政策',
  138. icon: 'none'
  139. })
  140. }
  141. }).catch(err => {
  142. console.log('err', err);
  143. })
  144. },
  145. // 同意隐私协议
  146. changeAgree() {
  147. const that = this;
  148. let agree = true;
  149. if (that.agree) agree = false;
  150. that.$set(that, `agree`, agree);
  151. },
  152. // 查看隐私协议
  153. toAgree() {
  154. const that = this;
  155. uni.navigateTo({
  156. url: `/pagesAccount/other/agree`
  157. })
  158. },
  159. // 查询其他信息
  160. async searchOther() {
  161. const that = this;
  162. let res;
  163. res = await that.$api('dictdata', 'GET', {
  164. type: 'gender'
  165. })
  166. if (res.errcode == '0') {
  167. that.$set(that, `genderList`, res.data)
  168. }
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang="scss">
  174. .content {
  175. background-color: var(--rgb000);
  176. padding: 0 2vw;
  177. overflow-y: auto;
  178. .one {
  179. text-align: center;
  180. font-size: 30px;
  181. font-family: monospace;
  182. color: var(--rgbfff);
  183. padding: 6vw 0;
  184. }
  185. .two {
  186. margin: 0 0 4vw 0;
  187. .btn {
  188. padding: 2vw 0 0 0;
  189. text-align: center;
  190. button {
  191. width: 80%;
  192. background-color: var(--rgbfa4);
  193. color: var(--rgbfff);
  194. padding: 1vw 0;
  195. }
  196. }
  197. }
  198. }
  199. .agree {
  200. text-align: center;
  201. font-size: 12px;
  202. margin: 0 0 2vw 0;
  203. color: var(--rgbfff);
  204. }
  205. </style>