add.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. uni.getStorage({
  128. key: 'shop',
  129. success: async function(res) {
  130. that.$set(that.form, `shop`, res.data);
  131. const arr = await that.$api(`/userleader`, 'POST', that.form);
  132. if (arr.errcode == '0') {
  133. uni.showToast({
  134. title: `会员身份申请成功`,
  135. icon: 'success',
  136. });
  137. that.back();
  138. } else {
  139. uni.showToast({
  140. title: arr.errmsg,
  141. })
  142. }
  143. }
  144. })
  145. }
  146. })
  147. },
  148. async getData() {
  149. const that = this;
  150. let res = await that.$api('/userleader', 'GET', {
  151. user_id: that.form.user_id,
  152. })
  153. if (res.errcode == '0') {
  154. if (res.total > 0) {
  155. let data = res.data.find(i => i.status == '0');
  156. if (data) {
  157. return true
  158. } else {
  159. return false
  160. }
  161. } else {
  162. return false
  163. }
  164. }
  165. },
  166. // 会员记录
  167. toApply() {
  168. uni.navigateTo({
  169. url: `/pagesMy/apply/index`
  170. })
  171. },
  172. // 返回
  173. back() {
  174. uni.navigateBack({
  175. delta: 1
  176. })
  177. },
  178. },
  179. }
  180. </script>
  181. <style lang="scss">
  182. .main {
  183. display: flex;
  184. flex-direction: column;
  185. width: 100vw;
  186. height: 100vh;
  187. .one {
  188. padding: 2vw;
  189. .uni-input {
  190. border: #f1f1ff 1px solid;
  191. padding: 2vw 2vw;
  192. border-radius: 1vw;
  193. }
  194. .btn {
  195. text-align: center;
  196. margin: 0 0 1vw 0;
  197. button {
  198. margin: 0 2vw 2vw 2vw;
  199. background-color: #23B67A;
  200. color: var(--fffColor);
  201. }
  202. .name {
  203. color: var(--f85Color);
  204. font-size: var(--font14Size);
  205. }
  206. }
  207. .config {
  208. .rich-img {
  209. width: 100% !important;
  210. display: block;
  211. }
  212. }
  213. }
  214. }
  215. .uni-forms-item {
  216. margin-bottom: 6vw !important;
  217. display: flex;
  218. flex-direction: row;
  219. }
  220. .uni-data-checklist .checklist-group .checklist-box .checklist-content {
  221. width: 91vw;
  222. }
  223. </style>