comment.vue 13 KB

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