add.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <template>
  2. <div class="addActivity">
  3. <div class="reportBody">
  4. <ul class="detailUl">
  5. <li class="detailLi2">
  6. <span class="liName" style="margin-bottom: 16rpx"><span style="color: red">*</span> &nbsp;活动主题</span>
  7. <van-field
  8. :value="form.activityName"
  9. autosize
  10. type="textarea"
  11. placeholder="请填写活动名称"
  12. class="myField"
  13. maxlength="50"
  14. show-word-limit
  15. @change="changeActivityName"
  16. />
  17. </li>
  18. <li class="detailLi2">
  19. <span class="liName">
  20. <span style="color: red">*</span> &nbsp;选择类别
  21. </span>
  22. <div class="detailLi2Box">
  23. <div class="detailLi2BoxTop">
  24. <div class="checkItem" :class="item.value===form.activityType?'checked':''" v-for="item in tabList" @click="clickCheck(item)">{{item.label}}</div>
  25. </div>
  26. </div>
  27. </li>
  28. <li class="detailLi2">
  29. <span class="liName">
  30. <span style="color: red">*</span> &nbsp;主题图
  31. <span style="color: #B3B3B3;font-size: 28rpx">(支持图片/视频上传限20M内,最多1张)</span>
  32. </span>
  33. <div class="detailLi2Box" style="margin: 24rpx 0 0 0">
  34. <van-uploader
  35. :max-count="6"
  36. @delete="deleteRYXXZP"
  37. :file-list="fileList"
  38. @after-read="uploadRYXXZP"
  39. :show-upload="true"
  40. />
  41. </div>
  42. </li>
  43. <li class="detailLi" style="border-bottom: none">
  44. <span class="liName">
  45. <span style="color: red">*</span>&nbsp; 联系电话
  46. </span>
  47. <input placeholder="请填写" v-model="form.activityPhone" class="liIpt">
  48. </li>
  49. </ul>
  50. </div>
  51. <div class="reportBody">
  52. <ul class="detailUl">
  53. <li class="detailLi2">
  54. <span class="liName" style="margin-bottom: 16rpx"><span style="color: red">*</span>&nbsp; 活动举办</span>
  55. <van-field
  56. :value="form.activitiesNotice"
  57. autosize
  58. type="textarea"
  59. placeholder="请填写活动举办相关信息"
  60. class="myField"
  61. maxlength="2000"
  62. show-word-limit
  63. @change="changeNotice"
  64. />
  65. </li>
  66. <li class="detailLi2">
  67. <span class="liName" style="margin-bottom: 16rpx">
  68. <span style="color: red">*</span>&nbsp; 活动内容
  69. </span>
  70. <van-field
  71. :value="form.activityContent"
  72. autosize
  73. type="textarea"
  74. placeholder="请填写活动举办相关信息"
  75. class="myField"
  76. maxlength="2000"
  77. show-word-limit
  78. @change="changeContent"
  79. />
  80. <span class="liName" style="margin: 24rpx 0">
  81. <span style="color: #B3B3B3;font-size: 28rpx">(支持图片上传限20M内,最多6张)</span>
  82. </span>
  83. <div class="detailLi2Box">
  84. <van-uploader
  85. :max-count="6"
  86. @delete="deleteRYXXZP"
  87. :file-list="fileList"
  88. @after-read="uploadRYXXZP"
  89. :show-upload="true"
  90. />
  91. </div>
  92. </li>
  93. <li class="detailLi2">
  94. <span class="liName" style="margin-bottom: 16rpx">
  95. <span style="color: red">*</span>&nbsp; 活动时间
  96. </span>
  97. <div class="choosTimeBox">
  98. <input placeholder="请选择年月日时分" class="timeIpt" disabled v-model="form.activityStartTime" @click="showTime('actStartTime')">
  99. <span class="midZ">至</span>
  100. <input placeholder="请选择年月日时分" class="timeIpt" disabled v-model="form.activityEndTime" @click="showTime('actEndTime')">
  101. </div>
  102. </li>
  103. <li class="detailLi2" style="border-bottom: none">
  104. <span class="liName" style="margin-bottom: 16rpx">
  105. <span style="color: red">*</span>&nbsp; 活动地址
  106. </span>
  107. <div class="placeBox">
  108. <input placeholder="使用地图拾取" class="timeIpt" v-model="form.activityAddress" disabled>
  109. <van-icon name="location" style="color: rgba(51, 51, 51, 0.90);font-size: 30rpx" @tap="toMap"/>
  110. </div>
  111. <div class="placeBox">
  112. <input placeholder="请补充详细地址,如楼栋-门牌号" class="timeIpt" v-model="form.activityAddressDetail">
  113. </div>
  114. </li>
  115. </ul>
  116. </div>
  117. <div class="reportBody">
  118. <ul class="detailUl">
  119. <li class="detailLi2">
  120. <span class="liName" style="margin-bottom: 16rpx"><span style="color: red">*</span>&nbsp; 报名条件</span>
  121. <van-field
  122. :value="form.registrationConditions"
  123. autosize
  124. type="textarea"
  125. placeholder="请填写活动举办相关信息"
  126. class="myField"
  127. maxlength="2000"
  128. show-word-limit
  129. @change="changeCond"
  130. />
  131. </li>
  132. <li class="detailLi2">
  133. <span class="liName" style="margin-bottom: 16rpx">
  134. <span style="color: red">*</span>&nbsp; 报名时间
  135. </span>
  136. <div class="choosTimeBox">
  137. <input placeholder="请选择年月日时分" class="timeIpt" disabled v-model="regTime1" @click="showTime('regStartTime')">
  138. <span class="midZ">至</span>
  139. <input placeholder="自动带出" class="timeIpt" disabled v-model="form.activityStartTime" style="background: white">
  140. <!-- <span>活动开始时间</span>-->
  141. </div>
  142. </li>
  143. <li class="detailLi2" style="border-bottom: none">
  144. <span class="liName" style="margin-bottom: 16rpx">活动参与</span>
  145. <van-field
  146. :value="form.activityQuota"
  147. autosize
  148. type="textarea"
  149. placeholder="请填写限制人数等"
  150. class="myField"
  151. maxlength="2000"
  152. show-word-limit
  153. @change="changeQuota"
  154. />
  155. </li>
  156. </ul>
  157. </div>
  158. <div class="buttonBox">
  159. <button class="btn zcBtn">暂存</button>
  160. <button class="btn fbBtn" @tap="submit('发布')">发布</button>
  161. </div>
  162. <van-popup
  163. :show="timeShow"
  164. position="bottom"
  165. custom-style="height: 50%;"
  166. >
  167. <van-datetime-picker
  168. type="datetime"
  169. :value="currentDate"
  170. :formatter="formatter"
  171. @cancel="timeShow=false"
  172. @confirm="selectTime"
  173. />
  174. </van-popup>
  175. </div>
  176. </template>
  177. <script>
  178. import {getByCodes} from "@/js_sdk/http";
  179. export default {
  180. data(){
  181. return {
  182. dc_key:['activity_type'],
  183. timeShow:false,
  184. isCheck:false,
  185. isCheck2:false,
  186. time1Str:'',
  187. time2Str:'',
  188. regTime1:'',
  189. regTime1Str:'',
  190. place:'',
  191. currentDate: new Date().getTime(),
  192. form:{
  193. activityName:'',
  194. activityType:'3',
  195. activityPhone: '',
  196. activitiesNotice: '',
  197. activityContent: '',
  198. activityAddress:'',
  199. activityEndTime:'',
  200. activityStartTime:'',
  201. registrationConditions:'',
  202. activityAddressDetail:'',
  203. activityQuota:'',
  204. longitude:'',
  205. latitude:'',
  206. },
  207. phone:'',
  208. tabList:[],
  209. fileList:[],
  210. optionsType:'',
  211. timePickerType:'',
  212. }
  213. },
  214. onLoad(options) {
  215. console.log('options',options);
  216. },
  217. onShow(){
  218. this.getByCodes()
  219. },
  220. methods:{
  221. toMap(){
  222. let _this = this
  223. uni.chooseLocation({
  224. success: function (res) {
  225. console.log('选择的位置:', res.name);
  226. _this.form.activityAddress = res.name
  227. console.log('纬度:' + res.latitude + ',经度:' + res.longitude);
  228. _this.form.longitude = res.longitude
  229. _this.form.latitude = res.latitude
  230. // 其他业务逻辑
  231. },
  232. fail: function (error) {
  233. console.error('Choose location failed: ' + JSON.stringify(error));
  234. },
  235. complete: function () {
  236. console.log('chooseLocation operation is complete');
  237. }
  238. });
  239. },
  240. changeActivityName(e){
  241. this.form.activityName = e.detail
  242. },
  243. changeNotice(e){
  244. this.form.activitiesNotice = e.detail
  245. },
  246. changeContent(e){
  247. this.form.activityContent = e.detail
  248. },
  249. changeCond(e){
  250. this.form.registrationConditions = e.detail
  251. },
  252. changeQuota(e){
  253. this.form.activityQuota = e.detail
  254. },
  255. async getByCodes() {
  256. let data = await getByCodes(JSON.stringify(this.dc_key));
  257. this.tabList = this.$common.handleDicList(data).activity_type;
  258. console.log('this.tabList',this.tabList)
  259. },
  260. clickCheck(item){
  261. this.form.activityType = item.value
  262. },
  263. selectTime(e){
  264. const dateString = this.timestampToDate(e.detail);
  265. if(this.timePickerType === 'actStartTime'){
  266. this.time1Str = e.detail
  267. if (this.time2Str){
  268. if (this.time1Str >= this.time2Str){
  269. this.$showToast("请选择合理时间");
  270. return
  271. }else{
  272. this.form.activityStartTime = dateString
  273. }
  274. }else{
  275. this.form.activityStartTime = dateString
  276. }
  277. }else if(this.timePickerType === 'actEndTime'){
  278. this.time2Str = e.detail
  279. if (this.time1Str){
  280. if (this.time1Str >= this.time2Str){
  281. this.$showToast("请选择合理时间");
  282. return
  283. }else{
  284. this.form.activityEndTime = dateString
  285. }
  286. }else{
  287. this.form.activityEndTime = dateString
  288. }
  289. }else if(this.timePickerType === 'regStartTime'){
  290. this.regTime1Str = e.detail
  291. if (this.time1Str){
  292. if (this.time1Str <= this.regTime1Str){
  293. this.$showToast("请选择合理时间");
  294. return
  295. }else{
  296. this.regTime1 = dateString
  297. }
  298. }else{
  299. this.regTime1 = dateString
  300. }
  301. }
  302. this.timeShow = false
  303. // console.log(dateString)
  304. },
  305. showTime(e){
  306. if (e === 'regStartTime'){
  307. if (!this.form.activityStartTime){
  308. this.$showToast("请先在上方选择活动开始时间");
  309. }else{
  310. this.timePickerType = e
  311. this.timeShow = true
  312. }
  313. } else{
  314. this.timePickerType = e
  315. this.timeShow = true
  316. }
  317. },
  318. submit(e){
  319. const _this = this;
  320. if (_this.form.activityName === "") {
  321. this.$showToast("请填写活动主题");
  322. return;
  323. }
  324. if (_this.form.activityType === "") {
  325. this.$showToast("请选择活动类型");
  326. return;
  327. }
  328. if (_this.form.registrationStartTime === "") {
  329. this.$showToast("请选择报名开始时间");
  330. return;
  331. }
  332. if (_this.form.registrationEndTime === "") {
  333. this.$showToast("请选择报名结束时间");
  334. return;
  335. }
  336. if (_this.form.activityStartTime === "") {
  337. this.$showToast("请选择活动开始时间");
  338. return;
  339. }
  340. if (_this.form.activityEndTime === "") {
  341. this.$showToast("请选择活动结束时间");
  342. return;
  343. }
  344. if (!_this.fileList.length) {
  345. this.$showToast("请上传主题图");
  346. return;
  347. }
  348. if (_this.form.activityPhone === "") {
  349. this.$showToast("请输入联系电话");
  350. return;
  351. }
  352. if (_this.form.activityAddress === "") {
  353. this.$showToast("请输入活动地址");
  354. return;
  355. }
  356. // 差报名条件等必填
  357. console.log(_this.form)
  358. },
  359. deleteRYXXZP(event) {
  360. this.fileList.splice(event.detail.index, 1);
  361. this.$forceUpdate();
  362. },
  363. uploadRYXXZP(event) {
  364. // console.log(event)
  365. let that = this;
  366. const { file } = event.detail;
  367. console.log(event.detail)
  368. uni.uploadFile({
  369. url: that.$constant.BASE_URI + "/wx/fileController/upload",
  370. filePath: file.url,
  371. name: "file",
  372. formData: { user: "test" },
  373. success(res) {
  374. // 上传完成需要更新 fileList
  375. let data = JSON.parse(res.data);
  376. if (event.detail.file.type==='image'){
  377. that.fileList.push({
  378. imgUrl: "/FileController/download/" + data.data[0],
  379. id: data.data[0],
  380. url:
  381. that.$constant.BASE_URI +
  382. "/FileController/download/" +
  383. data.data[0],
  384. type:event.detail.file.type,
  385. isImage:true,
  386. });
  387. }else{
  388. that.fileList.push({
  389. imgUrl: "/FileController/download/" + data.data[0],
  390. id: data.data[0],
  391. url:
  392. that.$constant.BASE_URI +
  393. "/FileController/download/" +
  394. data.data[0],
  395. type:event.detail.file.type,
  396. isVideo:true
  397. });
  398. }
  399. },
  400. fail(res) {},
  401. });
  402. },
  403. // 时间选择单位
  404. formatter(type, val) {
  405. if (type === 'year') {
  406. return `${val}年`;
  407. } else if (type === 'month') {
  408. return `${val}月`;
  409. }else if (type === 'day') {
  410. return `${val}日`;
  411. }else if (type === 'hour') {
  412. return `${val}时`;
  413. }else if (type === 'minute') {
  414. return `${val}分`;
  415. }
  416. return val;
  417. },
  418. // 时间戳转换方法
  419. timestampToDate(timestamp) {
  420. const date = new Date(timestamp); // 如果timestamp是字符串,确保它是整数:parseInt(timestamp)
  421. const year = date.getFullYear();
  422. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  423. const day = date.getDate().toString().padStart(2, '0');
  424. const hours = date.getHours().toString().padStart(2, '0');
  425. const minutes = date.getMinutes().toString().padStart(2, '0');
  426. const seconds = date.getSeconds().toString().padStart(2, '0');
  427. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  428. },
  429. }
  430. }
  431. </script>
  432. <style lang="scss">
  433. .addActivity{
  434. .reportBody{
  435. margin-top: 24rpx;
  436. padding: 0rpx 36rpx;
  437. background: white;
  438. //height: 1416rpx;
  439. box-sizing: border-box;
  440. .record {
  441. display: flex;
  442. align-items: center;
  443. justify-content: flex-end;
  444. color: #0365F9;
  445. font-size: 32rpx;
  446. .recordImg{
  447. width: 36rpx;
  448. height: 36rpx;
  449. padding: 5rpx 0 0 10rpx;
  450. }
  451. }
  452. .detailUl{
  453. margin-top: 20rpx;
  454. .liName{
  455. font-size: 32rpx;
  456. color: rgba(51, 51, 51, 1);
  457. white-space: nowrap;
  458. }
  459. .liIpt{
  460. text-align: right;
  461. }
  462. .detailLi{
  463. display: flex;
  464. justify-content: space-between;
  465. align-items: center;
  466. padding: 32rpx 0;
  467. border-bottom: 2rpx solid #E6E6E6;
  468. .liInfo{
  469. display: inline-block;
  470. text-align: right;
  471. max-width: 428rpx;
  472. color: rgba(102, 102, 102, 1);
  473. font-size: 32rpx;
  474. line-height: 38rpx;
  475. display: flex;
  476. align-items: center;
  477. .radio{
  478. margin-left: 64rpx;
  479. }
  480. .phoneIcon{
  481. width: 64rpx;
  482. height: 64rpx;
  483. margin-left: 24rpx;
  484. }
  485. }
  486. }
  487. .detailLi2{
  488. display: flex;
  489. flex-direction: column;
  490. padding: 32rpx 0;
  491. border-bottom: 2rpx solid #E6E6E6;
  492. .detailLi2BoxTop{
  493. display: flex;
  494. flex-wrap: wrap;
  495. justify-content: space-between;
  496. margin: 12rpx 0;
  497. .checkItem{
  498. width: 160rpx;
  499. height: 64rpx;
  500. font-size: 28rpx;
  501. color: #666666;
  502. display: flex;
  503. align-items: center;
  504. justify-content: center;
  505. background: #F5F7FA;
  506. border-radius: 8rpx;
  507. margin: 12rpx 0;
  508. }
  509. .checked{
  510. background: #0365F9;
  511. color: white;
  512. }
  513. }
  514. .choosTimeBox{
  515. display: flex;
  516. align-items: center;
  517. justify-content: space-between;
  518. .timeIpt{
  519. width: 300rpx;
  520. height: 96rpx;
  521. background: rgba(245, 247, 250, 1);
  522. font-size: 32rpx;
  523. border-radius: 8rpx;
  524. padding: 0 20rpx;
  525. box-sizing: border-box;
  526. }
  527. .midZ{
  528. color: rgba(51, 51, 51, 1);
  529. font-size: 32rpx;
  530. }
  531. }
  532. .placeBox{
  533. display: flex;
  534. justify-content: space-between;
  535. align-items: center;
  536. font-size: 32rpx;
  537. margin: 12rpx 0;
  538. }
  539. }
  540. }
  541. }
  542. .van-cell {
  543. background: #F5F7FA !important;
  544. border-radius: 8rpx;
  545. font-size: 28rpx;
  546. }
  547. .buttonBox{
  548. display: flex;
  549. justify-content: center;
  550. .btn{
  551. width: 240rpx;
  552. height: 80rpx;
  553. display: flex;
  554. border-radius: 8rpx;
  555. align-items: center;
  556. justify-content: center;
  557. margin: 48rpx 16rpx 150rpx 16rpx;
  558. color: white;
  559. letter-spacing: 2rpx;
  560. text-indent: 2rpx;
  561. &::after{
  562. border: none;
  563. }
  564. }
  565. .zcBtn{
  566. background: rgba(254, 134, 67, 1);
  567. }
  568. .fbBtn{
  569. background: #0365F9;
  570. }
  571. }
  572. }
  573. </style>