postage.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. import recordSource from '../../utils/recordSource';
  2. const config = require('../../config.js')
  3. const getReq = config.getReq
  4. const buyVGoods = config.buyVGoods
  5. let app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. fGoodsRequesting:false,
  12. currentIndex: 0, //页签索引
  13. rechargeGearActiveIndex: 0, //挡位项目索引
  14. tips:'', //顶部tips
  15. inviter_tip:'',
  16. goods_inviter_tips: new Map(),
  17. goods:[], //挡位数据
  18. goods_id:'', //当前选中挡位的goods_id
  19. sinopec: { card_no: '', card_type: 'sinopec' },
  20. petrochina: { card_no: '', card_type: 'petrochina' },
  21. phone: { card_no: '', card_type: 'phone' },
  22. member_mobile:'',
  23. tabsData: [
  24. { id: 0, icon: '/image/postage/sinopec.png', title: '中国石化', tips: '选择油卡', card_type: 'sinopec', card_no: '' },
  25. { id: 1, icon: '/image/postage/petrochina.png', title: '中国石油', tips: '选择油卡', card_type: 'petrochina', card_no: '' }
  26. ],
  27. fromSource: '',
  28. payInfoChecked:true,
  29. showShareDialog:false,
  30. shareGoodsId:0,
  31. showtermsOfServiceDialog:false,
  32. special_id:0 //订单成功,弹出的专题页面
  33. },
  34. onShowShareDialog(){
  35. var goods_id = this.data.goods_id
  36. this.setData({
  37. showShareDialog:true,
  38. shareGoodsId: goods_id,
  39. })
  40. },
  41. onCloseShareDialog(){
  42. this.setData({
  43. showShareDialog:false
  44. })
  45. },
  46. onCheckedPayInfo(){
  47. this.setData({
  48. payInfoChecked:!this.data.payInfoChecked
  49. })
  50. },
  51. onShowPayInfoModal(){
  52. this.setData({
  53. showtermsOfServiceDialog:true
  54. })
  55. },
  56. onShowtermsOfServiceDialog(){
  57. this.setData({
  58. showtermsOfServiceDialog:false
  59. })
  60. },
  61. // 页签切换
  62. handlerClickTabItem(e) {
  63. var dataset = e.currentTarget.dataset
  64. const { activeindex, cardtype } = dataset
  65. console.log('handlerClickTabItem activeindex=', activeindex,'cart_type=', cardtype)
  66. this.setData({currentIndex: activeindex});
  67. },
  68. //充值档位切换
  69. handlerClickRechargeGear(e) {
  70. var dataset = e.currentTarget.dataset
  71. console.log('handlerClickRechargeGear dataset:', e.currentTarget.dataset)
  72. let goods_id = dataset.currentvalue
  73. this.setData({
  74. rechargeGearActiveIndex: dataset.activeindex,
  75. goods_id: goods_id,
  76. inviter_tip: this.data.goods_inviter_tips.get(goods_id)
  77. });
  78. },
  79. //跳转到油卡管理页面
  80. handlerAddCard(e){
  81. const { cardtype } = e.currentTarget.dataset
  82. app.navigateto(`/pages/postageManage/postageManage?card_type=${cardtype}`)
  83. },
  84. onAuthenPhone()
  85. {
  86. if (!app.globalData.hasmobile) {
  87. app.navigateto('/pages/auth/auth')
  88. return;
  89. }
  90. },
  91. /**
  92. * 生命周期函数--监听页面加载
  93. */
  94. onLoad: function (options)
  95. {
  96. this.requestGoods();
  97. },
  98. requestGoods()
  99. {
  100. if(this.fGoodsRequesting) return;
  101. this.fGoodsRequesting = true
  102. let fromSource = recordSource(app, `act=index&op=card_goods`)
  103. this.setData({
  104. fromSource: app.globalData.fromSource,
  105. });
  106. getReq(app, {
  107. act: 'index',
  108. op: 'card_goods',
  109. page_type: 'oil',
  110. from: fromSource
  111. }, (res) => {
  112. wx.stopPullDownRefresh()
  113. if (res.code == 200) {
  114. if (res.datas && res.datas.goods) {
  115. const datas = res.datas
  116. let goods_inviter_tips = this.formGoodsInviterTips(res.datas.goods_inviter_tips)
  117. const { tips = '', goods = [], cards = [], member_mobile,special_id} = datas
  118. let phone = app.getValueByKey('phone', cards)
  119. let petrochina = app.getValueByKey('petrochina', cards)
  120. let sinopec = app.getValueByKey('sinopec', cards)
  121. phone = app.isNullObject(phone) ? { card_no: '', card_type: 'phone' } : phone
  122. petrochina = app.isNullObject(petrochina) ? { card_no: '', card_type: 'petrochina' } : petrochina
  123. sinopec = app.isNullObject(sinopec) ? { card_no: '', card_type: 'sinopec' } : sinopec
  124. let goods_id = datas.goods[0].goods_id
  125. let inviter_tip = goods_inviter_tips.get(goods_id)
  126. this.setData({ tips, goods_inviter_tips, inviter_tip, goods, sinopec, petrochina, phone, goods_id, member_mobile, special_id});
  127. }
  128. }
  129. else {
  130. app.showToast(res.message)
  131. }
  132. this.fGoodsRequesting = false
  133. })
  134. },
  135. formGoodsInviterTips(godosInviterTips)
  136. {
  137. let ret = new Map();
  138. godosInviterTips.forEach(item => {
  139. let goods_id = item.goods_id
  140. let tip = item.tip
  141. ret.set(goods_id,tip)
  142. });
  143. return ret;
  144. },
  145. // 立即充值
  146. handlerRecharge()
  147. {
  148. if(!this.data.payInfoChecked) {
  149. wx.showToast({
  150. icon:'none',
  151. title: '请同意充值代缴服务说明'
  152. })
  153. return;
  154. }
  155. if (!app.globalData.hasmobile) {
  156. app.navigateto('/pages/auth/auth')
  157. return;
  158. }
  159. console.log('handlerRecharge:',this.data)
  160. const { goods_id } = this.data
  161. let card_type = ''
  162. let card_no = ''
  163. if (this.data.currentIndex == 0) {
  164. card_type = 'sinopec'
  165. card_no = this.data.sinopec.card_no
  166. } else {
  167. card_type = 'petrochina'
  168. card_no = this.data.petrochina.card_no
  169. }
  170. if(!card_no){
  171. app.showToast('卡号不能为空')
  172. return
  173. }
  174. buyVGoods(app,goods_id,1,{ card_no,card_type }, (res) => {
  175. let special_id = this.data.special_id
  176. let title = '支付成功'
  177. app.navigateto(`/pages/special/special?special_id=${special_id}&title=${title}`)
  178. }, (err) => {
  179. wx.showToast({
  180. icon: 'none',
  181. title: '支付未完成,订单将在10分钟后取消...',
  182. duration: 5000
  183. })
  184. let page = getCurrentPages().pop();
  185. page.onLoad()
  186. })
  187. },
  188. /**
  189. * 生命周期函数--监听页面初次渲染完成
  190. */
  191. onReady: function () {
  192. },
  193. /**
  194. * 生命周期函数--监听页面显示
  195. */
  196. onShow: function ()
  197. {
  198. const record = app.globalData.record || {}
  199. const { card_no = '', card_type = '' } = record
  200. app.setFromSource(this.data.fromSource)
  201. console.log('onShow ')
  202. if (!app.isNullObject(record) && card_no && card_type)
  203. {
  204. if (card_type === 'sinopec'){
  205. this.setData({ sinopec: { card_no: card_no, card_type:'sinopec'} })
  206. } else if(card_type === 'petrochina') {
  207. this.setData({ petrochina: { card_no: card_no, card_type: 'petrochina' }})
  208. }
  209. console.log(this.sinopec, this.petrochina)
  210. }
  211. },
  212. /**
  213. * 生命周期函数--监听页面隐藏
  214. */
  215. onHide: function () {
  216. if(this.data.onShowShareDialog) {
  217. this.setData({
  218. showShareDialog:true,
  219. // shareGoodsId:0,
  220. showtermsOfServiceDialog:false,
  221. onShowShareDialog:false
  222. })
  223. }
  224. else {
  225. this.setData({
  226. onShowShareDialog:false,
  227. showShareDialog:false,
  228. shareGoodsId:0,
  229. showtermsOfServiceDialog:false
  230. })
  231. }
  232. },
  233. onShareInfo: function () {
  234. console.log('onShareInfo')
  235. wx.getShareInfo({
  236. success: function (res) {
  237. console.log(res)
  238. }
  239. })
  240. },
  241. /**
  242. * 生命周期函数--监听页面卸载
  243. */
  244. onUnload: function () {
  245. },
  246. /**
  247. * 页面相关事件处理函数--监听用户下拉动作
  248. */
  249. onPullDownRefresh: function () {
  250. this.requestGoods();
  251. },
  252. /**
  253. * 页面上拉触底事件的处理函数
  254. */
  255. onReachBottom: function () {
  256. },
  257. onShareAppMessage: function () {
  258. this.setData({
  259. onShowShareDialog:true
  260. });
  261. return app.cardShareInfo();
  262. }
  263. })