shipyard.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. imageUrl: "../../images/logo541.png",
  60. };
  61. },
  62. makePhoneCall(e) {
  63. const phoneNumber = e.currentTarget.dataset.phone;
  64. if (phoneNumber) {
  65. wx.makePhoneCall({
  66. phoneNumber: phoneNumber,
  67. fail(err) {
  68. wx.showToast({
  69. title: "拨打电话失败",
  70. icon: "none",
  71. });
  72. },
  73. });
  74. } else {
  75. wx.showToast({
  76. title: "电话号码不存在",
  77. icon: "none",
  78. });
  79. }
  80. },
  81. async getShipyardList() {
  82. let { data } = await postApi("/shipyard/info", {
  83. currentPage: 1,
  84. size: 1000,
  85. });
  86. if (data.status === 0) {
  87. this.setData({
  88. shipyardList: data.result,
  89. });
  90. } else {
  91. this.setData({
  92. shipyardList: [],
  93. });
  94. }
  95. },
  96. });