Commit ec0eeb77ed9f7012db7a2cdbeb5211a8bcb268f0
1 parent
a78d19ac
服务卡项生成海报的优化
Showing
8 changed files
with
880 additions
and
548 deletions
packageA/pages/goodsInfo/goodsInfo.js
| ... | ... | @@ -27,6 +27,7 @@ Page({ |
| 27 | 27 | color_type: 0, //线条控制 |
| 28 | 28 | color_type_one: 0, |
| 29 | 29 | color_type_two: 1, |
| 30 | + is_share_text: 1, | |
| 30 | 31 | |
| 31 | 32 | gid: "", |
| 32 | 33 | stoid: o.stoid, |
| ... | ... | @@ -38,6 +39,8 @@ Page({ |
| 38 | 39 | data: null, |
| 39 | 40 | content: "", //商品详情 |
| 40 | 41 | |
| 42 | + | |
| 43 | + | |
| 41 | 44 | gallery: null, //图片滚动 |
| 42 | 45 | is_collect: 0, |
| 43 | 46 | collect_id: 0, |
| ... | ... | @@ -236,6 +239,8 @@ Page({ |
| 236 | 239 | th = ee, |
| 237 | 240 | gid = t.goods_id, |
| 238 | 241 | first_leader=t.first_leader, |
| 242 | + prom_type=t.prom_type, | |
| 243 | + prom_id=t.prom_id, | |
| 239 | 244 | room_id = t.room_id, |
| 240 | 245 | room_user_share = t.room_user_share; //如果是会员分享带有room_id的话,那么接下来会员分享就不传room_id |
| 241 | 246 | |
| ... | ... | @@ -250,21 +255,27 @@ Page({ |
| 250 | 255 | var gid_str = decodeURIComponent(t.scene); |
| 251 | 256 | gid_str=gid_str.split("_"); |
| 252 | 257 | gid=gid_str[0]; |
| 253 | - if(gid_str.length>1){ | |
| 258 | + if(gid_str.length>1 && gid_str[1] && parseInt(gid_str[1])>0){ | |
| 254 | 259 | first_leader=gid_str[1]; |
| 255 | 260 | } |
| 256 | 261 | //-- 如果有room_id的获取 -- |
| 257 | - if(gid_str.length>2 && gid_str[2]) { | |
| 262 | + if(gid_str.length>2 && gid_str[2] && parseInt(gid_str[2])>0) { | |
| 258 | 263 | room_id=gid_str[2]; |
| 259 | 264 | room_user_share=1; |
| 260 | 265 | }; |
| 266 | + | |
| 267 | + if(gid_str.length>3 && gid_str[3] && parseInt(gid_str[3])>0) { | |
| 268 | + prom_type=gid_str[3]; | |
| 269 | + prom_id=gid_str[4]; | |
| 270 | + } | |
| 271 | + | |
| 261 | 272 | }; |
| 262 | 273 | |
| 263 | 274 | //-- 设置顶部高度 -- |
| 264 | 275 | let height= getApp().globalData.navBarHeight; |
| 265 | 276 | ee.setData({ gid: gid,top_nav:height}); |
| 266 | 277 | |
| 267 | - if(first_leader) { | |
| 278 | + if(first_leader>0) { | |
| 268 | 279 | getApp().globalData.first_leader=first_leader; |
| 269 | 280 | //调用接口判断是不是会员 |
| 270 | 281 | getApp().request.promiseGet("/api/weshop/shoppingGuide/get/"+os.stoid+"/"+first_leader,{}).then(res=>{ |
| ... | ... | @@ -347,7 +358,37 @@ Page({ |
| 347 | 358 | } |
| 348 | 359 | }); |
| 349 | 360 | |
| 350 | - }, | |
| 361 | + //-- 自定义海报 -- | |
| 362 | + getApp().request.promiseGet("/api/weshop/goods/poster/page", { | |
| 363 | + data: { store_id: os.stoid, type: 1, is_use: 1 } | |
| 364 | + }).then(res => { | |
| 365 | + if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData[0]) { | |
| 366 | + | |
| 367 | + var poster_data = res.data.data.pageData[0]; | |
| 368 | + var json_str = poster_data.jsonStr; | |
| 369 | + | |
| 370 | + if (json_str) { | |
| 371 | + var json_data = JSON.parse(json_str); | |
| 372 | + if (json_data.bg_img) { | |
| 373 | + | |
| 374 | + //-- 把图片那到本地 -- | |
| 375 | + wx.getImageInfo({ | |
| 376 | + src: json_data.bg_img, | |
| 377 | + success: function (res) { | |
| 378 | + var path = res.path; | |
| 379 | + th.setData({ share_b_img: path }) | |
| 380 | + }, | |
| 381 | + fail: function (res) { } | |
| 382 | + }); | |
| 383 | + } | |
| 384 | + th.setData({ poster: json_data }) | |
| 385 | + | |
| 386 | + } | |
| 387 | + } | |
| 388 | + }) | |
| 389 | + | |
| 390 | + | |
| 391 | + }, | |
| 351 | 392 | |
| 352 | 393 | //-- 获取直播的分享人的导购信息 -- |
| 353 | 394 | async get_room_share_guide(share_openid) { |
| ... | ... | @@ -568,14 +609,13 @@ Page({ |
| 568 | 609 | // gid 在onload阶段已经保存在this.data中 |
| 569 | 610 | onShow: function() { |
| 570 | 611 | |
| 612 | + getApp().check_can_share(this); | |
| 571 | 613 | //-- 看一下隐私政策要不要显示 -- |
| 572 | 614 | var privacy_pop = this.selectComponent("#privacy_pop"); //组件的id |
| 573 | 615 | if (privacy_pop) { |
| 574 | 616 | privacy_pop.check_pri_show(); |
| 575 | 617 | } |
| 576 | 618 | |
| 577 | - getApp().check_can_share(); | |
| 578 | - | |
| 579 | 619 | var that=this;var th=this; |
| 580 | 620 | var ee = this,gid = this.data.gid, i = getApp().request; |
| 581 | 621 | |
| ... | ... | @@ -2100,494 +2140,7 @@ Page({ |
| 2100 | 2140 | return param < 10 ? '0' + param : param; |
| 2101 | 2141 | }, |
| 2102 | 2142 | |
| 2103 | - | |
| 2104 | - //--定义的保存图片方法,分享团--- | |
| 2105 | - saveImageToPhotosAlbum: function() { | |
| 2106 | - //--先判断会员状态-- | |
| 2107 | - // var user_info = getApp().globalData.userInfo; | |
| 2108 | - // if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) { | |
| 2109 | - // //getApp().my_warnning("请先登录",0,this); | |
| 2110 | - // wx.navigateTo({ url: '/packageE/pages/togoin/togoin', }) | |
| 2111 | - // return false; | |
| 2112 | - // } | |
| 2113 | - | |
| 2114 | - //类型 0普通商品 1秒杀商品 2商家和会员团 3阶梯团 4阶梯团 | |
| 2115 | - var type = this.data.prom_type; | |
| 2116 | - if (type == 6) type = 2; | |
| 2117 | - if (this.data.prom_act && this.data.prom_act.kttype == 3) type = 3; | |
| 2118 | - | |
| 2119 | - wx.showLoading({ | |
| 2120 | - title: '生成中...', | |
| 2121 | - }) | |
| 2122 | - var that = this, | |
| 2123 | - th = that; | |
| 2124 | - //设置画板显示,才能开始绘图 | |
| 2125 | - that.setData({ | |
| 2126 | - canvasHidden: false | |
| 2127 | - }) | |
| 2128 | - | |
| 2129 | - var app = getApp(); | |
| 2130 | - var unit = that.data.screenWidth / 750 * 1.35; //基础单位, | |
| 2131 | - var path2 = that.data.data.original_img; | |
| 2132 | - var scene = th.data.gid+""; | |
| 2133 | - var user_id = getApp().globalData.user_id?getApp().globalData.user_id:0; | |
| 2134 | - if(user_id>0) { | |
| 2135 | - scene+="_"+user_id; | |
| 2136 | - } | |
| 2137 | - //-- 如果不是会员分享过来的要分享给别人 -- | |
| 2138 | - if(getApp().globalData.room_id && th.data.data.goods_id==getApp().globalData.room_goods_id && !getApp().globalData.room_user_share) { | |
| 2139 | - //固定房间是第3个字符 | |
| 2140 | - if(!user_id) scene+="_0"; | |
| 2141 | - scene+="_"+getApp().globalData.room_id ; | |
| 2142 | - } | |
| 2143 | - ///二微码 | |
| 2144 | - var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" + | |
| 2145 | - os.stoid + "?sceneValue=" + scene + "&pageValue=pages/goods/goodsInfo/goodsInfo"; | |
| 2146 | - | |
| 2147 | - console.log(path3); | |
| 2148 | - | |
| 2149 | - //读取文件成功则OK-- | |
| 2150 | - wx.getImageInfo({ | |
| 2151 | - src: path3, | |
| 2152 | - success: function(res) { | |
| 2153 | - //回调写法 | |
| 2154 | - th.get_head_temp(th.get_goods_temp, function() { | |
| 2155 | - var vpath = res.path; | |
| 2156 | - var context = wx.createCanvasContext('share'); | |
| 2157 | - //先画背景 | |
| 2158 | - var pg_path = "../../../images/share/share_bg.png"; | |
| 2159 | - | |
| 2160 | - // context.fillStyle="#FFFFFF"; | |
| 2161 | - // context.fillRect(0,0,554 * unit, 899 * unit); | |
| 2162 | - | |
| 2163 | - //-- 如果有自定义海报的时候,判断背景的图片 -- | |
| 2164 | - if(th.data.share_b_img){ | |
| 2165 | - pg_path=th.data.share_b_img; | |
| 2166 | - } | |
| 2167 | - context.drawImage(pg_path, 0, 0, 554 * unit, 899 * unit); | |
| 2168 | - | |
| 2169 | - //-- 是自定义海报的情况下 -- | |
| 2170 | - if(th.data.poster && parseInt(th.data.poster.style)==2) { | |
| 2171 | - //在线上分享人的情况下 | |
| 2172 | - if(parseInt(th.data.poster.show_headpic)){ | |
| 2173 | - //获取坐标 | |
| 2174 | - var x=parseFloat(th.data.poster.head_x)*2; | |
| 2175 | - var y=parseFloat(th.data.poster.head_y)*2; | |
| 2176 | - var x1=(x+90) *unit; | |
| 2177 | - var y1=(y+50) *unit; | |
| 2178 | - //--昵称--- | |
| 2179 | - context.setFontSize(24 * unit) | |
| 2180 | - context.setFillStyle("black") | |
| 2181 | - context.fillText(app.globalData.userInfo.nickname, x1, y1); | |
| 2182 | - var width = 24 * app.globalData.userInfo.nickname.length * unit + 4 * unit; | |
| 2183 | - //强烈推荐 改许程 | |
| 2184 | - var tj_path = "../../../images/share/q_tj.png"; | |
| 2185 | - context.drawImage(tj_path, x1 + width, y1-22*unit, 85 * unit, 30 * unit); | |
| 2186 | - context.setFontSize(16 * unit) | |
| 2187 | - context.setLineJoin('round'); //交点设置成圆角 | |
| 2188 | - context.setFillStyle("white") | |
| 2189 | - context.fillText('强烈推荐', x1 + width+8*unit, y1-1*unit); | |
| 2190 | - | |
| 2191 | - //context.setFillStyle("black") | |
| 2192 | - //context.setFontSize(24 * unit) | |
| 2193 | - //context.fillText(getApp().globalData.config.store_name, 40 * unit, 130 * unit); | |
| 2194 | - } | |
| 2195 | - } else { | |
| 2196 | - //--昵称--- | |
| 2197 | - context.setFontSize(24 * unit) | |
| 2198 | - context.setFillStyle("black") | |
| 2199 | - context.fillText(app.globalData.userInfo.nickname, 152 * unit, 76 * unit); | |
| 2200 | - var width = 24 * app.globalData.userInfo.nickname.length * unit + 2 * unit; | |
| 2201 | - //强烈推荐 改许程 | |
| 2202 | - var tj_path = "../../../images/share/q_tj.png"; | |
| 2203 | - context.drawImage(tj_path, 152 * unit + width, 54 * unit, 85 * unit, 30 * unit); | |
| 2204 | - context.setFontSize(16 * unit); | |
| 2205 | - context.setLineJoin('round'); //交点设置成圆角 | |
| 2206 | - context.setFillStyle("white"); | |
| 2207 | - context.fillText('强烈推荐', 149 * unit + width + 15 * unit, 75 * unit); | |
| 2208 | - } | |
| 2209 | - | |
| 2210 | - | |
| 2211 | - //---产品名称--- | |
| 2212 | - //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度 | |
| 2213 | - if(type!=4){ | |
| 2214 | - context.setFillStyle("black"); | |
| 2215 | - context.setFontSize(21.3 * unit) | |
| 2216 | - th.draw_Text(context, th.data.data.goods_name, | |
| 2217 | - 38 * unit, 180 * unit, 200 * unit, 279 * unit, unit); | |
| 2218 | - //------产品的价格------- | |
| 2219 | - context.setFontSize(23 * unit) | |
| 2220 | - context.setFillStyle("red") | |
| 2221 | - context.fillText("¥", 416 * unit, 185 * unit); | |
| 2222 | - context.setFontSize(31 * unit) | |
| 2223 | - var pri0 = th.data.data.shop_price; | |
| 2224 | - if (th.data.prom_act) | |
| 2225 | - pri0 = th.data.prom_act.price; | |
| 2226 | - pri0 = parseFloat(pri0).toFixed(2); | |
| 2227 | - context.fillText(pri0, 438 * unit, 185 * unit); | |
| 2228 | - //---市场价划掉--- | |
| 2229 | - context.setFillStyle("gray") | |
| 2230 | - context.setFontSize(22 * unit) | |
| 2231 | - context.fillText("¥" + th.data.data.market_price, 426 * unit, 213 * unit); | |
| 2232 | - context.setStrokeStyle('gray'); | |
| 2233 | - context.setLineWidth(1 * unit); | |
| 2234 | - context.moveTo(426 * unit, 206 * unit); | |
| 2235 | - context.lineTo(510 * unit, 206 * unit); | |
| 2236 | - context.stroke(); | |
| 2237 | - | |
| 2238 | - }else{ | |
| 2239 | - context.setFillStyle("black"); | |
| 2240 | - context.setFontSize(21.3 * unit) | |
| 2241 | - th.draw_Text(context, th.data.data.goods_name, | |
| 2242 | - 38 * unit, 170 * unit, 20 * unit, 300*unit, unit); | |
| 2243 | - //------ 产品的价格 ----- | |
| 2244 | - var pri0 = th.data.prom_act.addmoney; | |
| 2245 | - var integral=th.data.prom_act.integral; | |
| 2246 | - var text= ""; | |
| 2247 | - if(integral){text=integral+"积分"; } | |
| 2248 | - if(pri0 && integral){ text+="+";} | |
| 2249 | - if(pri0){ text+="¥"+pri0;} | |
| 2250 | - | |
| 2251 | - if(!pri0 && !integral){ text="0积分";} | |
| 2252 | - context.setFillStyle("red"); | |
| 2253 | - context.fillText(text, 38 * unit, 235 * unit); | |
| 2254 | - | |
| 2255 | - } | |
| 2256 | - | |
| 2257 | - //---中间大图--- | |
| 2258 | - context.drawImage(th.data.share_goods_img, 70 * unit, 250 * unit, 408 * unit, 408 * unit); | |
| 2259 | - //-------大图后面就不一样了----------- | |
| 2260 | - switch (type) { | |
| 2261 | - case 0: //普通商品的展示 | |
| 2262 | - case 4: | |
| 2263 | - //中间的几个字 | |
| 2264 | - if(th.data.poster && parseInt(th.data.poster.style)==2 ){ | |
| 2265 | - if(parseInt(th.data.poster.show_quality)){ | |
| 2266 | - var g_path = "../../../images/share/s_gou.png"; | |
| 2267 | - context.drawImage(g_path, 56 * unit, 670 * unit, 22 * unit, 22 * unit); | |
| 2268 | - context.setFillStyle("red") | |
| 2269 | - context.setFontSize(18 * unit) | |
| 2270 | - context.fillText("正品保证", 84 * unit, 690 * unit); | |
| 2271 | - | |
| 2272 | - context.drawImage(g_path, 218 * unit, 670 * unit, 22 * unit, 22 * unit); | |
| 2273 | - context.setFillStyle("red") | |
| 2274 | - context.setFontSize(18 * unit) | |
| 2275 | - context.fillText("纯实体店", 246 * unit, 690 * unit); | |
| 2276 | - | |
| 2277 | - context.drawImage(g_path, 388 * unit, 670 * unit, 22 * unit, 22 * unit); | |
| 2278 | - context.setFillStyle("red") | |
| 2279 | - context.setFontSize(18 * unit) | |
| 2280 | - context.fillText("官方验证", 420 * unit, 690 * unit); | |
| 2281 | - } | |
| 2282 | - | |
| 2283 | - }else{ | |
| 2284 | - var g_path = "../../../images/share/s_gou.png"; | |
| 2285 | - context.drawImage(g_path, 56 * unit, 670 * unit, 22 * unit, 22 * unit); | |
| 2286 | - context.setFillStyle("red") | |
| 2287 | - context.setFontSize(18 * unit) | |
| 2288 | - context.fillText("正品保证", 84 * unit, 690 * unit); | |
| 2289 | - | |
| 2290 | - context.drawImage(g_path, 218 * unit, 670 * unit, 22 * unit, 22 * unit); | |
| 2291 | - context.setFillStyle("red") | |
| 2292 | - context.setFontSize(18 * unit) | |
| 2293 | - context.fillText("纯实体店", 246 * unit, 690 * unit); | |
| 2294 | - | |
| 2295 | - context.drawImage(g_path, 388 * unit, 670 * unit, 22 * unit, 22 * unit); | |
| 2296 | - context.setFillStyle("red") | |
| 2297 | - context.setFontSize(18 * unit) | |
| 2298 | - context.fillText("官方验证", 420 * unit, 690 * unit); | |
| 2299 | - } | |
| 2300 | - | |
| 2301 | - | |
| 2302 | - //---画线--- | |
| 2303 | - context.setLineWidth(1 * unit) | |
| 2304 | - context.moveTo(32 * unit, 710 * unit) | |
| 2305 | - context.lineTo(520 * unit, 710 * unit) | |
| 2306 | - context.stroke(); | |
| 2307 | - | |
| 2308 | - //---文字--- | |
| 2309 | - context.setFillStyle("black") | |
| 2310 | - context.setFontSize(22 * unit) | |
| 2311 | - | |
| 2312 | - if(type==0){ | |
| 2313 | - // 原来start ---> | |
| 2314 | - context.setFontSize(24 * unit) | |
| 2315 | - context.fillText(th.data.sto_sele_name_1, 40 * unit, 766 * unit); | |
| 2316 | - | |
| 2317 | - context.setFontSize(22 * unit) | |
| 2318 | - context.fillText("优惠乐翻天,精彩就在你身边", 40 * unit, 806 * unit); | |
| 2319 | - context.fillText("长按识别二维码,立即开始抢购", 40 * unit, 846 * unit); | |
| 2320 | - | |
| 2321 | - }else{ | |
| 2322 | - context.setFontSize(24 * unit) | |
| 2323 | - context.fillText(th.data.sto_sele_name_1, 40 * unit, 766 * unit); | |
| 2324 | - context.setFontSize(22 * unit) | |
| 2325 | - context.fillText("长按识别二维码", 40 * unit, 806 * unit); | |
| 2326 | - context.fillText("立即开始兑换", 40 * unit, 846 * unit); | |
| 2327 | - | |
| 2328 | - | |
| 2329 | - } | |
| 2330 | - | |
| 2331 | - //---二维吗图--- | |
| 2332 | - //-- 自定义海报 -- | |
| 2333 | - if(th.data.poster){ | |
| 2334 | - var erm_x= parseFloat(th.data.poster.ewm_x)*2; | |
| 2335 | - var erm_y= parseFloat(th.data.poster.ewm_y)*2; | |
| 2336 | - context.drawImage(vpath, erm_x * unit, erm_y * unit, 120 * unit, 120 * unit); | |
| 2337 | - }else{ | |
| 2338 | - //---二维吗图--- | |
| 2339 | - context.drawImage(vpath, 410 * unit, 726 * unit, 115 * unit, 125 * unit); | |
| 2340 | - } | |
| 2341 | - | |
| 2342 | - break; | |
| 2343 | - case 1: //秒杀商品的展示 | |
| 2344 | - //---画线--- | |
| 2345 | - context.setLineWidth(1 * unit) | |
| 2346 | - context.moveTo(32 * unit, 670 * unit) | |
| 2347 | - context.lineTo(520 * unit, 670 * unit) | |
| 2348 | - context.stroke(); | |
| 2349 | - | |
| 2350 | - //画秒杀的图片 | |
| 2351 | - var miaos_path = '../../../images/share/miao_share.png'; | |
| 2352 | - context.drawImage(miaos_path, 43 * unit, 700 * unit, 222 * unit, 40 * unit); | |
| 2353 | - | |
| 2354 | - context.setFillStyle("black") | |
| 2355 | - context.setFontSize(24 * unit) | |
| 2356 | - context.fillText(th.data.sto_sele_name_1, 40 * unit, 786 * unit); | |
| 2357 | - //---文字--- | |
| 2358 | - context.setFontSize(22 * unit) | |
| 2359 | - context.setFillStyle("black") | |
| 2360 | - context.fillText("特惠好物,限时秒杀", 40 * unit, 826 * unit); | |
| 2361 | - context.fillText("长按识别二维码,立即开始抢购", 40 * unit, 866 * unit); | |
| 2362 | - | |
| 2363 | - | |
| 2364 | - //---二维吗图--- | |
| 2365 | - //-- 自定义海报 -- | |
| 2366 | - if(th.data.poster){ | |
| 2367 | - var erm_x= parseFloat(th.data.poster.ewm_x)*2; | |
| 2368 | - var erm_y= parseFloat(th.data.poster.ewm_y)*2; | |
| 2369 | - context.drawImage(vpath, erm_x * unit, erm_y * unit, 120 * unit, 120 * unit); | |
| 2370 | - }else{ | |
| 2371 | - //---二维吗图--- | |
| 2372 | - context.drawImage(vpath, 420 * unit, 726 * unit, 120 * unit, 120 * unit); | |
| 2373 | - } | |
| 2374 | - break; | |
| 2375 | - | |
| 2376 | - case 2: //会员团和商家团的展示 | |
| 2377 | - //---画线--- | |
| 2378 | - context.setLineWidth(1 * unit) | |
| 2379 | - context.moveTo(32 * unit, 670 * unit) | |
| 2380 | - context.lineTo(520 * unit, 670 * unit) | |
| 2381 | - context.stroke(); | |
| 2382 | - //---文字--- | |
| 2383 | - | |
| 2384 | - context.setFillStyle("black") | |
| 2385 | - context.setFontSize(24 * unit) | |
| 2386 | - context.fillText(th.data.sto_sele_name_1, 40 * unit, 720 * unit); | |
| 2387 | - | |
| 2388 | - //绘制成团图片 | |
| 2389 | - var ct_img = "../../../images/share/ct_num.png"; | |
| 2390 | - context.drawImage(ct_img, 40 * unit, 740 * unit, 120 * unit, 30 * unit); | |
| 2391 | - var ct_num = th.data.prom_act.ct_num; | |
| 2392 | - context.setFontSize(14 * unit) | |
| 2393 | - context.font = 'normal'; | |
| 2394 | - context.setFillStyle("red") | |
| 2395 | - if (ct_num < 10) { | |
| 2396 | - context.fillText(ct_num + "人拼团", 92 * unit, 760 * unit); | |
| 2397 | - } else { | |
| 2398 | - context.fillText(ct_num + "人拼团", 86 * unit, 760 * unit); | |
| 2399 | - } | |
| 2400 | - context.setFontSize(22 * unit) | |
| 2401 | - context.fillText("已拼" + th.data.prom_act.buy_num + "份", 166 * unit, 763 * unit); | |
| 2402 | - | |
| 2403 | - context.setFillStyle("gray") | |
| 2404 | - context.fillText("快来和我一起拼团吧!", 40 * unit, 806 * unit); | |
| 2405 | - context.setFillStyle("black") | |
| 2406 | - context.font = 'normal bold 18px sans-serif'; | |
| 2407 | - context.setFontSize(21.3 * unit) | |
| 2408 | - context.fillText("长按识别二维码,立即参团", 40 * unit, 836 * unit); | |
| 2409 | - | |
| 2410 | - | |
| 2411 | - //---二维吗图--- | |
| 2412 | - //-- 自定义海报 -- | |
| 2413 | - if(th.data.poster){ | |
| 2414 | - var erm_x= parseFloat(th.data.poster.ewm_x)*2; | |
| 2415 | - var erm_y= parseFloat(th.data.poster.ewm_y)*2; | |
| 2416 | - context.drawImage(vpath, erm_x * unit, erm_y * unit, 120 * unit, 120 * unit); | |
| 2417 | - }else{ | |
| 2418 | - //---二维吗图--- | |
| 2419 | - context.drawImage(vpath, 420 * unit, 726 * unit, 120 * unit, 120 * unit); | |
| 2420 | - } | |
| 2421 | - break | |
| 2422 | - case 3: //阶梯团的展示 | |
| 2423 | - //---画线--- | |
| 2424 | - context.setLineWidth(1 * unit) | |
| 2425 | - context.moveTo(32 * unit, 670 * unit) | |
| 2426 | - context.lineTo(520 * unit, 670 * unit) | |
| 2427 | - context.stroke(); | |
| 2428 | - //---文字--- | |
| 2429 | - | |
| 2430 | - context.setFillStyle("black") | |
| 2431 | - context.setFontSize(24 * unit) | |
| 2432 | - context.fillText(th.data.sto_sele_name_1, 40 * unit, 720 * unit); | |
| 2433 | - | |
| 2434 | - //---绘制中间阶梯的价格--- | |
| 2435 | - var list = th.data.prom_act.ct_rylist; | |
| 2436 | - for (var i = 0; i < list.length; i++) { | |
| 2437 | - var item = list[i]; | |
| 2438 | - var wi = i * 90 * unit; | |
| 2439 | - context.font = 'normal'; | |
| 2440 | - context.setFontSize(16 * unit) | |
| 2441 | - context.setFillStyle("red") | |
| 2442 | - context.fillText("¥", 40 * unit + wi, 756 * unit); | |
| 2443 | - context.setFontSize(22 * unit) | |
| 2444 | - var pri = parseFloat(item.price).toFixed(2); | |
| 2445 | - context.fillText(pri, 56 * unit + wi, 756 * unit); | |
| 2446 | - context.setFillStyle("gray") | |
| 2447 | - context.fillText("满" + item.rynum + "人", 40 * unit + wi, 786 * unit); | |
| 2448 | - } | |
| 2449 | - //----------------下面部分---------------- | |
| 2450 | - // context.setFillStyle("gray") | |
| 2451 | - // context.fillText("快来和我一起拼团吧!", 40 * unit, 830 * unit); | |
| 2452 | - // context.setFillStyle("black") | |
| 2453 | - // context.font = 'normal bold 18px sans-serif'; | |
| 2454 | - // context.setFontSize(22 * unit) | |
| 2455 | - // context.fillText("长按识别二维码,立即参团", 40 * unit, 860 * unit); | |
| 2456 | - //context.setFillStyle("gray") | |
| 2457 | - context.setFillStyle("black") | |
| 2458 | - context.fillText("快来和我一起拼团吧!", 40 * unit, 820 * unit); | |
| 2459 | - //context.font = 'normal bold 18px sans-serif'; | |
| 2460 | - context.setFontSize(22 * unit) | |
| 2461 | - context.fillText("长按识别二维码,立即参团", 40 * unit, 850 * unit); | |
| 2462 | - | |
| 2463 | - | |
| 2464 | - //-- 自定义海报 -- | |
| 2465 | - if(th.data.poster){ | |
| 2466 | - var erm_x= parseFloat(th.data.poster.ewm_x)*2; | |
| 2467 | - var erm_y= parseFloat(th.data.poster.ewm_y)*2; | |
| 2468 | - context.drawImage(vpath, erm_x * unit, erm_y * unit, 120 * unit, 120 * unit); | |
| 2469 | - }else{ | |
| 2470 | - //---二维吗图--- | |
| 2471 | - context.drawImage(vpath, 420 * unit, 726 * unit, 120 * unit, 120 * unit); | |
| 2472 | - } | |
| 2473 | - break | |
| 2474 | - | |
| 2475 | - | |
| 2476 | - } | |
| 2477 | - | |
| 2478 | - | |
| 2479 | - //--- 如果是自定义海报的时候 --- | |
| 2480 | - if(th.data.poster && parseInt(th.data.poster.style)==2){ | |
| 2481 | - | |
| 2482 | - //如果显示会员信息的话 | |
| 2483 | - if(parseInt(th.data.poster.show_headpic)){ | |
| 2484 | - //获取坐标 | |
| 2485 | - var x= parseFloat(th.data.poster.head_x)*2; | |
| 2486 | - var y=parseFloat(th.data.poster.head_y)*2; | |
| 2487 | - //---绘制圆形要放在最后---- | |
| 2488 | - context.save(); | |
| 2489 | - context.beginPath(); | |
| 2490 | - var h_x = x* unit; | |
| 2491 | - var h_y = y * unit; | |
| 2492 | - var h_r = 40 * unit; | |
| 2493 | - var cx = h_x + h_r; | |
| 2494 | - var cy = h_y + h_r; | |
| 2495 | - context.arc(cx, cy, h_r, 0, Math.PI * 2, false); | |
| 2496 | - context.closePath(); | |
| 2497 | - context.fill(); | |
| 2498 | - context.clip(); | |
| 2499 | - context.drawImage(th.data.share_head, h_x, h_y, h_r * 2, h_r * 2); | |
| 2500 | - context.restore(); | |
| 2501 | - } | |
| 2502 | - | |
| 2503 | - }else{ | |
| 2504 | - //---绘制圆形要放在最后---- | |
| 2505 | - context.save(); | |
| 2506 | - context.beginPath(); | |
| 2507 | - var h_x = 60 * unit; | |
| 2508 | - var h_y = 24 * unit; | |
| 2509 | - var h_r = 40 * unit; | |
| 2510 | - var cx = h_x + h_r; | |
| 2511 | - var cy = h_y + h_r; | |
| 2512 | - context.arc(cx, cy, h_r, 0, Math.PI * 2, false); | |
| 2513 | - context.closePath(); | |
| 2514 | - context.fill(); | |
| 2515 | - context.clip(); | |
| 2516 | - context.drawImage(th.data.share_head, h_x, h_y, h_r * 2, h_r * 2); | |
| 2517 | - context.restore(); | |
| 2518 | - } | |
| 2519 | - | |
| 2520 | - | |
| 2521 | - //把画板内容绘制成图片,并回调 画板图片路径 | |
| 2522 | - context.draw(false, function() { | |
| 2523 | - setTimeout(function() { | |
| 2524 | - wx.canvasToTempFilePath({ | |
| 2525 | - x: 0, | |
| 2526 | - y: 0, | |
| 2527 | - width: 750, | |
| 2528 | - height: 1217, | |
| 2529 | - destWidth: 1.2 * 750 * 750 / that.data.screenWidth, | |
| 2530 | - destHeight: 1.2 * 1217 * 750 / that.data.screenWidth, | |
| 2531 | - canvasId: 'share', | |
| 2532 | - success: function(res) { | |
| 2533 | - that.setData({ | |
| 2534 | - shareImgPath: res.tempFilePath, | |
| 2535 | - canvasHidden: true | |
| 2536 | - }) | |
| 2537 | - if (!res.tempFilePath) { | |
| 2538 | - wx.showModal({ | |
| 2539 | - title: '提示', | |
| 2540 | - content: '图片绘制中,请稍后重试', | |
| 2541 | - showCancel: false | |
| 2542 | - }) | |
| 2543 | - return false; | |
| 2544 | - } | |
| 2545 | - // wx.previewImage({ | |
| 2546 | - // //将图片预览出来 | |
| 2547 | - // urls: [that.data.shareImgPath] | |
| 2548 | - // }); | |
| 2549 | - that.setData({ | |
| 2550 | - showPoster: true, | |
| 2551 | - }); | |
| 2552 | - wx.hideLoading(); | |
| 2553 | - } | |
| 2554 | - }) | |
| 2555 | - }, 500) | |
| 2556 | - | |
| 2557 | - }); | |
| 2558 | - }); | |
| 2559 | - } | |
| 2560 | - }); | |
| 2561 | - }, | |
| 2562 | - | |
| 2563 | 2143 | |
| 2564 | - //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度 | |
| 2565 | - draw_Text: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, unit) { | |
| 2566 | - var lineWidth = 0; | |
| 2567 | - var lastSubStrIndex = 0; //每次开始截取的字符串的索引 | |
| 2568 | - var han = 0; | |
| 2569 | - for (let i = 0; i < str.length; i++) { | |
| 2570 | - if (han == 2) return; | |
| 2571 | - //lineWidth += ctx.measureText(str[i]).width; | |
| 2572 | - lineWidth += ut.measureText(str[i], 21.3 * unit); | |
| 2573 | - if (lineWidth > canvasWidth) { | |
| 2574 | - han++; | |
| 2575 | - | |
| 2576 | - if (han == 2) | |
| 2577 | - ctx.fillText(str.substring(lastSubStrIndex, i) + '...', leftWidth, initHeight); //绘制截取部分 | |
| 2578 | - else | |
| 2579 | - ctx.fillText(str.substring(lastSubStrIndex, i), leftWidth, initHeight); | |
| 2580 | - | |
| 2581 | - initHeight += 22; //22为字体的高度 | |
| 2582 | - lineWidth = 0; | |
| 2583 | - lastSubStrIndex = i; | |
| 2584 | - titleHeight += 20; | |
| 2585 | - } | |
| 2586 | - if (i == str.length - 1) { //绘制剩余部分 | |
| 2587 | - ctx.fillText(str.substring(lastSubStrIndex, i + 1), leftWidth, initHeight); | |
| 2588 | - } | |
| 2589 | - } | |
| 2590 | - }, | |
| 2591 | 2144 | |
| 2592 | 2145 | // ----视频图片---- |
| 2593 | 2146 | // 图片计数器 |
| ... | ... | @@ -2665,37 +2218,45 @@ Page({ |
| 2665 | 2218 | }); |
| 2666 | 2219 | } |
| 2667 | 2220 | }, |
| 2668 | - //--获取商品图片的本地缓存,回调写法-- | |
| 2669 | - get_goods_temp: function(tt) { | |
| 2670 | - var ee = this; | |
| 2671 | - if (ee.data.share_goods_img) { | |
| 2672 | - tt(); | |
| 2673 | - return false; | |
| 2674 | - } | |
| 2675 | - //获取商品是分享图信息 | |
| 2676 | - wx.getImageInfo({ | |
| 2677 | - src: ee.data.data.original_img, | |
| 2678 | - success: function(res) { | |
| 2679 | - //res.path是网络图片的本地地址 | |
| 2680 | - ee.data.share_goods_img = res.path; | |
| 2681 | - tt(); | |
| 2682 | - }, | |
| 2683 | - fail: function(res) { | |
| 2684 | - //获取默认空白图 | |
| 2685 | - wx.getImageInfo({ | |
| 2686 | - src: ee.data.iurl+'/miniapp/images/default_g_img.gif', | |
| 2687 | - success: function(res) { | |
| 2688 | - ee.data.share_goods_img = res.path; //分享的图片不能用网络的 | |
| 2689 | - tt(); | |
| 2690 | - } | |
| 2691 | - }) | |
| 2692 | 2221 | |
| 2693 | - } | |
| 2694 | - }); | |
| 2695 | - }, | |
| 2222 | + //--获取商品图片的本地缓存,回调写法-- | |
| 2223 | + get_goods_temp: function(tt) { | |
| 2224 | + var ee = this; | |
| 2225 | + if (ee.data.share_goods_img) { | |
| 2226 | + tt(); | |
| 2227 | + return false; | |
| 2228 | + } | |
| 2696 | 2229 | |
| 2230 | + var img=ee.data.iurl+ee.data.data.image_url; | |
| 2231 | + if(ee.data.prom_act && ee.data.prom_act.share_img){ | |
| 2232 | + img=ee.data.iurl+ee.data.prom_act.share_img; | |
| 2233 | + } | |
| 2234 | + | |
| 2235 | + //获取商品是分享图信息 | |
| 2236 | + wx.getImageInfo({ | |
| 2237 | + src: img, | |
| 2238 | + success: function(res) { | |
| 2239 | + //res.path是网络图片的本地地址 | |
| 2240 | + ee.data.share_goods_img = res.path; | |
| 2241 | + tt(); | |
| 2242 | + }, | |
| 2243 | + fail: function(res) { | |
| 2244 | + //获取默认空白图 | |
| 2245 | + wx.getImageInfo({ | |
| 2246 | + src: ee.data.iurl+'/miniapp/images/default_g_img.gif', | |
| 2247 | + success: function(res) { | |
| 2248 | + ee.data.share_goods_img = res.path; //分享的图片不能用网络的 | |
| 2249 | + tt(); | |
| 2250 | + } | |
| 2251 | + }) | |
| 2252 | + | |
| 2253 | + } | |
| 2254 | + }); | |
| 2255 | + }, | |
| 2697 | 2256 | |
| 2698 | - //--跳转到商品详情页面-- | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + //--跳转到商品详情页面-- | |
| 2699 | 2260 | go_goods: function(e) { |
| 2700 | 2261 | var gid = e.currentTarget.dataset.gid; |
| 2701 | 2262 | var url = "/pages/goods/goodsInfo/goodsInfo?goods_id=" + gid; |
| ... | ... | @@ -3681,7 +3242,7 @@ Page({ |
| 3681 | 3242 | ee.get_normal(gid); |
| 3682 | 3243 | return false; |
| 3683 | 3244 | } |
| 3684 | - | |
| 3245 | + | |
| 3685 | 3246 | var t_gd = ee.data.data; |
| 3686 | 3247 | var prom_end_time = ut.formatTime(t.data.data.end_time, "yyyy-MM-dd hh:mm:ss"); |
| 3687 | 3248 | var prom_start_time = ut.formatTime(t.data.data.start_time, "yyyy-MM-dd hh:mm:ss"); |
| ... | ... | @@ -3694,6 +3255,7 @@ Page({ |
| 3694 | 3255 | prom_act: t.data.data, |
| 3695 | 3256 | prom_end_time: prom_end_time, |
| 3696 | 3257 | prom_start_time: prom_start_time, |
| 3258 | + is_share_text: t.data.data.is_share_text | |
| 3697 | 3259 | }); |
| 3698 | 3260 | |
| 3699 | 3261 | ee.get_sto(); |
| ... | ... | @@ -4105,9 +3667,728 @@ Page({ |
| 4105 | 3667 | }) |
| 4106 | 3668 | } |
| 4107 | 3669 | }, |
| 4108 | - | |
| 4109 | - | |
| 4110 | - | |
| 3670 | + | |
| 3671 | + clickShare() { | |
| 3672 | + this.setData({ | |
| 3673 | + share_hidden: true, | |
| 3674 | + }); | |
| 3675 | + }, | |
| 3676 | + send() { | |
| 3677 | + this.setData({ | |
| 3678 | + share_hidden: false, | |
| 3679 | + }); | |
| 3680 | + }, | |
| 3681 | + cancel() { | |
| 3682 | + this.setData({ | |
| 3683 | + share_hidden: false, | |
| 3684 | + }); | |
| 3685 | + }, | |
| 3686 | + | |
| 3687 | + | |
| 3688 | + saveImageFn(){ | |
| 3689 | + if(this.data.share_b_img){ | |
| 3690 | + this.saveImageToPhotosAlbum() | |
| 3691 | + }else{ | |
| 3692 | + this.saveImageToPhotosAlbumDef() | |
| 3693 | + } | |
| 3694 | + }, | |
| 3695 | + | |
| 3696 | + | |
| 3697 | + //--定义的保存图片方法,分享团--- | |
| 3698 | + saveImageToPhotosAlbum: function () { | |
| 3699 | + //--先判断会员状态-- | |
| 3700 | + // var user_info = getApp().globalData.userInfo; | |
| 3701 | + // if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) { | |
| 3702 | + // //getApp().my_warnning("请先登录",0,this); | |
| 3703 | + // wx.navigateTo({ url: '/packageE/pages/togoin/togoin', }) | |
| 3704 | + // return false; | |
| 3705 | + // } | |
| 3706 | + | |
| 3707 | + if (this.data.share_hidden) { | |
| 3708 | + this.setData({ | |
| 3709 | + share_hidden: false, | |
| 3710 | + }); | |
| 3711 | + }; | |
| 3712 | + | |
| 3713 | + //类型 0普通商品 1秒杀商品 2商家和会员团 3阶梯团 4阶梯团 | |
| 3714 | + var type = 8; | |
| 3715 | + wx.showLoading({ | |
| 3716 | + title: '生成中...', | |
| 3717 | + }) | |
| 3718 | + var that = this, | |
| 3719 | + th = that; | |
| 3720 | + //设置画板显示,才能开始绘图 | |
| 3721 | + that.setData({ | |
| 3722 | + canvasHidden: false | |
| 3723 | + }) | |
| 3724 | + | |
| 3725 | + var app = getApp(); | |
| 3726 | + var unit = that.data.screenWidth / 750 * 1.35; //基础单位, | |
| 3727 | + var path2 = that.data.data.original_img; | |
| 3728 | + | |
| 3729 | + var scene = th.data.gid + "_"+th.data.presellList.id; | |
| 3730 | + var user_id = getApp().globalData.user_id ? getApp().globalData.user_id : 0; | |
| 3731 | + if (user_id > 0) { | |
| 3732 | + scene += "_" + user_id; | |
| 3733 | + } | |
| 3734 | + //-- 如果不是会员分享过来的要分享给别人 -- | |
| 3735 | + if (getApp().globalData.room_id && th.data.data.goods_id == getApp().globalData.room_goods_id && !getApp().globalData.room_user_share) { | |
| 3736 | + //固定房间是第3个字符 | |
| 3737 | + if (!user_id) scene += "_0"; | |
| 3738 | + scene += "_" + getApp().globalData.room_id; | |
| 3739 | + } | |
| 3740 | + | |
| 3741 | + | |
| 3742 | + ///二微码 | |
| 3743 | + var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" + | |
| 3744 | + os.stoid + "?sceneValue=" + scene + "&pageValue=packageC/pages/presell/cardInfo/goodsInfo"; | |
| 3745 | + | |
| 3746 | + | |
| 3747 | + console.log(path3); | |
| 3748 | + | |
| 3749 | + //读取文件成功则OK-- | |
| 3750 | + wx.getImageInfo({ | |
| 3751 | + src: path3, | |
| 3752 | + success: function (res) { | |
| 3753 | + //回调写法 | |
| 3754 | + th.get_head_temp(th.get_goods_temp, function () { | |
| 3755 | + var vpath = res.path; | |
| 3756 | + var context = wx.createCanvasContext('share'); | |
| 3757 | + //先画背景 | |
| 3758 | + var pg_path = "../../../../images/share/share_bg.png"; | |
| 3759 | + | |
| 3760 | + //-- 如果有自定义海报的时候,判断背景的图片 -- | |
| 3761 | + if (th.data.share_b_img) { | |
| 3762 | + pg_path = th.data.share_b_img; | |
| 3763 | + } | |
| 3764 | + context.drawImage(pg_path, 0, 0, 554 * unit, 899 * unit); | |
| 3765 | + | |
| 3766 | + let nick=app.globalData.userInfo?app.globalData.userInfo.nickname:''; | |
| 3767 | + | |
| 3768 | + //-- 是自定义海报的情况下 -- | |
| 3769 | + if (th.data.poster && parseInt(th.data.poster.style) == 2) { | |
| 3770 | + //在线上分享人的情况下 | |
| 3771 | + if (parseInt(th.data.poster.show_headpic)) { | |
| 3772 | + //获取坐标 | |
| 3773 | + var x = parseFloat(th.data.poster.head_x) * 2; | |
| 3774 | + var y = parseFloat(th.data.poster.head_y) * 2; | |
| 3775 | + var x1 = (x + 90) * unit; | |
| 3776 | + var y1 = (y + 50) * unit; | |
| 3777 | + //--昵称--- | |
| 3778 | + context.setFontSize(24 * unit) | |
| 3779 | + context.setFillStyle("black") | |
| 3780 | + context.fillText(nick, x1, y1); | |
| 3781 | + var width = 24 * nick.length * unit + 4 * unit; | |
| 3782 | + //强烈推荐 改许程 | |
| 3783 | + var tj_path = "../../../../images/share/q_tj.png"; | |
| 3784 | + context.drawImage(tj_path, x1 + width, y1 - 22 * unit, 85 * unit, 30 * unit); | |
| 3785 | + context.setFontSize(16 * unit) | |
| 3786 | + context.setLineJoin('round'); //交点设置成圆角 | |
| 3787 | + context.setFillStyle("white") | |
| 3788 | + context.fillText('强烈推荐', x1 + width + 8 * unit, y1 - 1 * unit); | |
| 3789 | + | |
| 3790 | + //context.setFillStyle("black") | |
| 3791 | + //context.setFontSize(24 * unit) | |
| 3792 | + //context.fillText(getApp().globalData.config.store_name, 40 * unit, 130 * unit); | |
| 3793 | + } | |
| 3794 | + } else { | |
| 3795 | + //--昵称--- | |
| 3796 | + context.setFontSize(24 * unit) | |
| 3797 | + context.setFillStyle("black") | |
| 3798 | + context.fillText(nick, 152 * unit, 76 * unit); | |
| 3799 | + var width = 24 * nick.length * unit + 2 * unit; | |
| 3800 | + //强烈推荐 改许程 | |
| 3801 | + var tj_path = "../../../../images/share/q_tj.png"; | |
| 3802 | + context.drawImage(tj_path, 152 * unit + width, 54 * unit, 85 * unit, 30 * unit); | |
| 3803 | + context.setFontSize(16 * unit); | |
| 3804 | + context.setLineJoin('round'); //交点设置成圆角 | |
| 3805 | + context.setFillStyle("white"); | |
| 3806 | + context.fillText('强烈推荐', 149 * unit + width + 15 * unit, 75 * unit); | |
| 3807 | + } | |
| 3808 | + | |
| 3809 | + var share_title = th.data.presellForm.share_title; | |
| 3810 | + share_title=share_title ? share_title : th.data.data.goods_name; | |
| 3811 | + | |
| 3812 | + //---产品名称--- | |
| 3813 | + //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度 | |
| 3814 | + | |
| 3815 | + context.setFillStyle("black"); | |
| 3816 | + context.setFontSize(21.3 * unit) | |
| 3817 | + th.draw_Text(context, share_title, | |
| 3818 | + 80 * unit, 160 * unit, 200 * unit, 279 * unit, unit); | |
| 3819 | + | |
| 3820 | + //------产品的价格------- | |
| 3821 | + context.setFontSize(22 * unit) | |
| 3822 | + context.setFillStyle("red") | |
| 3823 | + | |
| 3824 | + | |
| 3825 | + var pri0 = th.data.presellList.presell_money; | |
| 3826 | + // if (th.data.prom_act) | |
| 3827 | + // pri0 = th.data.prom_act.price; | |
| 3828 | + pri0 = parseFloat(pri0).toFixed(2); | |
| 3829 | + var wd1 = th.data.screenWidth - ut.measureText(pri0, 31 * unit) - 25; | |
| 3830 | + context.fillText("¥", wd1 - 15, 160 * unit); | |
| 3831 | + context.setFontSize(22 * unit) | |
| 3832 | + context.fillText(pri0, wd1, 165 * unit); | |
| 3833 | + | |
| 3834 | + //---市场价划掉--- | |
| 3835 | + // context.setFillStyle("red") | |
| 3836 | + // context.setFontSize(22 * unit) | |
| 3837 | + // pri0 = "¥" + th.data.data.market_price.toFixed(2); | |
| 3838 | + // var wd2 = th.data.screenWidth - ut.measureText(pri0, 22 * unit) - 25; | |
| 3839 | + | |
| 3840 | + | |
| 3841 | + if(th.data.presellForm.presell_type==1){ | |
| 3842 | + // context.setStrokeStyle('gray'); | |
| 3843 | + // context.fillText(pri0, wd2, 213 * unit); | |
| 3844 | + // context.setLineWidth(1 * unit); | |
| 3845 | + // context.moveTo(wd2 - 5, 206 * unit); | |
| 3846 | + // context.lineTo(wd2 + ut.measureText(pri0, 22 * unit) + 5, 206 * unit); | |
| 3847 | + // context.stroke(); | |
| 3848 | + | |
| 3849 | + //-- 零售价的优化 -- | |
| 3850 | + var wp= th.data.screenWidth - ut.measureText(pri0, 22 * unit) - 50; | |
| 3851 | + var hp= 180 * unit | |
| 3852 | + th.draw_pos_price(context,wp,hp,th.data.data.show_price,unit); | |
| 3853 | + | |
| 3854 | + }else{ | |
| 3855 | + var wd2 = th.data.screenWidth - ut.measureText(pri0, 22 * unit) - 50; | |
| 3856 | + context.fillText('定金', wd2, 190 * unit); | |
| 3857 | + } | |
| 3858 | + | |
| 3859 | + | |
| 3860 | + //console.log(th.data.share_goods_img); | |
| 3861 | + //let share_goods_img=th.data.presellForm.share_img; | |
| 3862 | + //share_goods_img?share_goods_img:th.data.data.share_goods_img; | |
| 3863 | + //---中间大图--- | |
| 3864 | + context.drawImage(th.data.share_goods_img, 70 * unit, 210 * unit, 408 * unit, 408 * unit); | |
| 3865 | + //---自定义海报 产品质量保证 | |
| 3866 | + if(th.data.poster.show_quality==1 ){ | |
| 3867 | + var g_path = "/images/share/s_gou.png"; | |
| 3868 | + context.drawImage(g_path, 56 * unit, 630 * unit, 22 * unit, 22 * unit); | |
| 3869 | + context.setFillStyle("red") | |
| 3870 | + context.setFontSize(18 * unit) | |
| 3871 | + context.fillText("正品保证", 84 * unit, 650 * unit); | |
| 3872 | + | |
| 3873 | + context.drawImage(g_path, 218 * unit, 630 * unit, 22 * unit, 22 * unit); | |
| 3874 | + context.setFillStyle("red") | |
| 3875 | + context.setFontSize(18 * unit) | |
| 3876 | + context.fillText("纯实体店", 246 * unit, 650 * unit); | |
| 3877 | + | |
| 3878 | + context.drawImage(g_path, 388 * unit, 630 * unit, 22 * unit, 22 * unit); | |
| 3879 | + context.setFillStyle("red") | |
| 3880 | + context.setFontSize(18 * unit) | |
| 3881 | + context.fillText("官方验证", 420 * unit, 650 * unit); | |
| 3882 | + | |
| 3883 | + } | |
| 3884 | + | |
| 3885 | + //---画线--- | |
| 3886 | + // context.setLineWidth(1 * unit) | |
| 3887 | + // context.moveTo(32 * unit, 662 * unit) | |
| 3888 | + // context.lineTo(520 * unit, 662 * unit) | |
| 3889 | + // context.stroke(); | |
| 3890 | + | |
| 3891 | + //---文字--- | |
| 3892 | + context.setFillStyle("black") | |
| 3893 | + // context.setFontSize(22 * unit) | |
| 3894 | + context.setFontSize(24 * unit) | |
| 3895 | + context.fillText(th.data.sto_sele_name_1, 40 * unit, 700 * unit); | |
| 3896 | + context.setFillStyle("red") | |
| 3897 | + context.setFontSize(20 * unit) | |
| 3898 | + var presell_price = `预售价:${th.data.presellList.presell_price}` | |
| 3899 | + context.fillText(presell_price, 40 * unit, 750 * unit); | |
| 3900 | + context.setFillStyle("black") | |
| 3901 | + context.setFontSize(22 * unit) | |
| 3902 | + context.fillText("特惠好物,限时预售", 40 * unit, 800 * unit); | |
| 3903 | + context.fillText("长按识别二维码,立即开始抢购", 40 * unit, 840 * unit); | |
| 3904 | + | |
| 3905 | + //---二维吗图--- | |
| 3906 | + //-- 自定义海报 -- | |
| 3907 | + if (th.data.poster) { | |
| 3908 | + var erm_x = parseFloat(th.data.poster.ewm_x) * 2; | |
| 3909 | + var erm_y = parseFloat(th.data.poster.ewm_y) * 2; | |
| 3910 | + context.drawImage(vpath, erm_x * unit, erm_y * unit, 136 * unit, 136 * unit); | |
| 3911 | + } else { | |
| 3912 | + //---二维吗图--- | |
| 3913 | + context.drawImage(vpath, 390 * unit, 746 * unit, 130 * unit, 116 * unit); | |
| 3914 | + } | |
| 3915 | + | |
| 3916 | + //--- 如果是自定义海报的时候 --- | |
| 3917 | + if (th.data.poster && parseInt(th.data.poster.style) == 2) { | |
| 3918 | + | |
| 3919 | + //如果显示会员信息的话 | |
| 3920 | + if (parseInt(th.data.poster.show_headpic)) { | |
| 3921 | + //获取坐标 | |
| 3922 | + var x = parseFloat(th.data.poster.head_x) * 2; | |
| 3923 | + var y = parseFloat(th.data.poster.head_y) * 2; | |
| 3924 | + //---绘制圆形要放在最后---- | |
| 3925 | + context.save(); | |
| 3926 | + context.beginPath(); | |
| 3927 | + var h_x = x * unit; | |
| 3928 | + var h_y = y * unit; | |
| 3929 | + var h_r = 40 * unit; | |
| 3930 | + var cx = h_x + h_r; | |
| 3931 | + var cy = h_y + h_r; | |
| 3932 | + context.arc(cx, cy, h_r, 0, Math.PI * 2, false); | |
| 3933 | + context.closePath(); | |
| 3934 | + context.fill(); | |
| 3935 | + context.clip(); | |
| 3936 | + context.drawImage(th.data.share_head, h_x, h_y, h_r * 2, h_r * 2); | |
| 3937 | + context.restore(); | |
| 3938 | + } | |
| 3939 | + | |
| 3940 | + } else { | |
| 3941 | + //---绘制圆形要放在最后---- | |
| 3942 | + context.save(); | |
| 3943 | + context.beginPath(); | |
| 3944 | + var h_x = 60 * unit; | |
| 3945 | + var h_y = 24 * unit; | |
| 3946 | + var h_r = 40 * unit; | |
| 3947 | + var cx = h_x + h_r; | |
| 3948 | + var cy = h_y + h_r; | |
| 3949 | + context.arc(cx, cy, h_r, 0, Math.PI * 2, false); | |
| 3950 | + context.closePath(); | |
| 3951 | + context.fill(); | |
| 3952 | + context.clip(); | |
| 3953 | + context.drawImage(th.data.share_head, h_x, h_y, h_r * 2, h_r * 2); | |
| 3954 | + context.restore(); | |
| 3955 | + } | |
| 3956 | + | |
| 3957 | + | |
| 3958 | + if(th.data.poster.show_time==1){ | |
| 3959 | + var act_time=''; | |
| 3960 | + act_time="截止时间:"+ ut.formatTime(th.data.presellForm.end_time); | |
| 3961 | + context.setFillStyle("red") | |
| 3962 | + getApp().draw_Text(context, act_time,38 * unit, 880 * unit, 200 * unit, 340 * unit, unit); | |
| 3963 | + } | |
| 3964 | + | |
| 3965 | + //把画板内容绘制成图片,并回调 画板图片路径 | |
| 3966 | + context.draw(false, function () { | |
| 3967 | + setTimeout(function () { | |
| 3968 | + wx.canvasToTempFilePath({ | |
| 3969 | + x: 0, | |
| 3970 | + y: 0, | |
| 3971 | + width: 750, | |
| 3972 | + height: 1217, | |
| 3973 | + destWidth: 1.2 * 750 * 750 / that.data.screenWidth, | |
| 3974 | + destHeight: 1.2 * 1217 * 750 / that.data.screenWidth, | |
| 3975 | + canvasId: 'share', | |
| 3976 | + success: function (res) { | |
| 3977 | + | |
| 3978 | + that.setData({ | |
| 3979 | + shareImgPath: res.tempFilePath, | |
| 3980 | + canvasHidden: true | |
| 3981 | + }) | |
| 3982 | + | |
| 3983 | + if (!res.tempFilePath) { | |
| 3984 | + wx.showModal({ | |
| 3985 | + title: '提示', | |
| 3986 | + content: '图片绘制中,请稍后重试', | |
| 3987 | + showCancel: false | |
| 3988 | + }) | |
| 3989 | + return false; | |
| 3990 | + } | |
| 3991 | + | |
| 3992 | + // wx.previewImage({ | |
| 3993 | + // //将图片预览出来 | |
| 3994 | + // urls: [that.data.shareImgPath] | |
| 3995 | + // }); | |
| 3996 | + that.setData({ | |
| 3997 | + showPoster: true, | |
| 3998 | + }); | |
| 3999 | + wx.hideLoading(); | |
| 4000 | + } | |
| 4001 | + }) | |
| 4002 | + }, 500) | |
| 4003 | + | |
| 4004 | + }); | |
| 4005 | + }); | |
| 4006 | + }, | |
| 4007 | + fail: function (res) { | |
| 4008 | + console.log(res); | |
| 4009 | + wx.hideLoading(); | |
| 4010 | + | |
| 4011 | + } | |
| 4012 | + }); | |
| 4013 | + }, | |
| 4014 | + //--定义的保存图片方法,分享团--- | |
| 4015 | + saveImageToPhotosAlbumDef: function () { | |
| 4016 | + //--先判断会员状态-- | |
| 4017 | + // var user_info = getApp().globalData.userInfo; | |
| 4018 | + // if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) { | |
| 4019 | + // //getApp().my_warnning("请先登录",0,this); | |
| 4020 | + // wx.navigateTo({url: '/packageE/pages/togoin/togoin',}) | |
| 4021 | + // return false; | |
| 4022 | + // } | |
| 4023 | + | |
| 4024 | + if (this.data.share_hidden) { | |
| 4025 | + this.setData({share_hidden: false,}); | |
| 4026 | + }; | |
| 4027 | + | |
| 4028 | + //类型 0普通商品 1秒杀商品 2商家和会员团 3阶梯团 4阶梯团 | |
| 4029 | + var type = this.data.prom_type || 0; | |
| 4030 | + console.log('商品类型-----'); | |
| 4031 | + console.log(type); | |
| 4032 | + // if (type == 2) type = -1; | |
| 4033 | + if (type == 4) type = 0; | |
| 4034 | + if (type == 8) type = 0; | |
| 4035 | + if (type == 2) type = 0; | |
| 4036 | + if (type == 6) type = 2; // 6拼团 2团购 | |
| 4037 | + if (type == 10) type = -1; | |
| 4038 | + | |
| 4039 | + if (this.data.prom_act && this.data.prom_act.kttype == 3) type = 3; | |
| 4040 | + console.log('商品类型。。。。。'); | |
| 4041 | + console.log(type); | |
| 4042 | + wx.showLoading({title: '生成中...',}) | |
| 4043 | + var that = this, th = that; | |
| 4044 | + //设置画板显示,才能开始绘图 | |
| 4045 | + that.setData({ | |
| 4046 | + canvasHidden: false | |
| 4047 | + }) | |
| 4048 | + | |
| 4049 | + var app = getApp(); | |
| 4050 | + var unit = that.data.screenWidth / 750 * 1.35; //基础单位, | |
| 4051 | + var path2 = that.data.data.original_img; | |
| 4052 | + | |
| 4053 | + var scene = th.data.gid; | |
| 4054 | + var user_id = getApp().globalData.user_id ? getApp().globalData.user_id : 0; | |
| 4055 | + if (user_id > 0) { | |
| 4056 | + scene += "_" + user_id; | |
| 4057 | + } | |
| 4058 | + //-- 如果不是会员分享过来的要分享给别人 -- | |
| 4059 | + if (getApp().globalData.room_id && th.data.data.goods_id == getApp().globalData.room_goods_id && !getApp().globalData.room_user_share) { | |
| 4060 | + //固定房间是第3个字符 | |
| 4061 | + if (!user_id) scene += "_0"; | |
| 4062 | + scene += "_" + getApp().globalData.room_id; | |
| 4063 | + }else{ | |
| 4064 | + if (!user_id) scene += "_0"; | |
| 4065 | + scene += "_0"; | |
| 4066 | + } | |
| 4067 | + if(this.data.prom_type){ | |
| 4068 | + scene += "_" + this.data.prom_type+"_"+th.data.prom_id; | |
| 4069 | + } | |
| 4070 | + | |
| 4071 | + ///二微码 | |
| 4072 | + var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" + | |
| 4073 | + os.stoid + "?sceneValue=" + scene + "&pageValue=packageA/pages/goodsInfo/goodsInfo"; | |
| 4074 | + | |
| 4075 | + console.log(path3); | |
| 4076 | + | |
| 4077 | + | |
| 4078 | + // 读取文件成功则OK-- | |
| 4079 | + wx.getImageInfo({ | |
| 4080 | + src: path3, | |
| 4081 | + success: function (res) { | |
| 4082 | + // 回调写法 | |
| 4083 | + th.get_head_temp(th.get_goods_temp, function () { | |
| 4084 | + var vpath = res.path; | |
| 4085 | + var context = wx.createCanvasContext('share'); | |
| 4086 | + // 先画背景 | |
| 4087 | + var pg_path = "../../../../images/share/share_bg.png"; | |
| 4088 | + th.drawPoster(context, unit, th.data.share_goods_img, vpath, type); | |
| 4089 | + | |
| 4090 | + //把画板内容绘制成图片,并回调 画板图片路径 | |
| 4091 | + context.draw(false, function () { | |
| 4092 | + setTimeout(function () { | |
| 4093 | + wx.canvasToTempFilePath({ | |
| 4094 | + x: 0, | |
| 4095 | + y: 0, | |
| 4096 | + width: 750, | |
| 4097 | + height: 1217, | |
| 4098 | + destWidth: 1.2 * 750 * 750 / that.data.screenWidth, | |
| 4099 | + destHeight: 1.2 * 1217 * 750 / that.data.screenWidth, | |
| 4100 | + canvasId: 'share', | |
| 4101 | + success: function (res) { | |
| 4102 | + | |
| 4103 | + that.setData({ | |
| 4104 | + shareImgPath: res.tempFilePath, | |
| 4105 | + canvasHidden: true | |
| 4106 | + }) | |
| 4107 | + | |
| 4108 | + if (!res.tempFilePath) { | |
| 4109 | + wx.showModal({ | |
| 4110 | + title: '提示', | |
| 4111 | + content: '图片绘制中,请稍后重试', | |
| 4112 | + showCancel: false | |
| 4113 | + }) | |
| 4114 | + return false; | |
| 4115 | + } | |
| 4116 | + | |
| 4117 | + that.setData({ | |
| 4118 | + showPoster: true, | |
| 4119 | + }); | |
| 4120 | + wx.hideLoading(); | |
| 4121 | + } | |
| 4122 | + }) | |
| 4123 | + }, 500) | |
| 4124 | + | |
| 4125 | + }); | |
| 4126 | + }); | |
| 4127 | + }, | |
| 4128 | + fail: function (res) { | |
| 4129 | + console.log(res); | |
| 4130 | + wx.hideLoading(); | |
| 4131 | + | |
| 4132 | + } | |
| 4133 | + }); | |
| 4134 | + }, | |
| 4135 | + | |
| 4136 | + //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度 | |
| 4137 | + draw_Text: function (ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, unit) { | |
| 4138 | + var lineWidth = 0; | |
| 4139 | + var lastSubStrIndex = 0; //每次开始截取的字符串的索引 | |
| 4140 | + var han = 0; | |
| 4141 | + for (let i = 0; i < str.length; i++) { | |
| 4142 | + if (han == 2) return; | |
| 4143 | + //lineWidth += ctx.measureText(str[i]).width; | |
| 4144 | + lineWidth += ut.measureText(str[i], 21.3 * unit); | |
| 4145 | + if (lineWidth > canvasWidth) { | |
| 4146 | + han++; | |
| 4147 | + | |
| 4148 | + if (han == 2) | |
| 4149 | + ctx.fillText(str.substring(lastSubStrIndex, i) + '...', leftWidth, initHeight); //绘制截取部分 | |
| 4150 | + else | |
| 4151 | + ctx.fillText(str.substring(lastSubStrIndex, i), leftWidth, initHeight); | |
| 4152 | + | |
| 4153 | + initHeight += 22; //22为字体的高度 | |
| 4154 | + lineWidth = 0; | |
| 4155 | + lastSubStrIndex = i; | |
| 4156 | + titleHeight += 20; | |
| 4157 | + } | |
| 4158 | + if (i == str.length - 1) { //绘制剩余部分 | |
| 4159 | + ctx.fillText(str.substring(lastSubStrIndex, i + 1), leftWidth, initHeight); | |
| 4160 | + } | |
| 4161 | + } | |
| 4162 | + }, | |
| 4163 | + | |
| 4164 | + drawPoster(context, unit, img, vpath, type) { | |
| 4165 | + // 1.灰色背景 | |
| 4166 | + context.setFillStyle('#f2f1f6'); | |
| 4167 | + context.rect(0, 0, 554 * unit, 899 * unit); | |
| 4168 | + context.fill(); | |
| 4169 | + | |
| 4170 | + // 2.商城名称 | |
| 4171 | + let shopName = this.data.sto_sele_name_1; | |
| 4172 | + context.setTextAlign('center'); | |
| 4173 | + context.setFontSize(26 * unit); | |
| 4174 | + context.setFillStyle('black'); | |
| 4175 | + context.fillText(shopName, 277 * unit, 60 * unit); | |
| 4176 | + | |
| 4177 | + // 3.推荐来源 | |
| 4178 | + if(getApp().globalData.userInfo) { | |
| 4179 | + let fromText = `来自${getApp().globalData.userInfo.nickname}的推荐`; | |
| 4180 | + context.setTextAlign('center'); | |
| 4181 | + context.setFontSize(22 * unit); | |
| 4182 | + context.setFillStyle('#96959a'); | |
| 4183 | + context.fillText(fromText, 277 * unit, 105 * unit); | |
| 4184 | + } | |
| 4185 | + // 4.海报背景 | |
| 4186 | + context.setFillStyle('white'); | |
| 4187 | + context.fillRect(37 * unit, 157 * unit, 480 * unit, 673 * unit); | |
| 4188 | + | |
| 4189 | + // 5.商品图片 | |
| 4190 | + // 图片的x坐标 | |
| 4191 | + let bg_x = 37 * unit | |
| 4192 | + // 图片的y坐标 | |
| 4193 | + let bg_y = 157 * unit | |
| 4194 | + // 图片宽度 | |
| 4195 | + let bg_w = 480 * unit | |
| 4196 | + // 图片高度 | |
| 4197 | + let bg_h = 474 * unit | |
| 4198 | + // 图片圆角 | |
| 4199 | + let bg_r = 4 | |
| 4200 | + // 绘制海报背景图片圆角 | |
| 4201 | + context.save() | |
| 4202 | + context.beginPath() | |
| 4203 | + context.arc(bg_x + bg_r, bg_y + bg_r, bg_r, Math.PI, Math.PI * 1.5) | |
| 4204 | + context.arc(bg_x + bg_w - bg_r, bg_y + bg_r, bg_r, Math.PI * 1.5, Math.PI * 2) | |
| 4205 | + context.arc(bg_x + bg_w, bg_y + bg_h, bg_r, 0, Math.PI * 0.5) | |
| 4206 | + context.arc(bg_x, bg_y + bg_h, 0, Math.PI * 0.5, Math.PI) | |
| 4207 | + context.clip() | |
| 4208 | + context.drawImage(img, bg_x, bg_y, bg_w, bg_h); | |
| 4209 | + context.restore(); | |
| 4210 | + | |
| 4211 | + // 6.强烈推荐 | |
| 4212 | + let src = ''; | |
| 4213 | + context.beginPath(); | |
| 4214 | + if (type == 0) { // 普通 | |
| 4215 | + src = '../../../images/share/q_tj.png'; | |
| 4216 | + context.drawImage(src, 54 * unit, 648 * unit, 85 * unit, 30 * unit); | |
| 4217 | + context.setFontSize(16 * unit) | |
| 4218 | + context.setFillStyle("white") | |
| 4219 | + context.setTextAlign('left'); | |
| 4220 | + context.fillText('强烈推荐', 64 * unit, 668 * unit); | |
| 4221 | + } | |
| 4222 | + if (type == 1) { // 秒杀 | |
| 4223 | + | |
| 4224 | + if (this.data.is_share_text == 1) { | |
| 4225 | + src = '../../../images/share/miao_share.png'; | |
| 4226 | + context.drawImage(src, 54 * unit, 648 * unit, 200 * unit, 36 * unit); | |
| 4227 | + } | |
| 4228 | + context.setTextAlign('left'); | |
| 4229 | + } | |
| 4230 | + | |
| 4231 | + | |
| 4232 | + // 7.商品价格 | |
| 4233 | + let price = this.data.data.shop_price; | |
| 4234 | + if (this.data.card_field && this.data.data[this.data.card_field]) { | |
| 4235 | + price = this.data.data[this.data.card_field]; | |
| 4236 | + } | |
| 4237 | + if (this.data.prom_act) price = this.data.prom_price; | |
| 4238 | + price = parseFloat(price).toFixed(2); | |
| 4239 | + context.setFontSize(32 * unit); | |
| 4240 | + context.setFillStyle('#DE1117'); | |
| 4241 | + | |
| 4242 | + //price = this.data.presellList.presell_price | |
| 4243 | + context.fillText('¥' + price, 54 * unit, 735 * unit); | |
| 4244 | + //-- 零售价的优化 -- | |
| 4245 | + var wp= 62 * unit+ut.measureText('¥' + price, 32 * unit); | |
| 4246 | + var hp=735 * unit | |
| 4247 | + this.draw_pos_price(context,wp,hp,this.data.data.show_price,unit); | |
| 4248 | + | |
| 4249 | + | |
| 4250 | + // 8.商品标题 | |
| 4251 | + context.setFontSize(20 * unit); | |
| 4252 | + context.setFillStyle('#898989'); | |
| 4253 | + getApp().draw_Text(context, this.data.data.goods_name, 54 * unit, 800 * unit, 240 * unit, 280 * unit, unit, 1); | |
| 4254 | + | |
| 4255 | + // 9.小程序码 | |
| 4256 | + context.drawImage(vpath, 375 * unit, 660 * unit, 120 * unit, 120 * unit); | |
| 4257 | + context.setFontSize(16 * unit); | |
| 4258 | + context.setFillStyle('#777'); | |
| 4259 | + context.fillText('长按识别二维码', 378 * unit, 810 * unit); | |
| 4260 | + | |
| 4261 | + // 10.竖线 | |
| 4262 | + context.beginPath(); | |
| 4263 | + context.setFillStyle('#eee'); | |
| 4264 | + context.rect(354 * unit, 670 * unit, 1 * unit, 130 * unit); | |
| 4265 | + context.fill(); | |
| 4266 | + }, | |
| 4267 | + | |
| 4268 | + //---市场价划掉--- | |
| 4269 | + draw_pos_price(context,w,h,market_price,unit){ | |
| 4270 | + | |
| 4271 | + if(!this.data.sys_switch) return false; | |
| 4272 | + if(!this.data.sys_switch.is_retail_price) return false; | |
| 4273 | + | |
| 4274 | + context.setFillStyle("gray") | |
| 4275 | + context.setFontSize(22 * unit) | |
| 4276 | + var pri0 = "¥" + market_price.toFixed(2); | |
| 4277 | + context.fillText(pri0, w, h); | |
| 4278 | + | |
| 4279 | + var c_h=h-6; | |
| 4280 | + context.setStrokeStyle('gray'); | |
| 4281 | + context.setLineWidth(1 * unit); | |
| 4282 | + context.moveTo(w - 5, c_h); | |
| 4283 | + context.lineTo(w + ut.measureText(pri0, 22 * unit) + 5, c_h); | |
| 4284 | + context.stroke(); | |
| 4285 | + | |
| 4286 | + }, | |
| 4287 | + | |
| 4288 | + | |
| 4289 | + closePoster() { | |
| 4290 | + this.setData({ | |
| 4291 | + showPoster: false, | |
| 4292 | + }); | |
| 4293 | + }, | |
| 4294 | + | |
| 4295 | + // 保存图片到手机 | |
| 4296 | + savePic() { | |
| 4297 | + console.log('保存图片'); | |
| 4298 | + var self = this; | |
| 4299 | + // 获取用户的当前设置,返回值中有小程序已经向用户请求过的权限 | |
| 4300 | + this.getSetting().then((res) => { | |
| 4301 | + // 判断用户是否授权了保存到相册的权限,如果没有发起授权 | |
| 4302 | + if (!res.authSetting['scope.writePhotosAlbum']) { | |
| 4303 | + this.authorize().then(() => { | |
| 4304 | + // 同意授权后保存下载文件 | |
| 4305 | + this.saveImage(self.data.shareImgPath) | |
| 4306 | + .then(() => { | |
| 4307 | + self.setData({ | |
| 4308 | + showPoster: false | |
| 4309 | + }); | |
| 4310 | + }); | |
| 4311 | + }) | |
| 4312 | + } else { | |
| 4313 | + // 如果已经授权,保存下载文件 | |
| 4314 | + this.saveImage(self.data.shareImgPath) | |
| 4315 | + .then(() => { | |
| 4316 | + self.setData({ | |
| 4317 | + showPoster: false | |
| 4318 | + }); | |
| 4319 | + }); | |
| 4320 | + } | |
| 4321 | + | |
| 4322 | + }) | |
| 4323 | + }, | |
| 4324 | + | |
| 4325 | + // 发起首次授权请求 | |
| 4326 | + authorize() { | |
| 4327 | + // isFirst 用来记录是否为首次发起授权, | |
| 4328 | + // 如果首次授权拒绝后,isFirst赋值为1 | |
| 4329 | + let isFirst = wx.getStorageSync('isFirst') || 0; | |
| 4330 | + return new Promise((resolve, reject) => { | |
| 4331 | + wx.authorize({ | |
| 4332 | + scope: 'scope.writePhotosAlbum', | |
| 4333 | + // 同意授权 | |
| 4334 | + success: () => { | |
| 4335 | + resolve(); | |
| 4336 | + }, | |
| 4337 | + // 拒绝授权,这里是用户拒绝授权后的回调 | |
| 4338 | + fail: res => { | |
| 4339 | + if (isFirst === 0) { | |
| 4340 | + wx.setStorageSync('isFirst', 1); | |
| 4341 | + wx.showToast({ | |
| 4342 | + title: '保存失败', | |
| 4343 | + icon: 'none', | |
| 4344 | + duration: 1000 | |
| 4345 | + }) | |
| 4346 | + } else { | |
| 4347 | + this.showModal(); | |
| 4348 | + } | |
| 4349 | + console.log('拒绝授权'); | |
| 4350 | + reject(); | |
| 4351 | + } | |
| 4352 | + }) | |
| 4353 | + }) | |
| 4354 | + }, | |
| 4355 | + | |
| 4356 | + | |
| 4357 | + // 保存图片到系统相册 | |
| 4358 | + saveImage(saveUrl) { | |
| 4359 | + var self = this; | |
| 4360 | + return new Promise((resolve, reject) => { | |
| 4361 | + wx.saveImageToPhotosAlbum({ | |
| 4362 | + filePath: saveUrl, | |
| 4363 | + success: (res) => { | |
| 4364 | + wx.showToast({ | |
| 4365 | + title: '保存成功', | |
| 4366 | + duration: 1000, | |
| 4367 | + }); | |
| 4368 | + self.setData({ | |
| 4369 | + showPlaybill: 'true' | |
| 4370 | + }); | |
| 4371 | + resolve(); | |
| 4372 | + }, | |
| 4373 | + fail: () => { | |
| 4374 | + wx.showToast({ | |
| 4375 | + title: '保存失败', | |
| 4376 | + duration: 1000, | |
| 4377 | + }); | |
| 4378 | + } | |
| 4379 | + }) | |
| 4380 | + }) | |
| 4381 | + }, | |
| 4382 | + | |
| 4383 | + // 预览海报 | |
| 4384 | + previewPoster() { | |
| 4385 | + getApp().globalData.no_clear = 1; | |
| 4386 | + wx.previewImage({ | |
| 4387 | + current: this.data.shareImgPath, // 当前显示图片的http链接 | |
| 4388 | + urls: [this.data.shareImgPath], // 需要预览的图片http链接列表 | |
| 4389 | + }); | |
| 4390 | + }, | |
| 4391 | + | |
| 4111 | 4392 | |
| 4112 | 4393 | }); |
| 4113 | 4394 | ... | ... |
packageA/pages/goodsInfo/goodsInfo.json
| ... | ... | @@ -6,7 +6,8 @@ |
| 6 | 6 | "warn": "/components/long_warn/long_warn", |
| 7 | 7 | "serviceCard_recommend": "/components/serviceCard_list/serviceCard_list", |
| 8 | 8 | "privacy_pop": "/components/privacy_pop/privacy_pop", |
| 9 | - "top_nav": "/components/diy_top_nav/diy_top_nav" | |
| 9 | + "top_nav": "/components/diy_top_nav/diy_top_nav", | |
| 10 | + "share": "/components/share/share" | |
| 10 | 11 | }, |
| 11 | 12 | "navigationStyle": "custom" |
| 12 | 13 | } |
| 13 | 14 | \ No newline at end of file | ... | ... |
packageA/pages/goodsInfo/goodsInfo.wxml
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | <view class="container"> |
| 12 | 12 | |
| 13 | 13 | <view class="type-navbar_box"> |
| 14 | - <top_nav id="my-nav" bindclickShare="clickShare" nav_type="{{nav_type}}" is_share="{{false}}" | |
| 14 | + <top_nav id="my-nav" bindclickShare="clickShare" nav_type="{{nav_type}}" is_share="{{true}}" | |
| 15 | 15 | nav_frontColor="{{nav_frontColor}}" istop="{{(istop && searchbox_transparent && activeCategoryId==0) ? 1 : 0 }}" nav_backgroundColor="{{nav_backgroundColor}}" nav_title="{{gtitle}}"></top_nav> |
| 16 | 16 | </view> |
| 17 | 17 | |
| ... | ... | @@ -106,16 +106,25 @@ |
| 106 | 106 | <view class="market-price" style="overflow: hidden"></view> |
| 107 | 107 | </view> |
| 108 | 108 | |
| 109 | - <view> | |
| 110 | - <!-- 秒杀价 --> | |
| 111 | - <view class="co-red" wx:if="{{options.prom_type == 1}}"><text class="rel yuan fs28">¥</text>{{filters.toFix(prom_price,2)}}</view> | |
| 112 | - <!-- 手店价 --> | |
| 113 | - <view class="co-red" wx:else><text class="rel yuan fs28">¥</text>{{filters.toFix(data.shop_price,2)}}</view> | |
| 114 | - <!-- <view class="word-line fs20 xc-qtunit-price"> | |
| 115 | - 零售价¥{{filters.toFix(data.market_price,2)}} | |
| 116 | - </view> --> | |
| 117 | - <view class="goods-title"> | |
| 118 | - <view class="goods-name elli">{{data.goods_name}}</view> | |
| 109 | + | |
| 110 | + <view class="flex jc_sb"> | |
| 111 | + <view> | |
| 112 | + <!-- 秒杀价 --> | |
| 113 | + <view class="co-red" wx:if="{{options.prom_type == 1}}"><text class="rel yuan fs28">¥</text>{{filters.toFix(prom_price,2)}}</view> | |
| 114 | + <!-- 手店价 --> | |
| 115 | + <view class="co-red" wx:else><text class="rel yuan fs28">¥</text>{{filters.toFix(data.shop_price,2)}}</view> | |
| 116 | + <!-- <view class="word-line fs20 xc-qtunit-price"> | |
| 117 | + 零售价¥{{filters.toFix(data.market_price,2)}} | |
| 118 | + </view> --> | |
| 119 | + <view class="goods-title"> | |
| 120 | + <view class="goods-name elli">{{data.goods_name}}</view> | |
| 121 | + </view> | |
| 122 | + </view> | |
| 123 | + | |
| 124 | + <!-- 这个是分享按钮 --> | |
| 125 | + <view wx:if="{{isLogin}}" class="xc-share-frame t-c shrink0" bindtap="clickShare"> | |
| 126 | + <view class="iconfont icon-share"></view> | |
| 127 | + <view class="fs22 c-7b">分享</view> | |
| 119 | 128 | </view> |
| 120 | 129 | </view> |
| 121 | 130 | |
| ... | ... | @@ -970,14 +979,20 @@ |
| 970 | 979 | <canvas canvas-id='share' style='width:750rpx;height:1217rpx;background-color:white;' wx:if='{{!canvasHidden}}'></canvas> |
| 971 | 980 | <warn id="warn"></warn> |
| 972 | 981 | |
| 973 | - | |
| 974 | 982 | <view wx:if="{{showPoster}}"> |
| 975 | 983 | <view class="mask" catchtap="closePoster"></view> |
| 976 | 984 | <view class="poster-container"> |
| 977 | 985 | <view class="poster-wrapper"> |
| 978 | - <view class="poster"> | |
| 986 | + <view class="poster" bindtap="previewPoster"> | |
| 987 | + <!-- <view class="poster" bindtap="previewImage"> --> | |
| 979 | 988 | <image src="{{shareImgPath}}" class="poster-img" show-menu-by-longpress></image> |
| 980 | - <view class="btn-close" catchtap="closePoster"><text class="iconfont icon-close"></text></view> | |
| 989 | + <view class="btn-close" catchtap="closePoster"> | |
| 990 | + <text class="iconfont icon-close"></text> | |
| 991 | + </view> | |
| 992 | + </view> | |
| 993 | + <view class="btn-container"> | |
| 994 | + <!-- <button class="btn-share" open-type="share" bindtap="">微信好友分享</button> --> | |
| 995 | + <button class="btn-share" bindtap="savePic">保存到相册</button> | |
| 981 | 996 | </view> |
| 982 | 997 | </view> |
| 983 | 998 | </view> |
| ... | ... | @@ -1015,3 +1030,5 @@ |
| 1015 | 1030 | </view> |
| 1016 | 1031 | |
| 1017 | 1032 | <view class="mask2" bindtap="closeCS"></view> |
| 1033 | +<!-- 分享控件,底部弹出 --> | |
| 1034 | +<share id="share_button" bind:send="send" bind:cancel="cancel" bind:share_img="saveImageFn" wx:if="{{share_hidden}}"></share> | ... | ... |
packageA/pages/serviceCard_pd/goodsInfo/goodsInfo.js
| ... | ... | @@ -12,6 +12,7 @@ var more = function (e) { |
| 12 | 12 | }(require("../../../../utils/LoadMore.js")), |
| 13 | 13 | n = new more.default(); |
| 14 | 14 | var regeneratorRuntime = require('../../../../utils/runtime.js'); |
| 15 | +var self=null; | |
| 15 | 16 | |
| 16 | 17 | Page({ |
| 17 | 18 | data: { |
| ... | ... | @@ -1615,6 +1616,12 @@ Page({ |
| 1615 | 1616 | // return false; |
| 1616 | 1617 | // } |
| 1617 | 1618 | |
| 1619 | + if (this.data.share_hidden) { | |
| 1620 | + this.setData({ | |
| 1621 | + share_hidden: false, | |
| 1622 | + }); | |
| 1623 | + }; | |
| 1624 | + | |
| 1618 | 1625 | //类型 0普通商品 1秒杀商品 2商家和会员团 3阶梯团 4积分购 |
| 1619 | 1626 | var type = 2 |
| 1620 | 1627 | if (this.data.prom_act && this.data.prom_act.kttype == 3) type = 3; |
| ... | ... | @@ -3579,6 +3586,9 @@ Page({ |
| 3579 | 3586 | }); |
| 3580 | 3587 | }, |
| 3581 | 3588 | |
| 3589 | + send() { | |
| 3590 | + this.setData({ share_hidden: false, }); | |
| 3591 | + }, | |
| 3582 | 3592 | cancel() { |
| 3583 | 3593 | this.setData({ |
| 3584 | 3594 | share_hidden: false, |
| ... | ... | @@ -3975,6 +3985,15 @@ Page({ |
| 3975 | 3985 | } |
| 3976 | 3986 | }, |
| 3977 | 3987 | |
| 3988 | + // 预览海报 | |
| 3989 | + previewPoster() { | |
| 3990 | + getApp().globalData.no_clear = 1; | |
| 3991 | + wx.previewImage({ | |
| 3992 | + current: this.data.shareImgPath, // 当前显示图片的http链接 | |
| 3993 | + urls: [this.data.shareImgPath], // 需要预览的图片http链接列表 | |
| 3994 | + }); | |
| 3995 | + }, | |
| 3996 | + | |
| 3978 | 3997 | }); |
| 3979 | 3998 | |
| 3980 | 3999 | ... | ... |
packageA/pages/serviceCard_pd/goodsInfo/goodsInfo.wxml
| ... | ... | @@ -807,14 +807,20 @@ |
| 807 | 807 | <canvas canvas-id='share' style='width:750rpx;height:1217rpx;background-color:white;' wx:if='{{!canvasHidden}}'></canvas> |
| 808 | 808 | <warn id="warn"></warn> |
| 809 | 809 | |
| 810 | - | |
| 811 | 810 | <view wx:if="{{showPoster}}"> |
| 812 | 811 | <view class="mask" catchtap="closePoster"></view> |
| 813 | 812 | <view class="poster-container"> |
| 814 | 813 | <view class="poster-wrapper"> |
| 815 | - <view class="poster"> | |
| 814 | + <view class="poster" bindtap="previewPoster"> | |
| 815 | + <!-- <view class="poster" bindtap="previewImage"> --> | |
| 816 | 816 | <image src="{{shareImgPath}}" class="poster-img" show-menu-by-longpress></image> |
| 817 | - <view class="btn-close" catchtap="closePoster"><text class="iconfont icon-close"></text></view> | |
| 817 | + <view class="btn-close" catchtap="closePoster"> | |
| 818 | + <text class="iconfont icon-close"></text> | |
| 819 | + </view> | |
| 820 | + </view> | |
| 821 | + <view class="btn-container"> | |
| 822 | + <!-- <button class="btn-share" open-type="share" bindtap="">微信好友分享</button> --> | |
| 823 | + <button class="btn-share" bindtap="savePic">保存到相册</button> | |
| 818 | 824 | </view> |
| 819 | 825 | </view> |
| 820 | 826 | </view> | ... | ... |
packageA/pages/serviceCard_pd/goodsInfo/goodsInfo.wxss
| ... | ... | @@ -2744,7 +2744,7 @@ button.custom-service::after{ |
| 2744 | 2744 | left: 50%; |
| 2745 | 2745 | transform: translate(-50%, -50%); |
| 2746 | 2746 | width: calc(100% - 120rpx); |
| 2747 | - z-index: 1000; | |
| 2747 | + z-index: 10001; | |
| 2748 | 2748 | } |
| 2749 | 2749 | .mask { |
| 2750 | 2750 | position: fixed; |
| ... | ... | @@ -2752,7 +2752,7 @@ button.custom-service::after{ |
| 2752 | 2752 | left: 0; |
| 2753 | 2753 | width: 100%; |
| 2754 | 2754 | height: 100%; |
| 2755 | - z-index: 999; | |
| 2755 | + z-index: 10000; | |
| 2756 | 2756 | background-color: rgba(0,0,0,.4); |
| 2757 | 2757 | } |
| 2758 | 2758 | .poster-wrapper { | ... | ... |
packageC/pages/presell/cardInfo/goodsInfo.js
| ... | ... | @@ -2002,8 +2002,8 @@ Page({ |
| 2002 | 2002 | return false; |
| 2003 | 2003 | } |
| 2004 | 2004 | |
| 2005 | - var img=ee.data.iurl+ee.data.data.img_url; | |
| 2006 | - if(ee.data.prom_act){ | |
| 2005 | + var img=ee.data.iurl+ee.data.data.image_url; | |
| 2006 | + if(ee.data.prom_act && ee.data.prom_act.share_img){ | |
| 2007 | 2007 | img=ee.data.iurl+ee.data.prom_act.share_img; |
| 2008 | 2008 | } |
| 2009 | 2009 | |
| ... | ... | @@ -4073,7 +4073,14 @@ Page({ |
| 4073 | 4073 | }) |
| 4074 | 4074 | }, |
| 4075 | 4075 | |
| 4076 | - | |
| 4076 | + // 预览海报 | |
| 4077 | + previewPoster() { | |
| 4078 | + getApp().globalData.no_clear = 1; | |
| 4079 | + wx.previewImage({ | |
| 4080 | + current: this.data.shareImgPath, // 当前显示图片的http链接 | |
| 4081 | + urls: [this.data.shareImgPath], // 需要预览的图片http链接列表 | |
| 4082 | + }); | |
| 4083 | + }, | |
| 4077 | 4084 | |
| 4078 | 4085 | |
| 4079 | 4086 | ... | ... |
packageC/pages/presell/cardInfo/goodsInfo.wxml
| ... | ... | @@ -990,6 +990,7 @@ |
| 990 | 990 | <warn id="warn"></warn> |
| 991 | 991 | <!-- 分享控件,底部弹出 --> |
| 992 | 992 | <share id="share_button" bind:send="send" bind:cancel="cancel" bind:share_img="saveImageFn" wx:if="{{share_hidden}}"></share> |
| 993 | + | |
| 993 | 994 | <view wx:if="{{showPoster}}"> |
| 994 | 995 | <view class="mask" catchtap="closePoster"></view> |
| 995 | 996 | <view class="poster-container"> | ... | ... |