postage.js 7.0 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. shareGoodsId:0,
  31. showtermsOfServiceDialog:false
  32. },
  33. onShowShareDialog(){
  34. var goods_id = this.data.goods_id
  35. this.setData({
  36. showShareDialog:true,
  37. shareGoodsId: goods_id,
  38. })
  39. },
  40. onCloseShareDialog(){
  41. this.setData({
  42. showShareDialog:false
  43. })
  44. },
  45. onCheckedPayInfo(){
  46. this.setData({
  47. payInfoChecked:!this.data.payInfoChecked
  48. })
  49. },
  50. onShowPayInfoModal(){
  51. this.setData({
  52. showtermsOfServiceDialog:true
  53. })
  54. },
  55. onShowtermsOfServiceDialog(){
  56. this.setData({
  57. showtermsOfServiceDialog:false
  58. })
  59. },
  60. // 页签切换
  61. handlerClickTabItem(e) {
  62. var dataset = e.currentTarget.dataset
  63. const { activeindex, cardtype } = dataset
  64. console.log('handlerClickTabItem activeindex=', activeindex,'cart_type=', cardtype)
  65. this.setData({currentIndex: activeindex});
  66. },
  67. //充值档位切换
  68. handlerClickRechargeGear(e) {
  69. var dataset = e.currentTarget.dataset
  70. console.log('handlerClickRechargeGear dataset:', e.currentTarget.dataset)
  71. let goods_id = dataset.currentvalue
  72. this.setData({
  73. rechargeGearActiveIndex: dataset.activeindex,
  74. goods_id: goods_id,
  75. inviter_tip: this.data.goods_inviter_tips.get(goods_id)
  76. });
  77. },
  78. //跳转到油卡管理页面
  79. handlerAddCard(e){
  80. const { cardtype } = e.currentTarget.dataset
  81. app.navigateto(`/pages/postageManage/postageManage?card_type=${cardtype}`)
  82. },
  83. onAuthenPhone()
  84. {
  85. if (!app.globalData.hasmobile) {
  86. app.navigateto('/pages/auth/auth')
  87. return;
  88. }
  89. },
  90. /**
  91. * 生命周期函数--监听页面加载
  92. */
  93. onLoad: function (options)
  94. {
  95. this.requestGoods();
  96. },
  97. requestGoods()
  98. {
  99. if(this.fGoodsRequesting) return;
  100. this.fGoodsRequesting = true
  101. let fromSource = recordSource(app, `act=index&op=card_goods`)
  102. this.setData({
  103. fromSource: app.globalData.fromSource,
  104. });
  105. getReq(app, {
  106. act: 'index',
  107. op: 'card_goods',
  108. page_type: 'oil',
  109. from: fromSource
  110. }, (res) => {
  111. wx.stopPullDownRefresh()
  112. if (res.code == 200) {
  113. if (res.datas && res.datas.goods) {
  114. const datas = res.datas
  115. let goods_inviter_tips = this.formGoodsInviterTips(res.datas.goods_inviter_tips)
  116. const { tips = '', goods = [], cards = [], member_mobile} = datas
  117. let phone = app.getValueByKey('phone', cards)
  118. let petrochina = app.getValueByKey('petrochina', cards)
  119. let sinopec = app.getValueByKey('sinopec', cards)
  120. phone = app.isNullObject(phone) ? { card_no: '', card_type: 'phone' } : phone
  121. petrochina = app.isNullObject(petrochina) ? { card_no: '', card_type: 'petrochina' } : petrochina
  122. sinopec = app.isNullObject(sinopec) ? { card_no: '', card_type: 'sinopec' } : sinopec
  123. let goods_id = datas.goods[0].goods_id
  124. let inviter_tip = goods_inviter_tips.get(goods_id)
  125. this.setData({tips, goods_inviter_tips, inviter_tip, goods, sinopec, petrochina, phone, goods_id, member_mobile});
  126. }
  127. }
  128. else {
  129. app.showToast(res.message)
  130. }
  131. this.fGoodsRequesting = false
  132. })
  133. },
  134. formGoodsInviterTips(godosInviterTips)
  135. {
  136. let ret = new Map();
  137. godosInviterTips.forEach(item => {
  138. let goods_id = item.goods_id
  139. let tip = item.tip
  140. ret.set(goods_id,tip)
  141. });
  142. return ret;
  143. },
  144. // 立即充值
  145. handlerRecharge()
  146. {
  147. if(!this.data.payInfoChecked) {
  148. wx.showToast({
  149. icon:'none',
  150. title: '请同意充值代缴服务说明'
  151. })
  152. return;
  153. }
  154. if (!app.globalData.hasmobile) {
  155. app.navigateto('/pages/auth/auth')
  156. return;
  157. }
  158. console.log('handlerRecharge:',this.data)
  159. const { goods_id } = this.data
  160. let card_type = ''
  161. let card_no = ''
  162. if (this.data.currentIndex == 0) {
  163. card_type = 'sinopec'
  164. card_no = this.data.sinopec.card_no
  165. } else {
  166. card_type = 'petrochina'
  167. card_no = this.data.petrochina.card_no
  168. }
  169. if(!card_no){
  170. app.showToast('卡号不能为空')
  171. return
  172. }
  173. buyVGoods(app,goods_id,1,{ card_no,card_type }, (res) => {
  174. console.table({card_no,card_type})
  175. console.log('res:',res)
  176. let page = getCurrentPages().pop();
  177. page.onLoad()
  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. this.setData({
  217. showShareDialog:false,
  218. shareGoodsId:0,
  219. showtermsOfServiceDialog:false
  220. })
  221. },
  222. onShareInfo: function () {
  223. console.log('onShareInfo')
  224. wx.getShareInfo({
  225. success: function (res) {
  226. console.log(res)
  227. }
  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. })