active.vue 12 KB

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