sign.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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':'active_3']">
  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-zuobiao"></text>
  18. <span>{{info.address||'在线活动'}}</span>
  19. </view>
  20. <view class="one_1 text_color">
  21. <text class="t-icon t-icon-dianzan"></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="typeList"
  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. typeList: [],
  102. statusList: [],
  103. errors: {}
  104. }
  105. },
  106. onLoad: async function(e) {
  107. const that = this;
  108. that.$set(that, `id`, e && e.id || '');
  109. await that.searchToken();
  110. await that.searchOther();
  111. await that.search();
  112. },
  113. methods: {
  114. // 用户信息
  115. searchToken() {
  116. const that = this;
  117. try {
  118. const res = uni.getStorageSync('token');
  119. if (res) {
  120. const user = that.$jwt(res);
  121. that.$set(that, `user`, user);
  122. }
  123. } catch (e) {}
  124. },
  125. async searchOther() {
  126. const that = this;
  127. let res;
  128. // 查询证件类型
  129. res = await that.$api(`/dictData`, 'GET', {
  130. code: 'cardType',
  131. is_use: '0',
  132. })
  133. if (res.errcode == '0') that.$set(that, `typeList`, res.data);
  134. // 查询状态
  135. res = await that.$api(`/dictData`, 'GET', {
  136. code: 'matchStatus',
  137. is_use: '0',
  138. })
  139. if (res.errcode == '0') that.$set(that, `statusList`, res.data)
  140. },
  141. // 查询
  142. async search() {
  143. const that = this;
  144. if (that.id) {
  145. let res;
  146. res = await that.$api(`/match/${that.id}`, 'GET', {})
  147. if (res.errcode == '0') {
  148. that.$set(that, `info`, res.data)
  149. } else {
  150. uni.showToast({
  151. title: res.errmsg,
  152. icon: 'none'
  153. });
  154. }
  155. }
  156. },
  157. // 处理时间
  158. getTime(start_time, end_time) {
  159. if (start_time && end_time) {
  160. const start = new Date(start_time);
  161. const end = new Date(end_time);
  162. const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  163. const day = start.getDate();
  164. const weekday = weekdays[start.getDay()];
  165. const month = start.getMonth();
  166. const start_hours = start.getHours();
  167. const start_minutes = start.getMinutes();
  168. const end_hours = end.getHours();
  169. const end_minutes = end.getMinutes();
  170. 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')} `;
  171. }
  172. },
  173. // 处理字典表
  174. getDict(item, model) {
  175. const that = this;
  176. let res
  177. if (model == 'status') res = that.statusList.find(i => i.value == item)
  178. if (res) return res.label
  179. else return '暂无'
  180. },
  181. // 自定义的验证函数
  182. validateObject(obj) {
  183. const errors = {};
  184. if (!obj.name || obj.name.trim() === '') {
  185. errors.name = '请填写姓名!';
  186. }
  187. if (!obj.cardType || obj.cardType.trim() === '') {
  188. errors.cardType = '请选择证件类型!';
  189. }
  190. if (!obj.card || obj.card.trim() === '') {
  191. errors.card = '请填写证件号码!';
  192. } else {
  193. let regex;
  194. if (obj.cardType == '0') {
  195. regex = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  196. } else {
  197. regex =
  198. /(^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$)/;
  199. }
  200. if (!regex.test(obj.card)) errors.card = '请填写正确的证件号码!';
  201. }
  202. if (!obj.phone || obj.phone.trim() === '') {
  203. errors.phone = '请填写手机号!';
  204. } else {
  205. const regex = /^1[3456789]\d{9}$/;
  206. if (!regex.test(obj.phone)) errors.phone = '请填写正确的手机号码!';
  207. }
  208. if (!obj.email || obj.email.trim() === '') {
  209. errors.email = '请填写电子邮箱!';
  210. } else {
  211. const regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
  212. if (!regex.test(obj.email)) errors.email = '请填写正确的电子邮箱!';
  213. }
  214. if (!obj.communication || obj.communication.trim() === '') {
  215. errors.communication = '请填写微信/QQ!';
  216. }
  217. // 如果有错误,返回错误对象
  218. if (Object.keys(errors).length > 0) {
  219. return errors;
  220. }
  221. // 如果没有错误,返回null或undefined
  222. return null;
  223. },
  224. async formSubmit(e) {
  225. const that = this;
  226. var formdata = e.detail.value
  227. formdata.cardType = that.form.cardType
  228. const errorsInfo = await that.validateObject(formdata);
  229. // 检查是否有错误
  230. if (errorsInfo) {
  231. that.$set(that, `errors`, errorsInfo)
  232. // 遍历错误对象并显示错误信息
  233. for (const key in errorsInfo) {
  234. if (errorsInfo.hasOwnProperty(key)) {
  235. console.error(`${key} 错误: ${errorsInfo[key]}`);
  236. }
  237. }
  238. } else {
  239. that.$set(that, `errors`, {})
  240. let res;
  241. const data = {
  242. user: that.user.id,
  243. match: that.info.id,
  244. time: moment().format('YYYY-MM-DD HH:mm:ss')
  245. }
  246. res = await that.$api(`/sign`, 'POST', {
  247. ...formdata,
  248. ...data
  249. })
  250. if (res.errcode == '0') {
  251. uni.showModal({
  252. content: "报名成功!",
  253. showCancel: false
  254. });
  255. uni.navigateBack({
  256. delta: 1
  257. })
  258. } else {
  259. uni.showToast({
  260. title: res.errmsg,
  261. icon: 'none'
  262. });
  263. }
  264. }
  265. },
  266. }
  267. }
  268. </script>
  269. <style lang="scss" scoped>
  270. .main {
  271. background-color: var(--footColor);
  272. .one {
  273. margin: 0 0 3vw 0;
  274. padding: 0 2vw;
  275. background-color: var(--mainColor);
  276. .one_1 {
  277. display: flex;
  278. align-items: center;
  279. padding: 3vw 0;
  280. border-bottom: 1px solid var(--f5Color);
  281. font-size: var(--font14Size);
  282. span {
  283. margin: 0 0 0 1vw;
  284. }
  285. .t-icon {
  286. width: var(--font15Size) !important;
  287. height: var(--font15Size) !important;
  288. }
  289. }
  290. .one_2 {
  291. justify-content: space-between;
  292. .one_left {
  293. display: flex;
  294. align-items: center;
  295. }
  296. .one_right {
  297. display: flex;
  298. align-items: center;
  299. color: var(--mainColor);
  300. padding: 1vw;
  301. .t-icon {
  302. color: var(--mainColor) !important;
  303. }
  304. }
  305. .active_1 {
  306. background-color: #4caf50;
  307. }
  308. .active_2 {
  309. background-color: #2196f3;
  310. }
  311. .active_3 {
  312. background-color: #949698;
  313. }
  314. }
  315. .name {
  316. font-weight: bold;
  317. font-size: var(--font16Size);
  318. }
  319. .text_color {
  320. color: var(--f69Color);
  321. }
  322. }
  323. .two {
  324. padding: 2vw 0;
  325. background-color: var(--mainColor);
  326. .two_1 {
  327. .two_text {
  328. text-indent: 10px;
  329. border-left: 3px solid var(--f3CColor);
  330. font-weight: bold;
  331. font-size: var(--font16Size);
  332. }
  333. .two_remark {
  334. margin: 2vw 0 0 0;
  335. text-indent: 10px;
  336. color: var(--fF0Color);
  337. font-size: var(--font12Size);
  338. }
  339. }
  340. .two_2 {
  341. padding: 2vw;
  342. .other {
  343. padding: 4vw 2vw;
  344. border-bottom: 1px solid var(--footColor);
  345. }
  346. .value {
  347. display: flex;
  348. justify-content: space-between;
  349. align-items: center;
  350. background-color: var(--mainColor);
  351. .label {
  352. text-align: right;
  353. /deep/.uni-data-checklist .checklist-group .checklist-box {
  354. margin-right: 0 !important;
  355. margin-left: 25px !important;
  356. }
  357. .error-message {
  358. text-align: right;
  359. margin: 5px 0 0 0;
  360. color: var(--fF0Color);
  361. font-size: var(--font12Size);
  362. }
  363. }
  364. }
  365. .button {
  366. margin: 2vw 0 0 0;
  367. text-align: center;
  368. button {
  369. background-color: var(--f3CColor);
  370. border-radius: 2vw;
  371. }
  372. }
  373. }
  374. }
  375. }
  376. </style>