detail.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. // pages/kabaw/detail.js
  2. // 引入SDK核心类
  3. var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js'), WxParse = require("../../wxParse/wxParse.js");
  4. // 实例化API核心类
  5. var qqmapsdk = new QQMapWX({
  6. key: 'YGZBZ-QSKCU-7LGVI-2WWXU-E5YEJ-2WFBA' // 必填
  7. });
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. is_sell:1,
  14. qrurl:'',
  15. detail:'',
  16. way:'',
  17. useqr:false,
  18. can_use:'',
  19. },
  20. //在Page({})中使用下列代码
  21. //触发表单提交事件,调用接口
  22. jingwei(e) {
  23. var _this = this;
  24. //调用地址解析接口
  25. qqmapsdk.geocoder({
  26. //获取表单传入地址
  27. address: e, //地址参数,例:固定地址,address: '北京市海淀区彩和坊路海淀西大街74号'
  28. success: function (res) {//成功后的回调
  29. console.log(res);
  30. var res = res.result;
  31. var latitude = res.location.lat;
  32. var longitude = res.location.lng;
  33. wx.getLocation({
  34. type: 'gcj02', //返回可以用于wx.openLocation的经纬度
  35. success(res) {
  36. const latitude = latitude
  37. const longitude = longitude
  38. wx.openLocation({
  39. latitude,
  40. longitude,
  41. scale: 18
  42. })
  43. }
  44. })
  45. },
  46. fail: function (error) {
  47. console.error(error);
  48. },
  49. complete: function (res) {
  50. console.log(res);
  51. }
  52. })
  53. },
  54. /**
  55. * 生命周期函数--监听页面加载
  56. */
  57. onLoad: function (options) {
  58. this.jingwei('成都市傲城')
  59. console.log(options)
  60. // var item = JSON.parse(options.id)
  61. // console.log(item)
  62. this.setData({
  63. // detail:item,
  64. way:options.way,
  65. send_id:options.send_id
  66. })
  67. var id = options.id
  68. if (options.way == 'use') {
  69. this.getdetail(id)
  70. } else {
  71. this.getbuydetail(id)
  72. }
  73. },
  74. getdetail: function (id) {
  75. var that = this
  76. console.log(getApp().api.everyday_coupon.user_info)
  77. getApp().request({
  78. url: getApp().api.everyday_coupon.coupondetail,
  79. data: {
  80. coupon_id: id
  81. },
  82. success: function (t) {
  83. console.log(t)
  84. var list = t.data.list
  85. WxParse.wxParse("detail", "html", list.desc, that)
  86. that.setData({
  87. detail: list
  88. })
  89. }
  90. })
  91. },
  92. getbuydetail: function (id) {
  93. var that = this
  94. console.log(getApp().api.everyday_coupon.user_info)
  95. getApp().request({
  96. url: getApp().api.everyday_coupon.buydetail,
  97. data: {
  98. coupon_id: id
  99. },
  100. success: function (t) {
  101. console.log(t)
  102. var list = t.data.list
  103. WxParse.wxParse("detail", "html", list.desc, that)
  104. that.setData({
  105. detail: list
  106. })
  107. }
  108. })
  109. },
  110. touse:function(){
  111. var that = this
  112. console.log('使用优惠券')
  113. },
  114. useit: function () {
  115. var that = this
  116. console.log('购买优惠券')
  117. var that = this
  118. console.log(getApp().api.everyday_coupon.user_info)
  119. getApp().request({
  120. url: getApp().api.everyday_coupon.usecoupon,
  121. data: {
  122. user_coupon_id: that.data.detail.user_coupon_id,
  123. },
  124. success: function (t) {
  125. console.log(t)
  126. if (t.code != 0) {
  127. return wx.showModal({
  128. title: '提示',
  129. content: t.msg,
  130. showCancel: false
  131. })
  132. }
  133. var url = ''
  134. if (t.data) {
  135. url = t.data.url ? t.data.url : '';
  136. }else{
  137. }
  138. that.setData({
  139. useqr:true,
  140. qrurl: url
  141. })
  142. }
  143. })
  144. },
  145. shuaxin:function(){
  146. var that = this
  147. wx.showModal({
  148. title: '提示',
  149. content: '确定刷新吗?',
  150. success:function(res){
  151. if(res.confirm){
  152. console.log('1')
  153. that.shua()
  154. } else {
  155. console.log('0')
  156. }
  157. }
  158. })
  159. },
  160. shuas: function () {
  161. var that = this
  162. console.log(getApp().api.everyday_coupon.user_info)
  163. getApp().request({
  164. url: getApp().api.everyday_coupon.shuaxin,
  165. data: {
  166. id: that.data.detail.user_coupon_id,
  167. },
  168. success: function (t) {
  169. console.log(t)
  170. if (t.code != 0) {
  171. return wx.showModal({
  172. title: '提示',
  173. content: t.msg,
  174. showCancel: false,
  175. success: function (res) {
  176. if (res.confirm) {
  177. var detail = that.data.detail
  178. that.getdetail(detail.id)
  179. }
  180. }
  181. })
  182. } else if (t.code == 0) {
  183. var detail = that.data.detail
  184. detail.user_coupon_id = t.data ? t.data.id : 0
  185. console.log(detail)
  186. that.setData({
  187. detail: detail
  188. })
  189. that.getdetail(detail.id)
  190. }
  191. }
  192. })
  193. },
  194. shua:function(){
  195. var that = this
  196. console.log(getApp().api.everyday_coupon.user_info)
  197. getApp().request({
  198. url: getApp().api.everyday_coupon.shuaxin,
  199. data: {
  200. id: that.data.detail.user_coupon_id,
  201. },
  202. success: function (t) {
  203. console.log(t)
  204. if (t.code != 0) {
  205. return wx.showModal({
  206. title: '提示',
  207. content: t.msg,
  208. showCancel: false,
  209. success:function(res){
  210. if(res.confirm){
  211. var detail = that.data.detail
  212. that.getdetail(detail.id)
  213. }
  214. }
  215. })
  216. }else if(t.code==0){
  217. var detail = that.data.detail
  218. detail.user_coupon_id = t.data ? t.data.id:0
  219. console.log(detail)
  220. that.setData({
  221. detail: detail
  222. })
  223. that.getdetail(detail.id)
  224. that.useit()
  225. }
  226. }
  227. })
  228. },
  229. gothere:function(){
  230. var that = this
  231. wx.getLocation({//获取当前经纬度
  232. type: 'wgs84', //返回可以用于wx.openLocation的经纬度,官方提示bug: iOS 6.3.30 type 参数不生效,只会返回 wgs84 类型的坐标信息
  233. success: function (res) {
  234. wx.openLocation({//​使用微信内置地图查看位置。
  235. latitude: that.data.detail.lat,
  236. longitude: that.data.detail.lon,
  237. name: that.data.detail.shop_name,
  238. address: that.data.detail.address,
  239. })
  240. }
  241. })
  242. },
  243. close:function(){
  244. var num = this.data.detail.can_use
  245. var that = this
  246. if(num==1){
  247. wx.showModal({
  248. title: '提示',
  249. content: '是否已使用该张二维码?',
  250. confirmText:'已使用',
  251. cancelText:'未使用',
  252. success:function(res){
  253. if(res.confirm){
  254. that.shuas()
  255. that.setData({
  256. useqr: false
  257. })
  258. } else {
  259. var detail = that.data.detail
  260. that.getdetail(detail.id)
  261. that.setData({
  262. useqr: false
  263. })
  264. }
  265. }
  266. })
  267. } else {
  268. that.setData({
  269. useqr: false
  270. })
  271. }
  272. },
  273. nopay: function (id) {
  274. var that = this
  275. var that = this
  276. console.log(getApp().api.everyday_coupon.user_info)
  277. getApp().request({
  278. url: getApp().api.everyday_coupon.cancelpaycoupon,
  279. data: {
  280. order_no: id,
  281. // send_id: that.data.send_id
  282. },
  283. success: function (t) {
  284. console.log(t)
  285. }
  286. })
  287. },
  288. buy: function () {
  289. var that = this
  290. console.log('购买优惠券')
  291. var that = this
  292. console.log(getApp().api.everyday_coupon.user_info)
  293. getApp().request({
  294. url: getApp().api.everyday_coupon.buycoupon,
  295. data: {
  296. id: that.data.detail.id,
  297. send_id:that.data.send_id
  298. },
  299. success: function (t) {
  300. console.log(t)
  301. if(t.code!=0){
  302. return wx.showModal({
  303. title: '提示',
  304. content: t.msg,
  305. showCancel: false,
  306. success:function(res){
  307. if(res.confirm){
  308. that.nopay(t.order_no)
  309. }
  310. }
  311. })
  312. }
  313. var dt = t.data
  314. var num = t.num ? t.num:''
  315. if(that.data.detail.is_pay==1){
  316. wx.requestPayment(
  317. {
  318. 'timeStamp': dt.timeStamp,
  319. 'nonceStr': dt.nonceStr,
  320. 'package': dt.package,
  321. 'signType': 'MD5',
  322. 'paySign': dt.paySign,
  323. 'success': function (res) {
  324. console.log(res)
  325. // wx.redirectTo({
  326. // url: '/pages/kabaw/kabaw',
  327. // })
  328. wx.showModal({
  329. title: '提示',
  330. content: '购买成功,共购买' + num + '张',
  331. showCancel: false,
  332. success: function (res) {
  333. if (res.confirm) {
  334. // wx.redirectTo({
  335. // url: '/pages/kabaw/kabaw',
  336. // })
  337. wx.navigateBack({
  338. })
  339. }
  340. }
  341. })
  342. },
  343. 'fail': function (res) {
  344. console.log(res)
  345. that.nopay(t.order_no)
  346. },
  347. 'complete': function (res) { }
  348. })
  349. }else{
  350. wx.showModal({
  351. title: '提示',
  352. content: '领取成功,共领取' + num+'张',
  353. showCancel:false,
  354. success:function(res){
  355. if(res.confirm){
  356. // wx.redirectTo({
  357. // url: '/pages/kabaw/kabaw',
  358. // })
  359. wx.navigateBack({
  360. })
  361. }
  362. }
  363. })
  364. }
  365. }
  366. })
  367. },
  368. del: function (id) {
  369. var that = this
  370. console.log('购买优惠券')
  371. var that = this
  372. console.log(getApp().api.everyday_coupon.user_info)
  373. getApp().request({
  374. url: getApp().api.everyday_coupon.delcard,
  375. data: {
  376. user_everyday_coupon_id: that.data.detail.id,
  377. // send_id: that.data.send_id
  378. },
  379. success: function (t) {
  380. console.log(t)
  381. }
  382. })
  383. },
  384. /**
  385. * 生命周期函数--监听页面初次渲染完成
  386. */
  387. onReady: function () {
  388. },
  389. /**
  390. * 生命周期函数--监听页面显示
  391. */
  392. onShow: function () {
  393. },
  394. /**
  395. * 生命周期函数--监听页面隐藏
  396. */
  397. onHide: function () {
  398. },
  399. /**
  400. * 生命周期函数--监听页面卸载
  401. */
  402. onUnload: function () {
  403. },
  404. /**
  405. * 页面相关事件处理函数--监听用户下拉动作
  406. */
  407. onPullDownRefresh: function () {
  408. },
  409. /**
  410. * 页面上拉触底事件的处理函数
  411. */
  412. onReachBottom: function () {
  413. },
  414. /**
  415. * 用户点击右上角分享
  416. */
  417. onShareAppMessage: function () {
  418. }
  419. })