postage.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. tabsData: [
  23. { id: 0, icon: '/image/postage/sinopec.png', title: '中国石化', tips: '选择油卡', card_type: 'sinopec', card_no: '' },
  24. { id: 1, icon: '/image/postage/petrochina.png', title: '中国石油', tips: '选择油卡', card_type: 'petrochina', card_no: '' }
  25. ],
  26. fromSource: '',
  27. payInfoChecked:true
  28. },
  29. onCheckedPayInfo(){
  30. this.setData({
  31. payInfoChecked:!this.data.payInfoChecked
  32. })
  33. },
  34. onShowPayInfoModal(){
  35. wx.showModal({
  36. title: '充值代缴服务说明',
  37. content: '充值代缴服务说明',
  38. showCancel:false,
  39. success (res) {
  40. if (res.confirm) {
  41. console.log('用户点击确定')
  42. } else if (res.cancel) {
  43. console.log('用户点击取消')
  44. }
  45. }
  46. })
  47. },
  48. // 页签切换
  49. handlerClickTabItem(e) {
  50. var dataset = e.currentTarget.dataset
  51. const { activeindex, cardtype } = dataset
  52. console.log('handlerClickTabItem activeindex=', activeindex,'cart_type=', cardtype)
  53. this.setData({currentIndex: activeindex});
  54. },
  55. //充值档位切换
  56. handlerClickRechargeGear(e) {
  57. var dataset = e.currentTarget.dataset
  58. console.log('handlerClickRechargeGear dataset:', e.currentTarget.dataset)
  59. let goods_id = dataset.currentvalue
  60. this.setData({
  61. rechargeGearActiveIndex: dataset.activeindex,
  62. goods_id: goods_id,
  63. inviter_tip: this.data.goods_inviter_tips.get(goods_id)
  64. });
  65. },
  66. //跳转到油卡管理页面
  67. handlerAddCard(e){
  68. const { cardtype } = e.currentTarget.dataset
  69. app.navigateto(`/pages/postageManage/postageManage?card_type=${cardtype}`)
  70. },
  71. /**
  72. * 生命周期函数--监听页面加载
  73. */
  74. onLoad: function (options)
  75. {
  76. this.requestGoods();
  77. },
  78. requestGoods()
  79. {
  80. if(this.fGoodsRequesting) return;
  81. this.fGoodsRequesting = true
  82. let fromSource = recordSource(app, `act=index&op=card_goods`)
  83. this.setData({
  84. fromSource: app.globalData.fromSource,
  85. });
  86. getReq(app, {
  87. act: 'index',
  88. op: 'card_goods',
  89. page_type: 'oil',
  90. from: fromSource
  91. }, (res) => {
  92. wx.stopPullDownRefresh()
  93. if (res.code == 200) {
  94. if (res.datas && res.datas.goods) {
  95. const datas = res.datas
  96. let goods_inviter_tips = this.formGoodsInviterTips(res.datas.goods_inviter_tips)
  97. const { tips = '', goods = [], cards = [], } = datas
  98. let phone = app.getValueByKey('phone', cards)
  99. let petrochina = app.getValueByKey('petrochina', cards)
  100. let sinopec = app.getValueByKey('sinopec', cards)
  101. phone = app.isNullObject(phone) ? { card_no: '', card_type: 'phone' } : phone
  102. petrochina = app.isNullObject(petrochina) ? { card_no: '', card_type: 'petrochina' } : petrochina
  103. sinopec = app.isNullObject(sinopec) ? { card_no: '', card_type: 'sinopec' } : sinopec
  104. let goods_id = datas.goods[0].goods_id
  105. let inviter_tip = goods_inviter_tips.get(goods_id)
  106. this.setData({ tips, goods_inviter_tips, inviter_tip, goods, sinopec, petrochina, phone, goods_id });
  107. }
  108. }
  109. else {
  110. app.showToast(res.message)
  111. }
  112. this.fGoodsRequesting = false
  113. })
  114. },
  115. formGoodsInviterTips(godosInviterTips)
  116. {
  117. let ret = new Map();
  118. godosInviterTips.forEach(item => {
  119. let goods_id = item.goods_id
  120. let tip = item.tip
  121. ret.set(goods_id,tip)
  122. });
  123. return ret;
  124. },
  125. // 立即充值
  126. handlerRecharge()
  127. {
  128. if(!this.data.payInfoChecked) {
  129. wx.showToast({
  130. icon:'none',
  131. title: '请同意充值代缴服务说明'
  132. })
  133. return;
  134. }
  135. if (!app.globalData.hasmobile) {
  136. app.navigateto('/pages/auth/auth')
  137. return;
  138. }
  139. console.log('handlerRecharge:',this.data)
  140. const { goods_id } = this.data
  141. let card_type = ''
  142. let card_no = ''
  143. if (this.data.currentIndex == 0) {
  144. card_type = 'sinopec'
  145. card_no = this.data.sinopec.card_no
  146. } else {
  147. card_type = 'petrochina'
  148. card_no = this.data.petrochina.card_no
  149. }
  150. if(!card_no){
  151. app.showToast('卡号不能为空')
  152. return
  153. }
  154. buyVGoods(app,goods_id,1,{ card_no,card_type }, (res) => {
  155. console.table({card_no,card_type})
  156. console.log('res:',res)
  157. let page = getCurrentPages().pop();
  158. page.onLoad()
  159. }, (err) => {
  160. wx.showToast({
  161. icon: 'none',
  162. title: '支付未完成,订单将在10分钟后取消...',
  163. duration: 5000
  164. })
  165. let page = getCurrentPages().pop();
  166. page.onLoad()
  167. })
  168. },
  169. /**
  170. * 生命周期函数--监听页面初次渲染完成
  171. */
  172. onReady: function () {
  173. },
  174. /**
  175. * 生命周期函数--监听页面显示
  176. */
  177. onShow: function ()
  178. {
  179. const record = app.globalData.record || {}
  180. const { card_no = '', card_type = '' } = record
  181. app.setFromSource(this.data.fromSource)
  182. console.log('onShow ')
  183. if (!app.isNullObject(record) && card_no && card_type)
  184. {
  185. if (card_type === 'sinopec'){
  186. this.setData({ sinopec: { card_no: card_no, card_type:'sinopec'} })
  187. } else if(card_type === 'petrochina') {
  188. this.setData({ petrochina: { card_no: card_no, card_type: 'petrochina' }})
  189. }
  190. console.log(this.sinopec, this.petrochina)
  191. }
  192. },
  193. /**
  194. * 生命周期函数--监听页面隐藏
  195. */
  196. onHide: function () {
  197. },
  198. /**
  199. * 生命周期函数--监听页面卸载
  200. */
  201. onUnload: function () {
  202. },
  203. /**
  204. * 页面相关事件处理函数--监听用户下拉动作
  205. */
  206. onPullDownRefresh: function () {
  207. this.requestGoods();
  208. },
  209. /**
  210. * 页面上拉触底事件的处理函数
  211. */
  212. onReachBottom: function () {
  213. },
  214. onShareAppMessage: function () {
  215. return app.cardShareInfo();
  216. }
  217. })