publish.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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="recruitmentList" @change="handelRecruitment">
  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">{{recruitment}}</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="activityformList" @change="handelActivityform">
  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">{{activityform}}</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="addressList" @change="handeladdress">
  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">{{address}}</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="date" :value="activityDate" :start="startDate" :end="endDate"
  111. @change="activityDateChange">
  112. <view class="optionItem">
  113. <view class="option_left">
  114. <text class="option_text">
  115. 活动时间
  116. </text>
  117. </view>
  118. <view class="option_right">
  119. <view class="input_details">
  120. <view class="details">
  121. <view class="uni-input text">{{ activityDate }}</view>
  122. </view>
  123. <view class="arrow">
  124. <image src="../../static/mine/arrow-right.png" mode="aspectFill"></image>
  125. </view>
  126. </view>
  127. </view>
  128. </view>
  129. </picker>
  130. </view>
  131. </view>
  132. <view class="userOptionsBox">
  133. <view class="optionsItemBox">
  134. <picker mode="selector" :range="fundsList" @change="handelFunds">
  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">{{funds}}</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="date" :value="deadlineDate" :start="startDate" :end="endDate"
  158. @change="deadlineDateChange">
  159. <view class="optionItem">
  160. <view class="option_left">
  161. <text class="option_text">
  162. 报名截止
  163. </text>
  164. </view>
  165. <view class="option_right">
  166. <view class="input_details">
  167. <view class="details">
  168. <view class="uni-input text">{{ deadlineDate }}</view>
  169. </view>
  170. <view class="arrow">
  171. <image src="../../static/mine/arrow-right.png" mode="aspectFill"></image>
  172. </view>
  173. </view>
  174. </view>
  175. </view>
  176. </picker>
  177. </view>
  178. </view>
  179. </view>
  180. <view class="" style="height: 10vh;width: 750rpx;position: relative;">
  181. <view class="publish_now">
  182. <button class="btn" @click="submitForm">立即发布</button>
  183. </view>
  184. </view>
  185. </view>
  186. </template>
  187. <script>
  188. export default {
  189. data() {
  190. const currentDate = this.getDate({
  191. format: true
  192. })
  193. return {
  194. navBarData: {
  195. title: '发布', //导航栏标题
  196. btn: 1 //是否显示返回按钮 0不显示 1 显示
  197. },
  198. // 标题
  199. activitytitle: '',
  200. // 内容
  201. activityintro: '',
  202. // 图片
  203. pic: '../../static/publish/photo.png',
  204. imageValue: '',
  205. // 人数
  206. recruitmentList: Array.from({
  207. length: 100
  208. }, (_, index) => index + 1), //100人
  209. recruitment: '无',
  210. // 活动形式
  211. activityformList: ['户外活动', 'xxxx', 'xxxx'],
  212. activityform: '无',
  213. // 活动地址
  214. addressList: ['深圳xxxx大学', '深圳xxxx大学', '深圳xxxx大学'],
  215. address: '无',
  216. // 活动费用
  217. fundsList: Array.from({
  218. length: 30
  219. }, (_, index) => (index + 1) * 100).map(item => item),
  220. funds: '无',
  221. activityDate: currentDate,
  222. deadlineDate: currentDate,
  223. activeList: []
  224. };
  225. },
  226. computed: {
  227. startDate() {
  228. return this.getDate('start');
  229. },
  230. endDate() {
  231. return this.getDate('end');
  232. }
  233. },
  234. methods: {
  235. uploadPic() {
  236. uni.chooseImage({
  237. count: 1, // 图片数量
  238. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  239. sourceType: ['album', 'camera'], //从相册选择或者拍照
  240. success: (res) => {
  241. const tempFilePaths = res.tempFilePaths[0];
  242. console.log(this);
  243. let that=this
  244. const uploadTask = uni.uploadFile({
  245. url: 'http://139.159.246.165:7006/img', // post请求地址
  246. filePath: tempFilePaths,
  247. name: 'file', // 待确认
  248. header: {
  249. // 不要写这个不然报错
  250. // 'Content-Type': 'multipart/form-data',
  251. },
  252. success: function(res) {
  253. // console.log(res.data);
  254. that.imageValue = res.data
  255. // let url = JSON.parse(res.data)
  256. // console.log(url.data);
  257. },
  258. fail: function(uploadFileFail) {
  259. console.log('Error:', uploadFileFail.data);
  260. },
  261. complete: () => {
  262. // 接口调用结束的回调函数(调用成功、失败都会执行)
  263. // console.log('Complete:');
  264. }
  265. });
  266. }
  267. });
  268. },
  269. submitForm() {
  270. if (
  271. this.activitytitle.trim() === '' ||
  272. this.activityintro.trim() === '' ||
  273. this.imageValue == '' ||
  274. this.recruitment.value === '无' ||
  275. this.activityform.trim() === '无' ||
  276. this.address.trim() === '无' ||
  277. this.funds === '无'
  278. ) {
  279. // 弹出弹框或其他处理逻辑
  280. uni.showToast({
  281. title: '请填写完整的表单内容',
  282. icon: 'none'
  283. });
  284. return;
  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. recruitment: this.recruitment,
  293. activityform: this.activityform,
  294. address: this.address,
  295. funds: this.funds,
  296. activityDate: this.activityDate,
  297. deadlineDate: this.deadlineDate,
  298. // price: "188",
  299. // count: "6",
  300. };
  301. console.log(formData);
  302. this.$request('/insertActive', 'POST', formData).then(res => {
  303. console.log(res.data);
  304. if(res.code==200){
  305. uni.switchTab({
  306. url:"/pages/activityPage/activityPage"
  307. })
  308. }
  309. })
  310. },
  311. handelRecruitment(e) {
  312. this.recruitment = this.recruitmentList[e.detail.value]
  313. console.log(this.imageValue);
  314. },
  315. handelActivityform(e) {
  316. this.activityform = this.activityformList[e.detail.value]
  317. },
  318. handeladdress(e) {
  319. this.address = this.addressList[e.detail.value]
  320. },
  321. handelFunds(e) {
  322. this.funds = this.fundsList[e.detail.value]
  323. },
  324. activityDateChange: function(e) {
  325. this.activityDate = e.detail.value
  326. },
  327. deadlineDateChange: function(e) {
  328. this.deadlineDate = e.detail.value
  329. },
  330. getDate(type) {
  331. const date = new Date();
  332. let year = date.getFullYear();
  333. let month = date.getMonth() + 1;
  334. let day = date.getDate();
  335. if (type === 'start') {
  336. year = year - 60;
  337. } else if (type === 'end') {
  338. year = year + 2;
  339. }
  340. month = month > 9 ? month : '0' + month;
  341. day = day > 9 ? day : '0' + day;
  342. return `${year}-${month}-${day}`;
  343. },
  344. },
  345. }
  346. </script>
  347. <style lang="scss" scoped>
  348. .publish {
  349. .liu {
  350. //留白
  351. width: 750rpx;
  352. height: 68rpx;
  353. position: absolute;
  354. bottom: 0;
  355. background-color: #ffffff;
  356. }
  357. .pubTitle {
  358. width: 750rpx;
  359. height: 96rpx;
  360. padding: 24rpx 30rpx 0 30rpx;
  361. .title {
  362. font-size: 32rpx;
  363. line-height: 48rpx;
  364. font-weight: 500;
  365. }
  366. }
  367. .pubMid {
  368. width: 750rpx;
  369. // height: 504rpx;
  370. padding: 24rpx 30rpx 0 30rpx;
  371. // background-color: #8BBEFF;
  372. .mid {
  373. width: 690rpx;
  374. height: 440rpx;
  375. // background-color: #f2f2f2;
  376. .txt {
  377. width: 690rpx;
  378. height: 192rpx;
  379. .txtClass {
  380. width: 100%;
  381. height: 100%;
  382. font-size: 28rpx;
  383. font-weight: 400;
  384. line-height: 48rpx;
  385. }
  386. }
  387. .pic {
  388. width: 224rpx;
  389. height: 224rpx;
  390. background-color: rgba(242, 242, 242, 1);
  391. display: flex;
  392. position: relative;
  393. justify-content: center;
  394. align-items: center;
  395. .pic_show {
  396. position: absolute;
  397. top: 0;
  398. left: 0;
  399. width: 100%;
  400. height: 100%;
  401. z-index: 10;
  402. background-color: #8BBEFF;
  403. image {
  404. width: 100%;
  405. height: 100%;
  406. }
  407. }
  408. .picCont {
  409. display: flex;
  410. flex-direction: column;
  411. justify-content: center;
  412. align-items: center;
  413. image {
  414. width: 56rpx;
  415. height: 66rpx;
  416. }
  417. }
  418. }
  419. }
  420. }
  421. // background-color: #fff;
  422. height: 100vh;
  423. .textCont {
  424. padding: 16px;
  425. }
  426. .addPhoto {
  427. background-color: #f2f2f2;
  428. width: 224rpx;
  429. height: 224rpx;
  430. display: flex;
  431. color: #616161;
  432. flex-direction: column;
  433. align-items: center;
  434. justify-content: center;
  435. margin-left: 30rpx;
  436. image {
  437. width: 50px;
  438. height: 50px;
  439. // margin-left: 48px;
  440. }
  441. .photo {
  442. color: #000000A3;
  443. // padding-left: 44px;
  444. // font-size: 14px;
  445. }
  446. .num {
  447. color: #919191;
  448. // padding-left: 56px;
  449. // font-size: 14px;
  450. }
  451. }
  452. .userOptionsBox {
  453. width: 750rpx;
  454. height: 96rpx;
  455. display: flex;
  456. justify-content: center;
  457. align-items: center;
  458. .optionsItemBox {
  459. width: 690rpx;
  460. .optionItem {
  461. display: flex;
  462. justify-content: space-between;
  463. align-items: center;
  464. .option_left {
  465. display: flex;
  466. align-items: center;
  467. font-size: 28rpx;
  468. line-height: 48rpx;
  469. font-weight: 400;
  470. }
  471. .option_right {
  472. height: 40rpx;
  473. .input_details {
  474. display: flex;
  475. align-items: center;
  476. .details {
  477. display: flex;
  478. flex-direction: row;
  479. .text {
  480. font-size: 28rpx;
  481. color: rgb(153, 153, 153);
  482. }
  483. }
  484. .arrow {
  485. display: flex;
  486. image {
  487. width: 32rpx;
  488. height: 32rpx;
  489. }
  490. }
  491. }
  492. }
  493. }
  494. }
  495. }
  496. .publish_now {
  497. position: absolute;
  498. // bottom: 100rpx;
  499. display: flex;
  500. width: 750rpx;
  501. justify-content: center;
  502. padding-bottom: 50rpx;
  503. .btn {
  504. width: 432rpx;
  505. height: 88rpx;
  506. line-height: 88rpx;
  507. // background-color: #8BBEFF;
  508. background: rgba(0, 86, 168, 1);
  509. color: #fff;
  510. display: flex;
  511. flex-direction: column;
  512. align-items: center;
  513. margin-top: 20px;
  514. }
  515. }
  516. }
  517. </style>