news.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <view>
  3. <view class="con">
  4. <editor id="editor" @input="descInput" class="ql-container" :placeholder="placeholderText"></editor>
  5. <!-- <view class="upload ddflex" @tap="uploadVodChangeHandle"><image src="../static/images/upload.png"></image>上传视频</view> -->
  6. <view class="imgbox ddflex">
  7. <view class="imgs" v-for="(item, index) in zhiPicUrls" :key="index">
  8. <image :src="item" class="img" @tap="previewImg(zhiPicUrls, index)" mode="aspectFill"></image>
  9. <image src="../static/images/close.png" class="del" @tap="cleanimages(index)"></image>
  10. </view>
  11. <view class="video" :hidden="!videoInfo">
  12. <video :src="videoInfo" :show-center-play-btn="false" :controls="isCotrols" :autoplay="isCotrols" :id="'myVideo'"></video>
  13. <view class="video-play ddflex" @click="videoPlay()" v-if="isShowPlayBtn"><image src="../../static/images/play.png"></image></view>
  14. <image src="../static/images/close.png" class="del" @click="clearVideo"></image>
  15. </view>
  16. <block v-if="zhiPicUrls.length < picCount && !videoInfo">
  17. <view class="upload ddflex" @click="uploadImgs" v-if="config.open_community_video != 1 || zhiPicUrls.length > 0"><image src="../static/images/upload.png"></image>上传图片</view>
  18. <view class="upload ddflex" @click="showPop" v-if="config.open_community_video == 1&&zhiPicUrls.length == 0"><image src="../static/images/upload.png"></image>上传图片或视频</view>
  19. </block>
  20. </view>
  21. </view>
  22. <view class="other">
  23. <view class="li ddflex" @click="isDaka?'':jumpUrl('/office/topic/topic')">
  24. <image src="../static/images/tj_htico.png" class="o-ico"></image>
  25. <view class="fflex">话题</view>
  26. <view class="sel-ht" v-if="htObj"><text>#{{htObj.title}}</text><!-- <text>#张丹丹推荐绘本</text> --></view>
  27. <image src="../../static/pages/images/more.png" class="rico"></image>
  28. </view>
  29. <!-- <view class="li ddflex" @click="jumpUrl(productList.length>0 ? '/office/product/product':'/office/add/add')">
  30. <image src="../static/images/tj_spico.png" class="o-ico"></image>
  31. <view class="fflex">商品</view>
  32. <view class="sel-ht" v-if="productList.length>0">{{productList.length}}件商品</view>
  33. <image src="../../static/pages/images/more.png" class="rico"></image>
  34. </view> -->
  35. <view class="li ddflex" @click="jumpUrl('/office/addActivity/addActivity')">
  36. <image src="../static/images/tj_spico.png" class="o-ico"></image>
  37. <view class="fflex">链接</view>
  38. <view class="sel-ht" v-if="productList.length>0&&newsType==11">{{productList.length}}个活动</view>
  39. <image src="../../static/pages/images/more.png" class="rico"></image>
  40. </view>
  41. <view class="li ddflex" @click="jumpUrl('/office/vote/vote' + (pollObj ? '?pollId=' + pollObj.id : ''))">
  42. <image src="../static/images/tj_tpico.png" class="o-ico"></image>
  43. <view class="fflex">投票</view>
  44. <view class="sel-ht" v-if="pollObj">发起投票</view>
  45. <image src="../../static/pages/images/more.png" class="rico"></image>
  46. </view>
  47. <view class="li ddflex" @click="chooseLocation" v-if="showArea"><!-- @click="jumpUrl('/office/location/index')" -->
  48. <image src="../static/images/tj_wzico.png" class="o-ico"></image>
  49. <view class="fflex">位置</view>
  50. <view class="sel-ht" v-if="location">{{location.poiName}}</view>
  51. <image src="../../static/pages/images/more.png" class="rico"></image>
  52. </view>
  53. <view class="li ddflex" v-else><!-- @click="jumpUrl('/office/location/index')" -->
  54. <image src="../static/images/tj_wzico.png" class="o-ico"></image>
  55. <view class="fflex">位置</view>
  56. <switch style="scale: 0.7;transform-origin: right;" color="var(--main)" @click="openArea()"></switch>
  57. </view>
  58. </view>
  59. <view class="loca" v-if="showArea">
  60. <scroll-view scroll-x="true" class="locas">
  61. <view class="lis" @click="closeArea()" >不开启定位</view>
  62. <view :class="'lis'+(poiIndex == index ? ' active':'')" @click="checkLocation(item,index)" v-for="(item,index) in poiList" :key="index">{{item.title}}</view>
  63. </scroll-view>
  64. </view>
  65. <view style="height: 160rpx"></view>
  66. <view class="btn-after" @click="submit()">发布帖子</view>
  67. <view class="ceng" @click="hidePop" v-if="isShowPop"></view>
  68. <view class="popup savepadding" :style="'bottom:'+popBottom">
  69. <view class="pop-list">
  70. <view class="li" @tap="uploadImgs">图片</view>
  71. <view class="li" @tap="uploadVodChangeHandle">视频</view>
  72. </view>
  73. <view class="pop-cancel" @click="hidePop">取消</view>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. const app = getApp();
  79. const req = require('../../utils/request.js');
  80. const QQMapWX = require("../../utils/qqmap.js");
  81. const requsetmessage = require('../../utils/requestmessage.js');
  82. import VODUpload from '@/utils/aliyun-upload-sdk-1.0.1.min.js'
  83. const api = require('../../utils/api.js');
  84. export default {
  85. data() {
  86. return {
  87. placeholderText: '请输入内容',
  88. picCount: 9,
  89. title: 'Hello',
  90. desc: '', //描述
  91. zhiPicUrls: [],
  92. newsType: 1, //1 聊一聊 ,2 提问
  93. htObj: '', //选中的话题对象
  94. pollObj: '', //投票对象
  95. productList: [] ,//选中的商品list
  96. treeObj: '',//社区类型
  97. topicId: '',//圈子ID
  98. isVideo: false,//是否上传视频
  99. uploader: '',
  100. isStart: false,
  101. videoInfo: '',
  102. fileName: '',//视频名称
  103. popBottom: '-100%',
  104. isShowPop: false,
  105. isShowPlayBtn: true,
  106. isCotrols: false,
  107. config: {},
  108. location: {},
  109. poiIndex: -1,
  110. poiList: [],
  111. userGroupId: '',//团队id
  112. isShowPopCenter:false,
  113. isDaka:false,
  114. isOpenWeRunData:false,
  115. showArea:true,//是否选择定位
  116. };
  117. },
  118. onLoad(opt) {
  119. this.newsType = opt.newsType;
  120. if(opt.isVideo){
  121. this.isVideo = true;
  122. }
  123. if(opt.userGroupId) this.userGroupId = opt.userGroupId;
  124. this.topicId = opt.topicId
  125. uni.setNavigationBarTitle({
  126. title: '编辑动态'
  127. });
  128. this.placeholderText = '请输入内容';
  129. QQMapWX.initMap();
  130. let location = {
  131. latitude: req.getStorage('loctionAddressMap').location.lat,
  132. longitude: req.getStorage('loctionAddressMap').location.lng
  133. }
  134. QQMapWX.reverseGeocoder(location, data => {
  135. this.poiList = data.pois;
  136. this.checkLocation(this.poiList[0],0)
  137. });
  138. },
  139. onShow() {
  140. this.isOpenWeRunData = req.getStorage('isOpenWeRunData')
  141. this.config = JSON.parse(req.getStorage('configRes'))
  142. },
  143. methods: {
  144. descInput(event) {
  145. this.desc = event.detail.html;
  146. console.log('desc数据>>>>>>', this.desc);
  147. if (this.desc) {
  148. this.descLength = event.detail.text.length - 1;
  149. } else {
  150. this.descLength = 0;
  151. }
  152. },
  153. uploadImgs() {
  154. let that = this;
  155. that.hidePop()
  156. uni.chooseImage({
  157. count: that.picCount - that.zhiPicUrls.length,
  158. sizeType: ['original', 'compressed'],
  159. sourceType: ['album', 'camera'],
  160. success: function({ tempFilePaths }) {
  161. uni.showLoading({
  162. title: '上传中'
  163. });
  164. var promise = Promise.all(
  165. tempFilePaths.map(tempFilePath => {
  166. return new Promise(function(resolve, reject) {
  167. req.uploadFile('/api/nocheck/upload', tempFilePath, res => {
  168. let picUrls = that.zhiPicUrls;
  169. that.zhiPicUrls = picUrls.concat(res.src);
  170. resolve()
  171. });
  172. });
  173. })
  174. );
  175. promise
  176. .then(function(results) {
  177. uni.hideLoading()
  178. console.log(results);
  179. })
  180. .catch(function(err) {
  181. uni.hideLoading()
  182. console.log(err);
  183. });
  184. }
  185. });
  186. },
  187. //预览图片
  188. previewImg(picUrls, index) {
  189. //预览合同图片
  190. var src = picUrls[index];
  191. let imgs = picUrls;
  192. uni.previewImage({
  193. current: src, // 当前显示图片的http链接
  194. urls: imgs
  195. });
  196. },
  197. cleanimages(index) {
  198. // 删除图片
  199. let arr = this.zhiPicUrls;
  200. arr.splice(index, 1);
  201. this.zhiPicUrls = arr;
  202. },
  203. chooseLocation(){
  204. let that = this;
  205. uni.chooseLocation({//choosePoi不返回经纬度
  206. success: function (res) {
  207. console.log('位置名称:' , res);
  208. that.location = {
  209. poiName: res.name,
  210. poiAddress: res.address,
  211. poiLongitude: res.longitude,
  212. poiLatitude: res.latitude
  213. }
  214. that.reverseGeocoder(res);
  215. }
  216. });
  217. },
  218. reverseGeocoder(location) {
  219. QQMapWX.initMap();
  220. QQMapWX.reverseGeocoder(location, data => {
  221. this.location.poiRegionalism = data.ad_info.adcode.substring(0, 2) + "0000," + data.ad_info.adcode.substring(0, 4) +"00," + data.ad_info.adcode
  222. console.log('解析后的地址地址数据:', data,this.location.poiRegionalism);
  223. });
  224. },
  225. checkLocation(item,index){
  226. if(this.poiIndex == index) return false;
  227. this.poiIndex = index;
  228. this.location = {
  229. poiName: item.title,
  230. poiAddress: item.address,
  231. poiLongitude: item.location.lng,
  232. poiLatitude: item.location.lat,
  233. poiRegionalism: item.ad_info.adcode.substring(0, 2) + "0000," + item.ad_info.adcode.substring(0, 4) +"00," + item.ad_info.adcode
  234. }
  235. },
  236. async submit() {
  237. var dataPream = {};
  238. dataPream.type = this.newsType;
  239. if (!this.desc) {
  240. return req.msg('请输入内容');
  241. }
  242. dataPream.content = this.desc;
  243. //图片
  244. if (this.zhiPicUrls.length > 0) {
  245. dataPream.url = this.zhiPicUrls.join(',');
  246. }
  247. //视频
  248. if (this.videoInfo) {
  249. dataPream.url = this.videoInfo;
  250. }
  251. //话题
  252. if(this.topicId){
  253. dataPream.dialogueId = this.topicId;
  254. }
  255. if (this.htObj) {
  256. dataPream.dialogueId = this.htObj.id;
  257. }
  258. if (this.treeObj) {
  259. dataPream.treeId = this.treeObj.id;
  260. }
  261. //投票
  262. if (this.pollObj) {
  263. dataPream.pollId = this.pollObj.id;
  264. }
  265. //产品
  266. if (this.productList && this.productList.length > 0) {
  267. if(this.newsType==10||this.newsType==11){
  268. dataPream.productIds = this.productList[0].id
  269. }else{
  270. let idList = [];
  271. this.productList.map(it => {
  272. let obj={
  273. productId: it.id
  274. }
  275. idList.push(obj);
  276. });
  277. dataPream.productsList = idList;
  278. }
  279. }
  280. // 位置
  281. if(this.location&&this.location.poiName){
  282. dataPream.poiName = this.location.poiName;
  283. dataPream.poiAddress = this.location.poiAddress;
  284. dataPream.poiLongitude = this.location.poiLongitude;
  285. dataPream.poiLatitude = this.location.poiLatitude;
  286. dataPream.poiRegionalism = this.location.poiRegionalism
  287. }
  288. if(this.userGroupId) dataPream.userGroupId = this.userGroupId;
  289. // await requsetmessage.remindIntegral().then(res => {});
  290. uni.showLoading({
  291. mask: true
  292. })
  293. req.postRequest('/api/v3/moments/save', dataPream, data => {
  294. uni.hideLoading();
  295. if (this.newsType == 2) {
  296. req.msg('提问发表成功');
  297. } else {
  298. req.msg('动态发表成功');
  299. }
  300. let pages = getCurrentPages(); //获取所有页面栈实例列表
  301. let prevPage = pages[pages.length - 2]; //上一页页面实例
  302. prevPage.$vm.isRefresh = true;
  303. setTimeout(() => {
  304. uni.navigateBack();
  305. }, 1500);
  306. });
  307. },
  308. showPop(){
  309. this.isShowPop = true
  310. this.popBottom = 0
  311. },
  312. hidePop(){
  313. this.isShowPop = false
  314. this.isShowPopCenter = false
  315. this.popBottom = '-100%'
  316. },
  317. uploadVodChangeHandle: function (e) {
  318. let self = this;
  319. self.hidePop()
  320. wx.chooseMedia({
  321. count: 1, //上传视频的个数
  322. mediaType:['video'], //限制上传的类型为video
  323. sourceType:['album', 'camera'], //视频选择来源
  324. maxDuration: 58, //拍摄限制时间
  325. camera: 'back', //采用后置摄像头
  326. success:function(res){
  327. //获取临时存放的视频资源
  328. // let tempFilePath=res.tempFiles[0]
  329. console.log('视频文件==',res)
  330. var file = {url: res.tempFiles[0].tempFilePath, coverUrl: res.tempFiles[0].thumbTempFilePath};
  331. self.fileName = res.tempFiles[0].tempFilePath.substring(res.tempFiles[0].tempFilePath.lastIndexOf('/') + 1)
  332. uni.showLoading({
  333. title: '视频上传中'
  334. })
  335. self.upLoadVideo(res.tempFiles[0].tempFilePath)
  336. },
  337. })
  338. },
  339. upLoadVideo(tempFilePath){
  340. req.uploadFile('/api/nocheck/upload',tempFilePath,res=>{
  341. this.videoInfo = res.src
  342. uni.hideLoading()
  343. })
  344. },
  345. clearVideo(){
  346. this.videoInfo = ''
  347. },
  348. videoPlay(){
  349. var that = this;
  350. this.isShowPlayBtn = false;
  351. this.isCotrols = true;
  352. var videoContext = uni.createVideoContext('myVideo') // 对应的视频id
  353. videoContext.play()
  354. },
  355. jumpUrl(url){
  356. this.isShowPopCenter = false
  357. uni.navigateTo({
  358. url: url
  359. })
  360. },
  361. onEditorReady(text) {
  362. var that = this;
  363. uni.createSelectorQuery().select('#editor').context((res) => {
  364. let editorCtx = res.context;
  365. editorCtx.setContents({//赋值
  366. html:text
  367. });
  368. }).exec()
  369. },
  370. // 发帖隐藏定位
  371. closeArea(){
  372. this.showArea = false
  373. this.poiIndex = -1;
  374. this.location = {}
  375. },
  376. // 开启发帖定位
  377. openArea(){
  378. this.showArea = true
  379. this.checkLocation(this.poiList[0],0)
  380. }
  381. }
  382. };
  383. </script>
  384. <style>
  385. @import './news.css';
  386. </style>