123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- // pages/kabaw/detail.js
- // 引入SDK核心类
- var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js'), WxParse = require("../../wxParse/wxParse.js");
- // 实例化API核心类
- var qqmapsdk = new QQMapWX({
- key: 'YGZBZ-QSKCU-7LGVI-2WWXU-E5YEJ-2WFBA' // 必填
- });
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- is_sell:1,
- qrurl:'',
- detail:'',
- way:'',
- useqr:false,
- can_use:'',
- },
- //在Page({})中使用下列代码
- //触发表单提交事件,调用接口
- jingwei(e) {
- var _this = this;
- //调用地址解析接口
- qqmapsdk.geocoder({
- //获取表单传入地址
- address: e, //地址参数,例:固定地址,address: '北京市海淀区彩和坊路海淀西大街74号'
- success: function (res) {//成功后的回调
- console.log(res);
- var res = res.result;
- var latitude = res.location.lat;
- var longitude = res.location.lng;
- wx.getLocation({
- type: 'gcj02', //返回可以用于wx.openLocation的经纬度
- success(res) {
- const latitude = latitude
- const longitude = longitude
- wx.openLocation({
- latitude,
- longitude,
- scale: 18
- })
- }
- })
- },
- fail: function (error) {
- console.error(error);
- },
- complete: function (res) {
- console.log(res);
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.jingwei('成都市傲城')
- console.log(options)
- // var item = JSON.parse(options.id)
-
- // console.log(item)
- this.setData({
- // detail:item,
- way:options.way,
- send_id:options.send_id
- })
- var id = options.id
- if (options.way == 'use') {
- this.getdetail(id)
- } else {
- this.getbuydetail(id)
- }
- },
- getdetail: function (id) {
- var that = this
- console.log(getApp().api.everyday_coupon.user_info)
- getApp().request({
- url: getApp().api.everyday_coupon.coupondetail,
- data: {
- coupon_id: id
- },
- success: function (t) {
- console.log(t)
- var list = t.data.list
- WxParse.wxParse("detail", "html", list.desc, that)
- that.setData({
- detail: list
- })
- }
- })
- },
- getbuydetail: function (id) {
- var that = this
- console.log(getApp().api.everyday_coupon.user_info)
- getApp().request({
- url: getApp().api.everyday_coupon.buydetail,
- data: {
- coupon_id: id
- },
- success: function (t) {
- console.log(t)
- var list = t.data.list
- WxParse.wxParse("detail", "html", list.desc, that)
- that.setData({
- detail: list
- })
- }
- })
- },
- touse:function(){
- var that = this
- console.log('使用优惠券')
- },
- useit: function () {
- var that = this
- console.log('购买优惠券')
- var that = this
- console.log(getApp().api.everyday_coupon.user_info)
- getApp().request({
- url: getApp().api.everyday_coupon.usecoupon,
- data: {
- user_coupon_id: that.data.detail.user_coupon_id,
- },
- success: function (t) {
- console.log(t)
- if (t.code != 0) {
- return wx.showModal({
- title: '提示',
- content: t.msg,
- showCancel: false
- })
- }
- var url = ''
- if (t.data) {
- url = t.data.url ? t.data.url : '';
- }else{
-
- }
- that.setData({
- useqr:true,
- qrurl: url
- })
- }
- })
- },
- shuaxin:function(){
- var that = this
- wx.showModal({
- title: '提示',
- content: '确定刷新吗?',
- success:function(res){
- if(res.confirm){
- console.log('1')
- that.shua()
- } else {
- console.log('0')
- }
- }
- })
- },
- shuas: function () {
- var that = this
- console.log(getApp().api.everyday_coupon.user_info)
- getApp().request({
- url: getApp().api.everyday_coupon.shuaxin,
- data: {
- id: that.data.detail.user_coupon_id,
- },
- success: function (t) {
- console.log(t)
- if (t.code != 0) {
- return wx.showModal({
- title: '提示',
- content: t.msg,
- showCancel: false,
- success: function (res) {
- if (res.confirm) {
- var detail = that.data.detail
- that.getdetail(detail.id)
- }
- }
- })
- } else if (t.code == 0) {
- var detail = that.data.detail
- detail.user_coupon_id = t.data ? t.data.id : 0
- console.log(detail)
- that.setData({
- detail: detail
- })
- that.getdetail(detail.id)
- }
- }
- })
- },
- shua:function(){
- var that = this
- console.log(getApp().api.everyday_coupon.user_info)
- getApp().request({
- url: getApp().api.everyday_coupon.shuaxin,
- data: {
- id: that.data.detail.user_coupon_id,
- },
- success: function (t) {
- console.log(t)
- if (t.code != 0) {
- return wx.showModal({
- title: '提示',
- content: t.msg,
- showCancel: false,
- success:function(res){
- if(res.confirm){
- var detail = that.data.detail
- that.getdetail(detail.id)
- }
- }
- })
- }else if(t.code==0){
- var detail = that.data.detail
- detail.user_coupon_id = t.data ? t.data.id:0
- console.log(detail)
- that.setData({
- detail: detail
- })
- that.getdetail(detail.id)
- that.useit()
- }
- }
- })
- },
- gothere:function(){
- var that = this
- wx.getLocation({//获取当前经纬度
- type: 'wgs84', //返回可以用于wx.openLocation的经纬度,官方提示bug: iOS 6.3.30 type 参数不生效,只会返回 wgs84 类型的坐标信息
- success: function (res) {
- wx.openLocation({//使用微信内置地图查看位置。
- latitude: that.data.detail.lat,
- longitude: that.data.detail.lon,
- name: that.data.detail.shop_name,
- address: that.data.detail.address,
- })
- }
- })
- },
- close:function(){
- var num = this.data.detail.can_use
- var that = this
- if(num==1){
- wx.showModal({
- title: '提示',
- content: '是否已使用该张二维码?',
- confirmText:'已使用',
- cancelText:'未使用',
- success:function(res){
- if(res.confirm){
- that.shuas()
- that.setData({
- useqr: false
- })
- } else {
- var detail = that.data.detail
- that.getdetail(detail.id)
- that.setData({
- useqr: false
- })
- }
- }
- })
- } else {
- that.setData({
- useqr: false
- })
- }
- },
- nopay: function (id) {
- var that = this
- var that = this
- console.log(getApp().api.everyday_coupon.user_info)
- getApp().request({
- url: getApp().api.everyday_coupon.cancelpaycoupon,
- data: {
- order_no: id,
- // send_id: that.data.send_id
- },
- success: function (t) {
- console.log(t)
- }
- })
- },
- buy: function () {
- var that = this
- console.log('购买优惠券')
- var that = this
- console.log(getApp().api.everyday_coupon.user_info)
- getApp().request({
- url: getApp().api.everyday_coupon.buycoupon,
- data: {
- id: that.data.detail.id,
- send_id:that.data.send_id
- },
- success: function (t) {
- console.log(t)
- if(t.code!=0){
- return wx.showModal({
- title: '提示',
- content: t.msg,
- showCancel: false,
- success:function(res){
- if(res.confirm){
- that.nopay(t.order_no)
- }
- }
- })
- }
- var dt = t.data
- var num = t.num ? t.num:''
- if(that.data.detail.is_pay==1){
- wx.requestPayment(
- {
- 'timeStamp': dt.timeStamp,
- 'nonceStr': dt.nonceStr,
- 'package': dt.package,
- 'signType': 'MD5',
- 'paySign': dt.paySign,
- 'success': function (res) {
- console.log(res)
- // wx.redirectTo({
- // url: '/pages/kabaw/kabaw',
- // })
- wx.showModal({
- title: '提示',
- content: '购买成功,共购买' + num + '张',
- showCancel: false,
- success: function (res) {
- if (res.confirm) {
- // wx.redirectTo({
- // url: '/pages/kabaw/kabaw',
- // })
- wx.navigateBack({
- })
- }
- }
- })
- },
- 'fail': function (res) {
- console.log(res)
- that.nopay(t.order_no)
- },
- 'complete': function (res) { }
- })
- }else{
- wx.showModal({
- title: '提示',
- content: '领取成功,共领取' + num+'张',
- showCancel:false,
- success:function(res){
- if(res.confirm){
- // wx.redirectTo({
- // url: '/pages/kabaw/kabaw',
- // })
- wx.navigateBack({
- })
- }
- }
- })
- }
-
- }
- })
- },
- del: function (id) {
- var that = this
- console.log('购买优惠券')
- var that = this
- console.log(getApp().api.everyday_coupon.user_info)
- getApp().request({
- url: getApp().api.everyday_coupon.delcard,
- data: {
- user_everyday_coupon_id: that.data.detail.id,
- // send_id: that.data.send_id
- },
- success: function (t) {
- console.log(t)
-
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|