postage.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. },
  31. onShowShareDialog(){
  32. this.setData({
  33. showShareDialog:true
  34. })
  35. },
  36. onCloseShareDialog(){
  37. this.setData({
  38. showShareDialog:false
  39. })
  40. },
  41. onCheckedPayInfo(){
  42. this.setData({
  43. payInfoChecked:!this.data.payInfoChecked
  44. })
  45. },
  46. onShowPayInfoModal(){
  47. let lines = [
  48. '1、本服务为全国加油卡代充服务、故 不提供充值发票;',
  49. '2、支付成功后,需收到充值成功通知短信后,方可到 加油站圈存后加油使用;',
  50. '3、每用户(手机号、设备号、加油卡号)每月最多能充2000且至多充值15笔;',
  51. '4、不支持副卡、增票卡、过期卡、黑名单卡、挂失卡、注销卡、电子卡、车队卡等特殊卡种;',
  52. '5、中石油不支持第三方虚拟手机号段充值;',
  53. '6、充值操作以油卡卡号为准,请认真填写,如因填写卡号有误而导致充值不成功或误充值,相关后果由本人承担;',
  54. '7、短信通知号码的收集仅用于后期充值信息的发送使用,特此说明;'
  55. ]
  56. let content = lines.join("\r\n");
  57. wx.showModal({
  58. title: '充值代缴服务说明',
  59. content: content,
  60. showCancel:false,
  61. success (res) {
  62. if (res.confirm) {
  63. console.log('用户点击确定')
  64. } else if (res.cancel) {
  65. console.log('用户点击取消')
  66. }
  67. }
  68. })
  69. },
  70. // 页签切换
  71. handlerClickTabItem(e) {
  72. var dataset = e.currentTarget.dataset
  73. const { activeindex, cardtype } = dataset
  74. console.log('handlerClickTabItem activeindex=', activeindex,'cart_type=', cardtype)
  75. this.setData({currentIndex: activeindex});
  76. },
  77. //充值档位切换
  78. handlerClickRechargeGear(e) {
  79. var dataset = e.currentTarget.dataset
  80. console.log('handlerClickRechargeGear dataset:', e.currentTarget.dataset)
  81. let goods_id = dataset.currentvalue
  82. this.setData({
  83. rechargeGearActiveIndex: dataset.activeindex,
  84. goods_id: goods_id,
  85. inviter_tip: this.data.goods_inviter_tips.get(goods_id)
  86. });
  87. },
  88. //跳转到油卡管理页面
  89. handlerAddCard(e){
  90. const { cardtype } = e.currentTarget.dataset
  91. app.navigateto(`/pages/postageManage/postageManage?card_type=${cardtype}`)
  92. },
  93. onAuthenPhone()
  94. {
  95. if (!app.globalData.hasmobile) {
  96. app.navigateto('/pages/auth/auth')
  97. return;
  98. }
  99. },
  100. /**
  101. * 生命周期函数--监听页面加载
  102. */
  103. onLoad: function (options)
  104. {
  105. this.requestGoods();
  106. },
  107. requestGoods()
  108. {
  109. if(this.fGoodsRequesting) return;
  110. this.fGoodsRequesting = true
  111. let fromSource = recordSource(app, `act=index&op=card_goods`)
  112. this.setData({
  113. fromSource: app.globalData.fromSource,
  114. });
  115. getReq(app, {
  116. act: 'index',
  117. op: 'card_goods',
  118. page_type: 'oil',
  119. from: fromSource
  120. }, (res) => {
  121. wx.stopPullDownRefresh()
  122. if (res.code == 200) {
  123. if (res.datas && res.datas.goods) {
  124. const datas = res.datas
  125. let goods_inviter_tips = this.formGoodsInviterTips(res.datas.goods_inviter_tips)
  126. const { tips = '', goods = [], cards = [], member_mobile} = datas
  127. let phone = app.getValueByKey('phone', cards)
  128. let petrochina = app.getValueByKey('petrochina', cards)
  129. let sinopec = app.getValueByKey('sinopec', cards)
  130. phone = app.isNullObject(phone) ? { card_no: '', card_type: 'phone' } : phone
  131. petrochina = app.isNullObject(petrochina) ? { card_no: '', card_type: 'petrochina' } : petrochina
  132. sinopec = app.isNullObject(sinopec) ? { card_no: '', card_type: 'sinopec' } : sinopec
  133. let goods_id = datas.goods[0].goods_id
  134. let inviter_tip = goods_inviter_tips.get(goods_id)
  135. this.setData({tips, goods_inviter_tips, inviter_tip, goods, sinopec, petrochina, phone, goods_id, member_mobile});
  136. }
  137. }
  138. else {
  139. app.showToast(res.message)
  140. }
  141. this.fGoodsRequesting = false
  142. })
  143. },
  144. formGoodsInviterTips(godosInviterTips)
  145. {
  146. let ret = new Map();
  147. godosInviterTips.forEach(item => {
  148. let goods_id = item.goods_id
  149. let tip = item.tip
  150. ret.set(goods_id,tip)
  151. });
  152. return ret;
  153. },
  154. // 立即充值
  155. handlerRecharge()
  156. {
  157. if(!this.data.payInfoChecked) {
  158. wx.showToast({
  159. icon:'none',
  160. title: '请同意充值代缴服务说明'
  161. })
  162. return;
  163. }
  164. if (!app.globalData.hasmobile) {
  165. app.navigateto('/pages/auth/auth')
  166. return;
  167. }
  168. console.log('handlerRecharge:',this.data)
  169. const { goods_id } = this.data
  170. let card_type = ''
  171. let card_no = ''
  172. if (this.data.currentIndex == 0) {
  173. card_type = 'sinopec'
  174. card_no = this.data.sinopec.card_no
  175. } else {
  176. card_type = 'petrochina'
  177. card_no = this.data.petrochina.card_no
  178. }
  179. if(!card_no){
  180. app.showToast('卡号不能为空')
  181. return
  182. }
  183. buyVGoods(app,goods_id,1,{ card_no,card_type }, (res) => {
  184. console.table({card_no,card_type})
  185. console.log('res:',res)
  186. let page = getCurrentPages().pop();
  187. page.onLoad()
  188. }, (err) => {
  189. wx.showToast({
  190. icon: 'none',
  191. title: '支付未完成,订单将在10分钟后取消...',
  192. duration: 5000
  193. })
  194. let page = getCurrentPages().pop();
  195. page.onLoad()
  196. })
  197. },
  198. /**
  199. * 生命周期函数--监听页面初次渲染完成
  200. */
  201. onReady: function () {
  202. },
  203. /**
  204. * 生命周期函数--监听页面显示
  205. */
  206. onShow: function ()
  207. {
  208. const record = app.globalData.record || {}
  209. const { card_no = '', card_type = '' } = record
  210. app.setFromSource(this.data.fromSource)
  211. console.log('onShow ')
  212. if (!app.isNullObject(record) && card_no && card_type)
  213. {
  214. if (card_type === 'sinopec'){
  215. this.setData({ sinopec: { card_no: card_no, card_type:'sinopec'} })
  216. } else if(card_type === 'petrochina') {
  217. this.setData({ petrochina: { card_no: card_no, card_type: 'petrochina' }})
  218. }
  219. console.log(this.sinopec, this.petrochina)
  220. }
  221. },
  222. /**
  223. * 生命周期函数--监听页面隐藏
  224. */
  225. onHide: function () {
  226. this.setData({
  227. showShareDialog:false
  228. })
  229. },
  230. /**
  231. * 生命周期函数--监听页面卸载
  232. */
  233. onUnload: function () {
  234. },
  235. /**
  236. * 页面相关事件处理函数--监听用户下拉动作
  237. */
  238. onPullDownRefresh: function () {
  239. this.requestGoods();
  240. },
  241. /**
  242. * 页面上拉触底事件的处理函数
  243. */
  244. onReachBottom: function () {
  245. },
  246. onShareAppMessage: function () {
  247. return app.cardShareInfo();
  248. }
  249. })