publish.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. <template>
  2. <view class="publish">
  3. <statusBar :item="navBarData"></statusBar>
  4. <view class="" style="background-color: #ffffff;">
  5. <view class="pubTitle">
  6. <input class="title" style="" placeholder="活动标题" v-model="activitytitle" />
  7. </view>
  8. <view class="pubMid">
  9. <view class="mid">
  10. <view class="txt">
  11. <textarea class="txtClass" value="" placeholder="请输入内容" v-model="activityintro" />
  12. </view>
  13. <!-- <uni-file-picker :v-model="imageValue" fileMediatype="image" file-extname="png,jpg,jpeg"
  14. @select="select" @success="success" limit="1"> -->
  15. <!-- 上传图片 -->
  16. <view class="pic" @click="uploadPic">
  17. <view class="picCont">
  18. <image :src="pic" mode="aspectFill"></image>
  19. <view
  20. style="font-size: 24rpx;line-height: 40rpx;font-weight: 400;color: rgba(0, 0, 0, 0.6);">
  21. 添加图片
  22. </view>
  23. <view
  24. style="font-size: 20rpx;line-height: 36rpx;font-weight: 400;color: rgba(0, 0, 0, 0.4);">
  25. (0/1)
  26. </view>
  27. </view>
  28. <view class="pic_show" v-if="imageValue!==''">
  29. <image :src="imageValue" mode="aspectFill"></image>
  30. </view>
  31. </view>
  32. <!-- <view class="pic_show">
  33. <image :src="imageValue" mode="aspectFill"></image>
  34. </view> -->
  35. <!-- </uni-file-picker> -->
  36. <!-- <beUpload @getFile="getFile" :navName="'上传文件'" :accept="accept" :progress="progress"></beUpload> -->
  37. </view>
  38. </view>
  39. <view class="userOptionsBox">
  40. <view class="optionsItemBox">
  41. <picker mode="selector" :range="classifyList" @change="handelclassify">
  42. <view class="optionItem">
  43. <view class="option_left">
  44. <text class="option_text">
  45. 活动分类
  46. </text>
  47. </view>
  48. <view class="option_right">
  49. <view class="input_details">
  50. <view class="details">
  51. <view class="uni-input text">{{classify}}</view>
  52. </view>
  53. <view class="arrow">
  54. <image src="../../static/mine/arrow-right.png" mode="aspectFill"></image>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </picker>
  60. </view>
  61. </view>
  62. <view class="userOptionsBox">
  63. <view class="optionsItemBox">
  64. <picker mode="selector" :range="recruitmentList" @change="handelRecruitment">
  65. <view class="optionItem">
  66. <view class="option_left">
  67. <text class="option_text">
  68. 招募人数
  69. </text>
  70. </view>
  71. <view class="option_right">
  72. <view class="input_details">
  73. <view class="details">
  74. <view class="uni-input text">{{recruitment}}</view>
  75. </view>
  76. <view class="arrow">
  77. <image src="../../static/mine/arrow-right.png" mode="aspectFill"></image>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </picker>
  83. </view>
  84. </view>
  85. <view class="userOptionsBox">
  86. <view class="optionsItemBox">
  87. <picker mode="selector" :range="activityformList" @change="handelActivityform">
  88. <view class="optionItem">
  89. <view class="option_left">
  90. <text class="option_text">
  91. 活动形式
  92. </text>
  93. </view>
  94. <view class="option_right">
  95. <view class="input_details">
  96. <view class="details">
  97. <view class="uni-input text">{{activityform}}</view>
  98. </view>
  99. <view class="arrow">
  100. <image src="../../static/mine/arrow-right.png" mode="aspectFill"></image>
  101. </view>
  102. </view>
  103. </view>
  104. </view>
  105. </picker>
  106. </view>
  107. </view>
  108. <view class="userOptionsBox">
  109. <view class="optionsItemBox">
  110. <picker mode="selector" :range="addressList" @change="handeladdress">
  111. <view class="optionItem">
  112. <view class="option_left">
  113. <text class="option_text">
  114. 活动地址
  115. </text>
  116. </view>
  117. <view class="option_right">
  118. <view class="input_details">
  119. <view class="details">
  120. <view class="uni-input text">{{address}}</view>
  121. </view>
  122. <view class="arrow">
  123. <image src="../../static/mine/arrow-right.png" mode="aspectFill"></image>
  124. </view>
  125. </view>
  126. </view>
  127. </view>
  128. </picker>
  129. </view>
  130. </view>
  131. <view class="userOptionsBox">
  132. <view class="optionsItemBox">
  133. <picker mode="date" :value="activityDate" :start="startDate" :end="endDate"
  134. @change="activityDateChange">
  135. <view class="optionItem">
  136. <view class="option_left">
  137. <text class="option_text">
  138. 活动时间
  139. </text>
  140. </view>
  141. <view class="option_right">
  142. <view class="input_details">
  143. <view class="details">
  144. <view class="uni-input text">{{ activityDate }}</view>
  145. </view>
  146. <view class="arrow">
  147. <image src="../../static/mine/arrow-right.png" mode="aspectFill"></image>
  148. </view>
  149. </view>
  150. </view>
  151. </view>
  152. </picker>
  153. </view>
  154. </view>
  155. <view class="userOptionsBox">
  156. <view class="optionsItemBox">
  157. <picker mode="selector" :range="fundsList" @change="handelFunds">
  158. <view class="optionItem">
  159. <view class="option_left">
  160. <text class="option_text">
  161. 活动费用
  162. </text>
  163. </view>
  164. <view class="option_right">
  165. <view class="input_details">
  166. <view class="details">
  167. <view class="uni-input text">{{funds}}</view>
  168. </view>
  169. <view class="arrow">
  170. <image src="../../static/mine/arrow-right.png" mode="aspectFill"></image>
  171. </view>
  172. </view>
  173. </view>
  174. </view>
  175. </picker>
  176. </view>
  177. </view>
  178. <view class="userOptionsBox">
  179. <view class="optionsItemBox">
  180. <picker mode="date" :value="deadlineDate" :start="startDate" :end="endDate"
  181. @change="deadlineDateChange">
  182. <view class="optionItem">
  183. <view class="option_left">
  184. <text class="option_text">
  185. 报名截止
  186. </text>
  187. </view>
  188. <view class="option_right">
  189. <view class="input_details">
  190. <view class="details">
  191. <view class="uni-input text">{{ deadlineDate }}</view>
  192. </view>
  193. <view class="arrow">
  194. <image src="../../static/mine/arrow-right.png" mode="aspectFill"></image>
  195. </view>
  196. </view>
  197. </view>
  198. </view>
  199. </picker>
  200. </view>
  201. </view>
  202. </view>
  203. <view class="" style="height: 10vh;width: 750rpx;position: relative;">
  204. <view class="publish_now">
  205. <button class="btn" @click="submitForm">立即发布</button>
  206. </view>
  207. </view>
  208. </view>
  209. </template>
  210. <script>
  211. export default {
  212. data() {
  213. const currentDate = this.getDate({
  214. format: true
  215. })
  216. return {
  217. navBarData: {
  218. title: '发布', //导航栏标题
  219. btn: 1 //是否显示返回按钮 0不显示 1 显示
  220. },
  221. // 标题
  222. activitytitle: '',
  223. // 内容
  224. activityintro: '',
  225. // 图片
  226. pic: '../../static/publish/photo.png',
  227. imageValue: '',
  228. // 分类
  229. classifyList: ['直播活动', '常规教研活动','专题教研活动'],
  230. classify: '请选择',
  231. // 人数
  232. recruitmentList: Array.from({
  233. length: 100
  234. }, (_, index) => index + 1), //100人
  235. recruitment: '请选择',
  236. // 活动形式
  237. activityformList: ['户外活动', 'xxxx', 'xxxx'],
  238. activityform: '请选择',
  239. // 活动地址
  240. addressList: ['深圳xxxx大学', '深圳xxxx大学', '深圳xxxx大学'],
  241. address: '请选择',
  242. // 活动费用
  243. fundsList: Array.from({
  244. length: 30
  245. }, (_, index) => (index + 1) * 100).map(item => item),
  246. funds: '请选择',
  247. activityDate: currentDate,
  248. deadlineDate: currentDate,
  249. activeList: []
  250. };
  251. },
  252. computed: {
  253. startDate() {
  254. return this.getDate('start');
  255. },
  256. endDate() {
  257. return this.getDate('end');
  258. }
  259. },
  260. methods: {
  261. submitForm() {
  262. if (
  263. this.activitytitle.trim() === '' ||
  264. this.activityintro.trim() === '' ||
  265. this.imageValue == '' ||
  266. this.classify == '请选择' ||
  267. this.recruitment.value === '请选择' ||
  268. this.activityform.trim() === '请选择' ||
  269. this.address.trim() === '请选择' ||
  270. this.funds === '请选择'
  271. ) {
  272. // 弹出弹框或其他处理逻辑
  273. uni.showToast({
  274. title: '请填写完整的表单内容',
  275. icon: 'none'
  276. });
  277. return;
  278. }
  279. if(this.classify=="直播活动"){
  280. this.classify=0
  281. }else if(this.classify=="常规教研活动"){
  282. this.classify=1
  283. }else{
  284. this.classify=2
  285. }
  286. // 将文本框内容和图片链接存储在一个对象中
  287. const formData = {
  288. id: this.$store.state.user.openid,
  289. activitytitle: this.activitytitle,
  290. activityintro: this.activityintro,
  291. img: this.imageValue,
  292. classify:this.classify,
  293. recruitment: this.recruitment,
  294. activityform: this.activityform,
  295. address: this.address,
  296. funds: this.funds,
  297. activityDate: this.activityDate,
  298. deadlineDate: this.deadlineDate,
  299. // price: "188",
  300. // count: "6",
  301. };
  302. // return console.log(formData);
  303. this.$request('/insertActive', 'POST', formData).then(res => {
  304. console.log(res.data);
  305. if (res.code == 200) {
  306. uni.switchTab({
  307. url: "/pages/activityPage/activityPage"
  308. })
  309. }
  310. })
  311. },
  312. handelclassify(e) {
  313. this.classify = this.classifyList[e.detail.value]
  314. console.log(this.classify);
  315. },
  316. handelRecruitment(e) {
  317. this.recruitment = this.recruitmentList[e.detail.value]
  318. console.log(this.imageValue);
  319. },
  320. handelActivityform(e) {
  321. this.activityform = this.activityformList[e.detail.value]
  322. },
  323. handeladdress(e) {
  324. this.address = this.addressList[e.detail.value]
  325. },
  326. handelFunds(e) {
  327. this.funds = this.fundsList[e.detail.value]
  328. },
  329. activityDateChange: function(e) {
  330. this.activityDate = e.detail.value
  331. },
  332. deadlineDateChange: function(e) {
  333. this.deadlineDate = e.detail.value
  334. },
  335. getDate(type) {
  336. const date = new Date();
  337. let year = date.getFullYear();
  338. let month = date.getMonth() + 1;
  339. let day = date.getDate();
  340. if (type === 'start') {
  341. year = year - 60;
  342. } else if (type === 'end') {
  343. year = year + 2;
  344. }
  345. month = month > 9 ? month : '0' + month;
  346. day = day > 9 ? day : '0' + day;
  347. return `${year}-${month}-${day}`;
  348. },
  349. // 上传图片
  350. uploadPic() {
  351. uni.chooseImage({
  352. count: 1, // 图片数量
  353. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  354. sourceType: ['album', 'camera'], //从相册选择或者拍照
  355. success: (res) => {
  356. const tempFilePaths = res.tempFilePaths[0];
  357. console.log(this);
  358. let that = this
  359. const uploadTask = uni.uploadFile({
  360. url: 'http://139.159.246.165:7006/img', // post请求地址
  361. // url: 'https://cxcy.ssti.net.cn/api/UploadFirmFile', // post请求地址
  362. filePath: tempFilePaths,
  363. filePath: tempFilePaths,
  364. name: 'file', // 待确认
  365. header: {
  366. // 不要写这个不然报错
  367. // 'Content-Type': 'multipart/form-data',
  368. },
  369. success: function(res) {
  370. // console.log(res.data);
  371. that.imageValue = res.data
  372. // let url = JSON.parse(res.data)
  373. // console.log(url.data);
  374. },
  375. fail: function(uploadFileFail) {
  376. console.log('Error:', uploadFileFail.data);
  377. },
  378. complete: () => {
  379. // 接口调用结束的回调函数(调用成功、失败都会执行)
  380. // console.log('Complete:');
  381. }
  382. });
  383. }
  384. });
  385. },
  386. },
  387. }
  388. </script>
  389. <style lang="scss" scoped>
  390. .publish {
  391. .liu {
  392. //留白
  393. width: 750rpx;
  394. height: 68rpx;
  395. position: absolute;
  396. bottom: 0;
  397. background-color: #ffffff;
  398. }
  399. .pubTitle {
  400. width: 750rpx;
  401. height: 96rpx;
  402. padding: 24rpx 30rpx 0 30rpx;
  403. .title {
  404. font-size: 32rpx;
  405. line-height: 48rpx;
  406. font-weight: 500;
  407. }
  408. }
  409. .pubMid {
  410. width: 750rpx;
  411. // height: 504rpx;
  412. padding: 24rpx 30rpx 0 30rpx;
  413. // background-color: #8BBEFF;
  414. .mid {
  415. width: 690rpx;
  416. height: 440rpx;
  417. // background-color: #f2f2f2;
  418. .txt {
  419. width: 690rpx;
  420. height: 192rpx;
  421. .txtClass {
  422. width: 100%;
  423. height: 100%;
  424. font-size: 28rpx;
  425. font-weight: 400;
  426. line-height: 48rpx;
  427. }
  428. }
  429. .pic {
  430. width: 224rpx;
  431. height: 224rpx;
  432. background-color: rgba(242, 242, 242, 1);
  433. display: flex;
  434. position: relative;
  435. justify-content: center;
  436. align-items: center;
  437. .pic_show {
  438. position: absolute;
  439. top: 0;
  440. left: 0;
  441. width: 100%;
  442. height: 100%;
  443. z-index: 10;
  444. background-color: #8BBEFF;
  445. image {
  446. width: 100%;
  447. height: 100%;
  448. }
  449. }
  450. .picCont {
  451. display: flex;
  452. flex-direction: column;
  453. justify-content: center;
  454. align-items: center;
  455. image {
  456. width: 56rpx;
  457. height: 66rpx;
  458. }
  459. }
  460. }
  461. }
  462. }
  463. // background-color: #fff;
  464. height: 100vh;
  465. .textCont {
  466. padding: 16px;
  467. }
  468. .addPhoto {
  469. background-color: #f2f2f2;
  470. width: 224rpx;
  471. height: 224rpx;
  472. display: flex;
  473. color: #616161;
  474. flex-direction: column;
  475. align-items: center;
  476. justify-content: center;
  477. margin-left: 30rpx;
  478. image {
  479. width: 50px;
  480. height: 50px;
  481. // margin-left: 48px;
  482. }
  483. .photo {
  484. color: #000000A3;
  485. // padding-left: 44px;
  486. // font-size: 14px;
  487. }
  488. .num {
  489. color: #919191;
  490. // padding-left: 56px;
  491. // font-size: 14px;
  492. }
  493. }
  494. .userOptionsBox {
  495. width: 750rpx;
  496. height: 96rpx;
  497. display: flex;
  498. justify-content: center;
  499. align-items: center;
  500. .optionsItemBox {
  501. width: 690rpx;
  502. .optionItem {
  503. display: flex;
  504. justify-content: space-between;
  505. align-items: center;
  506. .option_left {
  507. display: flex;
  508. align-items: center;
  509. font-size: 28rpx;
  510. line-height: 48rpx;
  511. font-weight: 400;
  512. }
  513. .option_right {
  514. height: 40rpx;
  515. .input_details {
  516. display: flex;
  517. align-items: center;
  518. .details {
  519. display: flex;
  520. flex-direction: row;
  521. .text {
  522. font-size: 28rpx;
  523. color: rgb(153, 153, 153);
  524. }
  525. }
  526. .arrow {
  527. display: flex;
  528. image {
  529. width: 32rpx;
  530. height: 32rpx;
  531. }
  532. }
  533. }
  534. }
  535. }
  536. }
  537. }
  538. .publish_now {
  539. position: absolute;
  540. // bottom: 100rpx;
  541. display: flex;
  542. width: 750rpx;
  543. justify-content: center;
  544. padding-bottom: 50rpx;
  545. .btn {
  546. width: 432rpx;
  547. height: 88rpx;
  548. line-height: 88rpx;
  549. // background-color: #8BBEFF;
  550. background: rgba(0, 86, 168, 1);
  551. color: #fff;
  552. display: flex;
  553. flex-direction: column;
  554. align-items: center;
  555. margin-top: 20px;
  556. }
  557. }
  558. }
  559. </style>