news.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <template>
  2. <view>
  3. <view class="con">
  4. <textarea id="editor" @input="descInput" class="ql-container" :placeholder="placeholderText"></textarea>
  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 v-if="havePermissionVote" 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. havePermissionVote:false,//是否有选择投票的权限
  117. };
  118. },
  119. onLoad(opt) {
  120. this.getUserPermission()
  121. this.newsType = opt.newsType;
  122. if(opt.isVideo){
  123. this.isVideo = true;
  124. }
  125. if(opt.userGroupId) this.userGroupId = opt.userGroupId;
  126. this.topicId = opt.topicId
  127. uni.setNavigationBarTitle({
  128. title: '编辑动态'
  129. });
  130. this.placeholderText = '请输入内容';
  131. QQMapWX.initMap();
  132. let location = {
  133. latitude: req.getStorage('loctionAddressMap').location.lat,
  134. longitude: req.getStorage('loctionAddressMap').location.lng
  135. }
  136. QQMapWX.reverseGeocoder(location, data => {
  137. this.poiList = data.pois;
  138. this.checkLocation(this.poiList[0],0)
  139. });
  140. },
  141. onShow() {
  142. this.isOpenWeRunData = req.getStorage('isOpenWeRunData')
  143. this.config = JSON.parse(req.getStorage('configRes'))
  144. },
  145. methods: {
  146. getUserPermission(){
  147. req.getRequest('/api/user/getUserPermission',{},res=>{
  148. if(res){
  149. this.havePermissionVote = res.map(item=>item.permissions).indexOf('sys:vote')>-1?true:false
  150. this.havePermissionTopic = res.map(item=>item.permissions).indexOf('sys:topic')>-1?true:false
  151. }
  152. })
  153. },
  154. descInput(event) {
  155. this.desc = event.detail.value;
  156. console.log('desc数据>>>>>>', this.desc);
  157. if (this.desc) {
  158. this.descLength = event.detail.value.length - 1;
  159. } else {
  160. this.descLength = 0;
  161. }
  162. },
  163. uploadImgs() {
  164. let that = this;
  165. that.hidePop()
  166. uni.chooseImage({
  167. count: that.picCount - that.zhiPicUrls.length,
  168. sizeType: ['original', 'compressed'],
  169. sourceType: ['album', 'camera'],
  170. success: function({ tempFilePaths }) {
  171. uni.showLoading({
  172. title: '上传中'
  173. });
  174. var promise = Promise.all(
  175. tempFilePaths.map(tempFilePath => {
  176. return new Promise(function(resolve, reject) {
  177. req.uploadFile('/api/nocheck/upload', tempFilePath, res => {
  178. let picUrls = that.zhiPicUrls;
  179. that.zhiPicUrls = picUrls.concat(res.src);
  180. resolve()
  181. });
  182. });
  183. })
  184. );
  185. promise
  186. .then(function(results) {
  187. uni.hideLoading()
  188. console.log(results);
  189. })
  190. .catch(function(err) {
  191. uni.hideLoading()
  192. console.log(err);
  193. });
  194. }
  195. });
  196. },
  197. //预览图片
  198. previewImg(picUrls, index) {
  199. //预览合同图片
  200. var src = picUrls[index];
  201. let imgs = picUrls;
  202. uni.previewImage({
  203. current: src, // 当前显示图片的http链接
  204. urls: imgs
  205. });
  206. },
  207. cleanimages(index) {
  208. // 删除图片
  209. let arr = this.zhiPicUrls;
  210. arr.splice(index, 1);
  211. this.zhiPicUrls = arr;
  212. },
  213. chooseLocation(){
  214. let that = this;
  215. uni.chooseLocation({//choosePoi不返回经纬度
  216. success: function (res) {
  217. console.log('位置名称:' , res);
  218. that.location = {
  219. poiName: res.name,
  220. poiAddress: res.address,
  221. poiLongitude: res.longitude,
  222. poiLatitude: res.latitude
  223. }
  224. that.reverseGeocoder(res);
  225. }
  226. });
  227. },
  228. reverseGeocoder(location) {
  229. QQMapWX.initMap();
  230. QQMapWX.reverseGeocoder(location, data => {
  231. this.location.poiRegionalism = data.ad_info.adcode.substring(0, 2) + "0000," + data.ad_info.adcode.substring(0, 4) +"00," + data.ad_info.adcode
  232. console.log('解析后的地址地址数据:', data,this.location.poiRegionalism);
  233. });
  234. },
  235. checkLocation(item,index){
  236. if(this.poiIndex == index) return false;
  237. this.poiIndex = index;
  238. this.location = {
  239. poiName: item.title,
  240. poiAddress: item.address,
  241. poiLongitude: item.location.lng,
  242. poiLatitude: item.location.lat,
  243. poiRegionalism: item.ad_info.adcode.substring(0, 2) + "0000," + item.ad_info.adcode.substring(0, 4) +"00," + item.ad_info.adcode
  244. }
  245. },
  246. async submit() {
  247. var dataPream = {};
  248. dataPream.type = this.newsType;
  249. if (!this.desc) {
  250. return req.msg('请输入内容');
  251. }
  252. dataPream.content = this.desc;
  253. //图片
  254. if (this.zhiPicUrls.length > 0) {
  255. dataPream.url = this.zhiPicUrls.join(',');
  256. }
  257. //视频
  258. if (this.videoInfo) {
  259. dataPream.url = this.videoInfo;
  260. }
  261. //话题
  262. if(this.topicId){
  263. dataPream.dialogueId = this.topicId;
  264. }
  265. if (this.htObj) {
  266. dataPream.dialogueId = this.htObj.id;
  267. }
  268. if (this.treeObj) {
  269. dataPream.treeId = this.treeObj.id;
  270. }
  271. //投票
  272. if (this.pollObj) {
  273. dataPream.pollId = this.pollObj.id;
  274. }
  275. //产品
  276. if (this.productList && this.productList.length > 0) {
  277. if(this.newsType==10||this.newsType==11){
  278. dataPream.productIds = this.productList[0].id
  279. }else{
  280. let idList = [];
  281. this.productList.map(it => {
  282. let obj={
  283. productId: it.id
  284. }
  285. idList.push(obj);
  286. });
  287. dataPream.productsList = idList;
  288. }
  289. }
  290. // 位置
  291. if(this.location&&this.location.poiName){
  292. dataPream.poiName = this.location.poiName;
  293. dataPream.poiAddress = this.location.poiAddress;
  294. dataPream.poiLongitude = this.location.poiLongitude;
  295. dataPream.poiLatitude = this.location.poiLatitude;
  296. dataPream.poiRegionalism = this.location.poiRegionalism
  297. }
  298. if(this.userGroupId) dataPream.userGroupId = this.userGroupId;
  299. // await requsetmessage.remindIntegral().then(res => {});
  300. uni.showLoading({
  301. mask: true
  302. })
  303. req.postRequest('/api/v3/moments/save', dataPream, data => {
  304. uni.hideLoading();
  305. if (this.newsType == 2) {
  306. req.msg('提问发表成功');
  307. } else {
  308. req.msg('动态发表成功');
  309. }
  310. let pages = getCurrentPages(); //获取所有页面栈实例列表
  311. let prevPage = pages[pages.length - 2]; //上一页页面实例
  312. prevPage.$vm.isRefresh = true;
  313. setTimeout(() => {
  314. uni.navigateBack();
  315. }, 1500);
  316. });
  317. },
  318. showPop(){
  319. this.isShowPop = true
  320. this.popBottom = 0
  321. },
  322. hidePop(){
  323. this.isShowPop = false
  324. this.isShowPopCenter = false
  325. this.popBottom = '-100%'
  326. },
  327. uploadVodChangeHandle: function (e) {
  328. let self = this;
  329. self.hidePop()
  330. wx.chooseMedia({
  331. count: 1, //上传视频的个数
  332. mediaType:['video'], //限制上传的类型为video
  333. sourceType:['album', 'camera'], //视频选择来源
  334. maxDuration: 58, //拍摄限制时间
  335. camera: 'back', //采用后置摄像头
  336. success:function(res){
  337. //获取临时存放的视频资源
  338. // let tempFilePath=res.tempFiles[0]
  339. console.log('视频文件==',res)
  340. var file = {url: res.tempFiles[0].tempFilePath, coverUrl: res.tempFiles[0].thumbTempFilePath};
  341. self.fileName = res.tempFiles[0].tempFilePath.substring(res.tempFiles[0].tempFilePath.lastIndexOf('/') + 1)
  342. uni.showLoading({
  343. title: '视频上传中'
  344. })
  345. self.upLoadVideo(res.tempFiles[0].tempFilePath)
  346. },
  347. })
  348. },
  349. upLoadVideo(tempFilePath){
  350. req.uploadFile('/api/nocheck/upload',tempFilePath,res=>{
  351. this.videoInfo = res.src
  352. uni.hideLoading()
  353. })
  354. },
  355. clearVideo(){
  356. this.videoInfo = ''
  357. },
  358. videoPlay(){
  359. var that = this;
  360. this.isShowPlayBtn = false;
  361. this.isCotrols = true;
  362. var videoContext = uni.createVideoContext('myVideo') // 对应的视频id
  363. videoContext.play()
  364. },
  365. jumpUrl(url){
  366. this.isShowPopCenter = false
  367. uni.navigateTo({
  368. url: url
  369. })
  370. },
  371. onEditorReady(text) {
  372. var that = this;
  373. uni.createSelectorQuery().select('#editor').context((res) => {
  374. let editorCtx = res.context;
  375. editorCtx.setContents({//赋值
  376. html:text
  377. });
  378. }).exec()
  379. },
  380. // 发帖隐藏定位
  381. closeArea(){
  382. this.showArea = false
  383. this.poiIndex = -1;
  384. this.location = {}
  385. },
  386. // 开启发帖定位
  387. openArea(){
  388. this.showArea = true
  389. this.checkLocation(this.poiList[0],0)
  390. }
  391. }
  392. };
  393. </script>
  394. <style>
  395. @import './news.css';
  396. </style>