index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // nova-tourism/pages/homestay/customer/select-customer/index.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. customers: []
  8. },
  9. navigate(){
  10. wx.navigateTo({
  11. url: `/nova-tourism/pages/homestay/customer/customer-info/index`
  12. })
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. },
  19. /**
  20. * 生命周期函数--监听页面初次渲染完成
  21. */
  22. onReady: function () {
  23. },
  24. /**
  25. * 生命周期函数--监听页面显示
  26. */
  27. onShow: function () {
  28. let customers = wx.getStorageSync('customers');
  29. if(customers.length){
  30. customers = customers.map(customer => {
  31. customer['idcard'] = this.hiddenMiddleText(customer['idcard'])
  32. customer['checked'] = false
  33. return customer;
  34. })
  35. }
  36. this.setData({
  37. customers
  38. })
  39. console.log(this.data.customers);
  40. },
  41. radioChange(event){
  42. console.log(111,event);
  43. let index = event.currentTarget.dataset.index;
  44. this.setData({
  45. [`customers[${index}].checked`] : !this.data.customers[index].checked
  46. })
  47. console.log(this.data.customers[index].checked);
  48. },
  49. toEdit(event){
  50. console.log(111,event);
  51. let name = event.currentTarget.dataset.name;
  52. wx.navigateTo({
  53. url: `/nova-tourism/pages/homestay/customer/customer-info/index?type=edit&name=${name}`
  54. })
  55. },
  56. hiddenMiddleText(text){
  57. return text.replace(/(.{5}).*(.{3})/, "$1********$2")
  58. },
  59. save(){
  60. let customers = this.checkedCustomer();
  61. if(!customers.length || customers.length == 0) return;
  62. // 入住人数据保存到上一页面,再进行跳转
  63. var pages = getCurrentPages();var prevPage = pages[pages.length - 2];
  64. console.log(pages,prevPage,customers);
  65. prevPage.setData({
  66. customers
  67. })
  68. wx.navigateBack({
  69. delta: 1,
  70. })
  71. },
  72. checkedCustomer(){
  73. let customers = []
  74. for (let index = 0; index < this.data.customers.length; index++) {
  75. let customer = this.data.customers[index];
  76. if(customer.checked == true){
  77. customers.push(customer)
  78. }
  79. }
  80. return customers
  81. },
  82. /**
  83. * 生命周期函数--监听页面隐藏
  84. */
  85. onHide: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面卸载
  89. */
  90. onUnload: function () {
  91. },
  92. /**
  93. * 页面相关事件处理函数--监听用户下拉动作
  94. */
  95. onPullDownRefresh: function () {
  96. },
  97. /**
  98. * 页面上拉触底事件的处理函数
  99. */
  100. onReachBottom: function () {
  101. },
  102. /**
  103. * 用户点击右上角分享
  104. */
  105. onShareAppMessage: function () {
  106. }
  107. })