var t = require("../../../utils/util.js"), ut = t, e = require("../../../utils/common.js"), a = require("../../../utils/wxParse/wxParse.js"), s = getApp(), i = s.request, rq = i, oo = s.globalData, o = s.globalData.setting, os = o; //评价加载更多 var more = function(e) { return e && e.__esModule ? e : { default: e }; }(require("../../../utils/LoadMore.js")), n = new more.default(); var utils = require('../../../utils/util.js'); var regeneratorRuntime = require('../../../utils/runtime.js'); Page({ data: { start_stop: 2, //秒杀开始 结束 的控制(1正在进行,2即将开始) color_type: 0, //线条控制 color_type_one: 0, color_type_two: 1, gid: "", stoid: o.stoid, url: o.url, resourceUrl: o.h5_url, //公众号那边的图片文件域名 iurl: o.imghost, defaultAvatar: o.resourceUrl + "/static/images/user68.jpg", data: null, content: "", //商品详情 gallery: null, //图片滚动 is_collect: 0, collect_id: 0, cartGoodsNum: 0, specSelect: 0, optionItemId: 0, goodsInputNum: 1, openSpecModal: !1, activeCategoryId: 0, supportPageScroll: !1, address: { address: "", district: 0 }, shipping: "", shippingCost: 0, enterAddressPage: !1, categories: [{ name: "商品", id: 0 }, { name: "详情", id: 1 }, { name: "评论", id: 2 }], activeCategoryId2: 0, categories2: [{ name: "商品详情", id: 0 }, { name: "规格参数", id: 1 }], activeCategoryId3: 1, categories3: [{ name: "全部", id: 1, num: 0 }, { name: "有图", id: 5, num: 0 }, { name: "好评", id: 2, num: 0 }, { name: "中评", id: 3, num: 0 }, { name: "差评", id: 4, num: 0 }, ], select: { price: 0, stock: 0, specName: "", activity: null }, //门店相关 ismend: 0, is_sec_mend: 0, sto_sele_name: "", //选中的门店名称 sto_sele_id: "", //选中的门店id sto_sele_keyid:'', //选中的门店线下 sto_sele_distr: "", //选择的门店的配送方式 is_show_sto_cat: 1, //是否显示门店分类 only_pk: null, all_sto: null, sec_sto: null, //选择了的门店分类 pickpu_list: null, //读出的所有门店list def_pickpu_list: null, //一开始5个门店list sec_pick_index: 0, //第二级门店选择ID fir_pick_index: 0, //第一级门店选择ID all_pick_list:null,//所有的门店先记录起来 //联系电话 mobile: '', //商品的活动类型 0普通 1秒杀 2团购 3优惠 4 积分购 6拼单 timer: [], //商品的购买次数 prom_buy_num: -1, g_buy_num: null, //会员自己的购买的拼单商品的情况 //购买的订单 buy_order: null, //1加入购物车 2立即购买 openSpecModal_ind: 0, //---计时器开关---- is_timer: 1, isshow: 0, bconfig: null, //基础配置 //会员分享的头像 share_head: "", share_goods_img: "", //----------视频图片data参数--------- current: 0, //图片计数 swiperCurrent: 0, //轮播的下标 hiddenn: 0, //控制轮播计数显示 screenWidth: 0, canvasHidden: 1, //--推荐-- store_config: null, is_show_pl: 0, //是否品类 is_show_pp: 0, //是否品牌 is_show_gb: 0, //是否国别 is_closecoupon: 0, select_store: 0, //选择更多 index: 1, more_store: 0, //选择门店 sort_store: 0, //门店分类 choice_sort_store: 0, //选择分类门店 new_user: 0, //新用户 def_pick_store: null, // 默认的门店 fir_def_store:null, //客户默认的门店的 lat: null, //维度 lon: null, //经度 is_get_local_ok: 0, //获取坐标是否完成 region_name: "门店分类", //区域的名字 is_gps: 1, open_ind_store: 0, //哪里打开的门店列表的控制属性 default_store: {}, //创建添加默认门店地址的对象 comments_no_more:0, is_collect_load:0, //是不是处理 is_newsales_rules:0, //是否开启最新的门店规则,此时会新读门店,当点击选择门店时会触发读取线下库存 sales_rules:1, //默认是线上销售 wait_for_user_store:null, poster:null, //自定义海报 share_b_img:'', //自定义分享的背景 showPoster: false, hui_condition:null, sto_sele_name_1:'',//分享的门店名称 }, //------初始化加载---------- onLoad: function(t) { console.log("--服务卡项--"); console.log(t); var ee = this, that = ee, th = ee, gid = t.goods_id, first_leader=t.first_leader; //-- 自定义海报 -- getApp().request.promiseGet("/api/weshop/goods/poster/page", { data:{store_id:os.stoid, type:1, is_use:1} }).then(res=>{ if(res.data.code==0 && res.data.data && res.data.data.pageData && res.data.data.pageData[0]){ var poster_data=res.data.data.pageData[0]; var json_str=poster_data.jsonStr; if(json_str){ var json_data=JSON.parse(json_str); if(json_data.bg_img){ //-- 把图片那到本地 -- wx.getImageInfo({ src:json_data.bg_img, success: function(res) { var path= res.path; th.setData({share_b_img:path}) }, fail: function(res) {} }); } th.setData({poster:json_data}) } } }) //---获取手机地址坐标-- //--如果tg_id是空的话,分享回来-- if (gid == undefined || gid == null || gid == "") { var gid_str = decodeURIComponent(t.scene); gid_str=gid_str.split("_"); gid=gid_str[0]; if(gid_str.length>1){ first_leader=gid_str[1]; } //-- 如果有room_id的获取 -- if(gid_str.length>2 && gid_str[2]){ room_id=gid_str[2]; room_user_share=1; } } ee.setData({ gid: gid}); if(first_leader){ getApp().globalData.first_leader=first_leader; //调用接口判断是不是会员 getApp().request.promiseGet("/api/weshop/shoppingGuide/get/"+os.stoid+"/"+first_leader,{}).then(res=>{ if(res.data.code==0){ getApp().globalData.guide_id=res.data.data.id; } }) } var c_guide_id=t.c_guide_id; if(c_guide_id){ th.data.c_guide_id=c_guide_id; } getApp().getConfig(function(e) { ee.setData({sto_sele_name_1:e.store_name}) }) //----获取系统参数----- getApp().getConfig2(function(e) { var json_d = JSON.parse(e.switch_list); ee.setData({ store_config: e, sys_switch:json_d, }); th.requestCardNum(), wx.pageScrollTo && th.setData({ supportPageScroll: !0 }); },1); //获取用户设备信息,屏幕宽度 wx.getSystemInfo({ success: res => { that.setData({ screenWidth: res.screenWidth }) } }); //获取用户的默认门店 getApp().get_user_store(function(e) { if(!e) { th.data.fir_def_store={}; //赋值空对象 return false; } var ee=JSON.parse(JSON.stringify(e)); //--定时器推迟一下-- setTimeout(function () { if(th.data.data) var g_distr_type=th.data.data.distr_type; //--如果默认门店不在等级卡的默认们店以内 if(that.data.storageId!=null && that.data.storageId!="" && that.data.storageId.indexOf(ee.keyid)==-1){ ee.is_no_dis=1; } var appd=getApp().globalData; var w_time = setInterval(function() { if (that.data.is_get_local_ok == 0) return false; clearInterval(w_time); var distance = null; var e=JSON.parse(JSON.stringify(ee)); //如果有开启近距离的话,同时距离优不一样了 if (that.data.lat != null) { //如果经纬度有变化的话 if( appd.lat==that.data.lat && appd.lon==that.data.lon && e.distance>0 ){ that.data.fir_def_store=e; that.setData({ def_pick_store: e, sto_sele_name: e.pickup_name, sto_sele_id: e.pickup_id, sto_sele_distr: e.distr_type, sto_sele_keyid:e.keyid, }) }else{ //要用接口是获取距离,js的计算不准 getApp().request.promiseGet("/api/weshop/pickup/list",{ data:{store_id:os.stoid,pickup_id:e.pickup_id,lat:th.data.lat,lon: th.data.lon}, }).then(res=>{ if(res.data.code==0){ e=res.data.data.pageData[0]; if (e){ e.is_no_dis=ee.is_no_dis; appd.pk_store=e; that.data.fir_def_store=e; that.setData({ def_pick_store: e, sto_sele_name: e.pickup_name, sto_sele_id: e.pickup_id, sto_sele_distr: e.distr_type, sto_sele_keyid:e.keyid, }) } } }) } //e.distance = distance; appd.lat=that.data.lat; appd.lon=that.data.lon; }else{ if (e) { e.distance = null; that.data.fir_def_store=e; that.setData({ def_pick_store: e, sto_sele_name: e.pickup_name, sto_sele_id: e.pickup_id, sto_sele_distr: e.distr_type, sto_sele_keyid:e.keyid, }) } } }, 500) },700) }); }, //------------程序初始化入口------------- async init(gid) {}, //---展示--- onShow: function() { var that=this; this.data.is_timer = 1; var ee = this,gid = this.data.gid, i = getApp().request; this.wait_for_store_config(); i.get("/api/weshop/serviceCard/get/" + o.stoid + "/" + ee.data.gid, { failRollback: !0, success: function(t) { if (t.data.code == 0) { that.setData({ 'data.goods_name': t.data.data.serviceName, 'data.shop_price': t.data.data.money, 'data.validDays': t.data.data.validDays, 'data.serviceContent': t.data.data.serviceContent, 'data.image_url': t.data.data.imgUrl, 'data.goods_id': t.data.data.id, 'data.id': t.data.data.id, }); //-----商品详情--- if(!t.data.data.serviceContent) t.data.data.serviceContent=" "; a.wxParse("content", "html", t.data.data.serviceContent, ee, 6); e.wxParseAddFullImageUrl(ee, "content"); //获取重表 getApp().promiseGet("/api/weshop/serviceItem/list",{ data:{store_id:o.stoid,service_id:t.data.data.id} }).then(res=>{ if(res.data.code==0){ var list=res.data.data; that.setData({service_list:list}) } }) } else { wx.showModal({ title: t.data.msg, showCancel: !1, complete: function() { wx.navigateBack(); } }); }; } }); this.data.enterAddressPage && (this.data.enterAddressPage = !1); this.get_sto(); }, enterAddress: function() { this.data.enterAddressPage = !0, wx.navigateTo({ url: "/pages/user/address_list/address_list?operate=selectAddress" }); }, onUnload: function() { for(var i = 1; i < 100; i++) { clearInterval(i); } }, onHide: function() { this.data.is_timer = 0; for(var i = 1; i < 100; i++) { clearInterval(i); } }, //----------三个选项按钮----------- tabClick: function(t) { var e = t.currentTarget.id; this.setData({ activeCategoryId: e }), 1 == e ? this.tabGoodsContent() : 2 == e && this.tabComment(); }, tabClick2: function(t) { this.setData({ activeCategoryId2: t.currentTarget.id }); }, tabClick3: function(t) { var e = this; if (t.currentTarget.id != this.data.activeCategoryId3) { e.data.c_curr_p = 1; this.setData({ activeCategoryId3: t.currentTarget.id, comments: null,comments_no_more:0,get_c:0, }); this.requestComments_new(); } }, doScrollTop: function() { wx.pageScrollTo({ scrollTop: 0 }); }, tabComment: function() { this.setData({ activeCategoryId: 2,comments_no_more:0,get_c:0 }), this.data.comments || this.requestComments_new(); }, //商品详情的时候调用 tabGoodsContent: function() { var th = this, i = getApp().request; this.setData({ activeCategoryId: 1 }); }, //------------加入购物车-------------- addCart: function(t) { var th = this; var ind = t.currentTarget.dataset.openSpecModal_ind; var action= t.currentTarget.dataset.action; if(!ind) ind = t.currentTarget.dataset.openspecmodal_ind; th.setData({ open_ind_store: ind }); if(action=="buy"){ //--------------此时操作的数据------------ var newd = { id: th.data.data.id, goods_num: th.data.goodsInputNum, pick_id: th.data.sto_sele_id, keyid: th.data.sto_sele_keyid, }; newd['pick_name'] = th.data.sto_sele_name; newd['guide_id'] = getApp().globalData.guide_id; newd['guide_type']=0; th.buyNow(newd); } }, //----------立即购买----------- buyNow: function(e) { getApp().globalData.service_now=e; wx.redirectTo({ url: "/packageA/pages/cart2_ser/cart2_ser", }); }, //----------增加购买数量----------- addCartNum: function(t) { this.checkCartNum(this.data.goodsInputNum + 1); }, //----------减少购买数量----------- subCartNum: function(t) { this.checkCartNum(this.data.goodsInputNum - 1); }, //----------输入框输入购买数量----------- inputCartNum: function(t) { this.checkCartNum(Number(t.detail.value)); }, //------检查数量是不是超出限购------ checkCartNum: function(t) { if(t<=0) return false; var th = this; th.setData({goodsInputNum:t}) }, closeSpecModal: function() { this.setData({ openSpecModal: !1, openSpecModal_pt: !1 }); }, openSpecModel: function(t) { var th=this; var open_store = t.currentTarget.dataset.ind; this.setData({ store: 0, choice_sort_store: 0, sort_store: 0, open_ind_store: open_store, }) //--先判断会员状态-- var user_info = getApp().globalData.userInfo; if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) { wx.navigateTo({ url: '/pages/togoin/togoin', }) return false; } var ind = t.currentTarget.dataset.ind; this.setData({ openSpecModal: !0, openSpecModal_ind: ind, }); }, //---------点击收藏和不收藏------------ collectGoods: function() { var t = this,i = getApp().request; var user_id = s.globalData.user_id; if (user_id == '') { getApp().getUserFir(function() {}); getApp().showWarning("未登录"); return false; } else { if(t.data.is_collect_load) return false; t.data.is_collect_load=1; if (t.data.is_collect == 1) { //删除收藏 i.delete("/api/weshop/goodscollect/del/" + o.stoid + "/" + t.data.collect_id, { success: function(e) { t.data.is_collect_load=0; if (e.data.code == 0) { t.setData({ is_collect: 0, collect_id: 0, }); } } }); } else { var timestamp = Date.parse(new Date()); timestamp = timestamp / 1000; var d = { goods_id: t.data.data.goods_id, user_id: s.globalData.user_id, store_id: o.stoid, add_time: timestamp, }; //加入收藏夹就是导购的ID if(getApp().globalData.guide_id){ d.guide_id=getApp().globalData.guide_id; d.guide_type=2; } i.post("/api/weshop/goodscollect/save", { //添加收藏 data: d, success: function(e) { t.data.is_collect_load=0; if (e.data.code == 0) { t.setData({ is_collect: 1, collect_id: e.data.data.collect_id, }); } } }); } } }, //---------联系客服------------ contactService: function() { s.getConfig(function(t) { if (t.store_tel == undefined) { getApp().request.get("/api/weshop/store/get/" + os.stoid, { isShowLoading: 1, data: {}, success: function(rs) { getApp().globalData.config = rs.data.data; if (rs.data.data.store_tel == null && rs.data.data.store_tel == undefined) { getApp().my_warnning("商家未设置电话", 0, th); return false; } s.confirmBox("请联系客服:" + rs.data.data.store_tel); } }) } else { s.confirmBox("请联系客服:" + t.store_tel); } }); }, //-------获取购物车数量---------- requestCardNum: function() { var t = this; getApp().request.get("/api/weshop/cart/page", { data: { store_id: o.stoid, user_id: s.globalData.user_id, state:0, is_gift:0 }, success: function(e) { var num = 0; for (var i = 0; i < e.data.data.pageData.length; i++) { num += e.data.data.pageData[i].goods_num; } t.setData({ cartGoodsNum: num }); } }); }, //--点击分享事件--- onShareAppMessage: function(t) { var th = this; var price = th.data.data.shop_price; if (th.data.prom_act) { price = th.data.prom_act.price; } var title= th.data.data.goods_name; var img=th.data.data.original_img; if(th.data.prom_type==6){ title=th.data.prom_act.share_title; img=th.data.iurl+th.data.prom_act.share_imgurl; } var url="/pages/goods/goodsInfo/goodsInfo?goods_id=" + th.data.gid; if(getApp().globalData.user_id){ url+="&first_leader="+getApp().globalData.user_id; } //-- 如果房间分享,且不是会员分享的 -- if(getApp().globalData.room_id && th.data.data.goods_id==getApp().globalData.room_goods_id && !getApp().globalData.room_user_share ){ url+="&room_id="+getApp().globalData.room_id+"&room_user_share=1"; } var ob={ title: price + "元 " +title, path:url, imageUrl: img, }; if(th.data.prom_type==6){ title+='\n'+th.data.prom_act.share_remark; ob.title=title; ob.desc=th.data.prom_act.share_remark; } //如果是积分购的时候 if(th.data.prom_type==4){ var name = th.data.prom_act.name; //-- 积分购的 -- var pri0 = th.data.prom_act.addmoney; var integral=th.data.prom_act.integral; var text=""; if(integral){text=integral+"积分"; } if(pri0 && integral){ text+="+";} if(pri0){ text+="¥"+pri0;} ob.title= text+" "+name; } return ob; }, //-----图片失败,默认图片----- bind_bnerr: function(e) { var _errImg = e.target.dataset.errorimg; var _errObj = {}; _errObj[_errImg] = this.data.iurl + "/miniapp/images/default_g_img.gif"; this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; }, //-----图片失败,默认图片----- bind_bnerr2: function(e) { var _errImg = e.target.dataset.errorimg; var _errObj = {}; _errObj[_errImg] = this.data.iurl + "/miniapp/images/hui_hear_pic.png" this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; }, //---------拿出门店分类和门店------------ get_sto(e) { var th = this,that=this; var timer_get = setInterval(function() { if (th.data.is_get_local_ok == 0) return false; var i = getApp().request; if (!th.data.data) return false; var dd= { store_id: o.stoid, isstop: 0, pageSize: 2000 } //如果有距离的话 if (th.data.lat != null) { dd.lat = th.data.lat; dd.lon = th.data.lon; } clearInterval(timer_get); //如果会员是有默认的门店话 if(!th.data.def_pick_store && th.data.fir_def_store){ th.setData({def_pick_store:th.data.fir_def_store}); } wx.showLoading({ title:'加载中.' }); //----------获取门店---------------- getApp().request.promiseGet("/api/weshop/pickup/list", { data: dd, }).then(res => { var e = res; if (e.data.code == 0) { //--普通门店排版-- setTimeout(function(){ var sto_list=th.data.data.storageId; if(sto_list){ for (var k = 0; k < e.data.data.pageData.length; k++) { var it=e.data.data.pageData[k]; if (sto_list.indexof(it.keyid)==-1) { //删除 e.data.data.pageData.splice(k--, 1); } } } //如果有开启距离的功能,没有设置默认门店,要用最近的门店作为默认门店 if(dd.lat && (!th.data.def_pick_store || JSON.stringify(th.data.def_pick_store)=='{}') && th.data.bconfig && th.data.bconfig.is_sort_storage){ th.setData({ def_pick_store:e.data.data.pageData[0], sto_sele_name: e.data.data.pageData[0].pickup_name, sto_sele_id: e.data.data.pageData[0].pickup_id, sto_sele_distr: e.data.data.pageData[0].distr_type }); th.data.fir_def_store=e.data.data.pageData[0]; } //-- 如果有默认选择门店的时候,要把默认门店放在第一位,修改不要配送方式的判断 -- if (th.data.def_pick_store && JSON.stringify(th.data.def_pick_store)!='{}'){ for (var k = 0; k < e.data.data.pageData.length; k++) { if (e.data.data.pageData[k].pickup_id == th.data.def_pick_store.pickup_id) { e.data.data.pageData.splice(k, 1); //删除 break; } } e.data.data.pageData.splice(0, 0, th.data.def_pick_store); //添加 } th.setData({all_pick_list:e.data.data.pageData}); th.deal_pickup(e); },800) } }) }, 200) }, //------------处理门店--------------- deal_pickup(e){ var th=this; if(!th.data.data) return false wx.hideLoading(); //单总量超出5个的时候 if (e.data.data.total > 5) { getApp().request.get("/api/weshop/storagecategory/page", { data: { store_id: o.stoid, is_show: 1, pageSize: 1000, orderField:"sort", orderType:'asc', }, success: function(ee) { if (ee.data.code == 0) { if (ee.data.data && ee.data.data.pageData && ee.data.data.pageData.length > 0) { var def_arr = new Array(); var ishas = 0; //-- 开始就看5个门店 -- for (var k = 0; k < 5; k++) { if (k == e.data.data.pageData.length) break; def_arr.push(e.data.data.pageData[k]); } th.setData({ def_pickpu_list: def_arr, pickpu_list: ee.data.data.pageData }); var sto_cate = ee.data.data.pageData; var sto_arr = e.data.data.pageData; var newarr = new Array(); var qita = new Array(); //----要进行门店分组-------- for (var i = 0; i < sto_arr.length; i++) { //找一下这个门店有没有在分类数组内 var find2 = 0, find2name = "",sort=0; for (var m = 0; m < sto_cate.length; m++) { if (sto_arr[i].category_id == sto_cate[m].cat_id) { find2 = sto_cate[m].cat_id; find2name = sto_cate[m].cat_name; sort = sto_cate[m].sort; break; } } if (newarr.length > 0) { var find = 0; //如果有找到,那门店就在这个分组内,否则,分类就要排在其他 if (find2 != 0) { for (var ii = 0; ii < newarr.length; ii++) { if (sto_arr[i].category_id == newarr[ii].cat_id) { newarr[ii].s_arr.push(sto_arr[i]); find = 1; break; } } if (find == 0) { var arr0 = new Array(); arr0.push(sto_arr[i]); var item = { cat_id: find2, name: find2name, sort:sort, s_arr: arr0 }; newarr.push(item); } } else { qita.push(sto_arr[i]); } } else { //如果有找到,那门店就在这个分组内,否则,分类就要排在其他 if (find2 != 0) { var arr0 = new Array(); arr0.push(sto_arr[i]); var item = { cat_id: find2, name: find2name, sort:sort, s_arr: arr0 }; newarr.push(item); } else { qita.push(sto_arr[i]); } } } //门店分类要排序下 function compare(property){ return function(a,b){ var value1 = a[property]; var value2 = b[property]; return value1 - value2; } } if(newarr.length>0) newarr.sort(compare("sort")); //----安排其他的分类----- if (qita.length > 0) { var item = { cat_id: -1, name: "其他", s_arr: qita }; newarr.push(item); } th.setData({ is_show_sto_cat: 1, all_sto: newarr }); } else { th.setData({ is_show_sto_cat: -1, only_pk: e.data.data.pageData }); //-----如果没有默认门店,要取第一个门店作为默认店.此时没有门店分类的情况------ if (!th.data.def_pick_store) { th.setData({def_pick_store:e.data.data.pageData[0]}) } } } else { th.setData({ is_show_sto_cat: -1, only_pk: e.data.data.pageData }); //-----如果没有默认门店,要取第一个门店作为默认店.此时没有门店分类的情况------ if (!th.data.def_pick_store) { th.setData({def_pick_store:e.data.data.pageData[0]}) } } } }); } else { th.setData({ is_show_sto_cat: 0, only_pk: e.data.data.pageData }); //-----如果没有默认门店,要取第一个门店作为默认店------ if (!th.data.def_pick_store && th.data.bconfig && th.data.bconfig.is_sort_storage) { th.setData({ def_pick_store:e.data.data.pageData[0], sto_sele_name: e.data.data.pageData[0].pickup_name, sto_sele_id: e.data.data.pageData[0].pickup_id, sto_sele_distr: e.data.data.pageData[0].distr_type }) } } }, //加载更多是靠这个函数 onReachBottom: function() { if (this.data.activeCategoryId == 2){ if(!this.data.comments_no_more) this.requestComments_new(); } var goods_list = this.selectComponent("#goods_list"); //组件的id if (goods_list) goods_list.get_list(); }, //---小于10的格式化函数---- timeFormat(param) { return param < 10 ? '0' + param : param; }, //--定义的保存图片方法,分享团--- saveImageToPhotosAlbum: function() { //--先判断会员状态-- var user_info = getApp().globalData.userInfo; if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) { //getApp().my_warnning("请先登录",0,this); wx.navigateTo({ url: '/pages/togoin/togoin', }) return false; } //类型 0普通商品 1秒杀商品 2商家和会员团 3阶梯团 4阶梯团 var type = this.data.prom_type; if (type == 6) type = 2; if (this.data.prom_act && this.data.prom_act.kttype == 3) type = 3; wx.showLoading({ title: '生成中...', }) var that = this, th = that; //设置画板显示,才能开始绘图 that.setData({ canvasHidden: false }) var app = getApp(); var unit = that.data.screenWidth / 750 * 1.35; //基础单位, var path2 = that.data.data.original_img; var scene = th.data.gid+""; var user_id = getApp().globalData.user_id?getApp().globalData.user_id:0; if(user_id>0) { scene+="_"+user_id; } //-- 如果不是会员分享过来的要分享给别人 -- if(getApp().globalData.room_id && th.data.data.goods_id==getApp().globalData.room_goods_id && !getApp().globalData.room_user_share) { //固定房间是第3个字符 if(!user_id) scene+="_0"; scene+="_"+getApp().globalData.room_id ; } ///二微码 var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" + os.stoid + "?sceneValue=" + scene + "&pageValue=pages/goods/goodsInfo/goodsInfo"; console.log(path3); //读取文件成功则OK-- wx.getImageInfo({ src: path3, success: function(res) { //回调写法 th.get_head_temp(th.get_goods_temp, function() { var vpath = res.path; var context = wx.createCanvasContext('share'); //先画背景 var pg_path = "../../../images/share/share_bg.png"; // context.fillStyle="#FFFFFF"; // context.fillRect(0,0,554 * unit, 899 * unit); //-- 如果有自定义海报的时候,判断背景的图片 -- if(th.data.share_b_img){ pg_path=th.data.share_b_img; } context.drawImage(pg_path, 0, 0, 554 * unit, 899 * unit); //-- 是自定义海报的情况下 -- if(th.data.poster && parseInt(th.data.poster.style)==2) { //在线上分享人的情况下 if(parseInt(th.data.poster.show_headpic)){ //获取坐标 var x=parseFloat(th.data.poster.head_x)*2; var y=parseFloat(th.data.poster.head_y)*2; var x1=(x+90) *unit; var y1=(y+50) *unit; //--昵称--- context.setFontSize(24 * unit) context.setFillStyle("black") context.fillText(app.globalData.userInfo.nickname, x1, y1); var width = 24 * app.globalData.userInfo.nickname.length * unit + 4 * unit; //强烈推荐 改许程 var tj_path = "../../../images/share/q_tj.png"; context.drawImage(tj_path, x1 + width, y1-22*unit, 85 * unit, 30 * unit); context.setFontSize(16 * unit) context.setLineJoin('round'); //交点设置成圆角 context.setFillStyle("white") context.fillText('强烈推荐', x1 + width+8*unit, y1-1*unit); //context.setFillStyle("black") //context.setFontSize(24 * unit) //context.fillText(getApp().globalData.config.store_name, 40 * unit, 130 * unit); } } else { //--昵称--- context.setFontSize(24 * unit) context.setFillStyle("black") context.fillText(app.globalData.userInfo.nickname, 152 * unit, 76 * unit); var width = 24 * app.globalData.userInfo.nickname.length * unit + 2 * unit; //强烈推荐 改许程 var tj_path = "../../../images/share/q_tj.png"; context.drawImage(tj_path, 152 * unit + width, 54 * unit, 85 * unit, 30 * unit); context.setFontSize(16 * unit); context.setLineJoin('round'); //交点设置成圆角 context.setFillStyle("white"); context.fillText('强烈推荐', 149 * unit + width + 15 * unit, 75 * unit); } //---产品名称--- //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度 if(type!=4){ context.setFillStyle("black"); context.setFontSize(21.3 * unit) th.draw_Text(context, th.data.data.goods_name, 38 * unit, 180 * unit, 200 * unit, 279 * unit, unit); //------产品的价格------- context.setFontSize(23 * unit) context.setFillStyle("red") context.fillText("¥", 416 * unit, 185 * unit); context.setFontSize(31 * unit) var pri0 = th.data.data.shop_price; if (th.data.prom_act) pri0 = th.data.prom_act.price; pri0 = parseFloat(pri0).toFixed(2); context.fillText(pri0, 438 * unit, 185 * unit); //---市场价划掉--- context.setFillStyle("gray") context.setFontSize(22 * unit) context.fillText("¥" + th.data.data.market_price, 426 * unit, 213 * unit); context.setStrokeStyle('gray'); context.setLineWidth(1 * unit); context.moveTo(426 * unit, 206 * unit); context.lineTo(510 * unit, 206 * unit); context.stroke(); }else{ context.setFillStyle("black"); context.setFontSize(21.3 * unit) th.draw_Text(context, th.data.data.goods_name, 38 * unit, 170 * unit, 20 * unit, 300*unit, unit); //------ 产品的价格 ----- var pri0 = th.data.prom_act.addmoney; var integral=th.data.prom_act.integral; var text= ""; if(integral){text=integral+"积分"; } if(pri0 && integral){ text+="+";} if(pri0){ text+="¥"+pri0;} if(!pri0 && !integral){ text="0积分";} context.setFillStyle("red"); context.fillText(text, 38 * unit, 235 * unit); } //---中间大图--- context.drawImage(th.data.share_goods_img, 70 * unit, 250 * unit, 408 * unit, 408 * unit); //-------大图后面就不一样了----------- switch (type) { case 0: //普通商品的展示 case 4: //中间的几个字 if(th.data.poster && parseInt(th.data.poster.style)==2 ){ if(parseInt(th.data.poster.show_quality)){ var g_path = "../../../images/share/s_gou.png"; context.drawImage(g_path, 56 * unit, 670 * unit, 22 * unit, 22 * unit); context.setFillStyle("red") context.setFontSize(18 * unit) context.fillText("正品保证", 84 * unit, 690 * unit); context.drawImage(g_path, 218 * unit, 670 * unit, 22 * unit, 22 * unit); context.setFillStyle("red") context.setFontSize(18 * unit) context.fillText("纯实体店", 246 * unit, 690 * unit); context.drawImage(g_path, 388 * unit, 670 * unit, 22 * unit, 22 * unit); context.setFillStyle("red") context.setFontSize(18 * unit) context.fillText("官方验证", 420 * unit, 690 * unit); } }else{ var g_path = "../../../images/share/s_gou.png"; context.drawImage(g_path, 56 * unit, 670 * unit, 22 * unit, 22 * unit); context.setFillStyle("red") context.setFontSize(18 * unit) context.fillText("正品保证", 84 * unit, 690 * unit); context.drawImage(g_path, 218 * unit, 670 * unit, 22 * unit, 22 * unit); context.setFillStyle("red") context.setFontSize(18 * unit) context.fillText("纯实体店", 246 * unit, 690 * unit); context.drawImage(g_path, 388 * unit, 670 * unit, 22 * unit, 22 * unit); context.setFillStyle("red") context.setFontSize(18 * unit) context.fillText("官方验证", 420 * unit, 690 * unit); } //---画线--- context.setLineWidth(1 * unit) context.moveTo(32 * unit, 710 * unit) context.lineTo(520 * unit, 710 * unit) context.stroke(); //---文字--- context.setFillStyle("black") context.setFontSize(22 * unit) if(type==0){ // 原来start ---> context.setFontSize(24 * unit) context.fillText(th.data.sto_sele_name_1, 40 * unit, 766 * unit); context.setFontSize(22 * unit) context.fillText("优惠乐翻天,精彩就在你身边", 40 * unit, 806 * unit); context.fillText("长按识别二维码,立即开始抢购", 40 * unit, 846 * unit); }else{ context.setFontSize(24 * unit) context.fillText(th.data.sto_sele_name_1, 40 * unit, 766 * unit); context.setFontSize(22 * unit) context.fillText("长按识别二维码", 40 * unit, 806 * unit); context.fillText("立即开始兑换", 40 * unit, 846 * unit); } //---二维吗图--- //-- 自定义海报 -- if(th.data.poster){ var erm_x= parseFloat(th.data.poster.ewm_x)*2; var erm_y= parseFloat(th.data.poster.ewm_y)*2; context.drawImage(vpath, erm_x * unit, erm_y * unit, 120 * unit, 120 * unit); }else{ //---二维吗图--- context.drawImage(vpath, 410 * unit, 726 * unit, 115 * unit, 125 * unit); } break; case 1: //秒杀商品的展示 //---画线--- context.setLineWidth(1 * unit) context.moveTo(32 * unit, 670 * unit) context.lineTo(520 * unit, 670 * unit) context.stroke(); //画秒杀的图片 var miaos_path = '../../../images/share/miao_share.png'; context.drawImage(miaos_path, 43 * unit, 700 * unit, 222 * unit, 40 * unit); context.setFillStyle("black") context.setFontSize(24 * unit) context.fillText(th.data.sto_sele_name_1, 40 * unit, 786 * unit); //---文字--- context.setFontSize(22 * unit) context.setFillStyle("black") context.fillText("特惠好物,限时秒杀", 40 * unit, 826 * unit); context.fillText("长按识别二维码,立即开始抢购", 40 * unit, 866 * unit); //---二维吗图--- //-- 自定义海报 -- if(th.data.poster){ var erm_x= parseFloat(th.data.poster.ewm_x)*2; var erm_y= parseFloat(th.data.poster.ewm_y)*2; context.drawImage(vpath, erm_x * unit, erm_y * unit, 120 * unit, 120 * unit); }else{ //---二维吗图--- context.drawImage(vpath, 420 * unit, 726 * unit, 120 * unit, 120 * unit); } break; case 2: //会员团和商家团的展示 //---画线--- context.setLineWidth(1 * unit) context.moveTo(32 * unit, 670 * unit) context.lineTo(520 * unit, 670 * unit) context.stroke(); //---文字--- context.setFillStyle("black") context.setFontSize(24 * unit) context.fillText(th.data.sto_sele_name_1, 40 * unit, 720 * unit); //绘制成团图片 var ct_img = "../../../images/share/ct_num.png"; context.drawImage(ct_img, 40 * unit, 740 * unit, 120 * unit, 30 * unit); var ct_num = th.data.prom_act.ct_num; context.setFontSize(14 * unit) context.font = 'normal'; context.setFillStyle("red") if (ct_num < 10) { context.fillText(ct_num + "人拼团", 92 * unit, 760 * unit); } else { context.fillText(ct_num + "人拼团", 86 * unit, 760 * unit); } context.setFontSize(22 * unit) context.fillText("已拼" + th.data.prom_act.buy_num + "份", 166 * unit, 763 * unit); context.setFillStyle("gray") context.fillText("快来和我一起拼团吧!", 40 * unit, 806 * unit); context.setFillStyle("black") context.font = 'normal bold 18px sans-serif'; context.setFontSize(21.3 * unit) context.fillText("长按识别二维码,立即参团", 40 * unit, 836 * unit); //---二维吗图--- //-- 自定义海报 -- if(th.data.poster){ var erm_x= parseFloat(th.data.poster.ewm_x)*2; var erm_y= parseFloat(th.data.poster.ewm_y)*2; context.drawImage(vpath, erm_x * unit, erm_y * unit, 120 * unit, 120 * unit); }else{ //---二维吗图--- context.drawImage(vpath, 420 * unit, 726 * unit, 120 * unit, 120 * unit); } break case 3: //阶梯团的展示 //---画线--- context.setLineWidth(1 * unit) context.moveTo(32 * unit, 670 * unit) context.lineTo(520 * unit, 670 * unit) context.stroke(); //---文字--- context.setFillStyle("black") context.setFontSize(24 * unit) context.fillText(th.data.sto_sele_name_1, 40 * unit, 720 * unit); //---绘制中间阶梯的价格--- var list = th.data.prom_act.ct_rylist; for (var i = 0; i < list.length; i++) { var item = list[i]; var wi = i * 90 * unit; context.font = 'normal'; context.setFontSize(16 * unit) context.setFillStyle("red") context.fillText("¥", 40 * unit + wi, 756 * unit); context.setFontSize(22 * unit) var pri = parseFloat(item.price).toFixed(2); context.fillText(pri, 56 * unit + wi, 756 * unit); context.setFillStyle("gray") context.fillText("满" + item.rynum + "人", 40 * unit + wi, 786 * unit); } //----------------下面部分---------------- // context.setFillStyle("gray") // context.fillText("快来和我一起拼团吧!", 40 * unit, 830 * unit); // context.setFillStyle("black") // context.font = 'normal bold 18px sans-serif'; // context.setFontSize(22 * unit) // context.fillText("长按识别二维码,立即参团", 40 * unit, 860 * unit); //context.setFillStyle("gray") context.setFillStyle("black") context.fillText("快来和我一起拼团吧!", 40 * unit, 820 * unit); //context.font = 'normal bold 18px sans-serif'; context.setFontSize(22 * unit) context.fillText("长按识别二维码,立即参团", 40 * unit, 850 * unit); //-- 自定义海报 -- if(th.data.poster){ var erm_x= parseFloat(th.data.poster.ewm_x)*2; var erm_y= parseFloat(th.data.poster.ewm_y)*2; context.drawImage(vpath, erm_x * unit, erm_y * unit, 120 * unit, 120 * unit); }else{ //---二维吗图--- context.drawImage(vpath, 420 * unit, 726 * unit, 120 * unit, 120 * unit); } break } //--- 如果是自定义海报的时候 --- if(th.data.poster && parseInt(th.data.poster.style)==2){ //如果显示会员信息的话 if(parseInt(th.data.poster.show_headpic)){ //获取坐标 var x= parseFloat(th.data.poster.head_x)*2; var y=parseFloat(th.data.poster.head_y)*2; //---绘制圆形要放在最后---- context.save(); context.beginPath(); var h_x = x* unit; var h_y = y * unit; var h_r = 40 * unit; var cx = h_x + h_r; var cy = h_y + h_r; context.arc(cx, cy, h_r, 0, Math.PI * 2, false); context.closePath(); context.fill(); context.clip(); context.drawImage(th.data.share_head, h_x, h_y, h_r * 2, h_r * 2); context.restore(); } }else{ //---绘制圆形要放在最后---- context.save(); context.beginPath(); var h_x = 60 * unit; var h_y = 24 * unit; var h_r = 40 * unit; var cx = h_x + h_r; var cy = h_y + h_r; context.arc(cx, cy, h_r, 0, Math.PI * 2, false); context.closePath(); context.fill(); context.clip(); context.drawImage(th.data.share_head, h_x, h_y, h_r * 2, h_r * 2); context.restore(); } //把画板内容绘制成图片,并回调 画板图片路径 context.draw(false, function() { setTimeout(function() { wx.canvasToTempFilePath({ x: 0, y: 0, width: 750, height: 1217, destWidth: 1.2 * 750 * 750 / that.data.screenWidth, destHeight: 1.2 * 1217 * 750 / that.data.screenWidth, canvasId: 'share', success: function(res) { that.setData({ shareImgPath: res.tempFilePath, canvasHidden: true }) if (!res.tempFilePath) { wx.showModal({ title: '提示', content: '图片绘制中,请稍后重试', showCancel: false }) return false; } // wx.previewImage({ // //将图片预览出来 // urls: [that.data.shareImgPath] // }); that.setData({ showPoster: true, }); wx.hideLoading(); } }) }, 500) }); }); } }); }, //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度 draw_Text: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, unit) { var lineWidth = 0; var lastSubStrIndex = 0; //每次开始截取的字符串的索引 var han = 0; for (let i = 0; i < str.length; i++) { if (han == 2) return; //lineWidth += ctx.measureText(str[i]).width; lineWidth += ut.measureText(str[i], 21.3 * unit); if (lineWidth > canvasWidth) { han++; if (han == 2) ctx.fillText(str.substring(lastSubStrIndex, i) + '...', leftWidth, initHeight); //绘制截取部分 else ctx.fillText(str.substring(lastSubStrIndex, i), leftWidth, initHeight); initHeight += 22; //22为字体的高度 lineWidth = 0; lastSubStrIndex = i; titleHeight += 20; } if (i == str.length - 1) { //绘制剩余部分 ctx.fillText(str.substring(lastSubStrIndex, i + 1), leftWidth, initHeight); } } }, // ----视频图片---- // 图片计数器 swiperChange: function(e) { var that = this; if (e.detail.current > 0) { that.setData({ hiddenn: 1, videopicture: 1, }) } else { that.setData({ hiddenn: 0, videopicture: 0, }) } if (e.detail.source == 'touch') { that.setData({ current: e.detail.current }) } }, //--获取头像的本地缓存,回调写法-- get_head_temp: function(tt, func) { var ee = this; if (ee.data.share_head) { tt(func); return false; } //---获取分享图片的本地地址,头像和商品图片---- var path2 = getApp().globalData.userInfo.head_pic; if (path2 == "") { ee.data.share_head = "../../../images/share/hui_hear_pic.png"; tt(func); } else { path2 = path2.replace("http://thirdwx.qlogo.cn", "https://wx.qlogo.cn"); path2 = path2.replace("https://thirdwx.qlogo.cn", "https://wx.qlogo.cn"); wx.getImageInfo({ src: path2, success: function(res) { //res.path是网络图片的本地地址 ee.data.share_head = res.path; tt(func); }, fail: function(res) { ee.data.share_head = "../../../images/share/hui_hear_pic.png"; //分享的图片不能用网络的 tt(func); } }); } }, //--获取商品图片的本地缓存,回调写法-- get_goods_temp: function(tt) { var ee = this; if (ee.data.share_goods_img) { tt(); return false; } //获取商品是分享图信息 wx.getImageInfo({ src: ee.data.data.original_img, success: function(res) { //res.path是网络图片的本地地址 ee.data.share_goods_img = res.path; tt(); }, fail: function(res) { ee.data.share_goods_img = "../../../images/share/default_g_img.gif"; //分享的图片不能用网络的 tt(); } }); }, //--跳转到商品详情页面-- go_goods: function(e) { var gid = e.currentTarget.dataset.gid; var url = "/pages/goods/goodsInfo/goodsInfo?goods_id=" + gid; getApp().goto(url); }, pop_err_img: function(e) { var txt = e.currentTarget.dataset.errorimg; var ob = {}; ob[txt] = this.data.iurl + "/miniapp/images/default_g_img.gif"; this.setData(ob); }, // 选择门店 choice_store: function(ee) { var th = this; var ind=ee.currentTarget.dataset.ind; var bconfig = th.data.bconfig; if(!th.data.only_pk && !th.data.def_pickpu_list){ getApp().confirmBox("门店库存不足", null, 25000, !1); return false; } if(th.data.only_pk && !th.data.only_pk.length){ getApp().confirmBox("门店库存不足", null, 25000, !1); return false; } if(th.data.def_pickpu_list && !th.data.def_pickpu_list.length){ getApp().confirmBox("门店库存不足", null, 25000, !1); return false; } if (bconfig && bconfig.is_sort_storage) { wx.getLocation({ type: 'gcj02', success: function(res) { th.data.lat = res.latitude; th.data.lon = res.longitude; th.data.is_get_local_ok = 1; th.setData({ is_gps: 1 }); th.get_sto(th.data.is_normal); }, fail: function(res) { th.data.is_get_local_ok = 1; th.get_sto(th.data.is_normal); if (res.errCode == 2) { th.setData({is_gps: 0}); if (th.data.is_gps == 0) { getApp().confirmBox("请开启GPS定位", null, 25000, !1); } } else { th.setData({ is_gps: "3" }); } } }) }else{ th.data.is_get_local_ok = 1; th.get_sto(th.data.is_normal); } if(ind!=undefined && ind!=null ){ this.setData({ open_ind_store: ind, store: 1, openSpecModal: !1, openSpecModal_pt: !1 }) }else{ this.setData({ store: 1, openSpecModal: !1, openSpecModal_pt: !1 }) } }, //关闭选择门店 close_popup: function(e) { var th=this; this.setData({ store: 0, choice_sort_store: 0, sort_store: 0, fir_pick_index:0, sec_pick_index:0 }) var openindstore=this.data.open_ind_store; if (openindstore == 1) { th.setData({ openSpecModal: !0, openSpecModal_ind: openindstore, }); } else if (openindstore == 2) { th.setData({ openSpecModal: !0, openSpecModal_ind: openindstore, }); } else if (openindstore == 4) { //4就是拼团 th.setData({ openSpecModal_pt: 1, //打开拼团购买界面 store: 0, //关闭门店 choice_sort_store: 0, //关闭门店2级 sort_store: 0, //关闭门店2级 }); } else { th.setData({ store: 0, choice_sort_store: 0, sort_store: 0 }) } }, //选择更多门店 more_store: function() { this.setData({ sort_store: 1 }); }, sort_store: function() { }, // 返回按钮 returns: function() { this.setData({ sort_store: 0, choice_sort_store: 0 }); }, //---选择分类门店--- choice_sort_store: function(e) { var index = e.currentTarget.dataset.index; var region_name = e.currentTarget.dataset.region; var item = this.data.all_sto[index]; this.setData({ region_name: region_name, sort_store: 0, choice_sort_store: 1, sec_sto: item, sec_pick_index: 0 }); }, choose_for_store_fir: function(e) { var index_c = e.currentTarget.dataset.ind; var th=this; th.setData({ fir_pick_index: index_c }) }, //确定def_pick为选择的门店 sure_pick: function(e) { var th = this; var item = null; var openindstore = th.data.open_ind_store; if (th.data.choice_sort_store == 0) { var index = th.data.fir_pick_index; if (th.data.is_show_sto_cat == 1) { item = th.data.def_pickpu_list[index]; } else { item = th.data.only_pk[index]; //当没有门店分类的时候 } } else { var index = th.data.sec_pick_index; item = th.data.sec_sto.s_arr[index]; } //判断门店的配送方式是不是匹配 if(th.data.storageId!=null && th.data.storageId!="" && th.data.storageId.indexOf(item.keyid)==-1){ wx.showToast({ title: "门店配送方式不匹配", icon: 'none', duration: 2000 }); return false; } th.setData({ def_pick_store: item, sto_sele_name: item.pickup_name, sto_sele_id: item.pickup_id, sto_sele_keyid: item.keyid, sto_sele_distr: item.distr_type, store: 0, choice_sort_store: 0, fir_pick_index: 0 }); if (openindstore == 1) { th.setData({ openSpecModal: !0, openSpecModal_ind: openindstore, }); } else if (openindstore == 2) { th.setData({ openSpecModal: !0, openSpecModal_ind: openindstore, }); } else if(openindstore == 4) { //4就是拼团 th.setData({ openSpecModal_pt: 1, //打开拼团购买界面 store: 0, //关闭门店 choice_sort_store: 0, //关闭门店2级 sort_store: 0, //关闭门店2级 }); } else { th.setData({ store: 0, choice_sort_store: 0, sort_store: 0 }) } }, //---点击二级之后的选择--- choose_for_store: function(e) { var index_c = e.currentTarget.dataset.ind; var th=this; th.setData({ sec_pick_index: index_c, fir_pick_index: index_c }) }, //把选择的门店设置成默认的门店def_pick set_def_pick: function(e) { var th = this; var item = null; if (th.data.choice_sort_store == 0) { var index = th.data.fir_pick_index; if (th.data.is_show_sto_cat == 1) { item = th.data.def_pickpu_list[index]; } else { item = th.data.only_pk[index]; //当没有门店分类的时候 } } else { var index = th.data.sec_pick_index; item = th.data.sec_sto.s_arr[index]; } //判断门店的配送方式是不是匹配 var g_distr_type = th.data.sele_g.distr_type; if(item.distr_type!=0 && g_distr_type!=0 && item.distr_type!=g_distr_type){ wx.showToast({ title: "门店配送方式不匹配", icon: 'none', duration: 2000 }); return false; } var store_id = o.stoid; var user_id = getApp().globalData.user_id; var def_pickup_id = item.pickup_id; getApp().request.put('/api/weshop/users/update', { data: { user_id:user_id, def_pickup_id:def_pickup_id }, success: function(res) { if (res.data.code == 0) { if (th.data.choice_sort_store == 0) th.setData({ fir_pick_index: 0 }); getApp().globalData.pk_store = item; } else { //s.showWarning("设置默认门店地址失败", null, 500, !1); getApp().my_warnning("设置默认门店地址失败",0,th) } } }); th.setData({ def_pick_store: item, sto_sele_name: item.pickup_name, sto_sele_id: item.pickup_id, sto_sele_keyid: item.keyid, sto_sele_distr: item.distr_type, store: 0, choice_sort_store: 0 }); var openindstore = th.data.open_ind_store; if (openindstore == 1) { th.setData({ openSpecModal: !0, openSpecModal_ind: openindstore, store: 0, choice_sort_store: 0, sort_store: 0, }); } else if (openindstore == 2) { th.setData({ openSpecModal: !0, openSpecModal_ind: openindstore, store: 0, choice_sort_store: 0, sort_store: 0, }); } else if (openindstore == 4) { //4就是拼团 th.setData({ openSpecModal_pt: 1, //打开拼团购买界面 store: 0, //关闭门店 choice_sort_store: 0, //关闭门店2级 sort_store: 0, //关闭门店2级 }); } else { th.setData({ store: 0, choice_sort_store: 0, sort_store: 0, }) } }, wait_for_store_config: function() { var th = this; var t_time = setInterval(function() { if (th.data.bconfig == null) false; var e = th.data.bconfig; if (e && e.is_sort_storage) { wx.getLocation({ type: 'gcj02', success: function(res) { th.data.lat = res.latitude; th.data.lon = res.longitude; th.data.is_get_local_ok = 1; }, fail: function(res) { if (res.errCode == 2) { th.setData({ is_gps: 0 }); if (th.data.is_gps == 0) { getApp().confirmBox("请开启GPS定位", null, 10000, !1); } } else { th.setData({ is_gps: "3" }); } th.data.is_get_local_ok = 1; } }) } else { th.data.is_get_local_ok = 1; } clearInterval(t_time); }, 500) }, //-- 根据ID拿出门店 -- get_pick_from_list(pid){ var all_pick_list=this.data.all_pick_list; for(var i in all_pick_list){ var item=all_pick_list[i]; if(item.pickup_id==pid){ return item;} } }, closePoster() { this.setData({ showPoster: false, }); }, // 保存图片到手机 savePic() { console.log('保存图片'); var self = this; // 获取用户的当前设置,返回值中有小程序已经向用户请求过的权限 this.getSetting().then((res) => { // 判断用户是否授权了保存到相册的权限,如果没有发起授权 if (!res.authSetting['scope.writePhotosAlbum']) { this.authorize().then(() => { // 同意授权后保存下载文件 this.saveImage(self.data.shareImgPath) .then(() => { self.setData({ showPoster: false }); }); }) } else { // 如果已经授权,保存下载文件 this.saveImage(self.data.shareImgPath) .then(() => { self.setData({ showPoster: false }); }); } }) }, // 获取用户已经授予了哪些权限 getSetting() { return new Promise((resolve, reject) => { wx.getSetting({ success: res => { resolve(res) } }) }) }, // 发起首次授权请求 authorize() { // isFirst 用来记录是否为首次发起授权, // 如果首次授权拒绝后,isFirst赋值为1 let isFirst = wx.getStorageSync('isFirst') || 0; return new Promise((resolve, reject) => { wx.authorize({ scope: 'scope.writePhotosAlbum', // 同意授权 success: () => { resolve(); }, // 拒绝授权,这里是用户拒绝授权后的回调 fail: res => { if(isFirst === 0) { wx.setStorageSync('isFirst', 1); wx.showToast({ title: '保存失败', icon: 'none', duration: 1000 }) } else { this.showModal(); } console.log('拒绝授权'); reject(); } }) }) }, // 保存图片到系统相册 saveImage(saveUrl) { var self = this; return new Promise((resolve, reject) => { wx.saveImageToPhotosAlbum({ filePath: saveUrl, success: (res) => { wx.showToast({ title: '保存成功', duration: 1000, }); self.setData({ showPlaybill: 'true' }); resolve(); }, fail: () => { wx.showToast({ title: '保存失败', duration: 1000, }); } }) }) }, previewImage() { wx.previewImage({ //将图片预览出来 urls: [this.data.shareImgPath] }); }, onShareTimeline() { return { title:this.data.data.goods_name + '-' + getApp().globalData.config.store_name, imageUrl:this.data.gallery[0].image_url, } }, });