const { getProjectNameLang } = require("../common");
var location = require("../../../mybehaviors/location/location");
// packageH/project_verification/VerificationProjectDetails/VerificationProjectDetails.js
const App = getApp();
const GetProjectUrl = App.getNetAddresss("plugin.store-projects.frontend.project.get-detail");
let Location = null;
Page({
  behaviors: [location],
  /**
   * 页面的初始数据
   */
  data: {
    projectId: null,
    project: null,
    stores: [],
    goods: [],
    projectNameLang: getProjectNameLang(),
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    if (!options.project_id) {
      wx.showToast({
        title: getProjectNameLang() + "不存在",
        icon: "none",
      });
      wx.navigateBack();
      return;
    }
    this.setData({
      projectId: options.project_id,
    });
    this._getLocation((res,point) => {
      Location = Location = {
        point: point
      };
      this.getProject();
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      path: "/packageH/project_verification/VerificationProjectDetails/VerificationProjectDetails?project_id=" + this.data.projectId,
    };
  },
  onShareTimeline() {
    return {
      query: "project_id=" + this.data.projectId,
    };
  },
  btnStore(e) {
    // 加store_type字段 1-门店 2-酒店
    let item = e.currentTarget.dataset.item;
    if(item.store_type == 2) {
      wx.redirectTo({
        url: "/packageC/hotel/HotelHome/HotelHome?id=" + item.id
      });
    }else {
      wx.redirectTo({
        url: "/packageC/o2o/HomeSeller/HomeSeller?store_id=" + item.id
      });
    }
  },
  getProject() {
    let point = App.qqMapTransBMap(parseFloat(Location.point.lng), parseFloat(Location.point.lat));
    App._getNetWork({
      url: GetProjectUrl,
      data: {
        lng: point.lng,
        lat: point.lat,
        project_id: this.data.projectId,
      },
      success: ({ data: { data: response }, result, msg }) => {
        if (result === 0) {
          wx.showToast({
            title: msg,
            icon: "none",
          });
          wx.navigateBack();
          return;
        }

        this.setData({
          project: response.project,
          stores: response.store,
          goods: response.goods,
        });
      },
    });
  },
});
