Commit 92cdf1fafc182a6b5b5eb5b2915ff60162f26fc6

Authored by yvan.ni
1 parent 90455731

预售的优化

packageC/pages/presell/cardInfo/goodsInfo.js
... ... @@ -223,7 +223,8 @@ Page({
223 223 nav_backgroundColor: "#ffffff",
224 224 nav_type: 2, //导航类型
225 225 istop: 0, //是否置顶风格为1
226   - searchbox_transparent: 1
  226 + searchbox_transparent: 1,
  227 + prom_type: 8,
227 228  
228 229 },
229 230  
... ... @@ -250,25 +251,56 @@ Page({
250 251 //检查测肤
251 252 getApp().check_skin_face(t,1,gid);
252 253  
  254 +
  255 + //-- 自定义海报 --
  256 + getApp().request.promiseGet("/api/weshop/goods/poster/page", {
  257 + data: { store_id: os.stoid, type: 1, is_use: 1 }
  258 + }).then(res => {
  259 + if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData[0]) {
  260 +
  261 + var poster_data = res.data.data.pageData[0];
  262 + var json_str = poster_data.jsonStr;
  263 +
  264 + if (json_str) {
  265 + var json_data = JSON.parse(json_str);
  266 + if (json_data.bg_img) {
  267 +
  268 + //-- 把图片那到本地 --
  269 + wx.getImageInfo({
  270 + src: json_data.bg_img,
  271 + success: function (res) {
  272 + var path = res.path;
  273 + th.setData({ share_b_img: path })
  274 + },
  275 + fail: function (res) { }
  276 + });
  277 + }
  278 + th.setData({ poster: json_data })
  279 +
  280 + }
  281 + }
  282 + })
  283 +
253 284 //-- 设置顶部高度 --
254 285 let height= getApp().globalData.navBarHeight;
255 286 ee.setData({ top_nav:height});
256 287  
257   - //---获取手机地址坐标--
258   - //--如果tg_id是空的话,分享回来--
259   - if (gid == undefined || gid == null || gid == "") {
260   - var gid_str = decodeURIComponent(t.scene);
261   - gid_str=gid_str.split("_");
262   - gid=gid_str[0];
263   - if(gid_str.length>1){
264   - first_leader=gid_str[1];
265   - }
266   - //-- 如果有room_id的获取 --
267   - if(gid_str.length>2 && gid_str[2]) {
268   - room_id=gid_str[2];
269   - room_user_share=1;
270   - };
271   - };
  288 +
  289 + //--如果tg_id是空的话,分享回来--
  290 + if (gid == undefined || gid == null || gid == "") {
  291 + var gid_str = decodeURIComponent(t.scene);
  292 + gid_str = gid_str.split("_");
  293 + gid = gid_str[0];
  294 + if (gid_str.length > 1) {
  295 + pre_id = gid_str[1];
  296 + first_leader = gid_str[2];
  297 + }
  298 + //-- 如果有room_id的获取 --
  299 + if (gid_str.length > 2 && gid_str[3]) {
  300 + room_id = gid_str[3];
  301 + room_user_share = 1;
  302 + }
  303 + }
272 304  
273 305 ee.setData({ gid: gid, pre_id: pre_id, presell_id: presell_id});
274 306  
... ... @@ -582,7 +614,7 @@ Page({
582 614 privacy_pop.check_pri_show();
583 615 }
584 616  
585   - getApp().check_can_share();
  617 + getApp().check_can_share(this);
586 618  
587 619 var that=this;var th=this;
588 620 var ee = this,gid = this.data.gid, i = getApp().request;
... ... @@ -1845,466 +1877,6 @@ Page({
1845 1877 return param < 10 ? '0' + param : param;
1846 1878 },
1847 1879  
1848   -
1849   - //--定义的保存图片方法,分享团---
1850   - saveImageToPhotosAlbum: function() {
1851   - //--先判断会员状态--
1852   - var user_info = getApp().globalData.userInfo;
1853   - if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
1854   - //getApp().my_warnning("请先登录",0,this);
1855   - wx.navigateTo({ url: '/packageE/pages/togoin/togoin', })
1856   - return false;
1857   - }
1858   -
1859   - //类型 0普通商品 1秒杀商品 2商家和会员团 3阶梯团 4阶梯团
1860   - var type = this.data.prom_type;
1861   - if (type == 6) type = 2;
1862   - if (this.data.prom_act && this.data.prom_act.kttype == 3) type = 3;
1863   -
1864   - wx.showLoading({
1865   - title: '生成中...',
1866   - })
1867   - var that = this,
1868   - th = that;
1869   - //设置画板显示,才能开始绘图
1870   - that.setData({
1871   - canvasHidden: false
1872   - })
1873   -
1874   - var app = getApp();
1875   - var unit = that.data.screenWidth / 750 * 1.35; //基础单位,
1876   - var path2 = that.data.data.original_img;
1877   - var scene = th.data.gid+"";
1878   - var user_id = getApp().globalData.user_id?getApp().globalData.user_id:0;
1879   - if(user_id>0) {
1880   - scene+="_"+user_id;
1881   - }
1882   - //-- 如果不是会员分享过来的要分享给别人 --
1883   - if(getApp().globalData.room_id && th.data.data.goods_id==getApp().globalData.room_goods_id && !getApp().globalData.room_user_share) {
1884   - //固定房间是第3个字符
1885   - if(!user_id) scene+="_0";
1886   - scene+="_"+getApp().globalData.room_id ;
1887   - }
1888   - ///二微码
1889   - var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" +
1890   - os.stoid + "?sceneValue=" + scene + "&pageValue=pages/goods/goodsInfo/goodsInfo";
1891   -
1892   - console.log(path3);
1893   -
1894   - //读取文件成功则OK--
1895   - wx.getImageInfo({
1896   - src: path3,
1897   - success: function(res) {
1898   - //回调写法
1899   - th.get_head_temp(th.get_goods_temp, function() {
1900   - var vpath = res.path;
1901   - var context = wx.createCanvasContext('share');
1902   - //先画背景
1903   - var pg_path = "../../../images/share/share_bg.png";
1904   -
1905   - // context.fillStyle="#FFFFFF";
1906   - // context.fillRect(0,0,554 * unit, 899 * unit);
1907   -
1908   - //-- 如果有自定义海报的时候,判断背景的图片 --
1909   - if(th.data.share_b_img){
1910   - pg_path=th.data.share_b_img;
1911   - }
1912   - context.drawImage(pg_path, 0, 0, 554 * unit, 899 * unit);
1913   -
1914   - //-- 是自定义海报的情况下 --
1915   - if(th.data.poster && parseInt(th.data.poster.style)==2) {
1916   - //在线上分享人的情况下
1917   - if(parseInt(th.data.poster.show_headpic)){
1918   - //获取坐标
1919   - var x=parseFloat(th.data.poster.head_x)*2;
1920   - var y=parseFloat(th.data.poster.head_y)*2;
1921   - var x1=(x+90) *unit;
1922   - var y1=(y+50) *unit;
1923   - //--昵称---
1924   - context.setFontSize(24 * unit)
1925   - context.setFillStyle("black")
1926   - context.fillText(app.globalData.userInfo.nickname, x1, y1);
1927   - var width = 24 * app.globalData.userInfo.nickname.length * unit + 4 * unit;
1928   - //强烈推荐 改许程
1929   - var tj_path = "../../../images/share/q_tj.png";
1930   - context.drawImage(tj_path, x1 + width, y1-22*unit, 85 * unit, 30 * unit);
1931   - context.setFontSize(16 * unit)
1932   - context.setLineJoin('round'); //交点设置成圆角
1933   - context.setFillStyle("white")
1934   - context.fillText('强烈推荐', x1 + width+8*unit, y1-1*unit);
1935   -
1936   - //context.setFillStyle("black")
1937   - //context.setFontSize(24 * unit)
1938   - //context.fillText(getApp().globalData.config.store_name, 40 * unit, 130 * unit);
1939   - }
1940   - } else {
1941   - //--昵称---
1942   - context.setFontSize(24 * unit)
1943   - context.setFillStyle("black")
1944   - context.fillText(app.globalData.userInfo.nickname, 152 * unit, 76 * unit);
1945   - var width = 24 * app.globalData.userInfo.nickname.length * unit + 2 * unit;
1946   - //强烈推荐 改许程
1947   - var tj_path = "../../../images/share/q_tj.png";
1948   - context.drawImage(tj_path, 152 * unit + width, 54 * unit, 85 * unit, 30 * unit);
1949   - context.setFontSize(16 * unit);
1950   - context.setLineJoin('round'); //交点设置成圆角
1951   - context.setFillStyle("white");
1952   - context.fillText('强烈推荐', 149 * unit + width + 15 * unit, 75 * unit);
1953   - }
1954   -
1955   -
1956   - //---产品名称---
1957   - //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度
1958   - if(type!=4){
1959   - context.setFillStyle("black");
1960   - context.setFontSize(21.3 * unit)
1961   - th.draw_Text(context, th.data.data.goods_name,
1962   - 38 * unit, 180 * unit, 200 * unit, 279 * unit, unit);
1963   - //------产品的价格-------
1964   - context.setFontSize(23 * unit)
1965   - context.setFillStyle("red")
1966   - context.fillText("¥", 416 * unit, 185 * unit);
1967   - context.setFontSize(31 * unit)
1968   - var pri0 = th.data.data.shop_price;
1969   - if (th.data.prom_act)
1970   - pri0 = th.data.prom_act.price;
1971   - pri0 = parseFloat(pri0).toFixed(2);
1972   - context.fillText(pri0, 438 * unit, 185 * unit);
1973   - //---市场价划掉---
1974   - context.setFillStyle("gray")
1975   - context.setFontSize(22 * unit)
1976   - context.fillText("¥" + th.data.data.market_price, 426 * unit, 213 * unit);
1977   - context.setStrokeStyle('gray');
1978   - context.setLineWidth(1 * unit);
1979   - context.moveTo(426 * unit, 206 * unit);
1980   - context.lineTo(510 * unit, 206 * unit);
1981   - context.stroke();
1982   -
1983   - }else{
1984   - context.setFillStyle("black");
1985   - context.setFontSize(21.3 * unit)
1986   - th.draw_Text(context, th.data.data.goods_name,
1987   - 38 * unit, 170 * unit, 20 * unit, 300*unit, unit);
1988   - //------ 产品的价格 -----
1989   - var pri0 = th.data.prom_act.addmoney;
1990   - var integral=th.data.prom_act.integral;
1991   - var text= "";
1992   - if(integral){text=integral+"积分"; }
1993   - if(pri0 && integral){ text+="+";}
1994   - if(pri0){ text+="¥"+pri0;}
1995   -
1996   - if(!pri0 && !integral){ text="0积分";}
1997   - context.setFillStyle("red");
1998   - context.fillText(text, 38 * unit, 235 * unit);
1999   -
2000   - }
2001   -
2002   - //---中间大图---
2003   - context.drawImage(th.data.share_goods_img, 70 * unit, 250 * unit, 408 * unit, 408 * unit);
2004   - //-------大图后面就不一样了-----------
2005   - switch (type) {
2006   - case 0: //普通商品的展示
2007   - case 4:
2008   - //中间的几个字
2009   - if(th.data.poster && parseInt(th.data.poster.style)==2 ){
2010   - if(parseInt(th.data.poster.show_quality)){
2011   - var g_path = "../../../images/share/s_gou.png";
2012   - context.drawImage(g_path, 56 * unit, 670 * unit, 22 * unit, 22 * unit);
2013   - context.setFillStyle("red")
2014   - context.setFontSize(18 * unit)
2015   - context.fillText("正品保证", 84 * unit, 690 * unit);
2016   -
2017   - context.drawImage(g_path, 218 * unit, 670 * unit, 22 * unit, 22 * unit);
2018   - context.setFillStyle("red")
2019   - context.setFontSize(18 * unit)
2020   - context.fillText("纯实体店", 246 * unit, 690 * unit);
2021   -
2022   - context.drawImage(g_path, 388 * unit, 670 * unit, 22 * unit, 22 * unit);
2023   - context.setFillStyle("red")
2024   - context.setFontSize(18 * unit)
2025   - context.fillText("官方验证", 420 * unit, 690 * unit);
2026   - }
2027   -
2028   - }else{
2029   - var g_path = "../../../images/share/s_gou.png";
2030   - context.drawImage(g_path, 56 * unit, 670 * unit, 22 * unit, 22 * unit);
2031   - context.setFillStyle("red")
2032   - context.setFontSize(18 * unit)
2033   - context.fillText("正品保证", 84 * unit, 690 * unit);
2034   -
2035   - context.drawImage(g_path, 218 * unit, 670 * unit, 22 * unit, 22 * unit);
2036   - context.setFillStyle("red")
2037   - context.setFontSize(18 * unit)
2038   - context.fillText("纯实体店", 246 * unit, 690 * unit);
2039   -
2040   - context.drawImage(g_path, 388 * unit, 670 * unit, 22 * unit, 22 * unit);
2041   - context.setFillStyle("red")
2042   - context.setFontSize(18 * unit)
2043   - context.fillText("官方验证", 420 * unit, 690 * unit);
2044   - }
2045   -
2046   -
2047   - //---画线---
2048   - context.setLineWidth(1 * unit)
2049   - context.moveTo(32 * unit, 710 * unit)
2050   - context.lineTo(520 * unit, 710 * unit)
2051   - context.stroke();
2052   -
2053   - //---文字---
2054   - context.setFillStyle("black")
2055   - context.setFontSize(22 * unit)
2056   -
2057   - if(type==0){
2058   - // 原来start --->
2059   - context.setFontSize(24 * unit)
2060   - context.fillText(th.data.sto_sele_name_1, 40 * unit, 766 * unit);
2061   -
2062   - context.setFontSize(22 * unit)
2063   - context.fillText("优惠乐翻天,精彩就在你身边", 40 * unit, 806 * unit);
2064   - context.fillText("长按识别二维码,立即开始抢购", 40 * unit, 846 * unit);
2065   -
2066   - }else{
2067   - context.setFontSize(24 * unit)
2068   - context.fillText(th.data.sto_sele_name_1, 40 * unit, 766 * unit);
2069   - context.setFontSize(22 * unit)
2070   - context.fillText("长按识别二维码", 40 * unit, 806 * unit);
2071   - context.fillText("立即开始兑换", 40 * unit, 846 * unit);
2072   -
2073   -
2074   - }
2075   -
2076   - //---二维吗图---
2077   - //-- 自定义海报 --
2078   - if(th.data.poster){
2079   - var erm_x= parseFloat(th.data.poster.ewm_x)*2;
2080   - var erm_y= parseFloat(th.data.poster.ewm_y)*2;
2081   - context.drawImage(vpath, erm_x * unit, erm_y * unit, 120 * unit, 120 * unit);
2082   - }else{
2083   - //---二维吗图---
2084   - context.drawImage(vpath, 410 * unit, 726 * unit, 115 * unit, 125 * unit);
2085   - }
2086   -
2087   - break;
2088   - case 1: //秒杀商品的展示
2089   - //---画线---
2090   - context.setLineWidth(1 * unit)
2091   - context.moveTo(32 * unit, 670 * unit)
2092   - context.lineTo(520 * unit, 670 * unit)
2093   - context.stroke();
2094   -
2095   - //画秒杀的图片
2096   - var miaos_path = '../../../images/share/miao_share.png';
2097   - context.drawImage(miaos_path, 43 * unit, 700 * unit, 222 * unit, 40 * unit);
2098   -
2099   - context.setFillStyle("black")
2100   - context.setFontSize(24 * unit)
2101   - context.fillText(th.data.sto_sele_name_1, 40 * unit, 786 * unit);
2102   - //---文字---
2103   - context.setFontSize(22 * unit)
2104   - context.setFillStyle("black")
2105   - context.fillText("特惠好物,限时秒杀", 40 * unit, 826 * unit);
2106   - context.fillText("长按识别二维码,立即开始抢购", 40 * unit, 866 * unit);
2107   -
2108   -
2109   - //---二维吗图---
2110   - //-- 自定义海报 --
2111   - if(th.data.poster){
2112   - var erm_x= parseFloat(th.data.poster.ewm_x)*2;
2113   - var erm_y= parseFloat(th.data.poster.ewm_y)*2;
2114   - context.drawImage(vpath, erm_x * unit, erm_y * unit, 120 * unit, 120 * unit);
2115   - }else{
2116   - //---二维吗图---
2117   - context.drawImage(vpath, 420 * unit, 726 * unit, 120 * unit, 120 * unit);
2118   - }
2119   - break;
2120   -
2121   - case 2: //会员团和商家团的展示
2122   - //---画线---
2123   - context.setLineWidth(1 * unit)
2124   - context.moveTo(32 * unit, 670 * unit)
2125   - context.lineTo(520 * unit, 670 * unit)
2126   - context.stroke();
2127   - //---文字---
2128   -
2129   - context.setFillStyle("black")
2130   - context.setFontSize(24 * unit)
2131   - context.fillText(th.data.sto_sele_name_1, 40 * unit, 720 * unit);
2132   -
2133   - //绘制成团图片
2134   - var ct_img = "../../../images/share/ct_num.png";
2135   - context.drawImage(ct_img, 40 * unit, 740 * unit, 120 * unit, 30 * unit);
2136   - var ct_num = th.data.prom_act.ct_num;
2137   - context.setFontSize(14 * unit)
2138   - context.font = 'normal';
2139   - context.setFillStyle("red")
2140   - if (ct_num < 10) {
2141   - context.fillText(ct_num + "人拼团", 92 * unit, 760 * unit);
2142   - } else {
2143   - context.fillText(ct_num + "人拼团", 86 * unit, 760 * unit);
2144   - }
2145   - context.setFontSize(22 * unit)
2146   - context.fillText("已拼" + th.data.prom_act.buy_num + "份", 166 * unit, 763 * unit);
2147   -
2148   - context.setFillStyle("gray")
2149   - context.fillText("快来和我一起拼团吧!", 40 * unit, 806 * unit);
2150   - context.setFillStyle("black")
2151   - context.font = 'normal bold 18px sans-serif';
2152   - context.setFontSize(21.3 * unit)
2153   - context.fillText("长按识别二维码,立即参团", 40 * unit, 836 * unit);
2154   -
2155   -
2156   - //---二维吗图---
2157   - //-- 自定义海报 --
2158   - if(th.data.poster){
2159   - var erm_x= parseFloat(th.data.poster.ewm_x)*2;
2160   - var erm_y= parseFloat(th.data.poster.ewm_y)*2;
2161   - context.drawImage(vpath, erm_x * unit, erm_y * unit, 120 * unit, 120 * unit);
2162   - }else{
2163   - //---二维吗图---
2164   - context.drawImage(vpath, 420 * unit, 726 * unit, 120 * unit, 120 * unit);
2165   - }
2166   - break
2167   - case 3: //阶梯团的展示
2168   - //---画线---
2169   - context.setLineWidth(1 * unit)
2170   - context.moveTo(32 * unit, 670 * unit)
2171   - context.lineTo(520 * unit, 670 * unit)
2172   - context.stroke();
2173   - //---文字---
2174   -
2175   - context.setFillStyle("black")
2176   - context.setFontSize(24 * unit)
2177   - context.fillText(th.data.sto_sele_name_1, 40 * unit, 720 * unit);
2178   -
2179   - //---绘制中间阶梯的价格---
2180   - var list = th.data.prom_act.ct_rylist;
2181   - for (var i = 0; i < list.length; i++) {
2182   - var item = list[i];
2183   - var wi = i * 90 * unit;
2184   - context.font = 'normal';
2185   - context.setFontSize(16 * unit)
2186   - context.setFillStyle("red")
2187   - context.fillText("¥", 40 * unit + wi, 756 * unit);
2188   - context.setFontSize(22 * unit)
2189   - var pri = parseFloat(item.price).toFixed(2);
2190   - context.fillText(pri, 56 * unit + wi, 756 * unit);
2191   - context.setFillStyle("gray")
2192   - context.fillText("满" + item.rynum + "人", 40 * unit + wi, 786 * unit);
2193   - }
2194   - //----------------下面部分----------------
2195   - // context.setFillStyle("gray")
2196   - // context.fillText("快来和我一起拼团吧!", 40 * unit, 830 * unit);
2197   - // context.setFillStyle("black")
2198   - // context.font = 'normal bold 18px sans-serif';
2199   - // context.setFontSize(22 * unit)
2200   - // context.fillText("长按识别二维码,立即参团", 40 * unit, 860 * unit);
2201   - //context.setFillStyle("gray")
2202   - context.setFillStyle("black")
2203   - context.fillText("快来和我一起拼团吧!", 40 * unit, 820 * unit);
2204   - //context.font = 'normal bold 18px sans-serif';
2205   - context.setFontSize(22 * unit)
2206   - context.fillText("长按识别二维码,立即参团", 40 * unit, 850 * unit);
2207   -
2208   -
2209   - //-- 自定义海报 --
2210   - if(th.data.poster){
2211   - var erm_x= parseFloat(th.data.poster.ewm_x)*2;
2212   - var erm_y= parseFloat(th.data.poster.ewm_y)*2;
2213   - context.drawImage(vpath, erm_x * unit, erm_y * unit, 120 * unit, 120 * unit);
2214   - }else{
2215   - //---二维吗图---
2216   - context.drawImage(vpath, 420 * unit, 726 * unit, 120 * unit, 120 * unit);
2217   - }
2218   - break
2219   -
2220   -
2221   - }
2222   -
2223   -
2224   - //--- 如果是自定义海报的时候 ---
2225   - if(th.data.poster && parseInt(th.data.poster.style)==2){
2226   -
2227   - //如果显示会员信息的话
2228   - if(parseInt(th.data.poster.show_headpic)){
2229   - //获取坐标
2230   - var x= parseFloat(th.data.poster.head_x)*2;
2231   - var y=parseFloat(th.data.poster.head_y)*2;
2232   - //---绘制圆形要放在最后----
2233   - context.save();
2234   - context.beginPath();
2235   - var h_x = x* unit;
2236   - var h_y = y * unit;
2237   - var h_r = 40 * unit;
2238   - var cx = h_x + h_r;
2239   - var cy = h_y + h_r;
2240   - context.arc(cx, cy, h_r, 0, Math.PI * 2, false);
2241   - context.closePath();
2242   - context.fill();
2243   - context.clip();
2244   - context.drawImage(th.data.share_head, h_x, h_y, h_r * 2, h_r * 2);
2245   - context.restore();
2246   - }
2247   -
2248   - }else{
2249   - //---绘制圆形要放在最后----
2250   - context.save();
2251   - context.beginPath();
2252   - var h_x = 60 * unit;
2253   - var h_y = 24 * unit;
2254   - var h_r = 40 * unit;
2255   - var cx = h_x + h_r;
2256   - var cy = h_y + h_r;
2257   - context.arc(cx, cy, h_r, 0, Math.PI * 2, false);
2258   - context.closePath();
2259   - context.fill();
2260   - context.clip();
2261   - context.drawImage(th.data.share_head, h_x, h_y, h_r * 2, h_r * 2);
2262   - context.restore();
2263   - }
2264   -
2265   -
2266   - //把画板内容绘制成图片,并回调 画板图片路径
2267   - context.draw(false, function() {
2268   - setTimeout(function() {
2269   - wx.canvasToTempFilePath({
2270   - x: 0,
2271   - y: 0,
2272   - width: 750,
2273   - height: 1217,
2274   - destWidth: 1.2 * 750 * 750 / that.data.screenWidth,
2275   - destHeight: 1.2 * 1217 * 750 / that.data.screenWidth,
2276   - canvasId: 'share',
2277   - success: function(res) {
2278   - that.setData({
2279   - shareImgPath: res.tempFilePath,
2280   - canvasHidden: true
2281   - })
2282   - if (!res.tempFilePath) {
2283   - wx.showModal({
2284   - title: '提示',
2285   - content: '图片绘制中,请稍后重试',
2286   - showCancel: false
2287   - })
2288   - return false;
2289   - }
2290   - // wx.previewImage({
2291   - // //将图片预览出来
2292   - // urls: [that.data.shareImgPath]
2293   - // });
2294   - that.setData({
2295   - showPoster: true,
2296   - });
2297   - wx.hideLoading();
2298   - }
2299   - })
2300   - }, 500)
2301   -
2302   - });
2303   - });
2304   - }
2305   - });
2306   - },
2307   -
2308 1880  
2309 1881 //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度
2310 1882 draw_Text: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, unit) {
... ... @@ -2381,45 +1953,52 @@ Page({
2381 1953 }, 500)
2382 1954 },
2383 1955  
2384   - //--获取头像的本地缓存,回调写法--
2385   - get_head_temp: function(tt, func) {
2386   - var ee = this;
2387   - if (ee.data.share_head) {
2388   - tt(func);
2389   - return false;
2390   - }
2391   - //---获取分享图片的本地地址,头像和商品图片----
2392   - var path2 = getApp().globalData.userInfo.head_pic;
2393   - if (path2 == "") {
2394   - ee.data.share_head = "../../../images/share/hui_hear_pic.png";
2395   - tt(func);
2396   - } else {
2397   - path2 = path2.replace("http://thirdwx.qlogo.cn", "https://wx.qlogo.cn");
2398   - path2 = path2.replace("https://thirdwx.qlogo.cn", "https://wx.qlogo.cn");
2399   - wx.getImageInfo({
2400   - src: path2,
2401   - success: function(res) {
2402   - //res.path是网络图片的本地地址
2403   - ee.data.share_head = res.path;
2404   - tt(func);
2405   - },
2406   - fail: function(res) {
2407   - ee.data.share_head = "../../../images/share/hui_hear_pic.png"; //分享的图片不能用网络的
2408   - tt(func);
  1956 + //--获取头像的本地缓存,回调写法--
  1957 + get_head_temp: function (tt, func) {
  1958 + var ee = this;
  1959 + if (ee.data.share_head) {
  1960 + tt(func);
  1961 + return false;
2409 1962 }
2410   - });
2411   - }
2412   - },
2413   - //--获取商品图片的本地缓存,回调写法--
  1963 + //---获取分享图片的本地地址,头像和商品图片----
  1964 + var path2 = getApp().globalData.userInfo.head_pic;
  1965 + if (path2 == "") {
  1966 + ee.data.share_head = "../../../../images/share/hui_hear_pic.png";
  1967 + tt(func);
  1968 + } else {
  1969 + path2 = path2.replace("http://thirdwx.qlogo.cn", "https://wx.qlogo.cn");
  1970 + path2 = path2.replace("https://thirdwx.qlogo.cn", "https://wx.qlogo.cn");
  1971 + wx.getImageInfo({
  1972 + src: path2,
  1973 + success: function (res) {
  1974 + //res.path是网络图片的本地地址
  1975 + ee.data.share_head = res.path;
  1976 + tt(func);
  1977 + },
  1978 + fail: function (res) {
  1979 + ee.data.share_head = "../../../../images/share/hui_hear_pic.png"; //分享的图片不能用网络的
  1980 + tt(func);
  1981 + }
  1982 + });
  1983 + }
  1984 + },
  1985 +
  1986 + //--获取商品图片的本地缓存,回调写法--
2414 1987 get_goods_temp: function(tt) {
2415 1988 var ee = this;
2416 1989 if (ee.data.share_goods_img) {
2417 1990 tt();
2418 1991 return false;
2419 1992 }
  1993 +
  1994 + var img=ee.data.iurl+ee.data.data.img_url;
  1995 + if(ee.data.prom_act){
  1996 + img=ee.data.iurl+ee.data.prom_act.share_img;
  1997 + }
  1998 +
2420 1999 //获取商品是分享图信息
2421 2000 wx.getImageInfo({
2422   - src: ee.data.data.original_img,
  2001 + src: img,
2423 2002 success: function(res) {
2424 2003 //res.path是网络图片的本地地址
2425 2004 ee.data.share_goods_img = res.path;
... ... @@ -3349,13 +2928,7 @@ Page({
3349 2928 };
3350 2929 })
3351 2930 },
3352   -
3353   -
3354   -
3355   -
3356 2931  
3357   -
3358   -
3359 2932 viewFlash(e) {
3360 2933 let prom_type = e.currentTarget.dataset.promtype;
3361 2934 let prom_id = e.currentTarget.dataset.promid;
... ... @@ -3366,9 +2939,7 @@ Page({
3366 2939 }
3367 2940 getApp().goto(url);
3368 2941 },
3369   -
3370   -
3371   -
  2942 +
3372 2943 //获取更多秒杀
3373 2944 get_more_flash: async function (func) {
3374 2945 var f_more = false;
... ... @@ -3787,8 +3358,712 @@ Page({
3787 3358 }
3788 3359 },
3789 3360  
  3361 + clickShare() {
  3362 + if (!getApp().globalData.user_id) {
  3363 + getApp().goto("/packageE/pages/togoin/togoin");
  3364 + return false;
  3365 + }
  3366 + this.setData({ share_hidden: true, });
  3367 + },
3790 3368  
3791   -
  3369 + send() {
  3370 + this.setData({ share_hidden: false, });
  3371 + },
  3372 +
  3373 + cancel() {
  3374 + this.setData({
  3375 + share_hidden: false,
  3376 + });
  3377 + },
  3378 +
  3379 + saveImageFn(){
  3380 + if(this.data.share_b_img){
  3381 + this.saveImageToPhotosAlbum()
  3382 + }else{
  3383 + this.saveImageToPhotosAlbumDef()
  3384 + }
  3385 + },
  3386 +
  3387 +
  3388 + //--定义的保存图片方法,分享团---
  3389 + saveImageToPhotosAlbum: function () {
  3390 + //--先判断会员状态--
  3391 + var user_info = getApp().globalData.userInfo;
  3392 + if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
  3393 + //getApp().my_warnning("请先登录",0,this);
  3394 + wx.navigateTo({ url: '/packageE/pages/togoin/togoin', })
  3395 + return false;
  3396 + }
  3397 +
  3398 + if (this.data.share_hidden) {
  3399 + this.setData({
  3400 + share_hidden: false,
  3401 + });
  3402 + };
  3403 +
  3404 + //类型 0普通商品 1秒杀商品 2商家和会员团 3阶梯团 4阶梯团
  3405 + var type = 8;
  3406 + wx.showLoading({
  3407 + title: '生成中...',
  3408 + })
  3409 + var that = this,
  3410 + th = that;
  3411 + //设置画板显示,才能开始绘图
  3412 + that.setData({
  3413 + canvasHidden: false
  3414 + })
  3415 +
  3416 + var app = getApp();
  3417 + var unit = that.data.screenWidth / 750 * 1.35; //基础单位,
  3418 + var path2 = that.data.data.original_img;
  3419 +
  3420 + var scene = th.data.gid + "_"+th.data.presellList.id;
  3421 + var user_id = getApp().globalData.user_id ? getApp().globalData.user_id : 0;
  3422 + if (user_id > 0) {
  3423 + scene += "_" + user_id;
  3424 + }
  3425 + //-- 如果不是会员分享过来的要分享给别人 --
  3426 + if (getApp().globalData.room_id && th.data.data.goods_id == getApp().globalData.room_goods_id && !getApp().globalData.room_user_share) {
  3427 + //固定房间是第3个字符
  3428 + if (!user_id) scene += "_0";
  3429 + scene += "_" + getApp().globalData.room_id;
  3430 + }
  3431 +
  3432 +
  3433 + ///二微码
  3434 + var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" +
  3435 + os.stoid + "?sceneValue=" + scene + "&pageValue=packageC/pages/presell/cardInfo/goodsInfo";
  3436 +
  3437 +
  3438 + console.log(path3);
  3439 +
  3440 + //读取文件成功则OK--
  3441 + wx.getImageInfo({
  3442 + src: path3,
  3443 + success: function (res) {
  3444 + //回调写法
  3445 + th.get_head_temp(th.get_goods_temp, function () {
  3446 + var vpath = res.path;
  3447 + var context = wx.createCanvasContext('share');
  3448 + //先画背景
  3449 + var pg_path = "../../../../images/share/share_bg.png";
  3450 +
  3451 + //-- 如果有自定义海报的时候,判断背景的图片 --
  3452 + if (th.data.share_b_img) {
  3453 + pg_path = th.data.share_b_img;
  3454 + }
  3455 + context.drawImage(pg_path, 0, 0, 554 * unit, 899 * unit);
  3456 +
  3457 + //-- 是自定义海报的情况下 --
  3458 + if (th.data.poster && parseInt(th.data.poster.style) == 2) {
  3459 + //在线上分享人的情况下
  3460 + if (parseInt(th.data.poster.show_headpic)) {
  3461 + //获取坐标
  3462 + var x = parseFloat(th.data.poster.head_x) * 2;
  3463 + var y = parseFloat(th.data.poster.head_y) * 2;
  3464 + var x1 = (x + 90) * unit;
  3465 + var y1 = (y + 50) * unit;
  3466 + //--昵称---
  3467 + context.setFontSize(24 * unit)
  3468 + context.setFillStyle("black")
  3469 + context.fillText(app.globalData.userInfo.nickname, x1, y1);
  3470 + var width = 24 * app.globalData.userInfo.nickname.length * unit + 4 * unit;
  3471 + //强烈推荐 改许程
  3472 + var tj_path = "../../../../images/share/q_tj.png";
  3473 + context.drawImage(tj_path, x1 + width, y1 - 22 * unit, 85 * unit, 30 * unit);
  3474 + context.setFontSize(16 * unit)
  3475 + context.setLineJoin('round'); //交点设置成圆角
  3476 + context.setFillStyle("white")
  3477 + context.fillText('强烈推荐', x1 + width + 8 * unit, y1 - 1 * unit);
  3478 +
  3479 + //context.setFillStyle("black")
  3480 + //context.setFontSize(24 * unit)
  3481 + //context.fillText(getApp().globalData.config.store_name, 40 * unit, 130 * unit);
  3482 + }
  3483 + } else {
  3484 + //--昵称---
  3485 + context.setFontSize(24 * unit)
  3486 + context.setFillStyle("black")
  3487 + context.fillText(app.globalData.userInfo.nickname, 152 * unit, 76 * unit);
  3488 + var width = 24 * app.globalData.userInfo.nickname.length * unit + 2 * unit;
  3489 + //强烈推荐 改许程
  3490 + var tj_path = "../../../../images/share/q_tj.png";
  3491 + context.drawImage(tj_path, 152 * unit + width, 54 * unit, 85 * unit, 30 * unit);
  3492 + context.setFontSize(16 * unit);
  3493 + context.setLineJoin('round'); //交点设置成圆角
  3494 + context.setFillStyle("white");
  3495 + context.fillText('强烈推荐', 149 * unit + width + 15 * unit, 75 * unit);
  3496 + }
  3497 +
  3498 + var share_title = th.data.presellForm.share_title;
  3499 + share_title=share_title ? share_title : th.data.data.goods_name;
  3500 +
  3501 + //---产品名称---
  3502 + //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度
  3503 +
  3504 + context.setFillStyle("black");
  3505 + context.setFontSize(21.3 * unit)
  3506 + th.draw_Text(context, share_title,
  3507 + 80 * unit, 160 * unit, 200 * unit, 279 * unit, unit);
  3508 +
  3509 + //------产品的价格-------
  3510 + context.setFontSize(22 * unit)
  3511 + context.setFillStyle("red")
  3512 +
  3513 +
  3514 + var pri0 = th.data.presellList.presell_money;
  3515 + // if (th.data.prom_act)
  3516 + // pri0 = th.data.prom_act.price;
  3517 + pri0 = parseFloat(pri0).toFixed(2);
  3518 + var wd1 = th.data.screenWidth - ut.measureText(pri0, 31 * unit) - 25;
  3519 + context.fillText("¥", wd1 - 15, 160 * unit);
  3520 + context.setFontSize(22 * unit)
  3521 + context.fillText(pri0, wd1, 165 * unit);
  3522 +
  3523 + //---市场价划掉---
  3524 + // context.setFillStyle("red")
  3525 + // context.setFontSize(22 * unit)
  3526 + // pri0 = "¥" + th.data.data.market_price.toFixed(2);
  3527 + // var wd2 = th.data.screenWidth - ut.measureText(pri0, 22 * unit) - 25;
  3528 +
  3529 +
  3530 + if(th.data.presellForm.presell_type==1){
  3531 + // context.setStrokeStyle('gray');
  3532 + // context.fillText(pri0, wd2, 213 * unit);
  3533 + // context.setLineWidth(1 * unit);
  3534 + // context.moveTo(wd2 - 5, 206 * unit);
  3535 + // context.lineTo(wd2 + ut.measureText(pri0, 22 * unit) + 5, 206 * unit);
  3536 + // context.stroke();
  3537 +
  3538 + //-- 零售价的优化 --
  3539 + var wp= th.data.screenWidth - ut.measureText(pri0, 22 * unit) - 50;
  3540 + var hp= 180 * unit
  3541 + th.draw_pos_price(context,wp,hp,th.data.data.market_price,unit);
  3542 +
  3543 + }else{
  3544 + var wd2 = th.data.screenWidth - ut.measureText(pri0, 22 * unit) - 50;
  3545 + context.fillText('定金', wd2, 190 * unit);
  3546 + }
  3547 +
  3548 +
  3549 + //console.log(th.data.share_goods_img);
  3550 + //let share_goods_img=th.data.presellForm.share_img;
  3551 + //share_goods_img?share_goods_img:th.data.data.share_goods_img;
  3552 + //---中间大图---
  3553 + context.drawImage(th.data.share_goods_img, 70 * unit, 210 * unit, 408 * unit, 408 * unit);
  3554 + //---自定义海报 产品质量保证
  3555 + if(th.data.poster.show_quality==1 ){
  3556 + var g_path = "/images/share/s_gou.png";
  3557 + context.drawImage(g_path, 56 * unit, 630 * unit, 22 * unit, 22 * unit);
  3558 + context.setFillStyle("red")
  3559 + context.setFontSize(18 * unit)
  3560 + context.fillText("正品保证", 84 * unit, 650 * unit);
  3561 +
  3562 + context.drawImage(g_path, 218 * unit, 630 * unit, 22 * unit, 22 * unit);
  3563 + context.setFillStyle("red")
  3564 + context.setFontSize(18 * unit)
  3565 + context.fillText("纯实体店", 246 * unit, 650 * unit);
  3566 +
  3567 + context.drawImage(g_path, 388 * unit, 630 * unit, 22 * unit, 22 * unit);
  3568 + context.setFillStyle("red")
  3569 + context.setFontSize(18 * unit)
  3570 + context.fillText("官方验证", 420 * unit, 650 * unit);
  3571 +
  3572 + }
  3573 +
  3574 + //---画线---
  3575 + // context.setLineWidth(1 * unit)
  3576 + // context.moveTo(32 * unit, 662 * unit)
  3577 + // context.lineTo(520 * unit, 662 * unit)
  3578 + // context.stroke();
  3579 +
  3580 + //---文字---
  3581 + context.setFillStyle("black")
  3582 + // context.setFontSize(22 * unit)
  3583 + context.setFontSize(24 * unit)
  3584 + context.fillText(th.data.sto_sele_name_1, 40 * unit, 700 * unit);
  3585 + context.setFillStyle("red")
  3586 + context.setFontSize(20 * unit)
  3587 + var presell_price = `预售价:${th.data.presellList.presell_price}`
  3588 + context.fillText(presell_price, 40 * unit, 750 * unit);
  3589 + context.setFillStyle("black")
  3590 + context.setFontSize(22 * unit)
  3591 + context.fillText("特惠好物,限时预售", 40 * unit, 800 * unit);
  3592 + context.fillText("长按识别二维码,立即开始抢购", 40 * unit, 840 * unit);
  3593 +
  3594 + //---二维吗图---
  3595 + //-- 自定义海报 --
  3596 + if (th.data.poster) {
  3597 + var erm_x = parseFloat(th.data.poster.ewm_x) * 2;
  3598 + var erm_y = parseFloat(th.data.poster.ewm_y) * 2;
  3599 + context.drawImage(vpath, erm_x * unit, erm_y * unit, 136 * unit, 136 * unit);
  3600 + } else {
  3601 + //---二维吗图---
  3602 + context.drawImage(vpath, 390 * unit, 746 * unit, 130 * unit, 116 * unit);
  3603 + }
  3604 +
  3605 + //--- 如果是自定义海报的时候 ---
  3606 + if (th.data.poster && parseInt(th.data.poster.style) == 2) {
  3607 +
  3608 + //如果显示会员信息的话
  3609 + if (parseInt(th.data.poster.show_headpic)) {
  3610 + //获取坐标
  3611 + var x = parseFloat(th.data.poster.head_x) * 2;
  3612 + var y = parseFloat(th.data.poster.head_y) * 2;
  3613 + //---绘制圆形要放在最后----
  3614 + context.save();
  3615 + context.beginPath();
  3616 + var h_x = x * unit;
  3617 + var h_y = y * unit;
  3618 + var h_r = 40 * unit;
  3619 + var cx = h_x + h_r;
  3620 + var cy = h_y + h_r;
  3621 + context.arc(cx, cy, h_r, 0, Math.PI * 2, false);
  3622 + context.closePath();
  3623 + context.fill();
  3624 + context.clip();
  3625 + context.drawImage(th.data.share_head, h_x, h_y, h_r * 2, h_r * 2);
  3626 + context.restore();
  3627 + }
  3628 +
  3629 + } else {
  3630 + //---绘制圆形要放在最后----
  3631 + context.save();
  3632 + context.beginPath();
  3633 + var h_x = 60 * unit;
  3634 + var h_y = 24 * unit;
  3635 + var h_r = 40 * unit;
  3636 + var cx = h_x + h_r;
  3637 + var cy = h_y + h_r;
  3638 + context.arc(cx, cy, h_r, 0, Math.PI * 2, false);
  3639 + context.closePath();
  3640 + context.fill();
  3641 + context.clip();
  3642 + context.drawImage(th.data.share_head, h_x, h_y, h_r * 2, h_r * 2);
  3643 + context.restore();
  3644 + }
  3645 +
  3646 +
  3647 + if(th.data.poster.show_time==1){
  3648 + var act_time='';
  3649 + act_time="截止时间:"+ ut.formatTime(th.data.presellForm.end_time);
  3650 + context.setFillStyle("red")
  3651 + getApp().draw_Text(context, act_time,38 * unit, 880 * unit, 200 * unit, 340 * unit, unit);
  3652 + }
  3653 +
  3654 + //把画板内容绘制成图片,并回调 画板图片路径
  3655 + context.draw(false, function () {
  3656 + setTimeout(function () {
  3657 + wx.canvasToTempFilePath({
  3658 + x: 0,
  3659 + y: 0,
  3660 + width: 750,
  3661 + height: 1217,
  3662 + destWidth: 1.2 * 750 * 750 / that.data.screenWidth,
  3663 + destHeight: 1.2 * 1217 * 750 / that.data.screenWidth,
  3664 + canvasId: 'share',
  3665 + success: function (res) {
  3666 +
  3667 + that.setData({
  3668 + shareImgPath: res.tempFilePath,
  3669 + canvasHidden: true
  3670 + })
  3671 +
  3672 + if (!res.tempFilePath) {
  3673 + wx.showModal({
  3674 + title: '提示',
  3675 + content: '图片绘制中,请稍后重试',
  3676 + showCancel: false
  3677 + })
  3678 + return false;
  3679 + }
  3680 +
  3681 + // wx.previewImage({
  3682 + // //将图片预览出来
  3683 + // urls: [that.data.shareImgPath]
  3684 + // });
  3685 + that.setData({
  3686 + showPoster: true,
  3687 + });
  3688 + wx.hideLoading();
  3689 + }
  3690 + })
  3691 + }, 500)
  3692 +
  3693 + });
  3694 + });
  3695 + },
  3696 + fail: function (res) {
  3697 + console.log(res);
  3698 + wx.hideLoading();
  3699 +
  3700 + }
  3701 + });
  3702 + },
  3703 + //--定义的保存图片方法,分享团---
  3704 + saveImageToPhotosAlbumDef: function () {
  3705 + //--先判断会员状态--
  3706 + var user_info = getApp().globalData.userInfo;
  3707 + if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
  3708 + //getApp().my_warnning("请先登录",0,this);
  3709 + wx.navigateTo({url: '/packageE/pages/togoin/togoin',})
  3710 + return false;
  3711 + }
  3712 +
  3713 + if (this.data.share_hidden) {
  3714 + this.setData({share_hidden: false,});
  3715 + };
  3716 +
  3717 + //类型 0普通商品 1秒杀商品 2商家和会员团 3阶梯团 4阶梯团
  3718 + var type = this.data.prom_type;
  3719 + console.log('商品类型-----');
  3720 + console.log(type);
  3721 + // if (type == 2) type = -1;
  3722 + if (type == 4) type = 0;
  3723 + if (type == 8) type = 0;
  3724 + if (type == 2) type = 0;
  3725 + if (type == 6) type = 2; // 6拼团 2团购
  3726 + if (type == 10) type = -1;
  3727 +
  3728 +
  3729 + if (this.data.prom_act && this.data.prom_act.kttype == 3) type = 3;
  3730 + console.log('商品类型。。。。。');
  3731 + console.log(type);
  3732 + wx.showLoading({title: '生成中...',})
  3733 + var that = this, th = that;
  3734 + //设置画板显示,才能开始绘图
  3735 + that.setData({
  3736 + canvasHidden: false
  3737 + })
  3738 +
  3739 + var app = getApp();
  3740 + var unit = that.data.screenWidth / 750 * 1.35; //基础单位,
  3741 + var path2 = that.data.data.original_img;
  3742 +
  3743 + var scene = th.data.gid + "_"+th.data.presellList.id;
  3744 + var user_id = getApp().globalData.user_id ? getApp().globalData.user_id : 0;
  3745 + if (user_id > 0) {
  3746 + scene += "_" + user_id;
  3747 + }
  3748 + //-- 如果不是会员分享过来的要分享给别人 --
  3749 + if (getApp().globalData.room_id && th.data.data.goods_id == getApp().globalData.room_goods_id && !getApp().globalData.room_user_share) {
  3750 + //固定房间是第3个字符
  3751 + if (!user_id) scene += "_0";
  3752 + scene += "_" + getApp().globalData.room_id;
  3753 + }
  3754 +
  3755 + ///二微码
  3756 + var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" +
  3757 + os.stoid + "?sceneValue=" + scene + "&pageValue=packageC/pages/presell/cardInfo/goodsInfo";
  3758 +
  3759 + console.log(path3);
  3760 +
  3761 +
  3762 + // 读取文件成功则OK--
  3763 + wx.getImageInfo({
  3764 + src: path3,
  3765 + success: function (res) {
  3766 + // 回调写法
  3767 + th.get_head_temp(th.get_goods_temp, function () {
  3768 + var vpath = res.path;
  3769 + var context = wx.createCanvasContext('share');
  3770 + // 先画背景
  3771 + var pg_path = "../../../../images/share/share_bg.png";
  3772 +
  3773 + th.drawPoster(context, unit, th.data.share_goods_img, vpath, type);
  3774 +
  3775 +
  3776 + //把画板内容绘制成图片,并回调 画板图片路径
  3777 + context.draw(false, function () {
  3778 + setTimeout(function () {
  3779 + wx.canvasToTempFilePath({
  3780 + x: 0,
  3781 + y: 0,
  3782 + width: 750,
  3783 + height: 1217,
  3784 + destWidth: 1.2 * 750 * 750 / that.data.screenWidth,
  3785 + destHeight: 1.2 * 1217 * 750 / that.data.screenWidth,
  3786 + canvasId: 'share',
  3787 + success: function (res) {
  3788 +
  3789 + that.setData({
  3790 + shareImgPath: res.tempFilePath,
  3791 + canvasHidden: true
  3792 + })
  3793 +
  3794 + if (!res.tempFilePath) {
  3795 + wx.showModal({
  3796 + title: '提示',
  3797 + content: '图片绘制中,请稍后重试',
  3798 + showCancel: false
  3799 + })
  3800 + return false;
  3801 + }
  3802 +
  3803 + that.setData({
  3804 + showPoster: true,
  3805 + });
  3806 + wx.hideLoading();
  3807 + }
  3808 + })
  3809 + }, 500)
  3810 +
  3811 + });
  3812 + });
  3813 + },
  3814 + fail: function (res) {
  3815 + console.log(res);
  3816 + wx.hideLoading();
  3817 +
  3818 + }
  3819 + });
  3820 + },
  3821 +
  3822 + //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度
  3823 + draw_Text: function (ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, unit) {
  3824 + var lineWidth = 0;
  3825 + var lastSubStrIndex = 0; //每次开始截取的字符串的索引
  3826 + var han = 0;
  3827 + for (let i = 0; i < str.length; i++) {
  3828 + if (han == 2) return;
  3829 + //lineWidth += ctx.measureText(str[i]).width;
  3830 + lineWidth += ut.measureText(str[i], 21.3 * unit);
  3831 + if (lineWidth > canvasWidth) {
  3832 + han++;
  3833 +
  3834 + if (han == 2)
  3835 + ctx.fillText(str.substring(lastSubStrIndex, i) + '...', leftWidth, initHeight); //绘制截取部分
  3836 + else
  3837 + ctx.fillText(str.substring(lastSubStrIndex, i), leftWidth, initHeight);
  3838 +
  3839 + initHeight += 22; //22为字体的高度
  3840 + lineWidth = 0;
  3841 + lastSubStrIndex = i;
  3842 + titleHeight += 20;
  3843 + }
  3844 + if (i == str.length - 1) { //绘制剩余部分
  3845 + ctx.fillText(str.substring(lastSubStrIndex, i + 1), leftWidth, initHeight);
  3846 + }
  3847 + }
  3848 + },
  3849 +
  3850 + drawPoster(context, unit, img, vpath, type) {
  3851 + // 1.灰色背景
  3852 + context.setFillStyle('#f2f1f6');
  3853 + context.rect(0, 0, 554 * unit, 899 * unit);
  3854 + context.fill();
  3855 +
  3856 + // 2.商城名称
  3857 + let shopName = this.data.sto_sele_name_1;
  3858 + context.setTextAlign('center');
  3859 + context.setFontSize(26 * unit);
  3860 + context.setFillStyle('black');
  3861 + context.fillText(shopName, 277 * unit, 60 * unit);
  3862 +
  3863 + // 3.推荐来源
  3864 + let fromText = `来自${getApp().globalData.userInfo.nickname}的推荐`;
  3865 + context.setTextAlign('center');
  3866 + context.setFontSize(22 * unit);
  3867 + context.setFillStyle('#96959a');
  3868 + context.fillText(fromText, 277 * unit, 105 * unit);
  3869 +
  3870 + // 4.海报背景
  3871 + context.setFillStyle('white');
  3872 + context.fillRect(37 * unit, 157 * unit, 480 * unit, 673 * unit);
  3873 +
  3874 + // 5.商品图片
  3875 + // 图片的x坐标
  3876 + let bg_x = 37 * unit
  3877 + // 图片的y坐标
  3878 + let bg_y = 157 * unit
  3879 + // 图片宽度
  3880 + let bg_w = 480 * unit
  3881 + // 图片高度
  3882 + let bg_h = 474 * unit
  3883 + // 图片圆角
  3884 + let bg_r = 4
  3885 + // 绘制海报背景图片圆角
  3886 + context.save()
  3887 + context.beginPath()
  3888 + context.arc(bg_x + bg_r, bg_y + bg_r, bg_r, Math.PI, Math.PI * 1.5)
  3889 + context.arc(bg_x + bg_w - bg_r, bg_y + bg_r, bg_r, Math.PI * 1.5, Math.PI * 2)
  3890 + context.arc(bg_x + bg_w, bg_y + bg_h, bg_r, 0, Math.PI * 0.5)
  3891 + context.arc(bg_x, bg_y + bg_h, 0, Math.PI * 0.5, Math.PI)
  3892 + context.clip()
  3893 + context.drawImage(img, bg_x, bg_y, bg_w, bg_h);
  3894 + context.restore();
  3895 +
  3896 + // 6.强烈推荐
  3897 + let src = '';
  3898 + context.beginPath();
  3899 + if (type == 0) { // 普通
  3900 + src = '../../../../images/share/q_tj.png';
  3901 + context.drawImage(src, 54 * unit, 648 * unit, 85 * unit, 30 * unit);
  3902 + context.setFontSize(16 * unit)
  3903 + context.setFillStyle("white")
  3904 + context.setTextAlign('left');
  3905 + context.fillText('强烈推荐', 64 * unit, 668 * unit);
  3906 + }
  3907 +
  3908 +
  3909 + // 7.商品价格
  3910 + let price = this.data.data.shop_price;
  3911 + if (this.data.card_field && this.data.data[this.data.card_field]) {
  3912 + price = this.data.data[this.data.card_field];
  3913 + }
  3914 + if (this.data.prom_act) price = this.data.prom_price;
  3915 + price = parseFloat(price).toFixed(2);
  3916 + context.setFontSize(32 * unit);
  3917 + context.setFillStyle('#DE1117');
  3918 +
  3919 + price = this.data.presellList.presell_price
  3920 + context.fillText('¥' + price, 54 * unit, 735 * unit);
  3921 +
  3922 +
  3923 + //-- 零售价的优化 --
  3924 + var wp= 62 * unit+ut.measureText('¥' + price, 32 * unit);
  3925 + var hp=735 * unit
  3926 + this.draw_pos_price(context,wp,hp,this.data.data.show_price,unit);
  3927 +
  3928 +
  3929 + // 8.商品标题
  3930 + context.setFontSize(20 * unit);
  3931 + context.setFillStyle('#898989');
  3932 + getApp().draw_Text(context, this.data.data.goods_name, 54 * unit, 800 * unit, 240 * unit, 280 * unit, unit, 1);
  3933 +
  3934 + // 9.小程序码
  3935 + context.drawImage(vpath, 375 * unit, 660 * unit, 120 * unit, 120 * unit);
  3936 + context.setFontSize(16 * unit);
  3937 + context.setFillStyle('#777');
  3938 + context.fillText('长按识别二维码', 378 * unit, 810 * unit);
  3939 +
  3940 + // 10.竖线
  3941 + context.beginPath();
  3942 + context.setFillStyle('#eee');
  3943 + context.rect(354 * unit, 670 * unit, 1 * unit, 130 * unit);
  3944 + context.fill();
  3945 + },
  3946 +
  3947 + //---市场价划掉---
  3948 + draw_pos_price(context,w,h,market_price,unit){
  3949 +
  3950 + if(!this.data.sys_switch) return false;
  3951 + if(!this.data.sys_switch.is_retail_price) return false;
  3952 +
  3953 + context.setFillStyle("gray")
  3954 + context.setFontSize(22 * unit)
  3955 + var pri0 = "¥" + market_price.toFixed(2);
  3956 + context.fillText(pri0, w, h);
  3957 +
  3958 + var c_h=h-6;
  3959 + context.setStrokeStyle('gray');
  3960 + context.setLineWidth(1 * unit);
  3961 + context.moveTo(w - 5, c_h);
  3962 + context.lineTo(w + ut.measureText(pri0, 22 * unit) + 5, c_h);
  3963 + context.stroke();
  3964 +
  3965 + },
  3966 +
  3967 +
  3968 + closePoster() {
  3969 + this.setData({
  3970 + showPoster: false,
  3971 + });
  3972 + },
  3973 +
  3974 + // 保存图片到手机
  3975 + savePic() {
  3976 + console.log('保存图片');
  3977 + var self = this;
  3978 + // 获取用户的当前设置,返回值中有小程序已经向用户请求过的权限
  3979 + this.getSetting().then((res) => {
  3980 + // 判断用户是否授权了保存到相册的权限,如果没有发起授权
  3981 + if (!res.authSetting['scope.writePhotosAlbum']) {
  3982 + this.authorize().then(() => {
  3983 + // 同意授权后保存下载文件
  3984 + this.saveImage(self.data.shareImgPath)
  3985 + .then(() => {
  3986 + self.setData({
  3987 + showPoster: false
  3988 + });
  3989 + });
  3990 + })
  3991 + } else {
  3992 + // 如果已经授权,保存下载文件
  3993 + this.saveImage(self.data.shareImgPath)
  3994 + .then(() => {
  3995 + self.setData({
  3996 + showPoster: false
  3997 + });
  3998 + });
  3999 + }
  4000 +
  4001 + })
  4002 + },
  4003 +
  4004 + // 发起首次授权请求
  4005 + authorize() {
  4006 + // isFirst 用来记录是否为首次发起授权,
  4007 + // 如果首次授权拒绝后,isFirst赋值为1
  4008 + let isFirst = wx.getStorageSync('isFirst') || 0;
  4009 + return new Promise((resolve, reject) => {
  4010 + wx.authorize({
  4011 + scope: 'scope.writePhotosAlbum',
  4012 + // 同意授权
  4013 + success: () => {
  4014 + resolve();
  4015 + },
  4016 + // 拒绝授权,这里是用户拒绝授权后的回调
  4017 + fail: res => {
  4018 + if (isFirst === 0) {
  4019 + wx.setStorageSync('isFirst', 1);
  4020 + wx.showToast({
  4021 + title: '保存失败',
  4022 + icon: 'none',
  4023 + duration: 1000
  4024 + })
  4025 + } else {
  4026 + this.showModal();
  4027 + }
  4028 + console.log('拒绝授权');
  4029 + reject();
  4030 + }
  4031 + })
  4032 + })
  4033 + },
  4034 +
  4035 +
  4036 + // 保存图片到系统相册
  4037 + saveImage(saveUrl) {
  4038 + var self = this;
  4039 + return new Promise((resolve, reject) => {
  4040 + wx.saveImageToPhotosAlbum({
  4041 + filePath: saveUrl,
  4042 + success: (res) => {
  4043 + wx.showToast({
  4044 + title: '保存成功',
  4045 + duration: 1000,
  4046 + });
  4047 + self.setData({
  4048 + showPlaybill: 'true'
  4049 + });
  4050 + resolve();
  4051 + },
  4052 + fail: () => {
  4053 + wx.showToast({
  4054 + title: '保存失败',
  4055 + duration: 1000,
  4056 + });
  4057 + }
  4058 + })
  4059 + })
  4060 + },
  4061 +
  4062 +
  4063 +
  4064 +
  4065 +
  4066 +
3792 4067  
3793 4068 });
3794 4069  
... ...
packageC/pages/presell/goodsInfo/goodsInfo.js
... ... @@ -1742,6 +1742,11 @@ Page({
1742 1742 var th = this;
1743 1743 var price = th.data.pre_arr.presell_price;
1744 1744 var img = th.data.data.original_img;
  1745 + //如果活动有设置分享图的时候
  1746 + if(this.data.presellForm.share_img){
  1747 + img = this.data.iurl+this.data.presellForm.share_img;
  1748 + }
  1749 +
1745 1750 var title = th.data.presellForm.share_title;
1746 1751 if (!title) title = th.data.prom_act.title;
1747 1752 if (th.data.prom_type == 4) title = th.data.prom_act.name;
... ... @@ -3240,7 +3245,7 @@ Page({
3240 3245 var unit = that.data.screenWidth / 750 * 1.35; //基础单位,
3241 3246 var path2 = that.data.data.original_img;
3242 3247  
3243   - var scene = th.data.gid + "_"+th.data.presellList.id;
  3248 + var scene = th.data.gid + "_"+th.data.presellList.id;
3244 3249 var user_id = getApp().globalData.user_id ? getApp().globalData.user_id : 0;
3245 3250 if (user_id > 0) {
3246 3251 scene += "_" + user_id;
... ... @@ -3349,7 +3354,7 @@ Page({
3349 3354 // pri0 = "¥" + th.data.data.market_price.toFixed(2);
3350 3355 // var wd2 = th.data.screenWidth - ut.measureText(pri0, 22 * unit) - 25;
3351 3356  
3352   -
  3357 +
3353 3358 if(th.data.presellForm.presell_type==1){
3354 3359 // context.setStrokeStyle('gray');
3355 3360 // context.fillText(pri0, wd2, 213 * unit);
... ... @@ -3367,7 +3372,7 @@ Page({
3367 3372 var wd2 = th.data.screenWidth - ut.measureText(pri0, 22 * unit) - 50;
3368 3373 context.fillText('定金', wd2, 190 * unit);
3369 3374 }
3370   -
  3375 +
3371 3376  
3372 3377 //console.log(th.data.share_goods_img);
3373 3378 //let share_goods_img=th.data.presellForm.share_img;
... ... @@ -3393,7 +3398,7 @@ Page({
3393 3398 context.fillText("官方验证", 420 * unit, 650 * unit);
3394 3399  
3395 3400 }
3396   -
  3401 +
3397 3402 //---画线---
3398 3403 // context.setLineWidth(1 * unit)
3399 3404 // context.moveTo(32 * unit, 662 * unit)
... ... @@ -3407,14 +3412,14 @@ Page({
3407 3412 context.fillText(th.data.sto_sele_name_1, 40 * unit, 700 * unit);
3408 3413 context.setFillStyle("red")
3409 3414 context.setFontSize(20 * unit)
3410   - var presell_price = `预售价:${th.data.presellList.presell_price}`
  3415 + var presell_price = `预售价:${th.data.presellList.presell_price}`
3411 3416 context.fillText(presell_price, 40 * unit, 750 * unit);
3412 3417 context.setFillStyle("black")
3413 3418 context.setFontSize(22 * unit)
3414 3419 context.fillText("特惠好物,限时预售", 40 * unit, 800 * unit);
3415 3420 context.fillText("长按识别二维码,立即开始抢购", 40 * unit, 840 * unit);
3416 3421  
3417   - //---二维吗图---
  3422 + //---二维吗图---
3418 3423 //-- 自定义海报 --
3419 3424 if (th.data.poster) {
3420 3425 var erm_x = parseFloat(th.data.poster.ewm_x) * 2;
... ... @@ -3523,7 +3528,7 @@ Page({
3523 3528 }
3524 3529 });
3525 3530 },
3526   - //--定义的保存图片方法,分享团---
  3531 + //--定义的保存图片方法,分享团---
3527 3532 saveImageToPhotosAlbumDef: function () {
3528 3533 //--先判断会员状态--
3529 3534 var user_info = getApp().globalData.userInfo;
... ... @@ -3867,6 +3872,7 @@ Page({
3867 3872 });
3868 3873 }
3869 3874 },
  3875 +
3870 3876 //--获取商品图片的本地缓存,回调写法--
3871 3877 get_goods_temp: function (tt) {
3872 3878 var ee = this;
... ... @@ -4635,6 +4641,11 @@ Page({
4635 4641 url+="&groupchat_id="+getApp().globalData.groupchat_id
4636 4642 }
4637 4643 let img = this.data.data.original_img;
  4644 + //如果活动有设置分享图的时候
  4645 + if(this.data.presellForm.share_img){
  4646 + img = this.data.iurl+this.data.presellForm.share_img;
  4647 + }
  4648 +
4638 4649 return {
4639 4650 title: this.data.data.goods_name + '-' + store_name,
4640 4651 query: 'first_leader='+user_id+url,
... ...