From 37a7089aa94ef79c663264e1382c01adbe683b13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E9=BE=99?= Date: Tue, 27 Feb 2024 10:25:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=8F=91=E7=A5=A8=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/trade.js | 3 + src/components/search-bar/index.js | 4 + src/components/sp-goods-price/index.js | 2 +- src/doc/goods.js | 1 + src/doc/trade.js | 1 + src/hooks/usePayment.js | 4 +- src/pages/cart/espier-checkout.js | 24 +- src/pages/index.js | 9 +- src/pages/item/espier-detail.js | 2 +- src/pages/item/list.js | 1 + src/subpage/pages/trade/invoice-info.js | 266 +++++++++++++++----- src/subpage/pages/trade/invoice-info.scss | 9 +- src/subpage/pages/trade/invoice-list.js | 2 +- src/subpage/pages/trade/invoice-record.js | 66 +++-- src/subpage/pages/trade/invoice-record.scss | 29 ++- src/subpages/member/index.js | 4 +- 16 files changed, 316 insertions(+), 111 deletions(-) diff --git a/src/api/trade.js b/src/api/trade.js index dd312d6..3de0b19 100755 --- a/src/api/trade.js +++ b/src/api/trade.js @@ -44,6 +44,9 @@ export function imgUpload (params = {}) { export function involiceList (params = {}) { return req.get(`/orders/invoice`, params) } +export function involiceResend (params = {}) { + return req.post(`/orders/invoice/resend`, params) +} export function zitiCode (params = {}) { return req.get(`/ziticode`, params) diff --git a/src/components/search-bar/index.js b/src/components/search-bar/index.js index 8628dbc..210e3e7 100755 --- a/src/components/search-bar/index.js +++ b/src/components/search-bar/index.js @@ -116,6 +116,10 @@ export default class SearchBar extends Component { handleBlurSearch = () => { this.props.onBlur?.() + this.setState({ + showSearchDailog: false, + isShowAction: false + }) } render () { diff --git a/src/components/sp-goods-price/index.js b/src/components/sp-goods-price/index.js index 8210411..b319f9a 100755 --- a/src/components/sp-goods-price/index.js +++ b/src/components/sp-goods-price/index.js @@ -43,7 +43,7 @@ function SpGoodsPrice (props) { } { - !isPoint && + !isPoint && } {/* {marketPrice > 0 && enMarketPrice && ( diff --git a/src/doc/goods.js b/src/doc/goods.js index 1647d88..8ce4037 100755 --- a/src/doc/goods.js +++ b/src/doc/goods.js @@ -123,6 +123,7 @@ export const GOODS_INFO = { itemBn: 'item_bn', itemName: 'itemName', itemName2: 'item_name_2', + pdp: 'pdp', brief: 'brief', img: 'pics[0]', imgs: 'pics', diff --git a/src/doc/trade.js b/src/doc/trade.js index 7b8f249..6f998cb 100755 --- a/src/doc/trade.js +++ b/src/doc/trade.js @@ -128,6 +128,7 @@ export const TRADE_AFTER_SALES_ITEM = { afterSalesMobile: ({ aftersales_address }) => aftersales_address.aftersales_mobile, afterSalesAddress: ({ aftersales_address }) => aftersales_address.aftersales_address, afterSalesContact: ({ aftersales_address }) => aftersales_address.aftersales_contact, + afterSalesZip: ({ aftersales_address }) => aftersales_address.post_code, aftersalesHours: ({ aftersales_address }) => aftersales_address.aftersales_hours, refundFee: ({ refund_fee }) => refund_fee / 100, sendbackData: 'sendback_data', diff --git a/src/hooks/usePayment.js b/src/hooks/usePayment.js index d12f222..d5418b4 100755 --- a/src/hooks/usePayment.js +++ b/src/hooks/usePayment.js @@ -19,11 +19,11 @@ export default (props = {}) => { // const { params, orderInfo } = state const cashierResultUrl = `/pages/cart/cashier-result` const $instance = getCurrentInstance() - console.log("🚀 ~ $instance.router:", $instance.router) + // console.log("🚀 ~ $instance.router:", $instance.router) const currentPath = $instance.router?.path const cashierPayment = (params, orderInfo) => { - console.log(`cashierPayment:`, params, orderInfo) + // console.log(`cashierPayment:`, params, orderInfo) const { pay_type, pay_channel } = params switch (pay_type) { case 'wxpay': diff --git a/src/pages/cart/espier-checkout.js b/src/pages/cart/espier-checkout.js index 0932d77..5b2982b 100755 --- a/src/pages/cart/espier-checkout.js +++ b/src/pages/cart/espier-checkout.js @@ -124,7 +124,7 @@ function CartCheckout (props) { scene, // 情景值 goodType = routerParams.goodType } = $instance?.router?.params || {} - console.log('$instance.router?.params:', $instance.router) + // console.log('$instance.router?.params:', $instance.router) useEffect(() => { if (isLogin) { getTradeSetting() @@ -148,7 +148,7 @@ function CartCheckout (props) { }, [isNewUser]) useEffect(() => { - console.log(`useEffect: payType: ${payType}, address: ${address}, zitiAddress: ${zitiAddress}, receiptType: ${receiptType}`) + // console.log(`useEffect: payType: ${payType}, address: ${address}, zitiAddress: ${zitiAddress}, receiptType: ${receiptType}`) if (receiptType && payType) { calcOrder() } @@ -249,7 +249,7 @@ function CartCheckout (props) { params['building_number'] = buildingNumber params['house_number'] = houseNumber } - console.log('trade params:', params) + // console.log('trade params:', params) if (params.pay_type === 'deposit') { // 验证余额额度是否可用 if (userInfo.deposit < totalInfo.total_fee / 100) { @@ -365,6 +365,24 @@ function CartCheckout (props) { // 开发票 const handleInvoiceClick = () => { + Taro.navigateTo({ + url: `/subpage/pages/trade/invoice-info?id=${totalInfo.tid || ''}`, + events: { + // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据 + acceptDataFromOpenedPage: function ({ data = {} }) { + const { invoiceTitle } = data + setState((draft) => { + draft.invoiceTitle = invoiceTitle + draft.paramsInfo = { ...paramsInfo, ...(data.paramsInfo || {}) } + }) + }, + }, + success: function (res) { + // 通过eventChannel向被打开页面传送数据 + res.eventChannel.emit('acceptDataFromOpenerPage', { data: totalInfo }) + } + }) + return authSetting('invoiceTitle', async () => { const res = await Taro.chooseInvoiceTitle() if (res.errMsg === 'chooseInvoiceTitle:ok') { diff --git a/src/pages/index.js b/src/pages/index.js index bde0656..860a27f 100755 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -215,7 +215,7 @@ function Home () { postions: 'left', url: '', img: 'index/rec/new.png', - list: newList + list: newList.map(item => ({ ...item, price: (item.price / 100) })) }, { type: 'hot', text: "热销单品", @@ -223,7 +223,7 @@ function Home () { postions: 'left', url: '', img: 'index/rec/hot.png', - list: hotList + list: hotList.map(item => ({ ...item, price: (item.price / 100) })) }, { type: 'jd', text: "ARIZONA", @@ -231,7 +231,7 @@ function Home () { postions: 'right', url: '', img: 'index/rec/jd.png', - list: jdList + list: jdList.map(item => ({ ...item, price: (item.price / 100) })) } ] }) @@ -246,12 +246,11 @@ function Home () { goods: (item.goods_info_detail || []).map((ite) => { return { itemName: ite.item_name, - price: ite.price, goods_id: ite.item_id, itemId: ite.item_id, pic: ite.pics?.[0], brief: ite.brief, - price: ite.price, + price: ite.price ? ite.price / 100 : 0, spec_images: ite.spec_images || [], tagList: ite.tagList || [] } diff --git a/src/pages/item/espier-detail.js b/src/pages/item/espier-detail.js index 3f11088..be1ea5e 100755 --- a/src/pages/item/espier-detail.js +++ b/src/pages/item/espier-detail.js @@ -604,7 +604,7 @@ function EspierDetail (props) { - {info.brief} + {info.pdp && {info.pdp}} {info?.itemName2 || info?.itemName} {/* {(isWeixin || isAPP()) && ( diff --git a/src/pages/item/list.js b/src/pages/item/list.js index e8e22ee..7092850 100755 --- a/src/pages/item/list.js +++ b/src/pages/item/list.js @@ -357,6 +357,7 @@ function ItemList () { placeholder='搜索商品' isOpened={true} onFocus={handleOnFocus} + onBlur={() => handleConfirm(keywords)} onChange={handleOnChange} onClear={handleOnClear} onCancel={handleSearchOff} diff --git a/src/subpage/pages/trade/invoice-info.js b/src/subpage/pages/trade/invoice-info.js index e4b6655..4e02faf 100755 --- a/src/subpage/pages/trade/invoice-info.js +++ b/src/subpage/pages/trade/invoice-info.js @@ -10,22 +10,54 @@ import doc from '@/doc' import './invoice-info.scss' import { useImmer } from 'use-immer' +import { useEffect } from 'react' const initState = { formList: [ { name: '抬头类型', type: 'checkbox', - key: 'invoice_title', + key: 'title', required: true, }, { name: '发票抬头', type: 'input', - key: 'invoice_title', + key: 'content', placeholder: '请填写抬头名称(必填)', required: true, }, + { + name: '企业税号', + type: 'input', + key: 'registration_number', + placeholder: '请填写企业税号(选填)', + required: true, + }, + { + name: '注册地址', + type: 'input', + key: 'company_address', + placeholder: '(选填)', + }, + { + name: '注册电话', + type: 'input', + key: 'company_phone', + placeholder: '(选填)', + }, + { + name: '开户银行', + type: 'input', + key: 'bankname', + placeholder: '(选填)', + }, + { + name: '银行账号', + type: 'input', + key: 'bankaccount', + placeholder: '(选填)', + }, { name: '邮箱地址', type: 'input', @@ -33,42 +65,52 @@ const initState = { placeholder: '用于接收电子发票(必填)', required: true, }, - { - name: '注册地址', - type: 'input', - key: 'addr', - placeholder: '(选填)', - }, - { - name: '注册电话', - type: 'input', - key: 'tel', - placeholder: '(选填)', - }, - { - name: '开户银行', - type: 'input', - key: 'yh', - placeholder: '(选填)', - }, - { - name: '银行账号', - type: 'input', - key: 'zh', - placeholder: '(选填)', - }, ], form: {}, showModal: false, visible: false, - showDetail: false + showDetail: false, + invoiceId: '', + invoice: {}, + orderInfo: {}, + loading: false, + title: '', + totalFee: '', + toastShow: false, + invoiceInfo: {} } function InvoiceInfo (props) { + const $instance = getCurrentInstance() const [state, setState] = useImmer(initState) - const { formList, form, showModal, visible, showDetail } = state + const { formList, form, showModal, visible, showDetail, invoiceId, invoice, orderInfo, loading, title, totalFee, toastShow, invoiceInfo } = state + const pages = getCurrentPages() + const current = pages[pages.length - 1] + const eventChannel = current.getOpenerEventChannel() - const onChangeItemCheck = () => { + useEffect(() => { + const { id } = $instance.router.params + if (id && id !== 'undefined') { + setState((draft) => { + draft.showDetail = true, + draft.invoiceId = id + }) + } + // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据 + eventChannel?.on('acceptDataFromOpenerPage', function ({ data }) { + setState((draft) => { + draft.orderInfo = data.order || data || {} + draft.invoiceInfo = data.invoice || {} + draft.form = data.order?.invoice || {} + draft.title = data.order?.title ? data.order.title === 'unit' ? '个人' : '企业' : '' + draft.totalFee = data.order?.total_fee ?? '' + }) + }) + }, []) + const onChangeItemCheck = (val) => { + setState((draft) => { + draft.form = { ...form, title: val } + }) } const hadnleInput = (val, item) => { @@ -83,11 +125,72 @@ function InvoiceInfo (props) { draft.visible = false }) } + + const handleSubmit = async () => { + const { email } = form + const emailReg = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ + if (!emailReg.test(email)) { + Taro.showToast({ + title: '邮箱格式不正确', + icon: 'none', + duration: 1000 + }) + return + } + setState((draft) => { + draft.visible = false + // draft.toastShow = true + // draft.showModal = true + }) + const res = await api.trade.involiceResend({ + order_id: orderInfo.order_id, + email + }) + Taro.showToast({ + title: '发送成功', + icon: 'success', + duration: 1500 + }) + setTimeout(() => { + Taro.navigateBack() + }, 2000) + } + + const handSubmitInvoice = () => { + const { email, title, content } = form + if (!title) { + Taro.showToast({ + title: '请选择抬头类型', + icon: 'none', + duration: 1000 + }) + return + } + if (!content) { + Taro.showToast({ + title: '请填写抬头名称', + icon: 'none', + duration: 1000 + }) + return + } + const emailReg = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ + if (!emailReg.test(email)) { + Taro.showToast({ + title: '邮箱格式不正确', + icon: 'none', + duration: 1000 + }) + return + } + eventChannel?.emit('acceptDataFromOpenedPage', { data: invoice }) + Taro.navigateBack() + } const handleInvoiceClick = () => { authSetting('invoiceTitle', async () => { const res = await Taro.chooseInvoiceTitle() if (res.errMsg === 'chooseInvoiceTitle:ok') { - log.debug('[invoice] info:', res) + // log.debug('[invoice] info:', res) const { type, content, @@ -110,50 +213,84 @@ function InvoiceInfo (props) { company_phone } } - console.log("🚀 ~ invoice_parmas:", invoice_parmas) - // setState((draft) => { - // draft.invoiceTitle = content - // draft.paramsInfo = { ...paramsInfo, ...invoice_parmas } - // }) + // console.log("🚀 ~ invoice_parmas:", invoice_parmas) + setState((draft) => { + draft.invoice = { + invoiceTitle: content, + paramsInfo: invoice_parmas + } + draft.form = invoice_parmas.invoice_content + }) } }) } - return + // 预览文件 + const preview = (url, fileName) => { + Taro.downloadFile({ + url: url, + success: function (res) { + console.log("下载:", res) + var filePath = res.tempFilePath + Taro.openDocument({ + filePath: filePath, + fileType: getFileType(url), + fileName: fileName, + success: function (res) { + console.log("打开:", res) + }, + }) + }, + }) + } + // 获取文件类型 + const getFileType = (name = '') => { + if (name.lastIndexOf(".") > -1) { + return name.slice(name.lastIndexOf(".") + 1).toLowerCase() + } else { + return "" + } + } + + + + + return - {showDetail && 共{0}张发票,含{1}个订单} + {showDetail && 共{1}张发票,含{1}个订单} 发票类型 电子发票 {showDetail ? - 查看 - + preview(invoiceInfo.pdf_info, invoiceInfo.invoice_title + invoiceInfo.invoice_no)}>查看 + + {/* */} : 一键授权微信发票} {showDetail && 发票状态 - 已申请 + {orderInfo.is_invoiced == 1 ? '已开票' : '已申请'} } 发票金额 - ¥9999 + ¥{totalFee ? parseFloat(totalFee).toFixed(2) : (orderInfo.total_fee ? (orderInfo.total_fee / 100).toFixed(2) : 0)} {formList.map((item) => {item.name} - {showDetail ? {form[item.key] || '测试'} : <>{item.type === 'checkbox' && + {showDetail && item.key !== 'email' ? {item.key === 'title' ? title || orderInfo.invoice?.[item.key] || form[item.key] : orderInfo.invoice?.[item.key] || form[item.key] || ''} : <>{item.type === 'checkbox' && - onChangeItemCheck()} > + onChangeItemCheck('individual')} > 个人/非企业单位 - + onChangeItemCheck('unit')} > 企业 @@ -173,11 +310,20 @@ function InvoiceInfo (props) { } - - setState((draft) => { - draft.visible = true - })} className={classNames("btn", { "btn-disabled": true })}>提交申请 - + {!showDetail ? + { + handSubmitInvoice() + // setState((draft) => { + // draft.visible = true + // }) + }} className={classNames("btn", { "btn-disabled": !form.title || !form.content || !form.email })}>提交申请 + : orderInfo.is_invoiced == 1 && + { + setState((draft) => { + draft.visible = true + }) + }} className={classNames("btn")}>重发发票 + } 抬头类型 - 电子发票 + {form.title === 'unit' ? '企业' : '个人'} 发票抬头 - 电子发票 + {form.content} + + + 税号 + {form.registration_number} } 邮箱地址 - 电子发票 + {form.email} - setState((draft) => { - draft.visible = false - draft.showModal = true - })} className={classNames("btn", { "notop": showDetail })}>提交申请 + 提交申请 - 已超重开发票时限 - 不可操作重开发票 + {/* 已超重开发票时限 + 不可操作重开发票 */} + 提交申请成功,请耐心等待 本页全选 - 下一步 + Taro.navigateTo({ url: '/subpage/pages/trade/invoice-info' })}>下一步 } {/* resolveOrderStatus(order_status), - totalItems: ({ items }) => items.reduce((acc, item) => +item.num + acc, 0), + totalItems: ({ items }) => items?.reduce((acc, item) => +item.num + acc, 0), payment: ({ total_fee }) => (total_fee / 100).toFixed(2), pay_type: 'pay_type', point: 'point', create_date: 'create_date', - order: ({ items }) => - pickBy(items, { - order_id: 'order_id', - item_id: 'item_id', - pic_path: 'pic', - title: 'item_name', - price: ({ item_fee }) => (+item_fee / 100).toFixed(2), - point: 'item_point', - num: 'num' - }) + invoice: ({ invoice }) => invoice ? JSON.parse(invoice) : {}, + id: 'id', + order_id: 'order_id', + status: 'status', + order: ({ order: { orderInfo }, order }) => { + return order.orderInfo ? { + time: formatDateTime(orderInfo.create_time), + tid: orderInfo.order_id, + total_fee: orderInfo.total_fee / 100, + order_id: orderInfo.order_id, + title: orderInfo.title, + invoice: orderInfo.invoice, + is_invoiced: orderInfo.is_invoiced + } : {} + } }) log.debug('[trade list] list fetched and processed: ', nList) this.setState({ - list: [...this.state.list, ...nList, {}, {}, {}, {}, {}, {}, {}, {}] + list: [...this.state.list, ...nList] }) return { total } @@ -130,6 +135,14 @@ export default class InvoiceList extends Component { onChangeItemCheck = (item) => { console.log(item, 'ckeck点击') } + goDetail = (item) => { + Taro.navigateTo({ + url: `/subpage/pages/trade/invoice-info?id=${item.id}`, + success: function (res) { + res.eventChannel?.emit('acceptDataFromOpenerPage', { data: item }) + } + }) + } render () { const { list, page } = this.state @@ -139,18 +152,23 @@ export default class InvoiceList extends Component { {list.map((item, idx) => { return ( - - - {idx + 1}发票金额: - + this.goDetail(item)} key={`invoice_item_${idx}`}> + 商品名称:{item.order?.title} + + + 订单编号:{item.order?.order_id} + 发票金额: + + + 发票类型:电子发票 + 抬头类型:{item.order?.invoice?.title === 'unit' ? '企业' : '个人'} + 申请时间:{item.order?.time || ''} + + + {item.order?.is_invoiced == 1 ? '已开票' : "已申请"} + {/* */} + - 发票类型:电子发票 - 抬头类型:{item.create_date} - 申请时间:{item.create_date || '2023-12-18 10:10'} - - - 已申请 - ) diff --git a/src/subpage/pages/trade/invoice-record.scss b/src/subpage/pages/trade/invoice-record.scss index f4679ca..52787d2 100755 --- a/src/subpage/pages/trade/invoice-record.scss +++ b/src/subpage/pages/trade/invoice-record.scss @@ -4,9 +4,9 @@ .trade-list { &__scroll { // @include page-scroll($tabs-height + $navigate-height + 10px, 0); - @include page-scroll(var(--nav-height), 140px); + @include page-scroll(var(--nav-height), 10px); padding-top: 20px; - padding-bottom: 210px; + padding-bottom: 50px; } } .invoice-item { @@ -15,18 +15,23 @@ box-sizing: border-box; background: #f7f7f7; border-radius: 6px; - display: flex; - align-items: center; - justify-content: space-between; + &-box { + display: flex; + align-items: center; + justify-content: space-between; + } + .icon-qianwang-01 { + font-size: 26px; + } + .right-item { + color: #000; + margin-bottom: 20px; + font-size: 26px; + line-height: 1; + } .right { display: flex; flex-direction: column; - margin-left: 10px; - &-item { - color: #000; - margin-bottom: 20px; - line-height: 1; - } &-item:last-child { margin-bottom: 0; } @@ -36,7 +41,7 @@ display: flex; align-items: center; .txt { - margin-right: 20px; + margin-right: 14px; } } } diff --git a/src/subpages/member/index.js b/src/subpages/member/index.js index 5ea3ab8..c95c3f0 100755 --- a/src/subpages/member/index.js +++ b/src/subpages/member/index.js @@ -452,7 +452,7 @@ function MemberIndex (props) { const { memberConfig } = config - console.log('====config===', config.menu) + // console.log('====config===', config.menu) return ( } isTop> @@ -709,7 +709,7 @@ function MemberIndex (props) { 地址管理 - + 发票管理