postageManage.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // pages/address/address.js
  2. const getReq = require('../../config.js').getReq
  3. let app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. list: [],
  10. firstLoad: true,
  11. fromPerson: false,
  12. card_type: ''
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. const { card_type } = options
  19. // wx.setNavigationBarTitle({ title })
  20. app.setCardType(card_type)
  21. console.log(card_type)
  22. this.setData({ card_type })
  23. this.getDatas()
  24. let len = getCurrentPages().length
  25. let prev = getCurrentPages()[len - 2]
  26. if(prev['route'].indexOf('/myhome/myhome') != -1) {
  27. this.setData({
  28. fromPerson: true
  29. })
  30. }
  31. },
  32. getDatas() {
  33. wx.showLoading({
  34. title: '加载中',
  35. })
  36. const params = {
  37. act: 'member_card',
  38. op: 'card_list',
  39. card_type: this.data.card_type //petrochina -> 中石油; sinopec -> 中石化; phone-> 手机卡; 不填的时候,返回所有
  40. }
  41. getReq(app,params, res => {
  42. wx.hideLoading()
  43. if (res.code == 200) {
  44. let list = res.datas.card_list
  45. if(!list.length) {
  46. app.clearRecord()
  47. }
  48. this.setData({
  49. list,
  50. firstLoad: false
  51. })
  52. }
  53. else {
  54. app.showToast(res.message)
  55. }
  56. })
  57. },
  58. check_record(e) {
  59. if(this.data.fromPerson) return;
  60. const dataset = e.currentTarget.dataset
  61. const { record } = dataset
  62. app.checkCurrentRecord(record)
  63. wx.navigateBack()
  64. },
  65. modify_address(e) {
  66. const dataset = e.currentTarget.dataset
  67. const { record } = dataset
  68. const { card_no, card_type, topcard_id } = record
  69. app.navigateto(`/pages/postageDetail/postageDetail?card_no=${card_no}&card_type=${card_type}&topcard_id=${topcard_id}`)
  70. },
  71. del_address(e) {
  72. const dataset = e.currentTarget.dataset
  73. const { record } = dataset
  74. const { topcard_id } = record
  75. wx.showModal({
  76. content: "确认删除此卡号吗",
  77. confirmText: "确定",
  78. cancelText: "取消",
  79. success: res => {
  80. if (res.confirm) {
  81. getReq(app,{
  82. act: 'member_card',
  83. op: 'card_del',
  84. topcard_id
  85. }, res => {
  86. if (res.code == 200) {
  87. this.getDatas()
  88. }
  89. })
  90. } else if (res.cancel) {
  91. }
  92. }
  93. })
  94. },
  95. /**
  96. * 生命周期函数--监听页面初次渲染完成
  97. */
  98. onReady: function () {
  99. },
  100. /**
  101. * 生命周期函数--监听页面显示
  102. */
  103. onShow: function () {
  104. if (!this.data.firstLoad) {
  105. this.setData({ card_type: app.globalData.card_type })
  106. this.getDatas()
  107. }
  108. },
  109. /**
  110. * 生命周期函数--监听页面隐藏
  111. */
  112. onHide: function () {
  113. },
  114. /**
  115. * 生命周期函数--监听页面卸载
  116. */
  117. onUnload: function () {
  118. },
  119. /**
  120. * 页面相关事件处理函数--监听用户下拉动作
  121. */
  122. onPullDownRefresh: function () {
  123. },
  124. /**
  125. * 页面上拉触底事件的处理函数
  126. */
  127. onReachBottom: function () {
  128. }
  129. })