postage.js 6.7 KB

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