record.vue 12 KB

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