postageManage.js 3.0 KB

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