postage.js 8.5 KB

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