import React, { Component } from 'react' import Taro, { getCurrentInstance } from '@tarojs/taro' import { View, Text } from '@tarojs/components' import { AtImagePicker, AtTag, AtTextarea, AtTabsPane, AtTabs } from 'taro-ui' import { SpCell, SpToast, SpHtml, SpImgPicker } from '@/components' import { connect } from 'react-redux' import api from '@/api' // import req from '@/api/req' import { Tracker } from '@/service' import { pickBy, classNames } from '@/utils' import S from '@/spx' import imgUploader from '@/utils/upload' import './refund.scss' @connect(({ colors }) => ({ colors: colors.current })) export default class TradeRefund extends Component { $instance = getCurrentInstance() constructor(props) { super(props) this.state = { // reason: ['多拍/拍错/不想要', '缺货', '买多了', '质量问题', '卖家发错货', '商品破损', '描述不符', '其他'], description: '', imgs: [], reason: [], curReasonIdx: null, goodStatus: ['未收到货', '已收到货'], curGoodIdx: null, isShowSegGoodSheet: false, isSameCurSegGood: false, curSegGoodValue: null, segTypes: [ { title: '仅退款', status: 'ONLY_REFUND' }, { title: '退货退款', status: 'REFUND_GOODS' } ], curSegIdx: 0, isShowSegTypeSheet: false, isSameCurSegType: false, curSegTypeValue: null, remind: {}, isInvalid: true } } componentDidMount() { this.fetch() const { status } = this.$instance.router.params const { segTypes, curSegIdx } = this.state let curIndex = 0 segTypes.map((item, index) => { item.status == status && (curIndex = index) }) this.setState({ curSegIdx: curIndex }) } async fetch() { Taro.showLoading({ mask: true }) const { aftersales_bn, order_id, isDelivery, delivery_status, deliverData } = this.$instance.router.params let detail = deliverData ? JSON.parse(deliverData) : null // 获取售后原因 const reasonList = await api.aftersales.reasonList() let params = null if (aftersales_bn) { const res = await api.aftersales.info({ aftersales_bn, detail, order_id }) if (!res) { this.setState({ reason: newReason, remind }) return } params = pickBy(res, { curSegIdx: ({ aftersales_type }) => this.state.segTypes.findIndex((t) => t.status === aftersales_type) || 0, curSegTypeValue: ({ aftersales_type }) => this.state.segTypes[this.state.segTypes.findIndex((t) => t.status === aftersales_type)] .title, curReasonIdx: ({ reason }) => reasonList.indexOf(reason) || 0, curSegReasonValue: 'reason', description: 'description', imgs: ({ evidence_pic }) => evidence_pic.map((url) => ({ url })) }) } Taro.hideLoading() const { reason: oldReason } = this.state const newReason = [...oldReason, ...reasonList] let remind = await api.aftersales.remindDetail() if (isDelivery === 'false' && delivery_status !== 'DONE') { this.setState({ segTypes: [{ title: '仅退款', status: 'ONLY_REFUND' }] }) } this.setState({ ...params, remind, reason: newReason }) } handleClickTag = (data) => { const idx = this.state.reason.indexOf(data.name) if (idx >= 0) { this.setState({ curReasonIdx: idx }) } } handleTextChange = (e) => { this.setState({ description: e }) } handleImageChange = async (data, type) => { if (type === 'remove') { this.setState({ imgs: data }) return } if (data.length > 3) { S.toast('最多上传3张图片') } const imgFiles = data.slice(0, 3) imgUploader.uploadImageFn(imgFiles).then((res) => { console.log('uploadImageFn:res', res) this.setState({ imgs: res }) }) } handleImageClick = () => {} handleClickTab = (idx) => { this.setState({ curSegIdx: idx }) } handleChangeRefundOptions = (type) => { if (type === 'type') { this.setState({ isShowSegTypeSheet: true }) } if (type === 'goods') { this.setState({ isShowSegGoodSheet: true }) } } handleClickSheet = (index, item, type) => { if (type === 'type') { this.setState({ curSegIdx: index === this.state.curSegIdx ? null : index, isSameCurSegType: index === this.state.curSegIdx ? !this.state.isSameCurSegType : true, isShowSegTypeSheet: false, curSegTypeValue: index === this.state.curSegIdx ? null : item.value }) } if (type === 'goods') { this.setState({ curGoodIdx: index === this.state.curGoodIdx ? null : index, isSameCurSegGood: index === this.state.curGoodIdx ? !this.state.isSameCurSegGood : true, isShowSegGoodSheet: false, curSegGoodValue: index === this.state.curGoodIdx ? null : item }) } } aftersalesAxios = async () => { await this.setState({ isInvalid: false }) const { segTypes, curSegIdx, curReasonIdx, description } = this.state const reason = this.state.reason[curReasonIdx] const aftersales_type = segTypes[curSegIdx].status const evidence_pic = this.state.imgs.map(({ url }) => url) const { order_id, aftersales_bn, deliverData } = this.$instance.router.params let detail = deliverData const data = { detail, order_id, aftersales_bn, aftersales_type, reason, description, evidence_pic } // console.log(data, 244) const method = aftersales_bn ? 'modify' : 'apply' await api.aftersales[method](data) // 退款退货 const { orderInfo } = await api.trade.detail(order_id) Tracker.dispatch('ORDER_REFUND', orderInfo) try { S.toast('操作成功') setTimeout(() => { Taro.redirectTo({ url: `/subpage/pages/trade/detail?id=${order_id}` }) this.setState({ isInvalid: true }) }, 100) } catch (e) { this.setState({ isInvalid: true }) } } handleSubmit = () => { let _this = this let templeparams = { 'temp_name': 'yykweishop', 'source_type': 'after_refund' } if (this.state.isInvalid) this.aftersalesAxios() // api.user.newWxaMsgTmpl(templeparams).then(tmlres => { // if (tmlres.template_id && tmlres.template_id.length > 0) { // wx.requestSubscribeMessage({ // tmplIds: tmlres.template_id, // success () { // _this.aftersalesAxios() // }, // fail () { // _this.aftersalesAxios() // } // }) // } else { // _this.aftersalesAxios() // } // }, () => { // _this.aftersalesAxios() // }) } render() { const { colors } = this.props const { segTypes, curSegIdx, reason, curReasonIdx, goodStatus, curGoodIdx, isShowSegGoodSheet, isSameCurSegGood, curSegGoodValue, description, imgs, remind } = this.state return ( {/* {segTypes.map((panes, pIdx) => ( ))} */} {reason && reason.map((item, idx) => { return ( {item} ) })} {/* { goodStatus.map((item, t_index) => { return( {item} { curSegGoodValue === item || (curGoodIdx === t_index && isSameCurSegGood) ? : } ) }) } */} {' '} {/* {curSegIdx === 1 ? ( */} 上传凭证 1 您可以上传最多3张图片 {' '} {/* ) : null} */} {remind && remind.is_open && ( 售后提醒 )} 提交 {/* {reason.map((item, idx) => { return ( {item} ) })} {curSegIdx === 1 && ( )} 提交申请 */} ) } }