comment.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <template>
  2. <view class="content-box">
  3. <!-- <view class="info-box">
  4. <view class="img-container">
  5. <label for="img">添加评论</label>
  6. <view class="note-image-box">
  7. <view class="note-image-item" v-for="(item,index) in uploadList" :key="index">
  8. <view class="close-icon" @click="delPhoto(index)">
  9. <uni-icons type="closeempty" size="18" color="#fff"></uni-icons>
  10. </view>
  11. <view class="image-box" @click="showLarge(item)">
  12. <image :src="item" mode="aspectFill"></image>
  13. </view>
  14. </view>
  15. <view v-if="uploadList.length < 3" class="note-image-item" @click="getImage('album')">
  16. <view class="image-box">
  17. <uni-icons type="plusempty" size="50" color="#eee"></uni-icons>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </view> -->
  23. <view class="info-box">
  24. <view class="info-title-box">
  25. <!-- <image src="/static/require-icon.png" mode="aspectFill"></image> -->
  26. <text>添加评论</text>
  27. </view>
  28. <view class="info-value-box">
  29. <textarea type="text" class="textarea-box" v-model="contentDesc"></textarea>
  30. </view>
  31. </view>
  32. <view class="footer-box">
  33. <!-- <button type="primary" class="submit-bth" style="background-color: #aaaaaa;" @click="goStep()">清空</button> -->
  34. <button type="primary" class="submit-bth" style="background-color: #169bd5;" @click="goStep()">提交</button>
  35. </view>
  36. <!-- <view class="mask-share-box" v-if="isShowShare">
  37. <image src="/static/share-arrow.png" mode="aspectFit"></image>
  38. <view>点击右上角分享</view>
  39. <button @click="closeShare">关闭</button>
  40. </view> -->
  41. <!-- <share-modal @closeShare="closeShare" :isShowShare="isShowShareModal"></share-modal> -->
  42. </view>
  43. </template>
  44. <script>
  45. import md5 from "@/common/md5.js";
  46. import shareModal from '@/components/share-modal/share-modal.vue'
  47. // var graceChecker = require("../../../common/graceChecker.js");
  48. export default {
  49. components: {
  50. "share-modal": shareModal,
  51. },
  52. data() {
  53. return {
  54. globalUrl:getApp().globalData.shareUrl,
  55. branchId:'',
  56. activeId:'',
  57. recordId:'',
  58. recordObj:{},
  59. imgIdList: [],
  60. uploadList:[],
  61. contentDesc:'',
  62. contentLink:'',
  63. type:'add',
  64. isShowShareModal:false,
  65. }
  66. },
  67. onLoad(option) {
  68. console.log(option)
  69. this.branchId = option.bId;
  70. this.activeId = option.aId;
  71. this.type = option.types;
  72. if(option.types === 'edit'){
  73. this.getInfos(option.id)
  74. }
  75. },
  76. onShow() {
  77. },
  78. onShareAppMessage() {
  79. return {
  80. title: '农工笔记',
  81. path:'/pages/index/activity/activity'
  82. }
  83. },
  84. methods: {
  85. goStep(){
  86. this.addOrEditActiveRecord();
  87. },
  88. closeShare(e){
  89. this.isShowShareModal = false;
  90. uni.showToast({
  91. title: "上传成功",
  92. icon: "none",
  93. duration: 2500,
  94. });
  95. setTimeout(()=>{uni.navigateBack({})},500)
  96. },
  97. getInfos(id){
  98. let md5Sign = md5(
  99. "method=" +"activity" + "&timestamp=" + getApp().globalData.globalTimestamp +
  100. "&secret=" + getApp().globalData.secret
  101. );
  102. let url = getApp().globalData.shareUrl +"api/api.php" +"?method=activity&action=files_info_by_id&timestamp=" +
  103. getApp().globalData.globalTimestamp + "&sign=" + md5Sign;
  104. uni.request({
  105. url: url,
  106. method: "POST",
  107. header: {
  108. "content-type": "application/x-www-form-urlencoded",
  109. },
  110. data: {
  111. openid:getApp().globalData.open_id,
  112. id:id
  113. },
  114. success: (res) => {
  115. if (res.data.code === 200) {
  116. let obj = res.data.data;
  117. // this.recordId = obj.id;
  118. // this.contentDesc = obj.content;
  119. // this.contentLink = obj.web_url;
  120. // this.uploadList = obj.pic_list.map((item)=>{return this.globalUrl + item.pic_url});
  121. // this.imgIdList = obj.pic_list.map((item)=>{return item.pic_id})
  122. }
  123. },
  124. fail: () => {
  125. console.log("连接失败");
  126. },
  127. });
  128. },
  129. addOrEditActiveFiles(){
  130. let url,data;
  131. let md5Sign = md5(
  132. "method=" +"activity" + "&timestamp=" + getApp().globalData.globalTimestamp +
  133. "&secret=" + getApp().globalData.secret
  134. );
  135. if(this.type === 'add'){
  136. url = getApp().globalData.shareUrl +"api/api.php" +"?method=activity&action=files_add&timestamp=" +
  137. getApp().globalData.globalTimestamp + "&sign=" + md5Sign;
  138. data = {
  139. openid:getApp().globalData.open_id,
  140. branch_id:this.branchId,
  141. activity_id:this.activeId,
  142. content:this.contentDesc,
  143. attach_ids:this.imgIdList.join()
  144. }
  145. }else {
  146. url = getApp().globalData.shareUrl +"api/api.php" +"?method=activity&action=files_update&timestamp=" +
  147. getApp().globalData.globalTimestamp + "&sign=" + md5Sign;
  148. data = {
  149. openid:getApp().globalData.open_id,
  150. id:this.recordId,
  151. branch_id:this.branchId,
  152. activity_id:this.activeId,
  153. content:this.contentDesc,
  154. attach_ids:this.imgIdList.join()
  155. }
  156. }
  157. uni.request({
  158. url: url,
  159. method: "POST",
  160. header: {
  161. "content-type": "application/x-www-form-urlencoded",
  162. },
  163. data:data,
  164. success: (res) => {
  165. if (res.data.code === 200) {
  166. if(this.type === 'edit'){
  167. uni.showToast({
  168. title: "修改成功",
  169. icon: "none",
  170. duration: 2500,
  171. });
  172. setTimeout(()=>{uni.navigateBack({})},500)
  173. }else {
  174. let types = 'add';
  175. let pages = getCurrentPages(); // 获取当前页面栈的实例,以数组形式按栈的顺序给出,第一个元素为首页,最后一个元素为当前页面。
  176. let nowPage = pages[pages.length - 1]; //当前页页面实例
  177. let prevPage = pages[pages.length - 2]; //上一页页面实例
  178. prevPage.$vm.pageShowShare(types)
  179. uni.showToast({
  180. title: "上传成功",
  181. icon: "none",
  182. duration: 2500,
  183. });
  184. setTimeout(()=>{uni.navigateBack({delta:1})},500)
  185. //this.isShowShareModal = true
  186. }
  187. }
  188. },
  189. fail: () => {
  190. console.log("连接失败");
  191. },
  192. });
  193. },
  194. chooseFile(){
  195. //chooseMessageFile
  196. let that = this;
  197. uni.chooseMessageFile({
  198. count: 3,
  199. type: 'file',
  200. success (res) {
  201. for(let i=0;i<res.tempFiles.length;i++){
  202. res.tempFiles[i].size = (res.tempFiles[i].size/1024) ;
  203. res.tempFiles[i].size = Math.trunc(res.tempFiles[i].size);
  204. let msg = {name:res.tempFiles[i].name,textValue:res.tempFiles[i].path,size:res.tempFiles[i].size};
  205. that.uploadFileRequest(msg)
  206. }
  207. }
  208. })
  209. console.log('文件上传')
  210. },
  211. uploadFileRequest(fileVal){
  212. let that = this;
  213. let md5Sign = md5(
  214. "method=" +"activity_file_upload" +"&timestamp=" +
  215. getApp().globalData.globalTimestamp +"&secret=" +getApp().globalData.secret
  216. );
  217. let url = getApp().globalData.shareUrl + "api/api.php" +"?method=activity_file_upload&timestamp=" +
  218. getApp().globalData.globalTimestamp +"&sign=" + md5Sign;
  219. uni.uploadFile({
  220. url:url, //需要设置为全局
  221. filePath:fileVal.textValue,
  222. name:'file',
  223. formData: {
  224. openid: getApp().globalData.open_id,
  225. file:fileVal.textValue,
  226. branch_id:this.branchId,
  227. file_name:fileVal.name
  228. },
  229. success: res => {
  230. this.fileObj = JSON.parse(res.data);
  231. console.log(this.fileObj.data)
  232. this.fileObj.data.url = getApp().globalData.shareUrl + this.fileObj.data.url;
  233. // let url = 'https://gdoctor.tcmlives.com'
  234. //let msg = msgType === 4 ? {textValue:url+ tmpres.msg.file_path} : {name:fileVal.name,size:fileVal.size,textValue: url+tmpres.msg.file_path};
  235. // that.sendMsg(msg,msgType);
  236. },
  237. fail:res=>{
  238. console.log("上传请求失败");
  239. console.log(res);
  240. }
  241. });
  242. },
  243. delPhoto(idx) {
  244. this.uploadList.splice(idx, 1);
  245. this.imgIdList.splice(idx, 1);
  246. },
  247. }
  248. }
  249. </script>
  250. <style lang="scss" scoped>
  251. .content {
  252. &_list{
  253. display: flex;
  254. flex-direction: row;
  255. align-items: center;
  256. justify-content:space-around;
  257. &_lable{
  258. }
  259. &_content{
  260. flex: 1;
  261. width: auto;
  262. text-align: right;
  263. }
  264. }
  265. }
  266. .content-box {
  267. width: 100%;
  268. /* height: 100%; */
  269. display: flex;
  270. flex-direction: column;
  271. align-items: center;
  272. /* justify-content: center; */
  273. }
  274. .header-box {
  275. width: 85%;
  276. height:80rpx;
  277. border: .5px dotted #00A1B4;
  278. border-radius: 50rpx;
  279. display: flex;
  280. justify-content: center;
  281. align-items: center;
  282. font-size: 24rpx;
  283. color:#00A1B4 ;
  284. /* font-family: PingFangSC-Regular; */
  285. margin-top: 2%;
  286. }
  287. .header-box image {
  288. width: 36rpx;
  289. height: 36rpx;
  290. margin-right: 1%;
  291. }
  292. .self-title-box {
  293. width: 90%;
  294. display: flex;
  295. align-items: center;
  296. font-size: 32rpx;
  297. letter-spacing: 2rpx;
  298. color:#3C3C3C ;
  299. /* font-family: SimHei; */
  300. margin: 4% auto;
  301. font-weight: bold;
  302. height: 50rpx;
  303. line-height: 50rpx;
  304. }
  305. .self-title-box image {
  306. width: 6rpx;
  307. height: 32rpx;
  308. margin-right: 2%;
  309. }
  310. .info-box {
  311. width: 90%;
  312. margin: 3% auto;
  313. display: flex;
  314. flex-direction: column;
  315. // align-items: center;
  316. // height: 180rpx;
  317. }
  318. .info-title-box {
  319. display: flex;
  320. align-items: center;
  321. font-size: 28rpx;
  322. }
  323. .info-title-box image{
  324. width: 15rpx;
  325. height: 15rpx;
  326. margin-right: 2%;
  327. }
  328. .info-value-box {
  329. width: 100%;
  330. }
  331. .info-value-box input {
  332. height: 88rpx;
  333. background: #f7f7f7;
  334. font-size: 26rpx;
  335. padding-left: 4%;
  336. margin: 2% auto;
  337. }
  338. .info-value-box picker {
  339. position: relative;
  340. }
  341. .info-value-box picker image {
  342. position: absolute;
  343. width: 25rpx;
  344. height: 25rpx;
  345. right: 10px;
  346. top: 30rpx;
  347. }
  348. .select-box {
  349. height: 80rpx;
  350. background: #f7f7f7;
  351. font-size: 26rpx;
  352. padding-left: 4%;
  353. margin: 2% auto;
  354. color: #888;
  355. line-height: 88rpx;
  356. }
  357. .info-gender-box {
  358. width: 75%;
  359. font-size: 28rpx;
  360. }
  361. .form-radio {
  362. transform: scale(0.6);
  363. }
  364. .padding-left-2 {
  365. // padding-left: 2%;
  366. }
  367. .margin-right-10 {
  368. margin-right: 10%;
  369. }
  370. .border-line-box {
  371. width: 100%;
  372. height: 20rpx;
  373. background: #f7f7f7;
  374. }
  375. .picker-box{
  376. display: flex;
  377. align-items: center;
  378. justify-content: space-between;
  379. height: 60rpx;
  380. line-height: 60rpx;
  381. background: #f7f7f7;
  382. height: 88rpx;
  383. line-height: 88rpx;
  384. background: #f7f7f7;
  385. font-size: 28rpx;
  386. padding-left: 4%;
  387. }
  388. .uni-input image {
  389. width: 40rpx;
  390. height: 40rpx;
  391. margin-right: 2%;
  392. float: right;
  393. }
  394. .textarea-box {
  395. background: #f7f7f7;
  396. min-height: 120rpx;
  397. font-size: 28rpx;
  398. margin: 5% auto;
  399. padding: 4%;
  400. margin-bottom: 8%;
  401. }
  402. .upload-box {
  403. display: flex;
  404. flex-flow: column;
  405. width: 22%;
  406. height: 100rpx;
  407. border-radius: 10rpx;
  408. padding-top: 15rpx;
  409. }
  410. image {
  411. width: 100rpx;
  412. height:100rpx;
  413. }
  414. .upload-box-photo {
  415. width: 25%;
  416. height: 100rpx;
  417. border-radius: 10rpx;
  418. padding-top: 15rpx;
  419. position: relative;
  420. margin-left: 20rpx;
  421. margin-right: 20rpx;
  422. }
  423. .del-icon {
  424. position: absolute;
  425. right: -15rpx;
  426. width: 30rpx;
  427. height: 30rpx;
  428. }
  429. .update_button {
  430. text-align: center;
  431. display: flex;
  432. flex-wrap: wrap;
  433. }
  434. .picker-class {
  435. border-radius: 10rpx;
  436. padding: 10rpx;
  437. width: 73%;
  438. font-size: 28rpx;
  439. background: #f5f5f5;
  440. }
  441. .picker-class image {
  442. width: 26rpx;
  443. height: 26rpx;
  444. }
  445. .submit-bth {
  446. width: 25%;
  447. font-size: 26rpx;
  448. margin: 0 0 5% 0;
  449. color: #fff;
  450. }
  451. .select-member {
  452. input {
  453. margin: 2% 2% 2% 0;
  454. height: 80rpx;
  455. line-height: 80rpx;
  456. }
  457. button {
  458. background-color: #169bd5;
  459. margin: 0;
  460. height: 60rpx;
  461. line-height: 60rpx;
  462. width: 20%;
  463. }
  464. }
  465. .check-class {
  466. margin-right:10rpx;
  467. transform:scale(.8);
  468. width: 48%;
  469. margin-top: 2%;
  470. }
  471. .step-box {
  472. display: flex;
  473. justify-content: space-evenly;
  474. align-items: center;
  475. width: 90%;
  476. margin: 5% 0 5% 0;
  477. }
  478. .step-1 {
  479. width: 60rpx;
  480. height: 60rpx;
  481. border-radius: 50%;
  482. background-color:#aaaaaa;
  483. text-align: center;
  484. line-height: 60rpx;
  485. color: #fff;
  486. }
  487. .footer-box {
  488. margin-top: 5%;
  489. width: 90%;
  490. display: flex;
  491. justify-content: space-evenly;
  492. }
  493. .textarea-box {
  494. background: #f7f7f7;
  495. min-height: 120rpx;
  496. font-size: 28rpx;
  497. margin: 3% auto;
  498. padding: 4%;
  499. }
  500. .img-container{
  501. width: 90%;
  502. font-size: 26rpx;
  503. .note-image-box{
  504. margin-top: 5px;
  505. display: flex;
  506. flex-wrap: wrap;
  507. padding: 10px;
  508. .note-image-item{
  509. position: relative;
  510. //这两个百分比很关键
  511. width: 33.33%;
  512. height: 0;
  513. padding-top: 33.33%;
  514. box-sizing: border-box;
  515. .close-icon{
  516. display: flex;
  517. justify-content: center;
  518. align-items: center;
  519. position: absolute;
  520. right: 0;
  521. top: 0;
  522. width: 22px;
  523. height: 22px;
  524. border-radius: 50%;
  525. background-color: #d5d5d5;
  526. z-index: 2;
  527. }
  528. .image-box{
  529. display: flex;
  530. justify-content: center;
  531. align-items: center;
  532. position: absolute;
  533. top: 5px;
  534. right: 5px;
  535. bottom: 5px;
  536. left: 5px;
  537. border: 1px #eee solid;
  538. border-radius: 5px;
  539. overflow: hidden;
  540. image{
  541. width: 100%;
  542. height: 100%;
  543. }
  544. }
  545. }
  546. }
  547. }
  548. </style>