add-luntan.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <template>
  2. <view class="add-luntan">
  3. <u-navbar :fixed="false" title="发帖子" bgColor='rgba(0,0,0,0)' placeholder :safeAreaInsetTop="true"
  4. @leftClick='leftClick()'>
  5. </u-navbar>
  6. <textarea placeholder="分享你的想法..." v-model="textarea" class="textarea"></textarea>
  7. <view class="upload-file u-flex u-flex-wrap">
  8. <view class="upload-btn" v-for="(item,index) in images" :key="index" style="border: none;"
  9. @click="$openimage(images,index)">
  10. <view class="del-img" @click.stop>
  11. <u-icon name="close-circle" size="18" color="red" @click="del(index)"></u-icon>
  12. </view>
  13. <image :src="item" mode="aspectFill" class="image"></image>
  14. </view>
  15. <view class="upload-btn u-flex u-row-center" @click="upload" v-if="images.length < 6">
  16. <image src="static/upload.png" class="upload" mode=""></image>
  17. </view>
  18. </view>
  19. <view class="quanzi-box u-flex u-row-between">
  20. <view v-if="quanzi.id" class="u-flex quanzi-content">
  21. <view class="quanzi-img1 u-flex u-row-center">
  22. <image src="../static/images/quanzi.png" mode=""></image>
  23. </view>
  24. <view class="quanzi-name1">
  25. {{quanzi.title}}
  26. </view>
  27. <u-icon @click="quanzi = {}" name="close" color="#0C66C2" size="24"></u-icon>
  28. </view>
  29. <view v-else class="u-flex" @click="show = true">
  30. <view class="quanzi-img u-flex u-row-center">
  31. <image src="../static/images/quanzi.png" mode=""></image>
  32. </view>
  33. <view class="quanzi-name">
  34. 选择圈子
  35. </view>
  36. </view>
  37. <u-icon name="arrow-right" @click="show = true"></u-icon>
  38. </view>
  39. <view class="fabu-btn" @click="toover">
  40. 立即发布
  41. </view>
  42. <u-popup :show="show" mode="bottom" round="28">
  43. <view class="quanzi-popup">
  44. <view class="popup-header u-flex u-row-between">
  45. <u-icon name="close" size="0" @click="show = false" color="#222222"></u-icon>
  46. <text class="text">添加圈子</text>
  47. <u-icon name="close" size="22" @click="show = false" color="#222222"></u-icon>
  48. </view>
  49. <view class="header-search">
  50. <view class="search-box u-flex">
  51. <u-icon name="search" color="#979797" size="36"></u-icon>
  52. <input type="text" class="input" placeholder="搜索圈子" v-model="keywords1" confirm-type="search"
  53. @confirm="tosearch">
  54. </view>
  55. </view>
  56. <view class="scroll-box u-flex">
  57. <scroll-view scroll-y="true" class="quanzi-right" @scrolltolower="todown">
  58. <view v-for="(a,b) in list" :key="b" class="right-item u-flex" @click="quanzi = a;show = false">
  59. <image :src="a.image" class="item-img" mode=""></image>
  60. <view class="item-text u-flex-col">
  61. <text>{{a.title}}</text>
  62. <text>{{a.article_count}}条内容|{{a.follow_count}}人关注</text>
  63. </view>
  64. </view>
  65. </scroll-view>
  66. </view>
  67. <view class="safe-area-inset-bottom"></view>
  68. </view>
  69. </u-popup>
  70. <u-modal @cancel="return1" @confirm="show1=false" :show="show1" :title="title" :content='content'
  71. confirmText='继续编辑' cancelText='退出' :showCancelButton='true' confirmColor="#0C66C2"></u-modal>
  72. </view>
  73. </template>
  74. <script>
  75. import {
  76. group_list,
  77. create_article
  78. } from "@/units/inquire.js"
  79. export default {
  80. data() {
  81. return {
  82. content: '现在退出内容将不会保留',
  83. title: '确定退出吗',
  84. show1: false,
  85. show: false,
  86. left: 0,
  87. page: 1,
  88. list: [],
  89. total: 0,
  90. textarea: '',
  91. quanzi: {},
  92. images: [],
  93. keywords1: '',
  94. keywords: ''
  95. }
  96. },
  97. onLoad(option) {
  98. if (option.quanzi) {
  99. this.quanzi = JSON.parse(option.quanzi)
  100. }
  101. this.getquanzi()
  102. },
  103. methods: {
  104. return1() {
  105. uni.navigateBack()
  106. },
  107. leftClick() {
  108. if (this.quanzi.id || this.textarea || this.images.join(",")) {
  109. this.show1 = true
  110. } else {
  111. uni.navigateBack()
  112. }
  113. },
  114. todown() {
  115. if (this.total != this.list.length) {
  116. this.page++
  117. this.getquanzi()
  118. }
  119. },
  120. tosearch() {
  121. this.keywords = this.keywords1
  122. this.page = 1
  123. this.list = []
  124. this.getquanzi()
  125. },
  126. del(index) {
  127. uni.showModal({
  128. title: "提示",
  129. content: "确定删除吗?",
  130. success: (e) => {
  131. if (e.confirm) {
  132. this.images.splice(index, 1)
  133. }
  134. }
  135. })
  136. },
  137. upload() {
  138. uni.chooseImage({
  139. count: 6 - this.images.length,
  140. success: (e) => {
  141. this.afterRead(e.tempFilePaths)
  142. },
  143. fail: (err) => {
  144. console.log(err);
  145. }
  146. })
  147. },
  148. async afterRead(lists) {
  149. uni.showLoading({
  150. mask: true,
  151. title: "上传中"
  152. })
  153. for (let i = 0; i < lists.length; i++) {
  154. const result = await this.uploadFilePromise(lists[i])
  155. if (result.code == 1) {
  156. this.images.push(result.data.fullurl)
  157. }
  158. }
  159. uni.hideLoading()
  160. },
  161. uploadFilePromise(url) {
  162. return new Promise((resolve, reject) => {
  163. uni.uploadFile({
  164. url: 'https://hire.hdlkeji.com' + '/api/common/upload',
  165. filePath: url,
  166. name: 'file',
  167. success: (res) => {
  168. setTimeout(() => {
  169. resolve(JSON.parse(res.data))
  170. }, 1000)
  171. },
  172. fail: (e) => {
  173. console.log(e);
  174. }
  175. })
  176. })
  177. },
  178. getquanzi() {
  179. group_list({
  180. page: this.page,
  181. keywords: this.keywords
  182. }).then(res => {
  183. this.list = this.list.concat(res.data.data)
  184. this.total = res.data.total
  185. })
  186. },
  187. toover() {
  188. if (!this.textarea) {
  189. this.$u.toast("请输入内容")
  190. return
  191. }
  192. // if (!this.quanzi.id) {
  193. // this.$u.toast("请选择圈子")
  194. // return
  195. // }
  196. uni.showLoading({
  197. mask: true,
  198. title: "请稍后"
  199. })
  200. create_article({
  201. circle_id: this.quanzi.id,
  202. content: this.textarea,
  203. images: this.images.join(",")
  204. }).then(res => {
  205. this.$u.toast(res.msg)
  206. if (res.code == 1) {
  207. setTimeout(() => {
  208. uni.redirectTo({
  209. url: "/pagesC/add-luntan-over?id=" + res.data.id
  210. })
  211. }, 800)
  212. }
  213. })
  214. }
  215. }
  216. }
  217. </script>
  218. <style lang="scss">
  219. .add-luntan {
  220. padding: 28rpx 32rpx;
  221. .fabu-btn {
  222. position: fixed;
  223. bottom: 30rpx;
  224. left: 32rpx;
  225. width: 686rpx;
  226. line-height: 92rpx;
  227. background: #0C66C2;
  228. border-radius: 12rpx;
  229. text-align: center;
  230. font-size: 32rpx;
  231. font-family: PingFangSC-Medium, PingFang SC;
  232. font-weight: 500;
  233. color: #FFFFFF;
  234. }
  235. .quanzi-popup {
  236. width: 750rpx;
  237. background: #FFFFFF;
  238. .scroll-box {
  239. height: 60vh;
  240. .quanzi-right {
  241. flex: 1;
  242. height: 100%;
  243. min-width: 1rpx;
  244. .right-item {
  245. padding: 22rpx 28rpx;
  246. .item-text {
  247. flex: 1;
  248. min-width: 1rpx;
  249. text:first-child {
  250. font-size: 28rpx;
  251. font-family: PingFangSC-Medium, PingFang SC;
  252. font-weight: 500;
  253. color: #222222;
  254. margin-bottom: 4rpx;
  255. }
  256. text:last-child {
  257. font-size: 22rpx;
  258. font-family: PingFangSC-Regular, PingFang SC;
  259. font-weight: 400;
  260. color: #777777;
  261. }
  262. }
  263. .item-img {
  264. width: 76rpx;
  265. height: 76rpx;
  266. border-radius: 10rpx;
  267. margin-right: 16rpx;
  268. background-color: rgba(0, 0, 0, 0.1);
  269. }
  270. }
  271. }
  272. .quanzi-left {
  273. width: 208rpx;
  274. background: #F6F6F6;
  275. height: 100%;
  276. .left-item {
  277. line-height: 96rpx;
  278. font-size: 30rpx;
  279. font-family: PingFangSC-Medium, PingFang SC;
  280. font-weight: 500;
  281. color: #777777;
  282. text-align: center;
  283. }
  284. .leftactive {
  285. background-color: #fff;
  286. font-size: 30rpx;
  287. font-family: PingFangSC-Medium, PingFang SC;
  288. font-weight: 500;
  289. color: #0C66C2;
  290. }
  291. }
  292. }
  293. .header-search {
  294. padding: 0 32rpx 36rpx 32rpx;
  295. border-bottom: 2rpx solid #F4F4F4;
  296. .search-box {
  297. height: 80rpx;
  298. background: #F6F6F6;
  299. border-radius: 16rpx;
  300. padding: 0 20rpx;
  301. .input {
  302. flex: 1;
  303. margin-left: 12rpx;
  304. font-size: 28rpx;
  305. }
  306. }
  307. }
  308. .popup-header {
  309. height: 120rpx;
  310. padding: 0 32rpx;
  311. .text {
  312. font-size: 36rpx;
  313. font-family: PingFangSC-Medium, PingFang SC;
  314. font-weight: 500;
  315. color: #222222;
  316. }
  317. }
  318. }
  319. .quanzi-box {
  320. height: 100rpx;
  321. border-bottom: 2rpx solid #F4F4F4;
  322. .quanzi-content {
  323. padding: 0 14rpx;
  324. height: 50rpx;
  325. background: rgba(12, 102, 194, 0.06);
  326. border-radius: 28rpx;
  327. .quanzi-name1 {
  328. font-size: 24rpx;
  329. font-family: PingFangSC-Medium, PingFang SC;
  330. font-weight: 500;
  331. color: #0C66C2;
  332. margin-right: 14rpx;
  333. }
  334. .quanzi-img1 {
  335. margin-right: 8rpx;
  336. image {
  337. width: 28rpx;
  338. height: 28rpx;
  339. }
  340. }
  341. }
  342. .quanzi-name {
  343. flex: 1;
  344. margin: 0 20rpx;
  345. font-size: 28rpx;
  346. font-family: PingFangSC-Medium, PingFang SC;
  347. font-weight: 500;
  348. color: #444444;
  349. }
  350. .quanzi-img {
  351. width: 48rpx;
  352. height: 48rpx;
  353. background: #F6F6F6;
  354. border-radius: 28rpx;
  355. image {
  356. width: 28rpx;
  357. height: 28rpx;
  358. }
  359. }
  360. }
  361. .upload-file {
  362. .upload-btn {
  363. margin-right: 10rpx;
  364. margin-bottom: 10rpx;
  365. width: 210rpx;
  366. height: 210rpx;
  367. border-radius: 20rpx;
  368. border: 2rpx dashed #D1D1D1;
  369. position: relative;
  370. .del-img {
  371. position: absolute;
  372. top: 0;
  373. right: 0;
  374. z-index: 10;
  375. }
  376. .image {
  377. width: 210rpx;
  378. height: 210rpx;
  379. }
  380. .upload {
  381. width: 88rpx;
  382. height: 88rpx;
  383. }
  384. }
  385. }
  386. .textarea {
  387. width: 100%;
  388. height: 300rpx;
  389. }
  390. }
  391. ::v-deep .u-navbar__content__left {
  392. padding: 0 !important;
  393. }
  394. </style>