import React, { Component } from 'react' import { View, Text, Button } from '@tarojs/components' import { connect } from 'react-redux' import { AtFloatLayout, AtInput, AtModal, AtModalHeader, AtModalContent, AtModalAction } from 'taro-ui' import { SpCheckbox } from '@/components' import './point-use.scss' import { DEFAULT_POINT_NAME } from '@/consts' @connect(({ sys, colors }) => ({ colors: colors.current, pointName: sys.pointName })) export default class PointUse extends Component { static defaultProps = { isOpened: false, disabledPoint: false } constructor(props) { super(props) this.state = { isOpenRule: false, point: null, localType: props.type } } componentWillReceiveProps = (nextProps) => { if (nextProps.type !== this.props.type) { this.setState({ localType: nextProps.type }) } } static options = { addGlobalClass: true } handleCancel = () => { this.setState({ localType: this.props.type //point:null }) this.props.onClose() } handleRuleOpen = () => { this.setState({ isOpenRule: true }) } handleRuleClose = () => { this.setState({ isOpenRule: false }) } handlePointChange = (value) => { const { info, defalutPaytype } = this.props const max_point = Number(info.max_point) if (value >= max_point) { this.setState({ localType: info.deduct_point_rule.full_amount ? 'point' : defalutPaytype, point: max_point }) return max_point } this.setState({ point: Number(value) > max_point ? max_point : value, localType: info.deduct_point_rule.full_amount ? Number(value) === max_point ? 'point' : defalutPaytype : defalutPaytype }) } handleUseFullAmount = (checked) => { const { info } = this.props const { localType } = this.state this.setState({ point: checked ? info.max_point : '', disabledPoint: checked ? true : false, localType: checked ? 'point' : localType }) } handleChange = (point, pay_type) => { this.props.onChange(point, pay_type) } render() { const { info, isOpened, loading, colors, pointName } = this.props const { point, isOpenRule, disabledPoint, localType } = this.state if (!info) { return null } const { deduct_point_rule = {} } = info return ( {pointName} 使用规则 {`用户可用${pointName}:`} {info.user_point} {`本单最大可用${pointName}:`} {info.max_point} {`请输入抵扣${pointName}`} {deduct_point_rule && deduct_point_rule.full_amount && info.max_point > 0 && ( 全额抵扣 )} 积分使用规则 使用条件 {`1.${DEFAULT_POINT_NAME}支付不得超出订单应付总金额的 ${deduct_point_rule.deduct_proportion_limit}%;`} 使用数量 {`2.${deduct_point_rule.deduct_point} ${pointName}抵 1 元;`} ) } }