import { queryMerchantStoreDetail } from '../../../services';
/**
 * @Auther: 陈林(wb-cl445194)
 * @Date: 2021/4/8 10:22 上午
 * @Description: 商家详情页
 */

Component({
  props: {
    query: {}
  },
  data: {
    current: 0,
    record: undefined
  },

  didMount() {
    this.fetchDetail();
  },

  methods: {
    onChange({
      detail: {
        current
      }
    }) {
      this.setData({
        current
      });
    },

    onOpenLocation() {
      const {
        record
      } = this.data;
      my.openLocation({
        longitude: record.merchantStoreLongitude,
        latitude: record.merchantStoreLatitude,
        name: record.merchantStoreName,
        address: record.merchantStoreAddress
      });
    },

    onMakePhoneCall() {
      my.makePhoneCall({
        number: this.data.record.contactInformation
      });
    },

    async fetchDetail() {
      const {
        merchantStoreCode,
        merchantStoreName
      } = this.props.query;
      const [, result] = await queryMerchantStoreDetail({
        merchantStoreCode,
        merchantStoreName
      });
      result && this.setData({
        record: result
      });
    }

  }
});