add.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <uni-forms ref="form" :modelValue="form" :rules="rules" label-width="auto">
  6. <uni-forms-item label="姓名" name="name">
  7. <uni-easyinput type="text" v-model="form.name" placeholder="请输入真实姓名" />
  8. </uni-forms-item>
  9. <uni-forms-item label="身份证号" name="card">
  10. <uni-easyinput type="text" v-model="form.card" placeholder="请输入身份证号" />
  11. </uni-forms-item>
  12. <uni-forms-item label="手机号" name="phone">
  13. <uni-easyinput type="text" v-model="form.phone" placeholder="请输入手机号" />
  14. </uni-forms-item>
  15. </uni-forms>
  16. <view class="btn">
  17. <button type="primary" @click="onSubmit('form')" size="mini">提交</button>
  18. <button type="primary" @click="toApply" size="mini">申请记录</button>
  19. <view class="btn_3">
  20. <checkbox-group @change="changeAgree">
  21. <label>
  22. <checkbox :checked="agree" />
  23. <text>我已阅读“团长规则”</text>
  24. </label>
  25. </checkbox-group>
  26. </view>
  27. </view>
  28. <view class="config">
  29. <rich-text :nodes="config&&config.leader_rule"></rich-text>
  30. </view>
  31. </view>
  32. </view>
  33. </mobile-frame>
  34. </template>
  35. <script>
  36. export default {
  37. data() {
  38. return {
  39. // 用戶协议
  40. agree: true,
  41. // 系统设置
  42. config: {},
  43. form: {},
  44. rules: {
  45. name: {
  46. rules: [{
  47. required: true,
  48. errorMessage: '请填写真实姓名',
  49. }]
  50. },
  51. phone: {
  52. rules: [{
  53. required: true,
  54. errorMessage: '请填写手机号码',
  55. }, {
  56. validateFunction: function(rule, value, data, callback) {
  57. let iphoneReg = (
  58. /^(13[0-9]|14[1579]|15[0-3,5-9]|16[6]|17[0123456789]|18[0-9]|19[89])\d{8}$/
  59. ); //手机号码
  60. if (!iphoneReg.test(value)) {
  61. callback('手机号码格式不正确,请重新填写')
  62. }
  63. }
  64. }]
  65. },
  66. card: {
  67. rules: [{
  68. required: true,
  69. errorMessage: '请填写身份证',
  70. }, {
  71. validateFunction: function(rule, value, data, callback) {
  72. let iphoneReg = (
  73. /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
  74. ); //
  75. if (!iphoneReg.test(value)) {
  76. callback('身份证格式不正确,请重新填写')
  77. }
  78. }
  79. }]
  80. },
  81. },
  82. };
  83. },
  84. onLoad: function(e) {
  85. const that = this;
  86. that.watchLogin();
  87. },
  88. methods: {
  89. watchLogin() {
  90. const that = this;
  91. uni.getStorage({
  92. key: 'token',
  93. success: async (res) => {
  94. let user = that.$jwt(res.data);
  95. if (user) {
  96. that.$set(that, `form`, {
  97. user_id: user.id,
  98. openid: user.openid,
  99. phone: user.phone
  100. })
  101. }
  102. // 系统设置
  103. let config = await that.$api(`/config`, 'GET', {});
  104. if (config.errcode == '0') that.$set(that, `config`, config.data);
  105. },
  106. fail: (err) => {}
  107. })
  108. },
  109. // 同意隐私协议
  110. changeAgree() {
  111. const that = this;
  112. let agree = true;
  113. if (that.agree) agree = false;
  114. that.$set(that, `agree`, agree);
  115. },
  116. // 返回
  117. back() {
  118. uni.navigateBack({
  119. delta: 1
  120. })
  121. },
  122. // 团长记录
  123. toApply() {
  124. uni.navigateTo({
  125. url: `/pagesMy/apply/index`
  126. })
  127. },
  128. // 提交保存
  129. onSubmit(ref) {
  130. const that = this;
  131. that.$refs[ref].validate().then(async params => {
  132. if (that.agree) {
  133. const arr = await that.$api(`/userleader`, 'POST', that.form);
  134. if (arr.errcode == '0') {
  135. uni.showToast({
  136. title: `团长身份申请成功`,
  137. icon: 'success',
  138. });
  139. that.back();
  140. } else {
  141. uni.showToast({
  142. title: arr.errmsg,
  143. })
  144. }
  145. } else {
  146. uni.showToast({
  147. title: '请阅读并同意用户协议和隐私政策',
  148. icon: 'none'
  149. })
  150. }
  151. })
  152. }
  153. },
  154. }
  155. </script>
  156. <style lang="scss">
  157. .main {
  158. display: flex;
  159. flex-direction: column;
  160. width: 100vw;
  161. height: 100vh;
  162. .one {
  163. padding: 2vw;
  164. .uni-input {
  165. border: #f1f1ff 1px solid;
  166. padding: 2vw 2vw;
  167. border-radius: 1vw;
  168. }
  169. .btn {
  170. text-align: center;
  171. margin: 0 0 1vw 0;
  172. button {
  173. margin: 0 2vw 2vw 2vw;
  174. background-color: #23B67A;
  175. color: var(--fffColor);
  176. }
  177. .name {
  178. color: var(--f85Color);
  179. font-size: var(--font14Size);
  180. }
  181. .btn_3 {
  182. width: 100vw;
  183. text-align: center;
  184. font-size: 12px;
  185. }
  186. }
  187. }
  188. }
  189. .uni-forms-item {
  190. margin-bottom: 6vw !important;
  191. display: flex;
  192. flex-direction: row;
  193. }
  194. </style>