add.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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="姓名" required name="name">
  7. <uni-easyinput type="text" v-model="form.name" placeholder="请输入真实姓名" />
  8. </uni-forms-item>
  9. <uni-forms-item label="身份证号" required name="card">
  10. <uni-easyinput type="text" v-model="form.card" placeholder="请输入身份证号" />
  11. </uni-forms-item>
  12. <uni-forms-item label="手机号" required name="phone">
  13. <uni-easyinput type="text" v-model="form.phone" placeholder="请输入手机号" />
  14. </uni-forms-item>
  15. <uni-forms-item>
  16. <uni-data-checkbox v-model="affirm" multiple :localdata="affirmList" @change="affirmChange" />
  17. </uni-forms-item>
  18. </uni-forms>
  19. <view class="btn">
  20. <button type="primary" @click="onSubmit('form')" size="mini"
  21. :disabled="is_affirm=='0'?true:false">提交</button>
  22. <button type="primary" @click="toApply" size="mini">申请记录</button>
  23. </view>
  24. <view class="config">
  25. <rich-text :nodes="config&&config.leader&&config.leader.rule"></rich-text>
  26. </view>
  27. </view>
  28. </view>
  29. </mobile-frame>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. // 系统设置
  36. config: {},
  37. form: {},
  38. rules: {
  39. name: {
  40. rules: [{
  41. required: true,
  42. errorMessage: '请填写真实姓名',
  43. }]
  44. },
  45. card: {
  46. rules: [{
  47. required: true,
  48. errorMessage: '请填写身份证',
  49. }]
  50. },
  51. phone: {
  52. rules: [{
  53. required: true,
  54. errorMessage: '请填写手机号码',
  55. }]
  56. },
  57. },
  58. affirmList: [],
  59. affirm: [],
  60. is_affirm: 0
  61. };
  62. },
  63. onLoad: function(e) {
  64. const that = this;
  65. that.watchLogin();
  66. that.searchConfig();
  67. },
  68. methods: {
  69. watchLogin() {
  70. const that = this;
  71. uni.getStorage({
  72. key: 'token',
  73. success: async (res) => {
  74. let user = that.$jwt(res.data);
  75. if (user) {
  76. that.$set(that, `form`, {
  77. user_id: user.id,
  78. openid: user.openid,
  79. phone: user.phone
  80. })
  81. }
  82. },
  83. fail: (err) => {}
  84. })
  85. },
  86. searchConfig() {
  87. const that = this;
  88. uni.getStorage({
  89. key: 'config',
  90. success: async (res) => {
  91. let data = res.data;
  92. if (data.leader && data.leader.rule) data.leader.rule = data.leader.rule.replace(
  93. /\<img/gi,
  94. '<img class="rich-img"');
  95. that.$set(that, `config`, data);
  96. // 整理复选框
  97. if (data.leader && data.leader.explain) {
  98. let list = [ //
  99. {
  100. text: data.leader.explain,
  101. value: 0
  102. }
  103. ]
  104. that.$set(that, `affirmList`, list)
  105. }
  106. },
  107. fail: (err) => {}
  108. })
  109. },
  110. // 选择
  111. affirmChange(e) {
  112. const that = this;
  113. const length = e.detail.value.length;
  114. that.$set(that, `is_affirm`, length)
  115. },
  116. // 提交保存
  117. onSubmit(ref) {
  118. const that = this;
  119. that.$refs[ref].validate().then(async params => {
  120. let is_data = await that.getData();
  121. if (is_data) {
  122. uni.showToast({
  123. title: `已有申请数据正在审核中,不可重复申请`,
  124. icon: 'none',
  125. });
  126. } else {
  127. const arr = await that.$api(`/userleader`, 'POST', that.form);
  128. if (arr.errcode == '0') {
  129. uni.showToast({
  130. title: `会员身份申请成功`,
  131. icon: 'success',
  132. });
  133. that.back();
  134. } else {
  135. uni.showToast({
  136. title: arr.errmsg,
  137. })
  138. }
  139. }
  140. })
  141. },
  142. async getData() {
  143. const that = this;
  144. let res = await that.$api('/userleader', 'GET', {
  145. user_id: that.form.user_id,
  146. })
  147. if (res.errcode == '0') {
  148. if (res.total > 0) {
  149. let data = res.data.find(i => i.status == '0');
  150. if (data) {
  151. return true
  152. } else {
  153. return false
  154. }
  155. } else {
  156. return false
  157. }
  158. }
  159. },
  160. // 会员记录
  161. toApply() {
  162. uni.navigateTo({
  163. url: `/pagesMy/apply/index`
  164. })
  165. },
  166. // 返回
  167. back() {
  168. uni.navigateBack({
  169. delta: 1
  170. })
  171. },
  172. },
  173. }
  174. </script>
  175. <style lang="scss">
  176. .main {
  177. display: flex;
  178. flex-direction: column;
  179. width: 100vw;
  180. height: 100vh;
  181. .one {
  182. padding: 2vw;
  183. .uni-input {
  184. border: #f1f1ff 1px solid;
  185. padding: 2vw 2vw;
  186. border-radius: 1vw;
  187. }
  188. .btn {
  189. text-align: center;
  190. margin: 0 0 1vw 0;
  191. button {
  192. margin: 0 2vw 2vw 2vw;
  193. background-color: #23B67A;
  194. color: var(--fffColor);
  195. }
  196. .name {
  197. color: var(--f85Color);
  198. font-size: var(--font14Size);
  199. }
  200. }
  201. .config {
  202. .rich-img {
  203. width: 100% !important;
  204. display: block;
  205. }
  206. }
  207. }
  208. }
  209. .uni-forms-item {
  210. margin-bottom: 6vw !important;
  211. display: flex;
  212. flex-direction: row;
  213. }
  214. .uni-data-checklist .checklist-group .checklist-box .checklist-content {
  215. width: 91vw;
  216. }
  217. </style>