Sanakey
2022-10-28 0e185fa6db8e3f4209e63c079750a26fe3feddaa
提交 | 用户 | age
d98d05 1 // pages/information/information.js
S 2 var utils = require("../../utils/util.js");
3 // var WxParse = require('../../src/wxParse/wxParse.js');
4 var app = getApp();
5 var doccode = '';
6 // var has
7
8 Page({
9
10   /**
11    * 页面的初始数据
12    */
13   data: {
14     latitude: '',
15     longitude: '',
16     name: '',
17     isShowMap: false,
18     // markers: [{
19     //   id: 1,
20     //   latitude: 23.099994,
21     //   longitude: 113.324520,
22     //   name: 'T.I.T 创意园',
23     //   iconPath:'/imgs/location.png',
24     //   callout:{
25     //     content: '123',
26     //   },
27     //   label:{
28     //     content:'456',
29     //     bgColor: '#fff',
30     //     padding: 5,
31     //     borderRadius: 5
32     //   }
33     // }],
34   },
35   // 图片点击
36   ItemTap: function (event) {
37
53cc6f 38     // var pathurl = event.currentTarget.dataset.pathurl;
f2daa4 39     var pathurl = event.currentTarget.dataset.pathurl || event.currentTarget.dataset.url;
d98d05 40     var istab = event.currentTarget.dataset.istab;
S 41     // var url = event.target.dataset.url || '';
42     if (pathurl.indexOf('http') >= 0) {
43       wx.navigateTo({
44         url: "../webView/webView?externalUrl=" + encodeURIComponent(pathurl)
45       });
46     } else if (pathurl !== '' && !istab) {
47       wx.navigateTo({
48         url: '/' + pathurl
49       });
50     } else if (pathurl !== '' && istab) {
51       wx.switchTab({
52         url: '/' + pathurl
53       });
54     }
55
56     console.log('图片点击链接为', pathurl);
57   },
58   /**
59    * 生命周期函数--监听页面加载
60    */
61   onLoad: async function (options) {
62     console.log('opt', options);
63     // console.log(Number(options.Longitude));
64     // console.log(Number(options.Latitude));
65     var name = options.name;
66     doccode = options.infordoc || '';
67     this.setData({
68       isRedirectTo: app.globalData.isRedirectTo,
69       infordoc: options.infordoc || '',
70       isShowMap: options.isShowMap || '',
71       longitude: Number(options.Longitude) || '',
72       latitude: Number(options.Latitude) || '',
73       name: options.Address || '',
74     });
75
76     if (options.Longitude && options.Latitude) {
77       let markers = [{
78         id: 1,
79         latitude: Number(options.Latitude),
80         longitude: Number(options.Longitude),
81         name: options.Address,
82         iconPath: '/imgs/location.png',
83         label: {
84           content: '点击图标在微信地图中查看',
85           bgColor: '#48c23d',
86           color: '#fff',
87           padding: 5,
88           borderRadius: 5
89         }
90       },
91         {
92           id: 1,
93           latitude: Number(options.Latitude),
94           longitude: Number(options.Longitude),
95           name: options.Address,
96           iconPath: '/imgs/location.png',
97           label: {
98             content: '点击图标在微信地图中查看',
99             bgColor: '#48c23d',
100             color: '#fff',
101             padding: 5,
102             borderRadius: 5
103           }
104         }];
105
106       this.setData({
107         markers
108       });
109     }
110
111
112     var infordoc = options.infordoc || '';
113     wx.showLoading({
114       title: '',
115     });
116     wx.request({
117       url: utils.getUrl('/shopping/information.do?m=get&OutFormat=json&infordoc=' + infordoc),
118       header: {
119         "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
120       },
121       method: "GET",
122       success: res => {
123         wx.hideLoading();
124         if(!utils.requestError(res)){
125           return false;
126         }
127         this.setData({
128           listItem: res.data.list || '',
129           description:res.data.description  || '',
130           bannerImages: res.data.bannerImages || '',
131           title: res.data.title,
132           isShowBannerOnDetailPage: res.data.isShowBannerOnDetailPage,
133           bottomList:res.data.bottomList
134         });
135         wx.setNavigationBarTitle({
136           title: name || this.data.title || app.globalData.titleName
137         });
138
139       
140         this.setData({
141           goodsItemImg: (res.data.bannerImages[0]?res.data.bannerImages[0]:(res.data.list[0]&&res.data.list[0].imgUrl))||'',
142           goodsItemName:res.data.title
143         })
144         // WxParse.wxParse('article', 'html', res.data.description, this, 5);
145       },
146       fail: function (errmsg) {
147         utils.requestFail(errmsg, '/shopping/getMatCodeList.do');
148       }
149
150     });
151
152     let [errMsg,qrRes] = await this.getPosterQrCode({
153       QrCodeType:60,
154       infordoc: options.infordoc
155     });
156     if (errMsg) {
157       return;
158     }
159     this.setData({
160       qrRes
161     })
162
163   },
164
165   async getPosterQrCode(params){
166     if (Object.prototype.toString.call(params)!=='[object Object]') {
167       throw 'params 应该为对象'
168     }
169     // QrCodeType : 10 商城首页 , 20 我的名片,30 商品明细,40 直播间,50 优惠劵,60 关于我们
170     // roomid , matcode , infordoc 根据需要传值
171     let data = {
172       QrCodeType:20
173     };
174     Object.assign(data,params);
175     let [errMsg,res] = await utils.to(
176       wx.$http.request({
177         url:'/shopping/poster/getQrCodeForPoster.do',
178         data
179       })
180     )
181     return [errMsg,res];
182     
183   },
184
185   // 返回首页
186   backIndex() {
187     wx.switchTab({
188       url: '../index/index',
189       success: function (res) {
190       },
191       fail: function (res) {
192       },
193       complete: function (res) {
194       },
195     });
196   },
197
198   goToHere(e) {
199     console.log(e)
200     wx.openLocation({ // 打开微信内置地图,实现导航功能(在内置地图里面打开地图软件)
201       latitude: this.data.latitude,
202       longitude: this.data.longitude,
203       name: this.data.name,
204       success: function (res) {
205         console.log(res);
206       },
207       fail: function (res) {
208         console.log(res);
209       }
210     });
211   },
212   /*查看图片*/
213   viewImg: function(e) {
214     var src = e.currentTarget.dataset.src;
215     // console.log(src)
216     wx.previewImage({
217       current: src, // 当前显示图片的http链接
218       urls: this.data.bannerImages // 需要预览的图片http链接列表
219     })
220   },
221
222   swiperImgload(e){
223     var imgWidth=e.detail.width;   //图片的原始宽度
224     var imgHeight = e.detail.height; //图片的原始高度
225     var sysInfo = wx.getSystemInfoSync();//同步获取设备宽度
226     var screenWidth=sysInfo.screenWidth; //获取屏幕的宽度
227     var scale = screenWidth / imgWidth;   //获取屏幕和原图的比例
228     this.setData({
229       swiperHeight:imgHeight*scale
230     })
231   },
232
233   /**
234    * 生命周期函数--监听页面初次渲染完成
235    */
236   onReady: function () {
237     // this.mapCtx = wx.createMapContext('myMap');
238     // this.mapCtx.moveToLocation()
239   },
240
241   /**
242    * 生命周期函数--监听页面显示
243    */
244   onShow: function () {
245     // 发送行为信息
246     if (app.globalData.FromUserId) {
247       utils.userBehavior('ViewInformation', {doccode:doccode});
248     }
249   },
250
251   /**
252    * 生命周期函数--监听页面隐藏
253    */
254   onHide: function () {
255
256   },
257
258   /**
259    * 生命周期函数--监听页面卸载
260    */
261   onUnload: function () {
262     // isRedirectTo值还原
263     app.globalData.isRedirectTo = false;
264   },
265
266   /**
267    * 页面相关事件处理函数--监听用户下拉动作
268    */
269   onPullDownRefresh: function () {
270
271   },
272
273   /**
274    * 页面上拉触底事件的处理函数
275    */
276   onReachBottom: function () {
277
278   },
279
280   /**
281    * 用户点击右上角分享
282    */
283   onShareAppMessage: function () {
284     // if (ops.from === 'button') {
285     //   // 来自页面内转发按钮
286     //   console.log(ops.target)
287     // }
288     return {
289       // title: app.globalData.titleName,
290       title: utils.getShareTitle(),
291       path: 'pages/information/information?FromUserId=' + app.globalData.FromUserId + '&FromOpenId=' + app.globalData.openID + '&OpenFrom=fromShare&infordoc=' + this.data.infordoc,
292       success: function (res) {
293         // 转发成功
294         console.log("转发成功:" + JSON.stringify(res));
295         // 发送行为信息
296         // utils.userBehavior('ForwardMyCard');
297         // utils.showModal(res)
298       },
299       fail: function (res) {
300         // 转发失败
301         console.log("转发失败:" + JSON.stringify(res));
302       }
303     };
304   }
305 });