add.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <view class="container main">
  3. <view class="one">
  4. <uni-forms ref="baseForm" :rules="rules" :modelValue="form" label-width="80px">
  5. <uni-forms-item label="姓名" required name="name">
  6. <uni-easyinput v-model="form.name" placeholder="请输入姓名" />
  7. </uni-forms-item>
  8. <uni-forms-item label="证件类型" required name="cardType">
  9. <uni-data-checkbox v-model="form.cardType" :localdata="typeList"
  10. :map="{text:'label',value:'value'}" />
  11. </uni-forms-item>
  12. <uni-forms-item label="证件号码" required name="card">
  13. <uni-easyinput v-model="form.card" placeholder="请输入证件号码" />
  14. </uni-forms-item>
  15. <uni-forms-item label="手机号" required name="phone">
  16. <uni-easyinput v-model="form.phone" placeholder="请输入手机号" />
  17. </uni-forms-item>
  18. <uni-forms-item label="电子邮箱" required name="email">
  19. <uni-easyinput v-model="form.email" placeholder="请输入电子邮箱" />
  20. </uni-forms-item>
  21. <uni-forms-item label="微信/QQ" required name="communication">
  22. <uni-easyinput v-model="form.communication" placeholder="请输入微信/QQ" />
  23. </uni-forms-item>
  24. </uni-forms>
  25. <view class="button">
  26. <view class="button_remark">*修改报名信息将会重新进行审核</view>
  27. <button type="primary" @click="submit('baseForm')">保存</button>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import moment from 'moment';
  34. export default {
  35. data() {
  36. return {
  37. id: "",
  38. user: {},
  39. form: {
  40. name: "",
  41. cardType: "",
  42. card: "",
  43. phone: "",
  44. email: "",
  45. communication: ""
  46. },
  47. typeList: [],
  48. // 校验规则
  49. rules: {
  50. name: {
  51. rules: [{
  52. required: true,
  53. errorMessage: '姓名不能为空'
  54. }]
  55. },
  56. },
  57. }
  58. },
  59. onLoad: async function(e) {
  60. const that = this;
  61. that.$set(that, `id`, e && e.id || '');
  62. await that.searchToken();
  63. await that.searchOther();
  64. await that.search();
  65. },
  66. methods: {
  67. // 用户信息
  68. searchToken() {
  69. const that = this;
  70. try {
  71. const res = uni.getStorageSync('token');
  72. if (res) {
  73. const user = that.$jwt(res);
  74. that.$set(that, `user`, user);
  75. }
  76. } catch (e) {}
  77. },
  78. async searchOther() {
  79. const that = this;
  80. let res;
  81. // 查询证件类型
  82. res = await that.$api(`/dictData`, 'GET', {
  83. code: 'cardType',
  84. is_use: '0',
  85. })
  86. if (res.errcode == '0') that.$set(that, `typeList`, res.data);
  87. },
  88. // 查询
  89. async search() {
  90. const that = this;
  91. if (that.id) {
  92. let res;
  93. res = await that.$api(`/sign/${that.id}`, 'GET', {})
  94. if (res.errcode == '0') {
  95. that.$set(that, `form`, res.data)
  96. } else {
  97. uni.showToast({
  98. title: res.errmsg,
  99. });
  100. }
  101. }
  102. },
  103. // 保存
  104. submit(ref) {
  105. const that = this;
  106. that.$refs[ref].validate().then(async res => {
  107. let arr;
  108. const data = {
  109. id: that.id,
  110. time: moment().format('YYYY-MM-DD HH:mm:ss'),
  111. status: '0'
  112. }
  113. arr = await that.$api(`/sign/${that.id}`, 'POST', {
  114. ...res,
  115. ...data
  116. })
  117. if (arr.errcode == '0') {
  118. uni.showModal({
  119. content: "修改报名信息成功!",
  120. showCancel: false
  121. });
  122. uni.navigateBack({
  123. delta: 1
  124. })
  125. } else {
  126. uni.showToast({
  127. title: arr.errmsg,
  128. });
  129. }
  130. }).catch(err => {
  131. console.log('err', err);
  132. })
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. .main {
  139. padding: 0 3vw;
  140. .one {
  141. .button_remark {
  142. margin: 2vw 0;
  143. text-indent: 10px;
  144. color: var(--fF0Color);
  145. font-size: var(--font12Size);
  146. }
  147. .button {
  148. margin: 2vw 0 0 0;
  149. button {
  150. background-color: var(--f3CColor);
  151. font-size: var(--font14Size);
  152. border-radius: 2vw;
  153. }
  154. }
  155. }
  156. }
  157. </style>