sign.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <view class="container main">
  3. <view class="one">
  4. <view class="one_1 name">{{info.name||'暂无活动名称'}}</view>
  5. <view class="one_1 one_2 text_color">
  6. <view class="one_left">
  7. <text class="t-icon t-icon-shizhong"></text>
  8. <span>{{getTime(info.start_time,info.end_time)||'暂无'}}</span>
  9. </view>
  10. <view class="one_right"
  11. :class="[info.match_status=='0'?'active_1':info.match_status=='1'?'active_2':info.match_status=='2'?'active_3':'active_4']">
  12. <text class="t-icon t-icon-shizhong-copy"></text>
  13. <span>{{getDict(info.match_status,'status')}}</span>
  14. </view>
  15. </view>
  16. <view class="one_1 text_color">
  17. <text class="t-icon t-icon-gonglve"></text>
  18. <span>{{getDict(info.match_type,'type')||'自办'}}</span>
  19. </view>
  20. <view class="one_1 text_color">
  21. <text class="t-icon t-icon-gongsi"></text>
  22. <span>{{info.work||'暂无组织单位'}}</span>
  23. </view>
  24. </view>
  25. <view class="two">
  26. <view class="two_1">
  27. <view class="two_text">填写报名信息</view>
  28. <view class="two_remark">*请如实填报报名信息,方便我们及时与您联系</view>
  29. </view>
  30. <view class="two_2">
  31. <form @submit="formSubmit">
  32. <view class="value other">
  33. <view class="title">姓名</view>
  34. <view class="label">
  35. <input name="name" class="input" :value="form.name" placeholder="请输入姓名" />
  36. <span v-if="errors.name" class="error-message">{{ errors.name }}</span>
  37. </view>
  38. </view>
  39. <view class="value other">
  40. <view class="title">证件类型</view>
  41. <view class="label">
  42. <uni-data-checkbox v-model="form.cardType" :localdata="cTypeList"
  43. :map="{text:'label',value:'value'}" />
  44. <span v-if="errors.cardType" class="error-message">{{ errors.cardType }}</span>
  45. </view>
  46. </view>
  47. <view class="value other">
  48. <view class="title">证件号码</view>
  49. <view class="label">
  50. <input name="card" class="input" :value="form.card" placeholder="请输入证件号码" />
  51. <span v-if="errors.card" class="error-message">{{ errors.card }}</span>
  52. </view>
  53. </view>
  54. <view class="value other">
  55. <view class="title">手机号</view>
  56. <view class="label">
  57. <input name="phone" class="input" :value="form.phone" placeholder="请输入手机号" />
  58. <span v-if="errors.phone" class="error-message">{{ errors.phone }}</span>
  59. </view>
  60. </view>
  61. <view class="value other">
  62. <view class="title">电子邮箱</view>
  63. <view class="label">
  64. <input name="email" class="input" :value="form.email" placeholder="请输入电子邮箱" />
  65. <span v-if="errors.email" class="error-message">{{ errors.email }}</span>
  66. </view>
  67. </view>
  68. <view class="value other">
  69. <view class="title">微信/QQ</view>
  70. <view class="label">
  71. <input name="communication" class="input" :value="form.communication"
  72. placeholder="请输入微信/QQ" />
  73. <span v-if="errors.communication" class="error-message">{{ errors.communication }}</span>
  74. </view>
  75. </view>
  76. <view class="button">
  77. <button type="warn" form-type="submit">提交</button>
  78. </view>
  79. </form>
  80. </view>
  81. </view>
  82. </view>
  83. </template>
  84. <script>
  85. import moment from 'moment';
  86. export default {
  87. components: {},
  88. data() {
  89. return {
  90. user: {},
  91. id: '',
  92. form: {
  93. name: "",
  94. cardType: "",
  95. card: "",
  96. phone: "",
  97. email: "",
  98. communication: ""
  99. },
  100. info: {},
  101. cTypeList: [],
  102. typeList: [],
  103. statusList: [],
  104. errors: {}
  105. }
  106. },
  107. onLoad: async function(e) {
  108. const that = this;
  109. that.$set(that, `id`, e && e.id || '');
  110. await that.searchToken();
  111. await that.searchOther();
  112. await that.search();
  113. },
  114. methods: {
  115. // 用户信息
  116. searchToken() {
  117. const that = this;
  118. try {
  119. const res = uni.getStorageSync('token');
  120. if (res) {
  121. const user = that.$jwt(res);
  122. that.$set(that, `user`, user);
  123. }
  124. } catch (e) {}
  125. },
  126. async searchOther() {
  127. const that = this;
  128. let res;
  129. // 查询证件类型
  130. res = await that.$api(`/dictData`, 'GET', {
  131. code: 'cardType',
  132. is_use: '0',
  133. })
  134. if (res.errcode == '0') that.$set(that, `cTypeList`, res.data);
  135. // 查询状态
  136. res = await that.$api(`/dictData`, 'GET', {
  137. code: 'matchStatus',
  138. is_use: '0',
  139. })
  140. if (res.errcode == '0') that.$set(that, `statusList`, res.data)
  141. // 赛事类型
  142. res = await that.$api(`/dictData`, 'GET', {
  143. code: 'activeType',
  144. is_use: '0',
  145. })
  146. if (res.errcode == '0') that.$set(that, `typeList`, res.data)
  147. },
  148. // 查询
  149. async search() {
  150. const that = this;
  151. if (that.id) {
  152. let res;
  153. res = await that.$api(`/match/${that.id}`, 'GET', {})
  154. if (res.errcode == '0') {
  155. that.$set(that, `info`, res.data)
  156. } else {
  157. uni.showToast({
  158. title: res.errmsg,
  159. icon: 'none'
  160. });
  161. }
  162. }
  163. },
  164. // 处理时间
  165. getTime(start_time, end_time) {
  166. if (start_time && end_time) {
  167. const start = new Date(start_time);
  168. const end = new Date(end_time);
  169. const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  170. const day = start.getDate();
  171. const weekday = weekdays[start.getDay()];
  172. const year = start.getFullYear();
  173. const month = start.getMonth();
  174. const start_hours = start.getHours();
  175. const start_minutes = start.getMinutes();
  176. const end_hours = end.getHours();
  177. const end_minutes = end.getMinutes();
  178. return `${year}/${month+1}/${day < 10 ? '0' + day : day} ${weekday} ${start_hours.toString().padStart(2, '0')}:${start_minutes.toString().padStart(2, '0')} - ${end_hours.toString().padStart(2, '0')}:${end_minutes.toString().padStart(2, '0')} `;
  179. }
  180. },
  181. // 处理字典表
  182. getDict(item, model) {
  183. const that = this;
  184. let res
  185. if (model == 'status') res = that.statusList.find(i => i.value == item)
  186. else if (model == 'type') res = that.typeList.find(i => i.value == item)
  187. if (res) return res.label
  188. else return '暂无'
  189. },
  190. // 自定义的验证函数
  191. validateObject(obj) {
  192. const errors = {};
  193. if (!obj.name || obj.name.trim() === '') {
  194. errors.name = '请填写姓名!';
  195. }
  196. if (!obj.cardType || obj.cardType.trim() === '') {
  197. errors.cardType = '请选择证件类型!';
  198. }
  199. if (!obj.card || obj.card.trim() === '') {
  200. errors.card = '请填写证件号码!';
  201. } else {
  202. let regex;
  203. if (obj.cardType == '0') {
  204. regex = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  205. } else {
  206. regex =
  207. /(^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$)/;
  208. }
  209. if (!regex.test(obj.card)) errors.card = '请填写正确的证件号码!';
  210. }
  211. if (!obj.phone || obj.phone.trim() === '') {
  212. errors.phone = '请填写手机号!';
  213. } else {
  214. const regex = /^1[3456789]\d{9}$/;
  215. if (!regex.test(obj.phone)) errors.phone = '请填写正确的手机号码!';
  216. }
  217. if (!obj.email || obj.email.trim() === '') {
  218. errors.email = '请填写电子邮箱!';
  219. } else {
  220. const regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
  221. if (!regex.test(obj.email)) errors.email = '请填写正确的电子邮箱!';
  222. }
  223. if (!obj.communication || obj.communication.trim() === '') {
  224. errors.communication = '请填写微信/QQ!';
  225. }
  226. // 如果有错误,返回错误对象
  227. if (Object.keys(errors).length > 0) {
  228. return errors;
  229. }
  230. // 如果没有错误,返回null或undefined
  231. return null;
  232. },
  233. async formSubmit(e) {
  234. const that = this;
  235. var formdata = e.detail.value
  236. formdata.cardType = that.form.cardType
  237. const errorsInfo = await that.validateObject(formdata);
  238. // 检查是否有错误
  239. if (errorsInfo) {
  240. that.$set(that, `errors`, errorsInfo)
  241. // 遍历错误对象并显示错误信息
  242. for (const key in errorsInfo) {
  243. if (errorsInfo.hasOwnProperty(key)) {
  244. console.error(`${key} 错误: ${errorsInfo[key]}`);
  245. }
  246. }
  247. } else {
  248. that.$set(that, `errors`, {})
  249. let res;
  250. const data = {
  251. user: that.user.id,
  252. match: that.info.id,
  253. time: moment().format('YYYY-MM-DD HH:mm:ss')
  254. }
  255. res = await that.$api(`/sign`, 'POST', {
  256. ...formdata,
  257. ...data
  258. })
  259. if (res.errcode == '0') {
  260. uni.showModal({
  261. content: "报名成功!",
  262. showCancel: false
  263. });
  264. uni.navigateBack({
  265. delta: 1
  266. })
  267. } else {
  268. uni.showToast({
  269. title: res.errmsg,
  270. icon: 'none'
  271. });
  272. }
  273. }
  274. },
  275. }
  276. }
  277. </script>
  278. <style lang="scss" scoped>
  279. .main {
  280. background-color: var(--footColor);
  281. .one {
  282. margin: 0 0 3vw 0;
  283. padding: 0 2vw;
  284. background-color: var(--mainColor);
  285. .one_1 {
  286. display: flex;
  287. align-items: center;
  288. padding: 3vw 0;
  289. border-bottom: 1px solid var(--f5Color);
  290. font-size: var(--font14Size);
  291. span {
  292. margin: 0 0 0 1vw;
  293. }
  294. .t-icon {
  295. width: var(--font15Size) !important;
  296. height: var(--font15Size) !important;
  297. }
  298. }
  299. .one_2 {
  300. justify-content: space-between;
  301. .one_left {
  302. display: flex;
  303. align-items: center;
  304. }
  305. .one_right {
  306. display: flex;
  307. align-items: center;
  308. color: var(--mainColor);
  309. padding: 1vw;
  310. .t-icon {
  311. color: var(--mainColor) !important;
  312. }
  313. }
  314. .active_1 {
  315. background-color: #4caf50;
  316. }
  317. .active_2 {
  318. background-color: #2196f3;
  319. }
  320. .active_3 {
  321. background-color: #FF5722;
  322. }
  323. .active_4 {
  324. background-color: #949698;
  325. }
  326. }
  327. .name {
  328. font-weight: bold;
  329. font-size: var(--font16Size);
  330. }
  331. .text_color {
  332. color: var(--f69Color);
  333. }
  334. }
  335. .two {
  336. padding: 2vw 0;
  337. background-color: var(--mainColor);
  338. .two_1 {
  339. .two_text {
  340. text-indent: 10px;
  341. border-left: 3px solid var(--f3CColor);
  342. font-weight: bold;
  343. font-size: var(--font16Size);
  344. }
  345. .two_remark {
  346. margin: 2vw 0 0 0;
  347. text-indent: 10px;
  348. color: var(--fF0Color);
  349. font-size: var(--font12Size);
  350. }
  351. }
  352. .two_2 {
  353. padding: 2vw;
  354. .other {
  355. padding: 4vw 2vw;
  356. border-bottom: 1px solid var(--footColor);
  357. }
  358. .value {
  359. display: flex;
  360. justify-content: space-between;
  361. align-items: center;
  362. background-color: var(--mainColor);
  363. .label {
  364. text-align: right;
  365. /deep/.uni-data-checklist .checklist-group .checklist-box {
  366. margin-right: 0 !important;
  367. margin-left: 25px !important;
  368. }
  369. .error-message {
  370. text-align: right;
  371. margin: 5px 0 0 0;
  372. color: var(--fF0Color);
  373. font-size: var(--font12Size);
  374. }
  375. }
  376. }
  377. .button {
  378. margin: 2vw 0 0 0;
  379. text-align: center;
  380. button {
  381. background-color: var(--f3CColor);
  382. border-radius: 2vw;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. </style>