active.vue 12 KB

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