shipyard.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // pages/shipyard/shipyard.js
  2. import { postApi } from "../../apis/api";
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. shipyardList: [],
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad(options) {
  14. this.getShipyardList();
  15. },
  16. /**
  17. * 生命周期函数--监听页面初次渲染完成
  18. */
  19. onReady() {},
  20. /**
  21. * 生命周期函数--监听页面显示
  22. */
  23. onShow() {
  24. if (typeof this.getTabBar === "function" && this.getTabBar()) {
  25. this.getTabBar().setData({
  26. selected: 4,
  27. });
  28. }
  29. },
  30. /**
  31. * 生命周期函数--监听页面隐藏
  32. */
  33. onHide() {},
  34. /**
  35. * 生命周期函数--监听页面卸载
  36. */
  37. onUnload() {},
  38. /**
  39. * 页面相关事件处理函数--监听用户下拉动作
  40. */
  41. onPullDownRefresh() {},
  42. /**
  43. * 页面上拉触底事件的处理函数
  44. */
  45. onReachBottom() {},
  46. /**
  47. * 用户点击右上角分享
  48. */
  49. share(e) {
  50. this.setData({
  51. shipyardId: e.currentTarget.dataset.id,
  52. shipyardName: e.currentTarget.dataset.title,
  53. });
  54. },
  55. onShareAppMessage() {
  56. return {
  57. title: this.data.shipyardName,
  58. path: `/pages/shipyard/sharePage/sharePage?shipyardId=${this.data.shipyardId}`,
  59. };
  60. },
  61. makePhoneCall(e) {
  62. const phoneNumber = e.currentTarget.dataset.phone;
  63. if (phoneNumber) {
  64. wx.makePhoneCall({
  65. phoneNumber: phoneNumber,
  66. fail(err) {
  67. wx.showToast({
  68. title: "拨打电话失败",
  69. icon: "none",
  70. });
  71. },
  72. });
  73. } else {
  74. wx.showToast({
  75. title: "电话号码不存在",
  76. icon: "none",
  77. });
  78. }
  79. },
  80. async getShipyardList() {
  81. let { data } = await postApi("/shipyard/info", {
  82. currentPage: 1,
  83. size: 1000,
  84. });
  85. if (data.status === 0) {
  86. this.setData({
  87. shipyardList: data.result,
  88. });
  89. } else {
  90. this.setData({
  91. shipyardList: [],
  92. });
  93. }
  94. },
  95. });