record.vue 14 KB

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