sign.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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 month = start.getMonth();
  173. const start_hours = start.getHours();
  174. const start_minutes = start.getMinutes();
  175. const end_hours = end.getHours();
  176. const end_minutes = end.getMinutes();
  177. return `${month}/${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')} `;
  178. }
  179. },
  180. // 处理字典表
  181. getDict(item, model) {
  182. const that = this;
  183. let res
  184. if (model == 'status') res = that.statusList.find(i => i.value == item)
  185. else if (model == 'type') res = that.typeList.find(i => i.value == item)
  186. if (res) return res.label
  187. else return '暂无'
  188. },
  189. // 自定义的验证函数
  190. validateObject(obj) {
  191. const errors = {};
  192. if (!obj.name || obj.name.trim() === '') {
  193. errors.name = '请填写姓名!';
  194. }
  195. if (!obj.cardType || obj.cardType.trim() === '') {
  196. errors.cardType = '请选择证件类型!';
  197. }
  198. if (!obj.card || obj.card.trim() === '') {
  199. errors.card = '请填写证件号码!';
  200. } else {
  201. let regex;
  202. if (obj.cardType == '0') {
  203. regex = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  204. } else {
  205. regex =
  206. /(^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$)/;
  207. }
  208. if (!regex.test(obj.card)) errors.card = '请填写正确的证件号码!';
  209. }
  210. if (!obj.phone || obj.phone.trim() === '') {
  211. errors.phone = '请填写手机号!';
  212. } else {
  213. const regex = /^1[3456789]\d{9}$/;
  214. if (!regex.test(obj.phone)) errors.phone = '请填写正确的手机号码!';
  215. }
  216. if (!obj.email || obj.email.trim() === '') {
  217. errors.email = '请填写电子邮箱!';
  218. } else {
  219. const regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
  220. if (!regex.test(obj.email)) errors.email = '请填写正确的电子邮箱!';
  221. }
  222. if (!obj.communication || obj.communication.trim() === '') {
  223. errors.communication = '请填写微信/QQ!';
  224. }
  225. // 如果有错误,返回错误对象
  226. if (Object.keys(errors).length > 0) {
  227. return errors;
  228. }
  229. // 如果没有错误,返回null或undefined
  230. return null;
  231. },
  232. async formSubmit(e) {
  233. const that = this;
  234. var formdata = e.detail.value
  235. formdata.cardType = that.form.cardType
  236. const errorsInfo = await that.validateObject(formdata);
  237. // 检查是否有错误
  238. if (errorsInfo) {
  239. that.$set(that, `errors`, errorsInfo)
  240. // 遍历错误对象并显示错误信息
  241. for (const key in errorsInfo) {
  242. if (errorsInfo.hasOwnProperty(key)) {
  243. console.error(`${key} 错误: ${errorsInfo[key]}`);
  244. }
  245. }
  246. } else {
  247. that.$set(that, `errors`, {})
  248. let res;
  249. const data = {
  250. user: that.user.id,
  251. match: that.info.id,
  252. time: moment().format('YYYY-MM-DD HH:mm:ss')
  253. }
  254. res = await that.$api(`/sign`, 'POST', {
  255. ...formdata,
  256. ...data
  257. })
  258. if (res.errcode == '0') {
  259. uni.showModal({
  260. content: "报名成功!",
  261. showCancel: false
  262. });
  263. uni.navigateBack({
  264. delta: 1
  265. })
  266. } else {
  267. uni.showToast({
  268. title: res.errmsg,
  269. icon: 'none'
  270. });
  271. }
  272. }
  273. },
  274. }
  275. }
  276. </script>
  277. <style lang="scss" scoped>
  278. .main {
  279. background-color: var(--footColor);
  280. .one {
  281. margin: 0 0 3vw 0;
  282. padding: 0 2vw;
  283. background-color: var(--mainColor);
  284. .one_1 {
  285. display: flex;
  286. align-items: center;
  287. padding: 3vw 0;
  288. border-bottom: 1px solid var(--f5Color);
  289. font-size: var(--font14Size);
  290. span {
  291. margin: 0 0 0 1vw;
  292. }
  293. .t-icon {
  294. width: var(--font15Size) !important;
  295. height: var(--font15Size) !important;
  296. }
  297. }
  298. .one_2 {
  299. justify-content: space-between;
  300. .one_left {
  301. display: flex;
  302. align-items: center;
  303. }
  304. .one_right {
  305. display: flex;
  306. align-items: center;
  307. color: var(--mainColor);
  308. padding: 1vw;
  309. .t-icon {
  310. color: var(--mainColor) !important;
  311. }
  312. }
  313. .active_1 {
  314. background-color: #4caf50;
  315. }
  316. .active_2 {
  317. background-color: #2196f3;
  318. }
  319. .active_3 {
  320. background-color: #FF5722;
  321. }
  322. .active_4 {
  323. background-color: #949698;
  324. }
  325. }
  326. .name {
  327. font-weight: bold;
  328. font-size: var(--font16Size);
  329. }
  330. .text_color {
  331. color: var(--f69Color);
  332. }
  333. }
  334. .two {
  335. padding: 2vw 0;
  336. background-color: var(--mainColor);
  337. .two_1 {
  338. .two_text {
  339. text-indent: 10px;
  340. border-left: 3px solid var(--f3CColor);
  341. font-weight: bold;
  342. font-size: var(--font16Size);
  343. }
  344. .two_remark {
  345. margin: 2vw 0 0 0;
  346. text-indent: 10px;
  347. color: var(--fF0Color);
  348. font-size: var(--font12Size);
  349. }
  350. }
  351. .two_2 {
  352. padding: 2vw;
  353. .other {
  354. padding: 4vw 2vw;
  355. border-bottom: 1px solid var(--footColor);
  356. }
  357. .value {
  358. display: flex;
  359. justify-content: space-between;
  360. align-items: center;
  361. background-color: var(--mainColor);
  362. .label {
  363. text-align: right;
  364. /deep/.uni-data-checklist .checklist-group .checklist-box {
  365. margin-right: 0 !important;
  366. margin-left: 25px !important;
  367. }
  368. .error-message {
  369. text-align: right;
  370. margin: 5px 0 0 0;
  371. color: var(--fF0Color);
  372. font-size: var(--font12Size);
  373. }
  374. }
  375. }
  376. .button {
  377. margin: 2vw 0 0 0;
  378. text-align: center;
  379. button {
  380. background-color: var(--f3CColor);
  381. border-radius: 2vw;
  382. }
  383. }
  384. }
  385. }
  386. }
  387. </style>