record.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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>
  46. </template>
  47. <script>
  48. import md5 from "@/common/md5.js";
  49. // import pickerAddress from '@/components/liudx-pickerAddress/index.vue'
  50. // var graceChecker = require("../../../common/graceChecker.js");
  51. export default {
  52. components: {
  53. },
  54. data() {
  55. return {
  56. globalUrl:getApp().globalData.shareUrl,
  57. branchId:'',
  58. activeId:'',
  59. recordId:'',
  60. recordObj:{},
  61. imgIdList: [],
  62. uploadList:[],
  63. contentDesc:'',
  64. contentLink:'',
  65. type:'add',
  66. }
  67. },
  68. onLoad(option) {
  69. console.log(option)
  70. this.branchId = option.bId;
  71. this.activeId = option.aId;
  72. this.type = option.types;
  73. if(option.types === 'edit'){
  74. this.getInfos(option.id)
  75. }
  76. },
  77. onShow() {
  78. },
  79. methods: {
  80. goStep(){
  81. this.addOrEditActiveRecord();
  82. },
  83. getInfos(id){
  84. let md5Sign = md5(
  85. "method=" +"activity" + "&timestamp=" + getApp().globalData.globalTimestamp +
  86. "&secret=" + getApp().globalData.secret
  87. );
  88. let url = getApp().globalData.shareUrl +"api/api.php" +"?method=activity&action=process_info_by_id&timestamp=" +
  89. getApp().globalData.globalTimestamp + "&sign=" + md5Sign;
  90. uni.request({
  91. url: url,
  92. method: "POST",
  93. header: {
  94. "content-type": "application/x-www-form-urlencoded",
  95. },
  96. data: {
  97. openid:getApp().globalData.open_id,
  98. id:id
  99. },
  100. success: (res) => {
  101. if (res.data.code === 200) {
  102. let obj = res.data.data;
  103. this.recordId = obj.id;
  104. this.contentDesc = obj.content;
  105. this.contentLink = obj.web_url;
  106. this.uploadList = obj.pic_list.map((item)=>{return this.globalUrl + item.pic_url});
  107. this.imgIdList = obj.pic_list.map((item)=>{return item.pic_id})
  108. }
  109. },
  110. fail: () => {
  111. console.log("连接失败");
  112. },
  113. });
  114. },
  115. addOrEditActiveRecord(){
  116. let url,data;
  117. let md5Sign = md5(
  118. "method=" +"activity" + "&timestamp=" + getApp().globalData.globalTimestamp +
  119. "&secret=" + getApp().globalData.secret
  120. );
  121. if(this.type === 'add'){
  122. url = getApp().globalData.shareUrl +"api/api.php" +"?method=activity&action=process_add&timestamp=" +
  123. getApp().globalData.globalTimestamp + "&sign=" + md5Sign;
  124. data = {
  125. openid:getApp().globalData.open_id,
  126. branch_id:this.branchId,
  127. activity_id:this.activeId,
  128. content:this.contentDesc,
  129. web_url:this.contentLink,
  130. attach_ids:this.imgIdList.join()
  131. }
  132. }else {
  133. url = getApp().globalData.shareUrl +"api/api.php" +"?method=activity&action=process_update&timestamp=" +
  134. getApp().globalData.globalTimestamp + "&sign=" + md5Sign;
  135. data = {
  136. openid:getApp().globalData.open_id,
  137. id:this.recordId,
  138. branch_id:this.branchId,
  139. activity_id:this.activeId,
  140. content:this.contentDesc,
  141. web_url:this.contentLink,
  142. attach_ids:this.imgIdList.join()
  143. }
  144. }
  145. uni.request({
  146. url: url,
  147. method: "POST",
  148. header: {
  149. "content-type": "application/x-www-form-urlencoded",
  150. },
  151. data:data,
  152. success: (res) => {
  153. if (res.data.code === 200) {
  154. if(this.type === 'edit'){
  155. uni.showToast({
  156. title: "修改成功",
  157. icon: "none",
  158. duration: 2500,
  159. });
  160. setTimeout(()=>{uni.navigateBack({})},500)
  161. }else {
  162. uni.showToast({
  163. title: "上传成功",
  164. icon: "none",
  165. duration: 2500,
  166. });
  167. setTimeout(()=>{uni.navigateBack({})},500)
  168. }
  169. }
  170. },
  171. fail: () => {
  172. console.log("连接失败");
  173. },
  174. });
  175. },
  176. getImage(type) {
  177. let that = this;
  178. if (that.uploadList.length >= 3) {
  179. uni.showToast({
  180. title: "最多上传3张图片",
  181. icon: "none",
  182. duration: 2500,
  183. });
  184. return;
  185. }
  186. uni.chooseImage({
  187. sourceType: [type],
  188. count:3 - that.uploadList.length,
  189. sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
  190. success: (res) => {
  191. for (let i = 0; i < res.tempFilePaths.length; i++) {
  192. that.uploadList.push(res.tempFilePaths[i]);
  193. that.uploadFileRequest(res.tempFilePaths[i]);
  194. }
  195. },
  196. });
  197. },
  198. uploadFileRequest(fileVal) {
  199. uni.showLoading({
  200. title: "上传中",
  201. mask: true,
  202. });
  203. let that = this;
  204. let md5Sign = md5(
  205. "method="+"activity_upload" +"&timestamp=" + getApp().globalData.globalTimestamp + "&secret=" +getApp().globalData.secret
  206. );
  207. let url = getApp().globalData.shareUrl + "api/api.php" +"?method=activity_upload&timestamp=" +
  208. getApp().globalData.globalTimestamp +"&sign=" + md5Sign;
  209. uni.uploadFile({
  210. url: url, //需要设置为全局
  211. filePath: fileVal,
  212. name: "file",
  213. formData: {
  214. openid: getApp().globalData.open_id,
  215. file: fileVal,
  216. branch_id:this.branchId
  217. },
  218. success: (res) => {
  219. let tmpres = JSON.parse(res.data);
  220. console.log(tmpres);
  221. uni.hideLoading();
  222. that.imgIdList.push(tmpres.data.id);
  223. },
  224. fail: (res) => {
  225. console.log("上传请求失败");
  226. console.log(res);
  227. },
  228. });
  229. },
  230. delPhoto(idx) {
  231. this.uploadList.splice(idx, 1);
  232. this.imgIdList.splice(idx, 1);
  233. },
  234. showLarge(src) {
  235. console.log(src)
  236. uni.previewImage({
  237. urls: [src],
  238. longPressActions: {
  239. itemList: ["发送给朋友", "保存图片"],
  240. success: function (data) {},
  241. fail: function (err) {
  242. console.log(err.errMsg);
  243. },
  244. },
  245. });
  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. image {
  410. width: 100rpx;
  411. height:100rpx;
  412. }
  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: 10rpx;
  421. }
  422. .del-icon {
  423. position: absolute;
  424. right: 0;
  425. width: 30rpx;
  426. height: 30rpx;
  427. }
  428. .update_button {
  429. text-align: center;
  430. display: flex;
  431. flex-wrap: wrap;
  432. }
  433. .picker-class {
  434. border-radius: 10rpx;
  435. padding: 10rpx;
  436. width: 73%;
  437. font-size: 28rpx;
  438. background: #f5f5f5;
  439. }
  440. .picker-class image {
  441. width: 26rpx;
  442. height: 26rpx;
  443. }
  444. .submit-bth {
  445. width: 25%;
  446. font-size: 26rpx;
  447. margin: 0 0 5% 0;
  448. color: #fff;
  449. }
  450. .select-member {
  451. input {
  452. margin: 2% 2% 2% 0;
  453. height: 80rpx;
  454. line-height: 80rpx;
  455. }
  456. button {
  457. background-color: #169bd5;
  458. margin: 0;
  459. height: 60rpx;
  460. line-height: 60rpx;
  461. width: 20%;
  462. }
  463. }
  464. .check-class {
  465. margin-right:10rpx;
  466. transform:scale(.8);
  467. width: 48%;
  468. margin-top: 2%;
  469. }
  470. .step-box {
  471. display: flex;
  472. justify-content: space-evenly;
  473. align-items: center;
  474. width: 90%;
  475. margin: 5% 0 5% 0;
  476. }
  477. .step-1 {
  478. width: 60rpx;
  479. height: 60rpx;
  480. border-radius: 50%;
  481. background-color:#aaaaaa;
  482. text-align: center;
  483. line-height: 60rpx;
  484. color: #fff;
  485. }
  486. .footer-box {
  487. margin-top: 15%;
  488. width: 90%;
  489. display: flex;
  490. justify-content: space-evenly;
  491. }
  492. .textarea-box {
  493. background: #f7f7f7;
  494. min-height: 120rpx;
  495. font-size: 28rpx;
  496. margin: 3% auto;
  497. padding: 4%;
  498. }
  499. </style>