add.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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') {
  105. if (config.data.leader_rule) config.data.leader_rule = config.data.leader_rule.replace(/\<img/gi,
  106. '<img class="rich-img"');
  107. that.$set(that, `config`, config.data);
  108. }
  109. },
  110. fail: (err) => {}
  111. })
  112. },
  113. // 同意隐私协议
  114. changeAgree() {
  115. const that = this;
  116. let agree = true;
  117. if (that.agree) agree = false;
  118. that.$set(that, `agree`, agree);
  119. },
  120. // 返回
  121. back() {
  122. uni.navigateBack({
  123. delta: 1
  124. })
  125. },
  126. // 团长记录
  127. toApply() {
  128. uni.navigateTo({
  129. url: `/pagesMy/apply/index`
  130. })
  131. },
  132. // 提交保存
  133. onSubmit(ref) {
  134. const that = this;
  135. that.$refs[ref].validate().then(async params => {
  136. if (that.agree) {
  137. const arr = await that.$api(`/userleader`, 'POST', that.form);
  138. if (arr.errcode == '0') {
  139. uni.showToast({
  140. title: `团长身份申请成功`,
  141. icon: 'success',
  142. });
  143. that.back();
  144. } else {
  145. uni.showToast({
  146. title: arr.errmsg,
  147. })
  148. }
  149. } else {
  150. uni.showToast({
  151. title: '请阅读并同意用户协议和隐私政策',
  152. icon: 'none'
  153. })
  154. }
  155. })
  156. }
  157. },
  158. }
  159. </script>
  160. <style lang="scss">
  161. .main {
  162. display: flex;
  163. flex-direction: column;
  164. width: 100vw;
  165. height: 100vh;
  166. .one {
  167. padding: 2vw;
  168. .uni-input {
  169. border: #f1f1ff 1px solid;
  170. padding: 2vw 2vw;
  171. border-radius: 1vw;
  172. }
  173. .btn {
  174. text-align: center;
  175. margin: 0 0 1vw 0;
  176. button {
  177. margin: 0 2vw 2vw 2vw;
  178. background-color: #23B67A;
  179. color: var(--fffColor);
  180. }
  181. .name {
  182. color: var(--f85Color);
  183. font-size: var(--font14Size);
  184. }
  185. .btn_3 {
  186. width: 100vw;
  187. text-align: center;
  188. font-size: 12px;
  189. }
  190. }
  191. }
  192. }
  193. .uni-forms-item {
  194. margin-bottom: 6vw !important;
  195. display: flex;
  196. flex-direction: row;
  197. }
  198. </style>