From 7cec485c9dfa5cab36daa63670df3ed1bbf01d89 Mon Sep 17 00:00:00 2001 From: Haiyi <1021441632@qq.com> Date: Thu, 8 Dec 2022 15:11:17 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix(ID1000933):=E9=94=80?= =?UTF-8?q?=E5=94=AE=E7=A0=81=E5=8D=95=E6=B2=A1=E6=9C=89=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=B0=8F=E8=AE=A1=E9=87=91=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/SaleCodeList/index.tsx | 316 +++++++++++++------------- src/pages/orderDetails/index.tsx | 10 +- 2 files changed, 168 insertions(+), 158 deletions(-) diff --git a/src/components/SaleCodeList/index.tsx b/src/components/SaleCodeList/index.tsx index 30f8ef9..b1b8823 100644 --- a/src/components/SaleCodeList/index.tsx +++ b/src/components/SaleCodeList/index.tsx @@ -1,172 +1,178 @@ -import { ScrollView, View, Image } from '@tarojs/components' -import { memo, useCallback, useEffect, useMemo, useState, useRef } from 'react' -import styles from './index.module.scss' +import { Image, ScrollView, View } from '@tarojs/components' +import Taro from '@tarojs/taro' +import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react' import classnames from 'classnames' +import styles from './index.module.scss' // import BottomBtns from '@/components/BottomBtns' import { formatPriceDiv } from '@/common/format' -import Taro from '@tarojs/taro' import Popup from '@/components/popup' import useCheckAuthorize from '@/use/useCheckAuthorize' import { alert } from '@/common/common' -import { GetPayCode } from "@/api/order" -import { formatWeightDiv, formatDateTime } from '@/common/format' +import { GetPayCode } from '@/api/order' +import { formatDateTime, formatWeightDiv } from '@/common/format' import { PAY_H5_CODE_URL } from '@/common/constant' + interface Props { - obj: any, - // picUrl?: string, - showPopup: boolean, - popupClose: () => void + obj: any + // picUrl?: string, + showPopup: boolean + popupClose: () => void } -export default memo((props: Props) => { +const codeList = (props: Props) => { + const { fetchData: payFetch } = GetPayCode() + const [PicUrl, setPicUrl] = useState('') + useEffect(() => { + // 判断进来的是否是空对象,减少性能问题 + const length = Object.keys(props.obj) + if (length.length > 0) { getPic() } + }, [props.obj]) - const { fetchData: payFetch } = GetPayCode() - const [PicUrl, setPicUrl] = useState('') - useEffect(() => { - //判断进来的是否是空对象,减少性能问题 - var length = Object.keys(props.obj); - if (length.length > 0) getPic() - }, [props.obj]) - - const getPic = async () => { - Taro.showLoading({ - title: '请稍等...', - mask: true - }) - const list: any = []; - props.obj.product_list?.forEach((item) => { - item.product_colors.forEach((it) => { - list.push({ - product_code: item.code, - product_name: item.name, - product_color_code: it.code, - product_color_name: it.name, - num: it.roll.toString(), - weight: formatWeightDiv(it.label_weight).toString(), - deduction_weight: formatWeightDiv(it.deductions_weight).toString(), - settle_weight: formatWeightDiv(it.settle_weight).toString(), - deduction_amount: (it.deductions_amount / 100).toString(), - sale_price: (it.sale_price / 100).toString(), - total_price: (it.estimate_amount / 100).toString(), - length: (it.length / 100).toString(), - weight_error: formatWeightDiv(it.settle_weight_error).toString(), - }); - }); - }); - const query = { - list: list, - title: "面料销售电子确认单", - show_qrcode: true, - show_barcode: true, - show_wait_pay_amount: true, - order_type: props.obj.sale_mode_name, - shipment_mode: props.obj.shipment_mode_name, - company: props.obj.title_purchaser_name, - sale_user: props.obj.sale_user_name, - order_created_time: formatDateTime(props.obj.create_time), - order_no: props.obj.order_no, - target_user_name: props.obj.target_user_name, - target_address: props.obj.address_detail, - target_description: props.obj.remark, - pay_account: props.obj.transfer_remittance_account, - bank_account_name: props.obj.account_name, - bank_name: props.obj.bank_of_deposit, - pay_type: props.obj.settle_mode_name, - client: props.obj.purchaser_name, - phone: props.obj.target_user_phone, - order_total_length: (props.obj.total_number / 100).toString(), - order_total_price: ( - props.obj.bill_total_sale_price / 100 - ).toString(), - total_weight_error_discount: ( - props.obj.total_weight_error_discount / 100 - ).toString(), - order_total_num: props.obj.total_number.toString(), - qrcode: `${PAY_H5_CODE_URL}?sale_order_no=${props.obj.order_no}`, - order_total_weight: (props.obj.total_weight / 1000).toString(), - estimate_amount: (props.obj.estimate_amount / 100).toString(), - total_sale_price: (props.obj.total_sale_price / 100).toString(), - show_total_sale_price: true, - show_total_weight_error_discount: true, - actual_amount: (props.obj.actual_amount / 100).toString(), - wait_pay_amount: (props.obj.wait_pay_amount / 100).toString(), - order_total_weight_error: ( - props.obj.total_weight_error / 1000 - ).toString(), - }; - const res = await payFetch(query) - if (res.data) { - setPicUrl(res.data.base64) - Taro.hideLoading() - } - } - - const fileData = useRef({ - filePath: '', - base64: '', + const getPic = async() => { + Taro.showLoading({ + title: '请稍等...', + mask: true, }) - - //预览图片 - const showImage = () => { - const time = new Date().valueOf() - const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(PicUrl) || [] - let filePath = Taro.env.USER_DATA_PATH + '/img' + time + '.' + format - fileData.current.filePath = filePath - fileData.current.base64 = bodyData - const save = Taro.getFileSystemManager() - save.writeFile({ - filePath: fileData.current.filePath, - data: fileData.current.base64, - encoding: 'base64', - }) - Taro.previewImage({ - current: fileData.current.filePath, // 当前显示 - urls: [fileData.current.filePath], // 需要预览的图片http链接列表 + const list: any = [] + props.obj.product_list?.forEach((item) => { + item.product_colors.forEach((it) => { + list.push({ + product_code: item.code, + product_name: item.name, + product_color_code: it.product_color_code, + product_color_name: it.product_color_name, + num: it.roll.toString(), + weight: formatWeightDiv(it.actual_weight).toString(), + sale_price: (it.sale_price / 100).toString(), + total_price: + it.total_sale_price !== 0 + ? (it.total_sale_price / 100).toString() + : (it.estimate_amount / 100).toString(), + length: (it.length / 100).toString(), + weight_error: formatWeightDiv(it.weight_error).toString(), }) + }) + }) + const query = { + list, + title: '面料销售电子确认单', + show_qrcode: true, + show_barcode: true, + order_type: props?.obj.sale_mode_name, + shipment_mode: props?.obj.shipment_mode_name, + company: props?.obj.title_purchaser_name, + sale_user: props?.obj.sale_user_name, + order_created_time: formatDateTime(props?.obj.create_time), + order_no: props?.obj.order_no, + target_user_name: props?.obj.target_user_name, + target_address: props?.obj.address_detail, + target_description: props?.obj.remark, + pay_account: props?.obj.transfer_remittance_account, + bank_account_name: props?.obj.account_name, + bank_name: props?.obj.bank_of_deposit, + pay_type: props?.obj.settle_mode_name, + client: props?.obj.purchaser_name, + phone: props?.obj.target_user_phone, + order_total_length: (props?.obj.total_number / 100).toString(), + order_total_price: ( + props?.obj.bill_total_sale_price / 100 + ).toString(), + total_weight_error_discount: ( + props?.obj.total_weight_error_discount / 100 + ).toString(), + order_total_num: props?.obj.total_number.toString(), + qrcode: `${PAY_H5_CODE_URL}?sale_order_no=${props?.obj.order_no}`, + order_total_weight: (props?.obj.total_weight / 1000).toString(), + estimate_amount: (props?.obj.estimate_amount / 100).toString(), + total_sale_price: (props?.obj.total_sale_price / 100).toString(), + actual_amount: (props?.obj.actual_amount / 100).toString(), + wait_pay_amount: (props?.obj.wait_pay_amount / 100).toString(), + order_total_weight_error: ( + props?.obj.total_weight_error / 1000 + ).toString(), + show_sale_price: props?.obj?.sale_mode === 0 && props?.obj?.is_display_price ? true : !!((props?.obj?.sale_mode === 1 || props?.obj?.sale_mode === 2)), + show_total_price: props?.obj?.sale_mode === 0 && props?.obj?.is_display_price ? true : !!((props?.obj?.sale_mode === 1 || props?.obj?.sale_mode === 2)), + show_estimate_amount: props?.obj?.sale_mode === 0 && props?.obj?.is_display_price ? true : !!((props?.obj?.sale_mode === 1 || props?.obj?.sale_mode === 2)), + show_total_sale_price: props?.obj?.sale_mode === 0 && props?.obj?.is_display_price ? true : !!((props?.obj?.sale_mode === 1 || props?.obj?.sale_mode === 2)), + show_total_weight_error_discount: props?.obj?.sale_mode === 0 && props?.obj?.is_display_price ? true : !!((props?.obj?.sale_mode === 1 || props?.obj?.sale_mode === 2)), + show_actual_amount: props?.obj?.sale_mode === 0 && props?.obj?.is_display_price ? true : !!((props?.obj?.sale_mode === 1 || props?.obj?.sale_mode === 2)), + show_wait_pay_amount: props?.obj?.sale_mode === 0 && props?.obj?.is_display_price ? true : !!((props?.obj?.sale_mode === 1 || props?.obj?.sale_mode === 2)), } - - //检查是否开启保存图片权限 - const { check } = useCheckAuthorize({ scope: 'scope.writePhotosAlbum', msg: '您没授权,无法保存图片' }) - const saveImageCheck = async () => { - const res = await check() - res && saveImage() + const res = await payFetch(query) + if (res.data) { + setPicUrl(res.data.base64) + Taro.hideLoading() } + } - //保存图片 - const saveImage = () => { - const time = new Date().valueOf() - const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(PicUrl) || [] - let filePath = Taro.env.USER_DATA_PATH + '/img' + time + '.' + format - fileData.current.filePath = filePath - fileData.current.base64 = bodyData - const save = Taro.getFileSystemManager() - save.writeFile({ - filePath: fileData.current.filePath, - data: fileData.current.base64, - encoding: 'base64', - }) - alert.loading('正在保存图片') - Taro.saveImageToPhotosAlbum({ - filePath: fileData.current.filePath, - success: function () { - alert.success('图片保存成功') - }, - fail: function (err) { - console.log('err::', err) - }, - }) - } + const fileData = useRef({ + filePath: '', + base64: '', + }) - return ( - props.popupClose?.()}> - - - - showImage()}> - - - saveImageCheck()}>保存图片 - - - ) -}) \ No newline at end of file + // 预览图片 + const showImage = () => { + const time = new Date().valueOf() + const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(PicUrl) || [] + const filePath = `${Taro.env.USER_DATA_PATH}/img${time}.${format}` + fileData.current.filePath = filePath + fileData.current.base64 = bodyData + const save = Taro.getFileSystemManager() + save.writeFile({ + filePath: fileData.current.filePath, + data: fileData.current.base64, + encoding: 'base64', + }) + Taro.previewImage({ + current: fileData.current.filePath, // 当前显示 + urls: [fileData.current.filePath], // 需要预览的图片http链接列表 + }) + } + + // 检查是否开启保存图片权限 + const { check } = useCheckAuthorize({ scope: 'scope.writePhotosAlbum', msg: '您没授权,无法保存图片' }) + const saveImageCheck = async() => { + const res = await check() + res && saveImage() + } + + // 保存图片 + const saveImage = () => { + const time = new Date().valueOf() + const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(PicUrl) || [] + const filePath = `${Taro.env.USER_DATA_PATH}/img${time}.${format}` + fileData.current.filePath = filePath + fileData.current.base64 = bodyData + const save = Taro.getFileSystemManager() + save.writeFile({ + filePath: fileData.current.filePath, + data: fileData.current.base64, + encoding: 'base64', + }) + alert.loading('正在保存图片') + Taro.saveImageToPhotosAlbum({ + filePath: fileData.current.filePath, + success() { + alert.success('图片保存成功') + }, + fail(err) { + console.log('err::', err) + }, + }) + } + + return ( + props.popupClose?.()}> + + + + showImage()}> + + + saveImageCheck()}>保存图片 + + + ) +} + +export default memo(codeList) diff --git a/src/pages/orderDetails/index.tsx b/src/pages/orderDetails/index.tsx index 9f861f1..c13f8ae 100644 --- a/src/pages/orderDetails/index.tsx +++ b/src/pages/orderDetails/index.tsx @@ -503,7 +503,6 @@ const OrderDetails = () => { title: '面料销售电子确认单', show_qrcode: true, show_barcode: true, - show_wait_pay_amount: true, order_type: infoObj.sale_mode_name, shipment_mode: infoObj.shipment_mode_name, company: infoObj.title_purchaser_name, @@ -531,13 +530,18 @@ const OrderDetails = () => { order_total_weight: (infoObj.total_weight / 1000).toString(), estimate_amount: (infoObj.estimate_amount / 100).toString(), total_sale_price: (infoObj.total_sale_price / 100).toString(), - show_total_sale_price: true, - show_total_weight_error_discount: true, actual_amount: (infoObj.actual_amount / 100).toString(), wait_pay_amount: (infoObj.wait_pay_amount / 100).toString(), order_total_weight_error: ( infoObj.total_weight_error / 1000 ).toString(), + show_sale_price: infoObj?.sale_mode === 0 && infoObj?.is_display_price ? true : !!((infoObj?.sale_mode === 1 || infoObj?.sale_mode === 2)), + show_total_price: infoObj?.sale_mode === 0 && infoObj?.is_display_price ? true : !!((infoObj?.sale_mode === 1 || infoObj?.sale_mode === 2)), + show_estimate_amount: infoObj?.sale_mode === 0 && infoObj?.is_display_price ? true : !!((infoObj?.sale_mode === 1 || infoObj?.sale_mode === 2)), + show_total_sale_price: infoObj?.sale_mode === 0 && infoObj?.is_display_price ? true : !!((infoObj?.sale_mode === 1 || infoObj?.sale_mode === 2)), + show_total_weight_error_discount: infoObj?.sale_mode === 0 && infoObj?.is_display_price ? true : !!((infoObj?.sale_mode === 1 || infoObj?.sale_mode === 2)), + show_actual_amount: infoObj?.sale_mode === 0 && infoObj?.is_display_price ? true : !!((infoObj?.sale_mode === 1 || infoObj?.sale_mode === 2)), + show_wait_pay_amount: infoObj?.sale_mode === 0 && infoObj?.is_display_price ? true : !!((infoObj?.sale_mode === 1 || infoObj?.sale_mode === 2)), } const res = await payFetch(query) if (res.data) {