sign.vue 11 KB

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