create_active.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. <template>
  2. <view class="create_active">
  3. <view class="img" v-if="!uploadImage">
  4. <u-upload ref="uUpload" :action="action" :auto-upload="true" :form-data='imageDate' :file-list="fileList"
  5. @on-success='uploadSuccess' :custom-btn="true" max-count="1">
  6. <view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
  7. <u-icon name="plus" size="50" color="#79573D"></u-icon>
  8. </view>
  9. </u-upload>
  10. <text>添加活动海报</text>
  11. <text style="font-size: 12px;">(最佳尺寸比例:215*74)</text>
  12. </view>
  13. <view class="img" v-else>
  14. <u-image height="100%" :src="uploadImage"></u-image>
  15. </view>
  16. <view class="title title1">
  17. <view class="line"></view>
  18. <text>基本信息</text>
  19. </view>
  20. <u-form :model="form" ref="uForm" class="form">
  21. <view class="posotion">
  22. <view class="star">
  23. *
  24. </view>
  25. <u-form-item label="活动标题" prop="title" :label-width="150">
  26. <u-input v-model="form.title" input-align="right" />
  27. </u-form-item>
  28. </view>
  29. <view class="posotion">
  30. <view class="star">
  31. *
  32. </view>
  33. <u-form-item label="活动类型" prop="type_id" :label-width="160">
  34. <view class="right" @click="choose_type">
  35. <text>{{current_type?current_type.label:'请选择'}}</text>
  36. <u-icon name="arrow-right" size="20" color="#C8C9CC"></u-icon>
  37. <!-- <view class="warning" v-if="is_warning">
  38. 请选择活动类型
  39. </view> -->
  40. </view>
  41. </u-form-item>
  42. </view>
  43. <u-picker v-model="type" mode="selector" :range="selector_type" @confirm="choose"></u-picker>
  44. <view class="posotion">
  45. <view class="star">
  46. *
  47. </view>
  48. <u-form-item label="活动开始时间" prop="start_time" :label-width="180">
  49. <view class="right" @click="actice_start_time = true">
  50. <text>{{form.start_time?form.start_time:'请选择'}}</text>
  51. <u-icon name="arrow-right" size="20" color="#C8C9CC"></u-icon>
  52. </view>
  53. </u-form-item>
  54. </view>
  55. <u-picker v-model="actice_start_time" mode="time" @confirm="time_choose"></u-picker>
  56. <view class="posotion">
  57. <view class="star">
  58. *
  59. </view>
  60. <u-form-item label="活动结束时间" prop="end_time" :label-width="180">
  61. <view class="right" @click="actice_end_time = true">
  62. <text>{{form.end_time?form.end_time:'请选择'}}</text>
  63. <u-icon name="arrow-right" size="20" color="#C8C9CC"></u-icon>
  64. </view>
  65. </u-form-item>
  66. </view>
  67. <u-picker v-model="actice_end_time" mode="time" @confirm="end_time_choose"></u-picker>
  68. <view class="posotion">
  69. <view class="star">
  70. *
  71. </view>
  72. <u-form-item label="活动形式" prop="shape" :label-width="150">
  73. <view class="right" @click="choose_shape">
  74. <text>{{current_shape?current_shape.label:'请选择'}}</text>
  75. <u-icon name="arrow-right" size="20" color="#C8C9CC"></u-icon>
  76. <view class="warning" v-if="is_shape_show">
  77. 请选择活动形式
  78. </view>
  79. </view>
  80. </u-form-item>
  81. </view>
  82. <u-picker v-model="is_shape" mode="selector" :range="selector" @confirm="shape_choose"></u-picker>
  83. <view class="posotion">
  84. <view class="star">
  85. *
  86. </view>
  87. <u-form-item label="联系人姓名" prop="contact_name" :label-width="150">
  88. <u-input v-model="form.contact_name" input-align="right" />
  89. </u-form-item>
  90. </view>
  91. <view class="posotion">
  92. <view class="star">
  93. *
  94. </view>
  95. <u-form-item label="联系人手机号" prop="contact_mobile" :label-width="180">
  96. <u-input v-model="form.contact_mobile" input-align="right" />
  97. </u-form-item>
  98. </view>
  99. <view class="posotion">
  100. <view class="star p_star">
  101. *
  102. </view>
  103. <view class="label">
  104. 地址
  105. </view>
  106. <u-form-item label="" prop="intro" :label-width="150">
  107. <u-input v-model="form.address" type="text" />
  108. </u-form-item>
  109. </view>
  110. <view class="posotion">
  111. <view class="star">
  112. *
  113. </view>
  114. <u-form-item label="活动详情" prop="body" :label-width="150">
  115. <view class="right" @click="goEdit">
  116. <!-- <VueEditor v-model="form.body" /> -->
  117. <text>{{form.body?'重新输入':'请点击跳转输入'}}</text>
  118. <u-icon name="arrow-right" size="20" color="#C8C9CC"></u-icon>
  119. </view>
  120. </u-form-item>
  121. </view>
  122. <view class="title">
  123. <view class="line"></view>
  124. <text>报名设置</text>
  125. </view>
  126. <view class="posotion">
  127. <view class="star">
  128. *
  129. </view>
  130. <u-form-item label="报名开始时间" prop="sign_up_start_time" :label-width="180">
  131. <view class="right" @click="actice_sign_up_start_time = true">
  132. <text>{{form.sign_up_start_time?form.sign_up_start_time:'请选择'}}</text>
  133. <u-icon name="arrow-right" size="20" color="#C8C9CC"></u-icon>
  134. </view>
  135. </u-form-item>
  136. </view>
  137. <u-picker v-model="actice_sign_up_start_time" mode="time" @confirm="sus_time_choose"></u-picker>
  138. <view class="posotion">
  139. <view class="star">
  140. *
  141. </view>
  142. <u-form-item label="报名结束时间" prop="sign_up_end_time" :label-width="180">
  143. <view class="right" @click="actice_sign_up_end_time = true">
  144. <text>{{form.sign_up_end_time?form.sign_up_end_time:'请选择'}}</text>
  145. <u-icon name="arrow-right" size="20" color="#C8C9CC"></u-icon>
  146. </view>
  147. </u-form-item>
  148. </view>
  149. <u-picker v-model="actice_sign_up_end_time" mode="time" @confirm="sue_time_choose"></u-picker>
  150. <view class="posotion">
  151. <view class="star">
  152. *
  153. </view>
  154. <u-form-item label="报名总人数" prop="total_nums" :label-width="180">
  155. <u-input v-model="form.total_nums" type="number" input-align="right" />
  156. </u-form-item>
  157. </view>
  158. <view class="posotion">
  159. <view class="star">
  160. *
  161. </view>
  162. <u-form-item label="活动状态" prop="status" :label-width="180">
  163. <u-radio-group v-model="form.status" @change="radioGroupChange">
  164. <u-radio name="1">
  165. 正常
  166. </u-radio>
  167. <u-radio name="0">
  168. 暂停
  169. </u-radio>
  170. </u-radio-group>
  171. </u-form-item>
  172. </view>
  173. </u-form>
  174. <view class="btn">
  175. <button type="default" @click="submit">提交</button>
  176. </view>
  177. <!-- <view class="pic">
  178. <view class="top">
  179. <text>活动相册</text>
  180. <u-switch v-model="switchVal"></u-switch>
  181. </view>
  182. <text>*开启后,活动详情显示相册板块</text>
  183. </view>
  184. <view class="pic">
  185. <view class="top">
  186. <text>活动评论</text>
  187. <u-switch v-model="switchVal"></u-switch>
  188. </view>
  189. <text>*开启后,活动详情显示评论板块</text>
  190. </view> -->
  191. <!-- <view class="pic">
  192. <view class="top">
  193. <text>活动互动</text>
  194. <u-switch v-model="switchVal"></u-switch>
  195. </view>
  196. <text>*开启后,活动详情显示互动板块</text>
  197. </view> -->
  198. <u-popup v-model="show" mode="bottom" height="100%">
  199. <view class="form">
  200. <view class="back" @click="show=!show">
  201. <u-icon name="arrow-left" color="#2979ff" size="28"></u-icon>
  202. </view>
  203. <u-navbar :is-back="false" title="填写信息"></u-navbar>
  204. <jinEdit placeholder="请输入内容..." @editOk="editOk" uploadFileUrl="/api/common/upload" :html="form.body">
  205. </jinEdit>
  206. </view>
  207. </u-popup>
  208. </view>
  209. </template>
  210. <script>
  211. import jinEdit from '../../components/jin-edit/jin-edit.vue';
  212. export default {
  213. components: {
  214. jinEdit
  215. },
  216. data() {
  217. return {
  218. form: {
  219. status: 1
  220. },
  221. is_warning: false,
  222. is_shape_show: false,
  223. type: false,
  224. actice_start_time: false,
  225. actice_end_time: false,
  226. is_shape: false,
  227. actice_sign_up_end_time: false,
  228. actice_sign_up_start_time: false,
  229. switchVal: false,
  230. selector: [],
  231. selector_type: [],
  232. show: false,
  233. rules: {
  234. title: [{
  235. required: true,
  236. message: '请输入活动标题',
  237. trigger: ['change', 'blur'],
  238. }],
  239. type_id: [{
  240. required: true,
  241. message: '请选择活动类型',
  242. trigger: ['change', 'blur'],
  243. }],
  244. start_time: [{
  245. required: true,
  246. message: '请选择活动开始时间',
  247. trigger: ['change', 'blur'],
  248. }],
  249. end_time: [{
  250. required: true,
  251. message: '请选择活动结束时间',
  252. trigger: ['change', 'blur'],
  253. }],
  254. sign_up_start_time: [{
  255. required: true,
  256. message: '请选择报名开始时间',
  257. trigger: ['change', 'blur'],
  258. }],
  259. sign_up_end_time: [{
  260. required: true,
  261. message: '请选择报名结束时间',
  262. trigger: ['change', 'blur'],
  263. }],
  264. total_nums: [{
  265. required: true,
  266. type: 'number',
  267. message: '请输入报名总人数',
  268. trigger: ['change', 'blur'],
  269. }],
  270. // shape: [{
  271. // required: true,
  272. // message: '请选择活动形式',
  273. // trigger: ['change', 'blur'],
  274. // }],
  275. contact_name: [{
  276. required: true,
  277. message: '请输入联系人姓名',
  278. trigger: ['change', 'blur'],
  279. }],
  280. contact_mobile: [{
  281. required: true,
  282. len: 11,
  283. message: '请输入联系人手机号',
  284. trigger: ['change', 'blur'],
  285. }],
  286. status: [{
  287. required: true,
  288. message: '请选择活动状态',
  289. trigger: ['change', 'blur'],
  290. }],
  291. address: [{
  292. required: true,
  293. message: '请输入活动地址',
  294. // 可以单个或者同时写两个触发验证方式
  295. trigger: ['change', 'blur'],
  296. }],
  297. body: [{
  298. required: true,
  299. message: '请输入活动内容',
  300. // 可以单个或者同时写两个触发验证方式
  301. trigger: ['change', 'blur'],
  302. }],
  303. },
  304. action: 'http://www.example.com/upload',
  305. fileList: [],
  306. imageDate: {
  307. file_type: 'img',
  308. type: 'course'
  309. }, //上传图片携带参数
  310. active_type: [],
  311. shape_list: [],
  312. current_type: '',
  313. current_shape: '',
  314. uploadImage: ''
  315. }
  316. },
  317. onShow() {
  318. this.action = '/api/common/upload'
  319. },
  320. methods: {
  321. goEdit() {
  322. this.show = true
  323. },
  324. // 点击发布
  325. editOk(res) {
  326. this.form.body = res.html
  327. console.log(this.form,'form')
  328. this.show = false
  329. },
  330. //上传图片成功
  331. uploadSuccess(data) {
  332. this.form.cover = data.data.id
  333. // this.form.headimg = data.data[0].url
  334. this.uploadImage = data.data.url
  335. // this.image_edit = 1
  336. },
  337. choose_type() {
  338. this.type = true
  339. this.active_type = uni.getStorageSync('type')
  340. this.selector_type = this.active_type.filter(item => {
  341. // if(item.label!='全部') {
  342. return item.label!='全部'
  343. // }
  344. })
  345. this.selector_type = this.selector_type.map(item=>{
  346. return item.label
  347. })
  348. console.log(this.active_type, 'active_type')
  349. console.log(this.selector_type, 'selector_type')
  350. },
  351. // picker选择的值
  352. choose(e) {
  353. this.current_type = this.active_type[e]
  354. // if(this.current_type.value == ""){
  355. // this.form.type_id = 0
  356. // return
  357. // }
  358. this.form.type_id = this.current_type.value
  359. // if (this.form.type_id || this.form.type_id == '') {
  360. // this.is_warning = false
  361. // }
  362. console.log(this.form.type_id, 'this.form.type_id')
  363. },
  364. //活动开始时间选择
  365. time_choose(e) {
  366. this.form.start_time = e.year + '-' + e.month + '-' + e.day
  367. },
  368. //活动结束时间选择
  369. end_time_choose(e) {
  370. this.form.end_time = e.year + '-' + e.month + '-' + e.day
  371. },
  372. choose_shape() {
  373. this.is_shape = true
  374. this.shape_list = uni.getStorageSync('shape')
  375. this.selector = this.shape_list.filter(item => {
  376. // if(item.label!='全部') {
  377. return item.label!='全部'
  378. // }
  379. })
  380. this.selector = this.selector.map(item => {
  381. return item.label
  382. })
  383. console.log(this.selector, 'selector')
  384. },
  385. //选择picker中的值
  386. shape_choose(e) {
  387. this.current_shape = this.shape_list[e]
  388. console.log(this.current_shape.value,'this.current_shape.value')
  389. // if(this.current_shape.value == ""){
  390. // this.form.shape = 0
  391. // }
  392. this.form.shape = this.current_shape.value
  393. },
  394. sus_time_choose(e) {
  395. this.form.sign_up_start_time = e.year + '-' + e.month + '-' + e.day
  396. },
  397. sue_time_choose(e) {
  398. this.form.sign_up_end_time = e.year + '-' + e.month + '-' + e.day
  399. },
  400. submit() {
  401. var reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
  402. // if (!this.form.type_id) {
  403. // this.is_warning = true
  404. // } else {
  405. // this.is_warning = false
  406. // }
  407. // if (!this.form.shape) {
  408. // this.is_shape_show = true
  409. // } else {
  410. // this.is_shape_show = false
  411. // }
  412. // this.$refs.uForm.validate(valid => {
  413. // if (valid) {
  414. // this.form.organization_id = this.vuex_user.organization_id
  415. // this.$u.post('/page/organization-activity', this.form).then(res => {
  416. // if (res.code == 200) {
  417. // uni.showToast({
  418. // title: '添加成功',
  419. // icon: 'none'
  420. // })
  421. // setTimeout(function() {
  422. // uni.reLaunch({
  423. // url: 'index'
  424. // })
  425. // }, 1500)
  426. // }
  427. // })
  428. // } else {
  429. // console.log('验证失败');
  430. // }
  431. // });
  432. if(!this.form.cover){
  433. uni.showToast({
  434. title: '请上传活动海报',
  435. icon: 'none'
  436. })
  437. return
  438. }
  439. else if (!this.form.title) {
  440. uni.showToast({
  441. title: '请填写活动标题',
  442. icon: 'none'
  443. })
  444. return
  445. }else if(this.form.type_id!=''&&!this.form.type_id){
  446. uni.showToast({
  447. title: '请选择活动类型',
  448. icon: 'none'
  449. })
  450. return
  451. }
  452. else if (!this.form.start_time) {
  453. uni.showToast({
  454. title: '请选择活动开始时间',
  455. icon: 'none'
  456. })
  457. return
  458. } else if (!this.form.end_time) {
  459. uni.showToast({
  460. title: '请选择活动结束时间',
  461. icon: 'none'
  462. })
  463. return
  464. } else if (this.form.shape!=''&&!this.form.shape) {
  465. uni.showToast({
  466. title: '请选择活动形式',
  467. icon: 'none'
  468. })
  469. return
  470. } else if (!this.form.contact_name) {
  471. uni.showToast({
  472. title: '请填写联系人姓名',
  473. icon: 'none'
  474. })
  475. return
  476. } else if(!this.form.contact_mobile){
  477. uni.showToast({
  478. title: '请正确填写联系人电话',
  479. icon: 'none'
  480. })
  481. return
  482. } else if(!reg_tel.test(this.form.contact_mobile)){
  483. uni.showToast({
  484. title: '请正确填写联系人电话',
  485. icon: 'none'
  486. })
  487. return
  488. }else if (!this.form.address) {
  489. uni.showToast({
  490. title: '请输入地址',
  491. icon: 'none'
  492. })
  493. return
  494. } else if (!this.form.body) {
  495. uni.showToast({
  496. title: '请输入活动详情',
  497. icon: 'none'
  498. })
  499. return
  500. } else if (!this.form.sign_up_start_time) {
  501. uni.showToast({
  502. title: '请选择报名开始时间',
  503. icon: 'none'
  504. })
  505. return
  506. } else if (!this.form.sign_up_end_time) {
  507. uni.showToast({
  508. title: '请选择报名结束时间',
  509. icon: 'none'
  510. })
  511. return
  512. }else if (!this.form.total_nums) {
  513. uni.showToast({
  514. title: '请输入报名总人数',
  515. icon: 'none'
  516. })
  517. return
  518. } else if (!this.form.status) {
  519. uni.showToast({
  520. title: '请选择活动状态',
  521. icon: 'none'
  522. })
  523. return
  524. }
  525. this.form.organization_id = this.vuex_user.organization_id
  526. this.$u.post('/page/organization-activity', this.form).then(res => {
  527. if (res.code == 200) {
  528. uni.showToast({
  529. title: '添加成功',
  530. icon: 'none'
  531. })
  532. setTimeout(function() {
  533. uni.reLaunch({
  534. url: 'index'
  535. })
  536. }, 1500)
  537. }
  538. })
  539. },
  540. radioGroupChange(e) {
  541. }
  542. },
  543. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  544. onReady() {
  545. this.$refs.uForm.setRules(this.rules);
  546. }
  547. }
  548. </script>
  549. <style lang="scss" scoped>
  550. .create_active {
  551. // padding: 0 16px;
  552. background-color: rgba($color: #C8C9CC, $alpha: 0.2);
  553. padding-bottom: 30px;
  554. .img {
  555. width: 100%;
  556. height: 200px;
  557. background-color: #C8C9CC;
  558. background-color: rgba($color: #C8C9CC, $alpha: 0.2);
  559. display: flex;
  560. flex-direction: column;
  561. align-items: center;
  562. justify-content: center;
  563. .slot-btn {
  564. border: 1px dashed #79573D;
  565. width: 70px;
  566. height: 70px;
  567. line-height: 70px;
  568. text-align: center;
  569. margin-bottom: 10px;
  570. }
  571. font-size: 14px;
  572. color: rgba($color: #C8C9CC, $alpha: 1.0);
  573. }
  574. .form {
  575. position: relative;
  576. .back {
  577. position: absolute;
  578. left: 10px;
  579. top: 0px;
  580. width: 30px;
  581. height: 44px;
  582. line-height: 44px;
  583. text-align: center;
  584. z-index: 9999;
  585. // background: #18B566;
  586. }
  587. }
  588. .title {
  589. display: flex;
  590. align-items: center;
  591. padding-top: 15px;
  592. padding-bottom: 10px;
  593. font-size: 14px;
  594. background-color: #fff;
  595. .line {
  596. width: 3px;
  597. height: 20px;
  598. background-color: #79573D;
  599. margin-right: 5px;
  600. }
  601. }
  602. .title1 {
  603. padding: 15px 16px 10px;
  604. }
  605. .form {
  606. padding: 0 16px;
  607. background-color: #fff;
  608. .posotion {
  609. position: relative;
  610. padding-left: 10px;
  611. .star {
  612. position: absolute;
  613. left: 0;
  614. top: 20px;
  615. color: red;
  616. }
  617. .label {
  618. margin-top: 10px;
  619. }
  620. .p_star {
  621. top: 0px;
  622. }
  623. }
  624. .right {
  625. width: 100%;
  626. text-align: right;
  627. color: #C8C9CC;
  628. }
  629. .warning {
  630. color: red;
  631. text-align: left;
  632. font-size: 12px;
  633. }
  634. }
  635. .pic {
  636. padding: 10px 16px;
  637. margin-top: 8px;
  638. background-color: #fff;
  639. color: #C8C9CC;
  640. font-size: 12px;
  641. .top {
  642. color: #333;
  643. font-size: 14px;
  644. display: flex;
  645. align-items: center;
  646. justify-content: space-between;
  647. }
  648. }
  649. .btn {
  650. button {
  651. z-index: 2;
  652. width: 90%;
  653. // position: fixed;
  654. // bottom: 0;
  655. margin-top: 15px;
  656. border-radius: 10px;
  657. background-color: #79573D;
  658. color: #fff;
  659. // border-radius: 0;
  660. &::after {
  661. border: none;
  662. }
  663. }
  664. }
  665. }
  666. </style>