index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <view class="register-bg">
  3. <view class="bg-container">
  4. 参会报名
  5. </view>
  6. <auth-wrap class="register-container" ref="authWrap">
  7. <view class="form-content" slot="content">
  8. <u--form
  9. labelPosition="left"
  10. :model="model1"
  11. :rules="rules"
  12. ref="uForm"
  13. @submit="onSubmit"
  14. >
  15. <u-form-item
  16. prop="userInfo.usrName"
  17. borderBottom
  18. >
  19. <u--input
  20. prefixIcon="account"
  21. v-model="model1.userInfo.usrName"
  22. border="none"
  23. ></u--input>
  24. </u-form-item>
  25. <u-form-item
  26. prop="userInfo.tel"
  27. borderBottom
  28. >
  29. <u--input
  30. prefixIcon="phone"
  31. placeholder="输入手机号"
  32. border="none"
  33. type="number"
  34. maxlength="11"
  35. v-model="model1.userInfo.tel"
  36. ></u--input>
  37. </u-form-item>
  38. <u-form-item
  39. label="性别"
  40. prop="userInfo.sex"
  41. borderBottom
  42. >
  43. <u-radio-group
  44. v-model="model1.userInfo.sex"
  45. placement="row"
  46. >
  47. <u-radio
  48. :style="{
  49. marginRight: '20rpx'
  50. }"
  51. v-for="(item, index) in sexList"
  52. :key="index"
  53. :label="item.name"
  54. :name="item.value"
  55. >
  56. </u-radio>
  57. </u-radio-group>
  58. </u-form-item>
  59. <u-form-item
  60. label="参会单位"
  61. prop="userInfo.enterpriseId"
  62. borderBottom
  63. >
  64. <SingleDropList
  65. :style="{
  66. marginLeft: '20rpx'
  67. }"
  68. :defaultValue="model1.userInfo.enterpriseId"
  69. :src="enterpriseList"
  70. placeholder="请选择参会单位"
  71. @onChange="enterpriseSelect"
  72. >
  73. </SingleDropList>
  74. </u-form-item>
  75. <u-form-item
  76. label="参会行程"
  77. prop="userInfo.tripId"
  78. borderBottom
  79. >
  80. <SingleDropList
  81. :style="{
  82. marginLeft: '20rpx'
  83. }"
  84. :defaultValue="model1.userInfo.tripId"
  85. :src="tripList"
  86. placeholder="请选择参会行程"
  87. @onChange="enterpriseTripSelect"
  88. >
  89. </SingleDropList>
  90. </u-form-item>
  91. </u--form>
  92. <u-button
  93. :style="{
  94. marginTop: '120rpx'
  95. }"
  96. type="primary"
  97. text="提交"
  98. :disabled="loading"
  99. :loading="loading"
  100. loadingText="正在提交..."
  101. @click="onSubmit"
  102. >
  103. </u-button>
  104. </view>
  105. </auth-wrap>
  106. </view>
  107. </template>
  108. <script>
  109. import { fetchEnterpriseList, fetchEnterpriseTripList, putUsrRegist } from '@/common/api';
  110. import { ICON_CFG } from '@/common/EnumConst';
  111. import AuthWrap from '@/components/AuthComp/index.vue';
  112. import SingleDropList from '@/components/SingleDropList/index.vue';
  113. import { getImageUrl, getUserInfo } from '@/util';
  114. export default {
  115. name: 'login',
  116. components: {
  117. AuthWrap,
  118. SingleDropList,
  119. },
  120. props: {},
  121. data() {
  122. return {
  123. ICON_CFG,
  124. showEnterprise: false,
  125. loading: false,
  126. model1: {
  127. userInfo: {
  128. usrName: '',
  129. sex: '',
  130. },
  131. },
  132. sexList: [
  133. {
  134. value: '0',
  135. name: '男',
  136. },
  137. {
  138. value: '1',
  139. name: '女',
  140. },
  141. {
  142. value: '2',
  143. name: '保密',
  144. },
  145. ],
  146. enterpriseList: [],
  147. tripList: [],
  148. rules: {
  149. 'userInfo.usrName': {
  150. type: 'string',
  151. required: true,
  152. message: '请填写姓名',
  153. trigger: ['blur', 'change'],
  154. },
  155. 'userInfo.tel': {
  156. type: 'string',
  157. max: 11,
  158. required: true,
  159. message: '请填写11位手机号',
  160. trigger: ['blur', 'change'],
  161. },
  162. },
  163. };
  164. },
  165. created() {
  166. },
  167. onLoad() {
  168. //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
  169. this.$refs.uForm.setRules(this.rules);
  170. this.$refs.authWrap.reloadPage();
  171. const user = getUserInfo();
  172. if (user) {
  173. this.model1.userInfo.usrName = user.usrName;
  174. this.model1.userInfo.tel = user.tel;
  175. this.model1.userInfo.sex = user.sex;
  176. this.model1.userInfo.enterpriseId = user.enterpriseId;
  177. this.model1.userInfo.tripId = user.tripId;
  178. }
  179. this.init();
  180. },
  181. onReady() {
  182. //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
  183. this.$refs.uForm.setRules(this.rules);
  184. },
  185. methods: {
  186. getImageUrl,
  187. enterpriseSelect(enterprise) {
  188. this.model1.userInfo.enterpriseId = enterprise.value;
  189. this.model1.userInfo.enterpriseName = enterprise.name;
  190. this.$refs.uForm.validateField('userInfo.enterpriseId');
  191. },
  192. enterpriseTripSelect(trip) {
  193. this.model1.userInfo.tripId = trip.value;
  194. this.model1.userInfo.enterpriseTripName = trip.name;
  195. this.$refs.uForm.validateField('userInfo.tripId');
  196. },
  197. async init() {
  198. const {
  199. code: enterpriseCode,
  200. rows: enterpriseData,
  201. } = await fetchEnterpriseList();
  202. const {
  203. code: tripCode,
  204. rows: tripData,
  205. } = await fetchEnterpriseTripList();
  206. this.enterpriseList = enterpriseData.map(item => {
  207. return {
  208. name: item.enterpriseName,
  209. value: item.id,
  210. };
  211. });
  212. this.tripList = tripData.map(item => {
  213. return {
  214. name: item.tripName,
  215. value: item.id,
  216. };
  217. });
  218. },
  219. onSubmit() {
  220. this.loading = true;
  221. this.$refs.uForm.validate().then(res => {
  222. putUsrRegist(this.model1.userInfo);
  223. this.loading = false;
  224. uni.showToast({
  225. title: '报名完成',
  226. icon: 'success',
  227. });
  228. uni.navigateBack({
  229. delta: 1,
  230. });
  231. }).catch(errors => {
  232. this.loading = false;
  233. });
  234. },
  235. hideKeyboard() {
  236. uni.hideKeyboard();
  237. },
  238. },
  239. };
  240. </script>
  241. <style lang="scss" src="./index.scss" />;