postageManage.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // pages/address/address.js
  2. const getReq = require('../../config.js').getReq
  3. let appInstance = 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. appInstance.setCardType(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('/person/person') != -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(params, res => {
  41. wx.hideLoading()
  42. if (res.code == 200) {
  43. let list = res.datas.card_list
  44. if(!list.length) {
  45. appInstance.clearRecord()
  46. }
  47. this.setData({
  48. list,
  49. firstLoad: false
  50. })
  51. }
  52. else {
  53. appInstance.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. appInstance.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. wx.navigateTo({
  69. url: `/pages/postageDetail/postageDetail?card_no=${card_no}&card_type=${card_type}&topcard_id=${topcard_id}`
  70. })
  71. },
  72. del_address(e) {
  73. const dataset = e.currentTarget.dataset
  74. const { record } = dataset
  75. const { topcard_id } = record
  76. wx.showModal({
  77. content: "确认删除此卡号吗",
  78. confirmText: "确定",
  79. cancelText: "取消",
  80. success: res => {
  81. if (res.confirm) {
  82. getReq({
  83. act: 'member_card',
  84. op: 'card_del',
  85. topcard_id
  86. }, function (res) {
  87. if (res.code == 200) {
  88. this.getDatas()
  89. }
  90. })
  91. } else if (res.cancel) {
  92. }
  93. }
  94. })
  95. },
  96. /**
  97. * 生命周期函数--监听页面初次渲染完成
  98. */
  99. onReady: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面显示
  103. */
  104. onShow: function () {
  105. if (!this.data.firstLoad) {
  106. this.setData({ card_type: appInstance.globalData.card_type })
  107. this.getDatas()
  108. }
  109. },
  110. /**
  111. * 生命周期函数--监听页面隐藏
  112. */
  113. onHide: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面卸载
  117. */
  118. onUnload: function () {
  119. },
  120. /**
  121. * 页面相关事件处理函数--监听用户下拉动作
  122. */
  123. onPullDownRefresh: function () {
  124. },
  125. /**
  126. * 页面上拉触底事件的处理函数
  127. */
  128. onReachBottom: function () {
  129. }
  130. })