1
0

poster.vue 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  1. <template>
  2. <app-layout>
  3. <view class="poster-goods">
  4. <view id="head" class="head">
  5. <view class="main-center cross-center">
  6. <!-- #ifdef MP-ALIPAY -->
  7. <canvas id="poster2" style="width: 750px; height: 1334px;position: fixed;top: 100%;left: 100%"></canvas>
  8. <!-- #endif -->
  9. <canvas type="2d" id="poster" style="width: 300px; height: 533.6px;"></canvas>
  10. </view>
  11. </view>
  12. <view class="setting">
  13. <view class="dir-left-nowrap line">
  14. <view class="box-grow-0 main-center cross-center label">
  15. <icon :class="getTheme + '-m-back ' + getTheme"></icon>
  16. <text>样式</text>
  17. </view>
  18. <view class="dir-left-wrap box-grow-1" :class="getTheme">
  19. <view v-for="(item,key) in styleList" :key="key"
  20. @click="changeStyle(item.value)"
  21. v-if="config.activity_poster_style.indexOf(item.value.toString()) !== -1"
  22. :class="item.value == selectForm.style ? 'active ' + getTheme + '-m-border ' + getTheme : ''"
  23. class="style-input main-center cross-center"
  24. >
  25. <text>{{item.label}}</text>
  26. <icon v-if="item.value == selectForm.style" class="icon-active"
  27. :class="getTheme + '-m-back ' + getTheme"></icon>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="dir-left-nowrap line" style="margin-bottom:5rpx">
  32. <view class="box-grow-0 main-center cross-center label">
  33. <icon :class="getTheme + '-m-back ' + getTheme"></icon>
  34. <text>类型</text>
  35. </view>
  36. <view class="dir-left-wrap box-grow-1" :class="getTheme">
  37. <view v-for="(item,key) in typeList" :key="key"
  38. @click="changeType(item.value)"
  39. :class="item.value == selectForm.type ? 'active ' + getTheme + '-m-border ' + getTheme : ''"
  40. class="style-input dir-left-nowrap main-center cross-center"
  41. >
  42. <view v-if="item.value === 1" class="type-pure"></view>
  43. <view v-if="item.value === 2" class="type-gradient"></view>
  44. <text>{{item.label}}</text>
  45. <icon v-if="item.value == selectForm.type" class="icon-active"
  46. :class="getTheme + '-m-back ' + getTheme"></icon>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="dir-left-nowrap line" v-if="selectForm.type == 1">
  51. <view class="box-grow-0 main-center cross-center label" style="margin-top: 19rpx">
  52. <icon :class="getTheme + '-m-back ' + getTheme"></icon>
  53. <text>颜色</text>
  54. </view>
  55. <view class="dir-left-wrap box-grow-1">
  56. <scroll-view scroll-x class="app-scroll" enable-flex="true">
  57. <view v-for="(color,key) in config.color" :key="key"
  58. @click="changeColor(color)"
  59. class="color-bg"
  60. :style="{'background': `${color}`}">
  61. <icon v-if="color == selectForm.color" class="icon-active"
  62. :class="getTheme + '-m-back ' + getTheme"></icon>
  63. </view>
  64. </scroll-view>
  65. </view>
  66. </view>
  67. <view class="button main-center cross-center" @click="submitSave"
  68. :class="getTheme + '-m-back ' + getTheme">保存图片
  69. </view>
  70. </view>
  71. </view>
  72. </app-layout>
  73. </template>
  74. <script>
  75. import {mapGetters, mapState} from 'vuex';
  76. export default {
  77. name: "goods",
  78. data() {
  79. return {
  80. styleList: [{
  81. label: '样式一',
  82. value: 1,
  83. }, {
  84. label: '样式二',
  85. value: 2,
  86. }, {
  87. label: '样式三',
  88. value: 3,
  89. }, {
  90. label: '样式四',
  91. value: 4,
  92. }],
  93. typeList: [],
  94. selectForm: null,
  95. config: {
  96. color: [],
  97. activity_poster_style: [],
  98. },
  99. address: '',
  100. info: {},
  101. activity: {},
  102. middleman: {},
  103. rpx: 1,
  104. canvas: null,
  105. canvas2: null,
  106. ctx: null,
  107. activity_id: 0,
  108. middleman_id: 0,
  109. }
  110. },
  111. computed: {
  112. ...mapGetters('mallConfig', {
  113. getTheme: 'getTheme',
  114. }),
  115. ...mapState({
  116. community: state => state.mallConfig.__wxapp_img.community,
  117. })
  118. },
  119. onLoad(options) {
  120. let that = this;
  121. that.activity_id = options.activity_id;
  122. that.middleman_id = options.middleman_id;
  123. uni.getSystemInfo({
  124. success(res) {
  125. that.rpx = res.windowWidth/375;
  126. }
  127. })
  128. that.loadData();
  129. },
  130. methods: {
  131. drawText(rate,ctx,t,font,x,y,w,center){
  132. let moreText = false;
  133. if(t.indexOf('我在') == 0 || t.indexOf('提货地址') == 0) {
  134. moreText = true;
  135. }
  136. var chr = t.split("");
  137. var temp = "";
  138. var row = [];
  139. if(rate == 1) {
  140. font = font*2
  141. }
  142. ctx.font = font + 'px sans-serif'
  143. ctx.fillStyle = "#353535";
  144. ctx.textBaseline = "middle";
  145. for(var a = 0; a < chr.length; a++){
  146. if( ctx.measureText(temp).width < w ){
  147. ;
  148. }
  149. else{
  150. row.push(temp);
  151. temp = "";
  152. }
  153. temp += chr[a];
  154. }
  155. row.push(temp);
  156. // #ifdef MP-ALIPAY
  157. row.shift();
  158. if(!moreText && rate == 1) {
  159. y = y + 20
  160. }
  161. // #endif
  162. if(row.length > 2) {
  163. for(var b = 0; b < 2; b++){
  164. if(center) {
  165. ctx.textAlign = 'center';
  166. }
  167. var str = row[b];
  168. if(str == undefined) {
  169. str = ''
  170. }
  171. if(b == 1){
  172. str = str.substring(0,str.length-1) + '...';
  173. }
  174. if(str !== '...') {
  175. ctx.fillText(str,x,y+(b+1)*font*1.2);
  176. }
  177. }
  178. }else {
  179. for(var b = 0; b < row.length; b++){
  180. if(center) {
  181. ctx.textAlign = 'center';
  182. }
  183. ctx.fillText(row[b],x,y+(b+1)*font*1.2);
  184. }
  185. }
  186. },
  187. fillRoundRect(cxt, x, y, width, height, radius, fillColor) {
  188. //圆的直径必然要小于矩形的宽高
  189. if (2 * radius > width || 2 * radius > height) { return false; }
  190. cxt.save();
  191. cxt.translate(x, y);
  192. //绘制圆角矩形的各个边
  193. this.drawRoundRectPath(cxt, width, height, radius);
  194. cxt.fillStyle = fillColor || "#000"; //若是给定了值就用给定的值否则给予默认值
  195. cxt.fill();
  196. cxt.restore();
  197. },
  198. strokeRoundRect(cxt, x, y, width, height, radius, lineWidth, strokeColor) {
  199. //圆的直径必然要小于矩形的宽高
  200. if (2 * radius > width || 2 * radius > height) { return false; }
  201. cxt.save();
  202. cxt.translate(x, y);
  203. //绘制圆角矩形的各个边
  204. this.drawRoundRectPath(cxt, width, height, radius);
  205. cxt.lineWidth = lineWidth || 2; //若是给定了值就用给定的值否则给予默认值2
  206. cxt.strokeStyle = strokeColor || "#000";
  207. cxt.stroke();
  208. cxt.restore();
  209. },
  210. drawRoundRectPath(cxt, width, height, radius) {
  211. cxt.beginPath(0);
  212. //从右下角顺时针绘制,弧度从0到1/2PI
  213. cxt.arc(width - radius, height - radius, radius, 0, Math.PI / 2);
  214. //矩形下边线
  215. cxt.lineTo(radius, height);
  216. //左下角圆弧,弧度从1/2PI到PI
  217. cxt.arc(radius, height - radius, radius, Math.PI / 2, Math.PI);
  218. //矩形左边线
  219. cxt.lineTo(0, radius);
  220. //左上角圆弧,弧度从PI到3/2PI
  221. cxt.arc(radius, radius, radius, Math.PI, Math.PI * 3 / 2);
  222. //上边线
  223. cxt.lineTo(width - radius, 0);
  224. //右上角圆弧
  225. cxt.arc(width - radius, radius, radius, Math.PI * 3 / 2, Math.PI * 2);
  226. //右边线
  227. cxt.lineTo(width, height - radius);
  228. cxt.closePath();
  229. },
  230. loadData() {
  231. const self = this;
  232. self.$request({
  233. url: self.$api.community.poster,
  234. data: {
  235. activity_id: self.activity_id,
  236. middleman_id: self.middleman_id
  237. }
  238. }).then(info => {
  239. self.$hideLoading();
  240. if (info.code === 0) {
  241. self.config = info.data.config;
  242. self.info = info.data.info;
  243. self.middleman = info.data.middleman;
  244. self.activity = info.data.activity;
  245. self.activity.goods_list = self.activity.goods_list.slice(0,6);
  246. self.typeList = [{
  247. label: '纯色',
  248. value: 1,
  249. }, {
  250. label: '背景图',
  251. value: 2,
  252. }];
  253. self.selectForm = {
  254. color: self.config['color'][0],
  255. style: self.config['activity_poster_style'][0],
  256. type: 2,
  257. }
  258. setTimeout(() => {
  259. const query = uni.createSelectorQuery()
  260. query.select('#poster')
  261. .fields({ node: true, size: true })
  262. .exec((res) => {
  263. // #ifndef MP-ALIPAY
  264. self.canvas = res[0].node
  265. self.ctx = self.canvas.getContext('2d')
  266. const dpr = uni.getSystemInfoSync().pixelRatio
  267. self.canvas.width = res[0].width * dpr
  268. self.canvas.height = res[0].height * dpr
  269. self.ctx.scale(dpr, dpr)
  270. self.created(self.canvas,self.ctx, 0.4);
  271. // #endif
  272. // #ifdef MP-ALIPAY
  273. self.$showLoading({
  274. type: 'global',
  275. text: '生成中...'
  276. });
  277. self.activity.goods_list.forEach((item, index) => {
  278. my.getImageInfo({
  279. src: item.cover_pic,
  280. success: function (res) {
  281. item.cover = res.path
  282. if(index == 5 || index == self.activity.goods_list.length -1) {
  283. self.canvas = uni.createCanvasContext('poster');
  284. self.normalCreated(self.canvas,0.4);
  285. self.canvas2 = uni.createCanvasContext('poster2');
  286. self.normalCreated(self.canvas2,1);
  287. }
  288. }
  289. })
  290. })
  291. // #endif
  292. }
  293. )
  294. });
  295. } else {
  296. uni.showToast({title: info.msg,icon: 'none'});
  297. }
  298. })
  299. },
  300. changeStyle(value) {
  301. const self = this;
  302. self.selectForm.style = value;
  303. setTimeout(() => {
  304. // #ifndef MP-ALIPAY
  305. self.created(self.canvas,self.ctx, 0.4);
  306. // #endif
  307. // #ifdef MP-ALIPAY
  308. self.normalCreated(self.canvas, 0.4);
  309. self.normalCreated(self.canvas2,1);
  310. // #endif
  311. });
  312. },
  313. changeType(value) {
  314. const self = this;
  315. self.selectForm.type = value;
  316. setTimeout(() => {
  317. // #ifndef MP-ALIPAY
  318. self.created(self.canvas,self.ctx, 0.4);
  319. // #endif
  320. // #ifdef MP-ALIPAY
  321. self.normalCreated(self.canvas, 0.4);
  322. self.normalCreated(self.canvas2,1);
  323. // #endif
  324. });
  325. },
  326. changeColor(value) {
  327. const self = this;
  328. self.selectForm.color = value;
  329. setTimeout(() => {
  330. // #ifndef MP-ALIPAY
  331. self.created(self.canvas,self.ctx, 0.4);
  332. // #endif
  333. // #ifdef MP-ALIPAY
  334. self.normalCreated(self.canvas, 0.4);
  335. self.normalCreated(self.canvas2,1);
  336. // #endif
  337. });
  338. },
  339. submitSave: function () {
  340. const self = this;
  341. self.$showLoading({title: `正在保存图片`});
  342. uni.canvasToTempFilePath({
  343. // #ifndef MP-ALIPAY
  344. canvas: self.canvas,
  345. // #endif
  346. // #ifdef MP-ALIPAY
  347. x: 0,
  348. y: 0,
  349. width: 750,
  350. height: 1334,
  351. destWidth: 750,
  352. destHeight: 1334,
  353. canvasId: 'poster2',
  354. // #endif
  355. success: function(res) {
  356. // #ifndef MP-ALIPAY
  357. uni.getImageInfo({
  358. src: res.tempFilePath,
  359. success: function (e) {
  360. uni.saveImageToPhotosAlbum({
  361. filePath: e.path,
  362. success: function () {
  363. uni.showToast({title: '保存成功'});
  364. },
  365. fail: function (err) {
  366. if (err.errMsg) {
  367. uni.showModal({
  368. title: '提示',
  369. content: '您好,请先授权保存到相册权限',
  370. showCancel: false,
  371. success(res) {
  372. if (res.confirm) {
  373. uni.openSetting({
  374. success(settingdata) {
  375. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  376. uni.saveImageToPhotosAlbum({
  377. filePath: e.tempFilePath,
  378. success: function () {
  379. uni.showToast({title: '保存成功'});
  380. },
  381. })
  382. } else {
  383. uni.showModal({
  384. title: '提示',
  385. content: '授权失败,请稍后重新获取',
  386. showCancel: false,
  387. })
  388. }
  389. }
  390. })
  391. }
  392. }
  393. })
  394. }
  395. },
  396. complete: function (e) {
  397. self.$hideLoading();
  398. }
  399. });
  400. },
  401. fail: function (e) {
  402. uni.showModal({
  403. title: '图片下载失败',
  404. content: e.errMsg,
  405. showCancel: false,
  406. });
  407. },
  408. complete: function (e) {
  409. self.$hideLoading();
  410. }
  411. });
  412. // #endif
  413. // #ifdef MP-ALIPAY
  414. my.saveImage({
  415. url: res.tempFilePath,
  416. success: () => {
  417. my.hideLoading();
  418. self.$hideLoading();
  419. uni.showToast({
  420. title: '保存成功',
  421. duration: 3000,
  422. icon: 'none',
  423. });
  424. },
  425. fail() {
  426. my.hideLoading();
  427. self.$hideLoading();
  428. },
  429. complete() {
  430. }
  431. });
  432. // #endif
  433. }
  434. })
  435. },
  436. // #ifndef MP-ALIPAY
  437. created(canvas, ctx,rpx) {
  438. let that = this;
  439. that.$showLoading({
  440. type: 'global',
  441. text: '生成中...'
  442. });
  443. ctx.clearRect(0, 0, 750*rpx,1334*rpx)
  444. that.address = that.middleman.city+that.middleman.district;
  445. if(that.middleman.city != that.middleman.province) {
  446. that.address = that.middleman.province + that.address
  447. }
  448. // 背景图
  449. if(that.selectForm.type == 1) {
  450. // 填充颜色
  451. ctx.fillStyle= that.selectForm.color;
  452. ctx.fillRect(0, 0, 750*rpx,1334*rpx);
  453. that.chooseStyle(canvas, ctx,rpx);
  454. }else {
  455. // 填充图片
  456. const bg = canvas.createImage();
  457. bg.src = that.config.image_bg;
  458. if(bg.src.indexOf('http://') == 0) {
  459. bg.src.replace('http://','https://')
  460. }
  461. bg.onload = () => {
  462. ctx.drawImage(bg, 0, 0, 750*rpx,1334*rpx)
  463. that.chooseStyle(canvas, ctx,rpx)
  464. }
  465. }
  466. },
  467. chooseStyle(canvas, ctx,rpx) {
  468. let that = this;
  469. const style = canvas.createImage();
  470. let x, y, size,textFont, textX, textY, textWidth,GoodsSize,infoX,infoY,infoSize,infoLeft,infoTop,qrX,qrY,qrWidth;
  471. // 样式一
  472. if(that.selectForm.style == 1) {
  473. x = 78*rpx;
  474. y = 133*rpx;
  475. size = 97*rpx;
  476. textFont = 13
  477. textX = 195*rpx
  478. textY = 130*rpx
  479. textWidth = 480*rpx
  480. GoodsSize = 370*rpx
  481. infoX = 132*rpx
  482. infoY = 1000*rpx
  483. infoSize = 33*rpx
  484. infoLeft = 64*rpx
  485. infoTop = 1060*rpx
  486. qrX = 440*rpx
  487. qrY = 984*rpx
  488. qrWidth = 240*rpx
  489. style.src = that.community.style1;
  490. }else if(that.selectForm.style == 2) {
  491. x = 80*rpx;
  492. y = 810*rpx;
  493. size = 97*rpx;
  494. textFont = 13
  495. textX = 197*rpx
  496. textY = 807*rpx
  497. textWidth = 480*rpx
  498. GoodsSize = 180*rpx
  499. infoX = 430*rpx
  500. infoY = 985*rpx
  501. infoSize = 33*rpx
  502. infoLeft = 360*rpx
  503. infoTop = 1045*rpx
  504. qrX = 70*rpx
  505. qrY = 945*rpx
  506. qrWidth = 240*rpx
  507. style.src = that.community.style2;
  508. }else if(that.selectForm.style == 3) {
  509. x = 80*rpx;
  510. y = 164*rpx;
  511. size = 97*rpx;
  512. textFont = 13
  513. textX = 200*rpx
  514. textY = 161*rpx
  515. textWidth = 480*rpx
  516. GoodsSize = 310*rpx
  517. infoX = 430*rpx
  518. infoY = 1040*rpx
  519. infoSize = 33*rpx
  520. infoLeft = 360*rpx
  521. infoTop = 1100*rpx
  522. qrX = 70*rpx
  523. qrY = 1000*rpx
  524. qrWidth = 240*rpx
  525. style.src = that.community.style3;
  526. }else if(that.selectForm.style == 4) {
  527. x = 56*rpx;
  528. y = 124*rpx;
  529. size = 97*rpx;
  530. textFont = 13
  531. textX = 192*rpx
  532. textY = 121*rpx
  533. textWidth = 480*rpx
  534. GoodsSize = 464*rpx
  535. infoX = 430*rpx
  536. infoY = 1040*rpx
  537. infoSize = 33*rpx
  538. infoLeft = 360*rpx
  539. infoTop = 1100*rpx
  540. qrX = 70*rpx
  541. qrY = 1000*rpx
  542. qrWidth = 240*rpx
  543. style.src = that.community.style4;
  544. }
  545. style.onload = () => {
  546. ctx.drawImage(style, 0, 0, 750*rpx,1334*rpx)
  547. // 头像
  548. ctx.save();
  549. ctx.beginPath();
  550. ctx.arc(size / 2 + x, size / 2 + y, size / 2, 0, Math.PI * 2, false);
  551. ctx.strokeStyle ='white';
  552. ctx.stroke();
  553. ctx.clip();
  554. const avatar = canvas.createImage();
  555. avatar.src = that.info.avatar;
  556. avatar.onload = () => {
  557. ctx.drawImage(avatar, x, y, size, size);
  558. ctx.restore();
  559. let tip = '我在'+that.address+that.middleman.location+'发现了一个超划算的团购!';
  560. ctx.textAlign = 'left'
  561. that.drawText(rpx,ctx,tip,textFont, textX, textY, textWidth);
  562. // 商品
  563. that.drawGoods(canvas, ctx,GoodsSize);
  564. that.drawInfo(canvas, ctx,infoX,infoY,infoSize,infoLeft,infoTop,that.address)
  565. // 二维码
  566. const qrcode = canvas.createImage();
  567. qrcode.src = that.activity.qrcode;
  568. qrcode.onload = () => {
  569. ctx.drawImage(qrcode,qrX, qrY, qrWidth, qrWidth);
  570. }
  571. }
  572. }
  573. },
  574. drawInfo(canvas, ctx,x,y,size,infoLeft,infoTop,address) {
  575. let that = this;
  576. let rpx = 0.26;
  577. // 团长头像
  578. const avatar = canvas.createImage();
  579. avatar.src = that.middleman.avatar;
  580. avatar.onload = () => {
  581. ctx.save();
  582. ctx.beginPath();
  583. ctx.arc(size / 2 + x, size / 2 + y, size / 2, 0, Math.PI * 2, false);
  584. ctx.strokeStyle ='white';
  585. ctx.stroke();
  586. ctx.clip();
  587. ctx.drawImage(avatar, x, y, size, size);
  588. ctx.restore();
  589. ctx.textAlign = 'left';
  590. ctx.font = '10px sans-serif';
  591. ctx.fillStyle = "#353535";
  592. ctx.fillText('团长:', infoLeft, infoTop-62*rpx);
  593. ctx.fillText('结束时间: ' + that.activity.end_at, infoLeft, infoTop);
  594. ctx.fillText(that.middleman.name, x+63*rpx, infoTop-62*rpx);
  595. that.drawText(rpx,ctx,'提货地址: '+address+that.middleman.detail,11, infoLeft, infoTop+10*rpx,500*rpx);
  596. }
  597. },
  598. drawGoods(canvas, ctx,top) {
  599. let that = this;
  600. let rpx = 0.4;
  601. let delLeft;
  602. let delWidth;
  603. let left;
  604. let sum = 0;
  605. // 单个商品
  606. const cover = canvas.createImage();
  607. if(that.activity.goods_list.length == 1) {
  608. cover.src = that.activity.goods_list[0].cover_pic;
  609. if(cover.src.indexOf('http://') == 0) {
  610. cover.src.replace('http://','https://')
  611. }
  612. cover.onload = () => {
  613. ctx.drawImage(cover,195*rpx, top, 360*rpx, 360*rpx);
  614. that.drawText(rpx,ctx,that.activity.goods_list[0].name,14, 370*rpx, top+360*rpx,590*rpx,true);
  615. ctx.textAlign = 'center';
  616. ctx.font = '14px sans-serif';
  617. ctx.fillStyle = "#ff4544";
  618. ctx.fillText('¥'+that.activity.goods_list[0].price, 370*rpx, top+490*rpx)
  619. ctx.font = '13px sans-serif';
  620. ctx.fillStyle = "#999999";
  621. ctx.fillText('¥'+that.activity.goods_list[0].original_price, 370*rpx, top+520*rpx);
  622. delWidth = (that.activity.goods_list[0].original_price.length + 1)*15+30;
  623. delLeft = 375 - delWidth/2;
  624. ctx.fillRect(delLeft*rpx,top+516*rpx,delWidth*rpx,1);
  625. that.$hideLoading();
  626. }
  627. // 两个商品
  628. }else if(that.activity.goods_list.length == 2) {
  629. top = top+15*rpx;
  630. for (var i = 0; i < that.activity.goods_list.length; i++){
  631. that.activity.goods_list[i].cover = canvas.createImage();
  632. that.activity.goods_list[i].cover.src = that.activity.goods_list[i].cover_pic;
  633. if(that.activity.goods_list[i].cover.src.indexOf('http://') == 0) {
  634. that.activity.goods_list[i].cover.src.replace('http://','https://')
  635. }
  636. that.activity.goods_list[i].cover.onload = () => {
  637. if(sum == 1) {
  638. left = 395*rpx;
  639. }else {
  640. left = 65*rpx;
  641. }
  642. that.strokeRoundRect(ctx, left, top, 290*rpx, 450*rpx, 8*rpx,2*rpx, '#e5e5e5');
  643. ctx.beginPath();
  644. ctx.save();
  645. let width = 266*rpx;
  646. let radius = 8*rpx;
  647. let angleLine = 10*rpx;
  648. let startTop = top + 2*rpx;
  649. let startLeft = left + 2*rpx;
  650. ctx.lineWidth = 1;
  651. ctx.strokeStyle ='white';
  652. ctx.moveTo(startLeft+angleLine,startTop);//出发点
  653. ctx.lineTo(startLeft+angleLine+width,startTop);//顶部
  654. ctx.arcTo(startLeft+angleLine*2+width,startTop,startLeft+angleLine*2+width,startTop+angleLine,radius);//右上角圆角
  655. ctx.lineTo(startLeft+angleLine*2+width,startTop+angleLine*2+width);//到右下角
  656. ctx.lineTo(startLeft,startTop+width+angleLine*2);//到左下角
  657. ctx.lineTo(startLeft,startTop+angleLine);//到左上角
  658. ctx.arcTo(startLeft,startTop,startLeft+angleLine,startTop,radius);//左上角圆角
  659. ctx.closePath();
  660. ctx.stroke();
  661. ctx.clip();
  662. ctx.drawImage(that.activity.goods_list[sum].cover,left+2*rpx, top+2*rpx, 286*rpx, 286*rpx);
  663. ctx.restore();
  664. that.drawText(rpx,ctx,that.activity.goods_list[sum].name,12, left+145*rpx, top+280*rpx,256*rpx,true);
  665. ctx.textAlign = 'center';
  666. ctx.font = '13px sans-serif';
  667. ctx.fillStyle = "#ff4544";
  668. ctx.fillText('¥'+that.activity.goods_list[sum].price, left+145*rpx, top+388*rpx)
  669. ctx.font = '11px sans-serif';
  670. ctx.fillStyle = "#999999";
  671. ctx.fillText('¥'+that.activity.goods_list[sum].original_price, left+145*rpx, top+418*rpx);
  672. delWidth = (that.activity.goods_list[sum].original_price.length + 1)*14+20;
  673. ctx.textAlign = 'center';
  674. delLeft = left+(145 - delWidth/2)*rpx
  675. ctx.fillRect(delLeft,top+414*rpx,delWidth*rpx,2*rpx);
  676. sum++
  677. if(sum == 2) {
  678. that.$hideLoading();
  679. }
  680. }
  681. }
  682. // 三个商品
  683. }else if(that.activity.goods_list.length == 3) {
  684. for (var i = 0; i < that.activity.goods_list.length; i++){
  685. that.activity.goods_list[i].cover = canvas.createImage();
  686. that.activity.goods_list[i].cover.src = that.activity.goods_list[i].cover_pic;
  687. if(that.activity.goods_list[i].cover.src.indexOf('http://') == 0) {
  688. that.activity.goods_list[i].cover.src.replace('http://','https://')
  689. }
  690. that.activity.goods_list[i].cover.onload = () => {
  691. if(sum > 0) {
  692. top = top + 182*rpx;
  693. }
  694. ctx.drawImage(that.activity.goods_list[sum].cover,65*rpx, top, 150*rpx, 150*rpx);
  695. ctx.beginPath();
  696. ctx.save();
  697. let width = 130*rpx;
  698. let radius = 8*rpx;
  699. let angleLine = 10*rpx;
  700. let startleft = 65*rpx;
  701. ctx.lineWidth = 1;
  702. ctx.strokeStyle ='white';
  703. ctx.moveTo(startleft+angleLine,top);//出发点
  704. ctx.arcTo(startleft+angleLine*2+width,top,startleft+angleLine*2+width,top+angleLine,radius);//右上角圆角
  705. ctx.arcTo(startleft+angleLine*2+width,top+angleLine*2+width,startleft+angleLine+width,top+angleLine*2+width,radius);//右下角圆角
  706. ctx.arcTo(startleft,top+width+angleLine*2,startleft,top+width+angleLine,radius);//左下角圆角
  707. ctx.arcTo(startleft,top,startleft+angleLine*2,top,radius);//左上角圆角
  708. ctx.closePath();
  709. ctx.stroke();
  710. ctx.clip();
  711. ctx.restore();
  712. ctx.textAlign = 'left';
  713. that.drawText(rpx,ctx,that.activity.goods_list[sum].name,13, 239*rpx, top-15*rpx,450*rpx);
  714. ctx.font = '13px sans-serif';
  715. ctx.fillStyle = "#ff4544";
  716. ctx.fillText('¥'+that.activity.goods_list[sum].price, 239*rpx, top+100*rpx)
  717. ctx.font = '11px sans-serif';
  718. ctx.fillStyle = "#999999";
  719. ctx.fillText('¥'+that.activity.goods_list[sum].original_price, 239*rpx, top+137*rpx);
  720. delWidth = (that.activity.goods_list[sum].original_price.length + 1)*15+12;
  721. delLeft = 239;
  722. ctx.fillRect(delLeft*rpx,top+135*rpx,delWidth*rpx,2*rpx);
  723. sum++
  724. if(sum == 3) {
  725. that.$hideLoading();
  726. }
  727. }
  728. }
  729. // 四个商品
  730. }else if(that.activity.goods_list.length == 4) {
  731. top = top - 10*rpx;
  732. for (var i = 0; i < that.activity.goods_list.length; i++){
  733. that.activity.goods_list[i].cover = canvas.createImage();
  734. that.activity.goods_list[i].cover.src = that.activity.goods_list[i].cover_pic;
  735. if(that.activity.goods_list[i].cover.src.indexOf('http://') == 0) {
  736. that.activity.goods_list[i].cover.src.replace('http://','https://')
  737. }
  738. that.activity.goods_list[i].cover.onload = () => {
  739. if(sum > 0) {
  740. top = top + 140*rpx;
  741. }
  742. ctx.beginPath();
  743. ctx.save();
  744. let width = 100*rpx;
  745. let radius = 8*rpx;
  746. let angleLine = 10*rpx;
  747. let left = 65*rpx;
  748. ctx.lineWidth = 1;
  749. ctx.strokeStyle ='white';
  750. ctx.moveTo(left+angleLine,top);//出发点
  751. ctx.arcTo(left+angleLine*2+width,top,left+angleLine*2+width,top+angleLine,radius);//右上角圆角
  752. ctx.arcTo(left+angleLine*2+width,top+angleLine*2+width,left+angleLine+width,top+angleLine*2+width,radius);//右下角圆角
  753. ctx.arcTo(left,top+width+angleLine*2,left,top+width+angleLine,radius);//左下角圆角
  754. ctx.arcTo(left,top,left+angleLine*2,top,radius);//左上角圆角
  755. ctx.closePath();
  756. ctx.stroke();
  757. ctx.clip();
  758. ctx.drawImage(that.activity.goods_list[sum].cover,65*rpx, top, 120*rpx, 120*rpx);
  759. ctx.restore();
  760. ctx.textAlign = 'left';
  761. that.drawText(rpx,ctx,that.activity.goods_list[sum].name,12, 209*rpx, top-25*rpx,480*rpx);
  762. ctx.font = '12px sans-serif';
  763. ctx.fillStyle = "#ff4544";
  764. ctx.fillText('¥'+that.activity.goods_list[sum].price, 209*rpx, top+80*rpx)
  765. ctx.font = '10px sans-serif';
  766. ctx.fillStyle = "#999999";
  767. ctx.fillText('¥'+that.activity.goods_list[sum].original_price, 209*rpx, top+102*rpx);
  768. delWidth = (that.activity.goods_list[sum].original_price.length + 1)*12+12;
  769. delLeft = 212;
  770. ctx.fillRect(delLeft*rpx,top+100*rpx,delWidth*rpx,2*rpx);
  771. sum++
  772. if(sum == 4) {
  773. that.$hideLoading();
  774. }
  775. }
  776. }
  777. // 五个商品
  778. }else if(that.activity.goods_list.length > 4) {
  779. for (var i = 0; i < that.activity.goods_list.length; i++){
  780. that.activity.goods_list[i].cover = canvas.createImage();
  781. that.activity.goods_list[i].cover.src = that.activity.goods_list[i].cover_pic;
  782. if(that.activity.goods_list[i].cover.src.indexOf('http://') == 0) {
  783. that.activity.goods_list[i].cover.src.replace('http://','https://')
  784. }
  785. that.activity.goods_list[i].cover.onload = () => {
  786. left = 48*rpx;
  787. delLeft = 192
  788. if(sum == 1 || sum == 3 || sum == 5) {
  789. left = 398*rpx;
  790. delLeft = 537;
  791. }
  792. if(sum == 0) {
  793. top = top + 20*rpx;
  794. }else if(sum == 2) {
  795. top = top + 172*rpx;
  796. }else if(sum == 4) {
  797. top = top + 172*rpx;
  798. }
  799. ctx.beginPath();
  800. ctx.save();
  801. let width = 100*rpx;
  802. let radius = 8*rpx;
  803. let angleLine = 10*rpx;
  804. ctx.lineWidth = 1;
  805. ctx.strokeStyle ='white';
  806. ctx.moveTo(left+angleLine,top);//出发点
  807. ctx.arcTo(left+angleLine*2+width,top,left+angleLine*2+width,top+angleLine,radius);//右上角圆角
  808. ctx.arcTo(left+angleLine*2+width,top+angleLine*2+width,left+angleLine+width,top+angleLine*2+width,radius);//右下角圆角
  809. ctx.arcTo(left,top+width+angleLine*2,left,top+width+angleLine,radius);//左下角圆角
  810. ctx.arcTo(left,top,left+angleLine*2,top,radius);//左上角圆角
  811. ctx.closePath();
  812. ctx.stroke();
  813. ctx.clip();
  814. ctx.drawImage(that.activity.goods_list[sum].cover,left, top, 120*rpx, 120*rpx);
  815. ctx.restore();
  816. ctx.textAlign = 'left';
  817. that.drawText(rpx,ctx,that.activity.goods_list[sum].name,12, left+134*rpx, top-25*rpx,166*rpx);
  818. ctx.font = '12px sans-serif';
  819. ctx.fillStyle = "#ff4544";
  820. ctx.fillText('¥'+that.activity.goods_list[sum].price, left+134*rpx, top+80*rpx)
  821. ctx.font = '10px sans-serif';
  822. ctx.fillStyle = "#999999";
  823. ctx.fillText('¥'+that.activity.goods_list[sum].original_price, left+134*rpx, top+102*rpx);
  824. delWidth = (that.activity.goods_list[sum].original_price.length + 1)*12+12;
  825. ctx.fillRect(delLeft*rpx,top+100*rpx,delWidth*rpx,2*rpx);
  826. sum++
  827. if(sum == 5) {
  828. that.$hideLoading();
  829. }
  830. }
  831. }
  832. }
  833. },
  834. // #endif
  835. // #ifdef MP-ALIPAY
  836. normalCreated(ctx,rpx) {
  837. let that = this;
  838. that.$showLoading({
  839. type: 'global',
  840. text: '生成中...'
  841. });
  842. that.address = that.middleman.city+that.middleman.district;
  843. if(that.middleman.city != that.middleman.province) {
  844. that.address = that.middleman.province + that.address
  845. }
  846. // 背景图
  847. if(that.selectForm.type == 1) {
  848. // 填充颜色
  849. ctx.fillStyle= that.selectForm.color;
  850. ctx.fillRect(0, 0, 750*rpx,1334*rpx);
  851. that.chooseNormalStyle(ctx,rpx)
  852. }else {
  853. my.getImageInfo({
  854. src: that.config.image_bg,
  855. success: function (res) {
  856. ctx.drawImage(res.path, 0, 0, 750*rpx, 1334*rpx);
  857. that.chooseNormalStyle(ctx,rpx)
  858. }
  859. })
  860. }
  861. },
  862. chooseNormalStyle(ctx,rpx) {
  863. let that = this;
  864. let x, y, size,textFont, textX, textY, textWidth,GoodsSize,infoX,infoY,infoSize,infoLeft,infoTop,qrX,qrY,qrWidth;
  865. let src = '';
  866. // 样式一
  867. if(that.selectForm.style == 1) {
  868. x = 78*rpx;
  869. y = 133*rpx;
  870. size = 97*rpx;
  871. textFont = 13
  872. textX = 195*rpx
  873. textY = 130*rpx
  874. textWidth = 480*rpx
  875. GoodsSize = 370*rpx
  876. infoX = 132*rpx
  877. infoY = 1000*rpx
  878. infoSize = 33*rpx
  879. infoLeft = 64*rpx
  880. infoTop = 1060*rpx
  881. qrX = 440*rpx
  882. qrY = 984*rpx
  883. qrWidth = 240*rpx
  884. src = that.community.style1;
  885. }else if(that.selectForm.style == 2) {
  886. x = 80*rpx;
  887. y = 810*rpx;
  888. size = 97*rpx;
  889. textFont = 13
  890. textX = 197*rpx
  891. textY = 807*rpx
  892. textWidth = 480*rpx
  893. GoodsSize = 180*rpx
  894. infoX = 430*rpx
  895. infoY = 985*rpx
  896. infoSize = 33*rpx
  897. infoLeft = 360*rpx
  898. infoTop = 1045*rpx
  899. qrX = 70*rpx
  900. qrY = 945*rpx
  901. qrWidth = 240*rpx
  902. src = that.community.style2;
  903. }else if(that.selectForm.style == 3) {
  904. x = 80*rpx;
  905. y = 164*rpx;
  906. size = 97*rpx;
  907. textFont = 13
  908. textX = 200*rpx
  909. textY = 161*rpx
  910. textWidth = 480*rpx
  911. GoodsSize = 310*rpx
  912. infoX = 430*rpx
  913. infoY = 1040*rpx
  914. infoSize = 33*rpx
  915. infoLeft = 360*rpx
  916. infoTop = 1100*rpx
  917. qrX = 70*rpx
  918. qrY = 1000*rpx
  919. qrWidth = 240*rpx
  920. src = that.community.style3;
  921. }else if(that.selectForm.style == 4) {
  922. x = 56*rpx;
  923. y = 124*rpx;
  924. size = 97*rpx;
  925. textFont = 13
  926. textX = 192*rpx
  927. textY = 121*rpx
  928. textWidth = 480*rpx
  929. GoodsSize = 464*rpx
  930. infoX = 430*rpx
  931. infoY = 1040*rpx
  932. infoSize = 33*rpx
  933. infoLeft = 360*rpx
  934. infoTop = 1100*rpx
  935. qrX = 70*rpx
  936. qrY = 1000*rpx
  937. qrWidth = 240*rpx
  938. src = that.community.style4;
  939. }
  940. ctx.drawImage(src, 0, 0, 750*rpx, 1334*rpx);
  941. // 头像
  942. ctx.save();
  943. ctx.beginPath();
  944. ctx.arc(size / 2 + x, size / 2 + y, size / 2, 0, Math.PI * 2, false);
  945. ctx.strokeStyle ='white';
  946. ctx.stroke();
  947. ctx.clip();
  948. let avatar = that.info.avatar;
  949. ctx.drawImage(avatar, x, y, size, size);
  950. ctx.restore();
  951. let tip = '我在'+that.address+that.middleman.location+'发现了一个超划算的团购!';
  952. ctx.textAlign = 'left';
  953. if(rpx == 1) {
  954. textWidth = 350
  955. }
  956. that.drawText(rpx,ctx,tip,textFont, textX, textY, textWidth);
  957. // 商品
  958. that.drawNormalGoods(ctx,GoodsSize,rpx);
  959. let infoRpx = 1;
  960. if(rpx != 1) {
  961. infoRpx = 0.26
  962. }
  963. that.drawNormalInfo(ctx,infoX,infoY,infoSize,infoLeft,infoTop,that.address,infoRpx)
  964. // 二维码
  965. my.getImageInfo({
  966. src: that.activity.qrcode,
  967. success: function (res) {
  968. ctx.drawImage(res.path,qrX, qrY, qrWidth, qrWidth);
  969. ctx.draw();
  970. }
  971. })
  972. },
  973. drawNormalGoods(ctx,top,rpx) {
  974. let that = this;
  975. let delLeft;
  976. let delWidth;
  977. let left;
  978. let goodsName;
  979. let sum = 0;
  980. // 单个商品
  981. let cover = '';
  982. if(that.activity.goods_list.length == 1) {
  983. ctx.drawImage(that.activity.goods_list[0].cover,195*rpx, top, 360*rpx, 360*rpx);
  984. if(rpx == 1) {
  985. goodsName = 350*rpx
  986. }else {
  987. goodsName = 590*rpx
  988. }
  989. that.drawText(rpx,ctx,that.activity.goods_list[0].name,14, 370*rpx, top+360*rpx,goodsName,true);
  990. ctx.textAlign = 'center';
  991. ctx.font = rpx != 1 ? '14px sans-serif' : '28px sans-serif';
  992. ctx.fillStyle = "#ff4544";
  993. ctx.fillText('¥'+that.activity.goods_list[0].price, 370*rpx, top+490*rpx)
  994. ctx.font = rpx != 1 ? '13px sans-serif' : '26px sans-serif';
  995. ctx.fillStyle = "#999999";
  996. ctx.fillText('¥'+that.activity.goods_list[0].original_price, 370*rpx, top+520*rpx);
  997. delWidth = (that.activity.goods_list[0].original_price.length + 1)*15+30;
  998. delLeft = 375 - delWidth/2;
  999. ctx.fillRect(delLeft*rpx,top+516*rpx,delWidth*rpx,1);
  1000. that.$hideLoading();
  1001. // 两个商品
  1002. }else if(that.activity.goods_list.length == 2) {
  1003. top = top+15*rpx;
  1004. for (var i = 0; i < that.activity.goods_list.length; i++){
  1005. if(sum == 1) {
  1006. left = 395*rpx;
  1007. }else {
  1008. left = 65*rpx;
  1009. }
  1010. that.strokeRoundRect(ctx, left, top, 290*rpx, 450*rpx, 8*rpx,2*rpx, '#e5e5e5');
  1011. ctx.beginPath();
  1012. ctx.save();
  1013. let width = 266*rpx;
  1014. let radius = 8*rpx;
  1015. let angleLine = 10*rpx;
  1016. let startTop = top + 2*rpx;
  1017. let startLeft = left + 2*rpx;
  1018. ctx.lineWidth = 1;
  1019. ctx.strokeStyle ='white';
  1020. ctx.moveTo(startLeft+angleLine,startTop);//出发点
  1021. ctx.lineTo(startLeft+angleLine+width,startTop);//顶部
  1022. ctx.arcTo(startLeft+angleLine*2+width,startTop,startLeft+angleLine*2+width,startTop+angleLine,radius);//右上角圆角
  1023. ctx.lineTo(startLeft+angleLine*2+width,startTop+angleLine*2+width);//到右下角
  1024. ctx.lineTo(startLeft,startTop+width+angleLine*2);//到左下角
  1025. ctx.lineTo(startLeft,startTop+angleLine);//到左上角
  1026. ctx.arcTo(startLeft,startTop,startLeft+angleLine,startTop,radius);//左上角圆角
  1027. ctx.closePath();
  1028. ctx.stroke();
  1029. ctx.clip();
  1030. ctx.drawImage(that.activity.goods_list[sum].cover,left+2*rpx, top+2*rpx, 286*rpx, 286*rpx);
  1031. ctx.restore();
  1032. that.drawText(rpx,ctx,that.activity.goods_list[sum].name,12, left+145*rpx, top+280*rpx,256*rpx,true);
  1033. ctx.textAlign = 'center';
  1034. ctx.font = rpx != 1 ? '13px sans-serif' : '26px sans-serif';
  1035. ctx.fillStyle = "#ff4544";
  1036. ctx.fillText('¥'+that.activity.goods_list[sum].price, left+145*rpx, top+388*rpx)
  1037. ctx.font = rpx != 1 ? '11px sans-serif' : '22px sans-serif';
  1038. ctx.fillStyle = "#999999";
  1039. ctx.fillText('¥'+that.activity.goods_list[sum].original_price, left+145*rpx, top+418*rpx);
  1040. delWidth = (that.activity.goods_list[sum].original_price.length + 1)*14+20;
  1041. ctx.textAlign = 'center';
  1042. delLeft = left+(145 - delWidth/2)*rpx
  1043. ctx.fillRect(delLeft,top+414*rpx,delWidth*rpx,2*rpx);
  1044. sum++
  1045. if(sum == 2) {
  1046. that.$hideLoading();
  1047. }
  1048. }
  1049. // 三个商品
  1050. }else if(that.activity.goods_list.length == 3) {
  1051. for (var i = 0; i < that.activity.goods_list.length; i++){
  1052. if(sum > 0) {
  1053. top = top + 182*rpx;
  1054. }
  1055. ctx.drawImage(that.activity.goods_list[sum].cover,65*rpx, top, 150*rpx, 150*rpx);
  1056. ctx.beginPath();
  1057. ctx.save();
  1058. let width = 130*rpx;
  1059. let radius = 8*rpx;
  1060. let angleLine = 10*rpx;
  1061. let startleft = 65*rpx;
  1062. ctx.lineWidth = 1;
  1063. ctx.strokeStyle ='white';
  1064. ctx.moveTo(startleft+angleLine,top);//出发点
  1065. ctx.arcTo(startleft+angleLine*2+width,top,startleft+angleLine*2+width,top+angleLine,radius);//右上角圆角
  1066. ctx.arcTo(startleft+angleLine*2+width,top+angleLine*2+width,startleft+angleLine+width,top+angleLine*2+width,radius);//右下角圆角
  1067. ctx.arcTo(startleft,top+width+angleLine*2,startleft,top+width+angleLine,radius);//左下角圆角
  1068. ctx.arcTo(startleft,top,startleft+angleLine*2,top,radius);//左上角圆角
  1069. ctx.closePath();
  1070. ctx.stroke();
  1071. ctx.clip();
  1072. ctx.restore();
  1073. ctx.textAlign = 'left';
  1074. that.drawText(rpx,ctx,that.activity.goods_list[sum].name,13, 239*rpx, top-15*rpx,350*rpx);
  1075. ctx.font = rpx != 1 ? '13px sans-serif' : '26px sans-serif';
  1076. ctx.fillStyle = "#ff4544";
  1077. ctx.fillText('¥'+that.activity.goods_list[sum].price, 239*rpx, top+100*rpx)
  1078. ctx.font = rpx != 1 ? '11px sans-serif' : '22px sans-serif';
  1079. ctx.fillStyle = "#999999";
  1080. ctx.fillText('¥'+that.activity.goods_list[sum].original_price, 239*rpx, top+137*rpx);
  1081. delWidth = (that.activity.goods_list[sum].original_price.length + 1)*15+12;
  1082. delLeft = 239;
  1083. ctx.fillRect(delLeft*rpx,top+135*rpx,delWidth*rpx,2*rpx);
  1084. sum++
  1085. if(sum == 3) {
  1086. that.$hideLoading();
  1087. }
  1088. }
  1089. // 四个商品
  1090. }else if(that.activity.goods_list.length == 4) {
  1091. top = top - 10*rpx;
  1092. for (var i = 0; i < that.activity.goods_list.length; i++){
  1093. if(sum > 0) {
  1094. top = top + 140*rpx;
  1095. }
  1096. ctx.beginPath();
  1097. ctx.save();
  1098. let width = 100*rpx;
  1099. let radius = 8*rpx;
  1100. let angleLine = 10*rpx;
  1101. let left = 65*rpx;
  1102. ctx.lineWidth = 1;
  1103. ctx.strokeStyle ='white';
  1104. ctx.moveTo(left+angleLine,top);//出发点
  1105. ctx.arcTo(left+angleLine*2+width,top,left+angleLine*2+width,top+angleLine,radius);//右上角圆角
  1106. ctx.arcTo(left+angleLine*2+width,top+angleLine*2+width,left+angleLine+width,top+angleLine*2+width,radius);//右下角圆角
  1107. ctx.arcTo(left,top+width+angleLine*2,left,top+width+angleLine,radius);//左下角圆角
  1108. ctx.arcTo(left,top,left+angleLine*2,top,radius);//左上角圆角
  1109. ctx.closePath();
  1110. ctx.stroke();
  1111. ctx.clip();
  1112. ctx.drawImage(that.activity.goods_list[sum].cover,65*rpx, top, 120*rpx, 120*rpx);
  1113. ctx.restore();
  1114. ctx.textAlign = 'left';
  1115. that.drawText(rpx,ctx,that.activity.goods_list[sum].name,12, 209*rpx, top-25*rpx,350*rpx);
  1116. ctx.font = rpx != 1 ? '12px sans-serif' : '24px sans-serif';
  1117. ctx.fillStyle = "#ff4544";
  1118. ctx.fillText('¥'+that.activity.goods_list[sum].price, 209*rpx, top+80*rpx)
  1119. ctx.font = rpx != 1 ? '10px sans-serif' : '20px sans-serif';
  1120. ctx.fillStyle = "#999999";
  1121. ctx.fillText('¥'+that.activity.goods_list[sum].original_price, 209*rpx, top+102*rpx);
  1122. delWidth = (that.activity.goods_list[sum].original_price.length + 1)*12+12;
  1123. delLeft = 212;
  1124. ctx.fillRect(delLeft*rpx,top+100*rpx,delWidth*rpx,2*rpx);
  1125. sum++
  1126. if(sum == 4) {
  1127. that.$hideLoading();
  1128. }
  1129. }
  1130. // 五个商品
  1131. }else if(that.activity.goods_list.length > 4) {
  1132. for (var i = 0; i < that.activity.goods_list.length; i++){
  1133. left = 48*rpx;
  1134. delLeft = 192
  1135. if(sum == 1 || sum == 3 || sum == 5) {
  1136. left = 398*rpx;
  1137. delLeft = 537;
  1138. }
  1139. if(sum == 0) {
  1140. top = top + 20*rpx;
  1141. }else if(sum == 2) {
  1142. top = top + 172*rpx;
  1143. }else if(sum == 4) {
  1144. top = top + 172*rpx;
  1145. }
  1146. ctx.beginPath();
  1147. ctx.save();
  1148. let width = 100*rpx;
  1149. let radius = 8*rpx;
  1150. let angleLine = 10*rpx;
  1151. ctx.lineWidth = 1;
  1152. ctx.strokeStyle ='white';
  1153. ctx.moveTo(left+angleLine,top);//出发点
  1154. ctx.arcTo(left+angleLine*2+width,top,left+angleLine*2+width,top+angleLine,radius);//右上角圆角
  1155. ctx.arcTo(left+angleLine*2+width,top+angleLine*2+width,left+angleLine+width,top+angleLine*2+width,radius);//右下角圆角
  1156. ctx.arcTo(left,top+width+angleLine*2,left,top+width+angleLine,radius);//左下角圆角
  1157. ctx.arcTo(left,top,left+angleLine*2,top,radius);//左上角圆角
  1158. ctx.closePath();
  1159. ctx.stroke();
  1160. ctx.clip();
  1161. ctx.drawImage(that.activity.goods_list[sum].cover,left, top, 120*rpx, 120*rpx);
  1162. ctx.restore();
  1163. ctx.textAlign = 'left';
  1164. that.drawText(rpx,ctx,that.activity.goods_list[sum].name,12, left+134*rpx, top-35*rpx,166*rpx);
  1165. ctx.font = rpx != 1 ? '12px sans-serif' : '24px sans-serif';
  1166. ctx.fillStyle = "#ff4544";
  1167. ctx.fillText('¥'+that.activity.goods_list[sum].price, left+134*rpx, top+80*rpx)
  1168. ctx.font = rpx != 1 ? '10px sans-serif' : '20px sans-serif';
  1169. ctx.fillStyle = "#999999";
  1170. ctx.fillText('¥'+that.activity.goods_list[sum].original_price, left+134*rpx, top+102*rpx);
  1171. delWidth = (that.activity.goods_list[sum].original_price.length + 1)*12+12;
  1172. ctx.fillRect(delLeft*rpx,top+100*rpx,delWidth*rpx,2*rpx);
  1173. sum++
  1174. if(sum == 5) {
  1175. that.$hideLoading();
  1176. }
  1177. }
  1178. }
  1179. },
  1180. drawNormalInfo(ctx,x,y,size,infoLeft,infoTop,address,rpx) {
  1181. let that = this;
  1182. // 团长头像
  1183. let avatar = that.middleman.avatar;
  1184. ctx.save();
  1185. ctx.beginPath();
  1186. ctx.arc(size / 2 + x, size / 2 + y, size / 2, 0, Math.PI * 2, false);
  1187. ctx.strokeStyle ='white';
  1188. ctx.stroke();
  1189. ctx.clip();
  1190. ctx.drawImage(avatar, x, y, size, size);
  1191. ctx.restore();
  1192. let nameRpx = rpx;
  1193. if(rpx == 1) {
  1194. nameRpx = 0.65
  1195. }
  1196. ctx.textAlign = 'left';
  1197. ctx.fillStyle = "#353535";
  1198. if(rpx == 1) {
  1199. ctx.font = '20px sans-serif'
  1200. }else {
  1201. ctx.font = '10px sans-serif'
  1202. }
  1203. ctx.fillText('团长:', infoLeft, infoTop-62*nameRpx);
  1204. ctx.fillText('结束时间: ' + that.activity.end_at, infoLeft, infoTop);
  1205. ctx.fillText(that.middleman.name, x+63*nameRpx, infoTop-62*nameRpx);
  1206. let addressWidth = 500*rpx;
  1207. if(rpx == 1) {
  1208. addressWidth = 300
  1209. }
  1210. that.drawText(rpx,ctx,'提货地址: '+address+that.middleman.detail,11, infoLeft, infoTop+10*rpx,addressWidth);
  1211. },
  1212. // #endif
  1213. },
  1214. }
  1215. </script>
  1216. <style scoped lang="scss">
  1217. $box: #f7f7f7;
  1218. ::-webkit-scrollbar {
  1219. width: 0;
  1220. height: 0;
  1221. color: transparent;
  1222. }
  1223. .app-scroll {
  1224. width: 100%;
  1225. white-space: nowrap;
  1226. padding: 0 #{14rpx};
  1227. }
  1228. .poster-goods {
  1229. .head {
  1230. width: 100%;
  1231. view {
  1232. margin: #{50rpx} auto;
  1233. }
  1234. }
  1235. .setting {
  1236. padding-top: #{20rpx};
  1237. font-size: #{24rpx};
  1238. color: #353535;
  1239. background: #FFFFFF;
  1240. padding-bottom: #{48rpx};
  1241. .line {
  1242. margin-bottom: #{24rpx};
  1243. .label {
  1244. height: #{56rpx};
  1245. icon {
  1246. background-image: url("../../../static/image/poster/mark.png");
  1247. background-size: 100% 100%;
  1248. height: #{21rpx};
  1249. width: #{21rpx};
  1250. background-repeat: no-repeat;
  1251. margin-left: #{24rpx};
  1252. border-radius: 50%;
  1253. }
  1254. text {
  1255. line-height: 1;
  1256. padding-left: #{12rpx};
  1257. padding-right: #{26rpx - 14rpx};
  1258. }
  1259. }
  1260. .style-input {
  1261. position: relative;
  1262. height: #{56rpx};
  1263. padding: 0 #{20rpx};
  1264. background: $box;
  1265. border-radius: #{5rpx};
  1266. margin: 0 #{14rpx};
  1267. .type-pure {
  1268. height: #{32rpx};
  1269. width: #{32rpx};
  1270. margin-right: #{10rpx};
  1271. background: #d8d8d8;
  1272. }
  1273. .type-gradient {
  1274. height: #{32rpx};
  1275. width: #{32rpx};
  1276. margin-right: #{10rpx};
  1277. background-image: url("./../image/icon.png");
  1278. background-size: 100% 100%;
  1279. }
  1280. }
  1281. }
  1282. .active {
  1283. border-width: #{3rpx};
  1284. border-style: solid;
  1285. background: #FFFFFF !important;
  1286. }
  1287. .icon-active {
  1288. background-image: url("../../../static/image/poster/input-active.png");
  1289. height: #{38rpx};
  1290. width: #{38rpx};
  1291. background-repeat: no-repeat;
  1292. background-size: 100% 100%;
  1293. position: absolute;
  1294. top: #{-19rpx};
  1295. right: #{-19rpx};
  1296. z-index: 10;
  1297. border-radius: 50%;
  1298. }
  1299. .line-input {
  1300. position: relative;
  1301. border-radius: #{5rpx};
  1302. margin: 0 #{14rpx} #{14rpx};
  1303. background: $box;
  1304. width: #{140rpx};
  1305. height: #{56rpx};
  1306. .icon-square {
  1307. background-size: 100% 100%;
  1308. height: #{32rpx};
  1309. width: #{32rpx};
  1310. background-repeat: no-repeat;
  1311. }
  1312. text {
  1313. margin-left: #{10rpx};
  1314. }
  1315. }
  1316. .color-bg {
  1317. position: relative;
  1318. display: inline-block;
  1319. height: #{60rpx};
  1320. width: #{60rpx};
  1321. border-radius: #{5rpx};
  1322. border: 1px solid #e5e5e5;
  1323. margin-right: #{26rpx};
  1324. margin-top: #{19rpx};
  1325. }
  1326. }
  1327. .button {
  1328. font-size: #{32rpx};
  1329. border-radius: #{40rpx};
  1330. height: #{68rpx};
  1331. margin: #{34rpx} auto 0;
  1332. color: #ffffff;
  1333. width: #{500rpx};
  1334. }
  1335. }
  1336. </style>