import { queryForRefundList } from './service';
import showToast from '../../utils/showToast';
import { connect } from 'herculex';
Component(connect({
  mapStateToProps: {
    cityCode: state => state.$global.cityCode,
    globalShopId: state => state.$global.globalShopId || '',
    globalShop: state => state.$global.globalShop || {}
  }
})({
  props: {
    componentData: {},
    hasRefund: false,
    showNavigateIcon: false,
    orderId: '',
    shop: null,
    refundDetailStatus: 'REFUND',
    refundTotalNum: 0,
    contactMobile: '',
    title: '门店自提',
    showMobile: true
  },

  didUpdate() {},

  async didMount() {
    const {
      hasRefund = '',
      orderId = ''
    } = this.props; // 有退款列表

    if (hasRefund) {
      try {
        const refundList = await queryForRefundList({
          orderId
        });
        this.setData({
          refundList
        });
      } catch (err) {
        showToast({
          type: 'fail',
          content: err.msg
        });
      }
    }
  },

  data: {
    refundList: [],
    phoneIcon: 'https://gw.alipayobjects.com/mdn/rms_0e8a29/afts/img/A*wbGKRoAg_EAAAAAAAAAAAAAAARQnAQ',
    navigationIcon: 'https://gw.alipayobjects.com/mdn/rms_0e8a29/afts/img/A*ppJgSIFM3DYAAAAAAAAAAAAAARQnAQ'
  },
  methods: {
    // 点击导航按钮
    navToStore() {
      // 有传递商店信息
      const {
        longitude,
        latitude,
        address
      } = this.props.shop || this.data.globalShop;

      if (Object.keys(this.props.shop).length) {
        my.openLocation({
          longitude,
          latitude,
          name: this.props.shop.storeName,
          address
        });
      } else {
        // 没有传递 从全局取
        const {
          storeName
        } = this.data.globalShop;
        my.openLocation({
          longitude,
          latitude,
          name: storeName,
          address
        });
      }
    },

    // 点击联系商家
    contactStore() {
      const {
        contactMobile = ''
      } = this.props.shop || this.data.globalShop;

      if (!contactMobile) {
        return my.showToast({
          content: '暂无联系方式'
        });
      }

      my.makePhoneCall({
        number: contactMobile
      });
    }

  }
}));