import { connect } from 'herculex';
Component(connect({
  mapStateToProps: {
    globalCar: state => state.$global.globalCar || []
  }
})({
  props: {
    componentData: {},
    position: 'absolute',
    discountShow: true,
    selectNum: 0,
    onConfirmClick: () => null,
    onCarClick: () => null,
    buttonText: '去结算',
    showIcon: true,
    showTip: false,
    totalPrice: '',
    disCountTotalPrice: '',
    packingFee: 0,
    showColorBtn: true,
    // 是否为确认按钮
    isConfirm: false,
    item: null,
    showColorCar: true,
    startDeliveryAmount: 0
  },
  data: {
    btnConfig: [{
      text: '我知道了',
      extClass: 'confirm',
      type: 'confirm'
    }],
    inActiveCarIcon: 'https://gw.alipayobjects.com/mdn/rms_0e8a29/afts/img/A*JCnoQ6bVRA4AAAAAAAAAAAAAARQnAQ',
    carIconAddress: 'https://gw.alipayobjects.com/mdn/rms_0e8a29/afts/img/A*1vZdQLgoYLIAAAAAAAAAAAAAARQnAQ'
  },

  didMount() {},

  didUpdate() {},

  methods: {
    showModal() {
      const {
        startDeliveryAmount
      } = this.props;
      const {
        disCountTotalPrice,
        deliveryPackingFee
      } = this.data.globalCar;
      my.alert({
        title: '起送说明',
        content: `购物车商品${disCountTotalPrice}元,打包费${deliveryPackingFee}元,起送金额为${startDeliveryAmount}元`,
        buttonText: '我知道了'
      });
    },

    onHandleClick(e) {
      const {
        formId = ''
      } = e.detail;
      const {
        isConfirm
      } = this.props;

      if (isConfirm) {
        return this.props.onConfirmClick(formId);
      }

      const {
        carts: carList = []
      } = this.data.globalCar;
      const carCheckedList = carList.filter(v => v.checkedState === 'Y' && v.status === 'Y');

      if (!carCheckedList.length) {
        return;
      }

      this.props.onConfirmClick();
    },

    openCarPop() {
      this.props.onCarClick();
    }

  }
}));