From 0a775d67b17400de3bbac4767d5ea25e6f0d14f9 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 06 二月 2023 15:15:00 +0800 Subject: [PATCH] 2023-02-06 --- src/tabviews/custom/components/module/voucher/index.jsx | 505 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 454 insertions(+), 51 deletions(-) diff --git a/src/tabviews/custom/components/module/voucher/index.jsx b/src/tabviews/custom/components/module/voucher/index.jsx index b36187e..82e9e79 100644 --- a/src/tabviews/custom/components/module/voucher/index.jsx +++ b/src/tabviews/custom/components/module/voucher/index.jsx @@ -1,47 +1,77 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Button, Select, Input, DatePicker } from 'antd' -// import { EditOutlined, ToolOutlined, DeleteOutlined, FontColorsOutlined } from '@ant-design/icons' +import { Button, Select, Input, Modal, DatePicker, notification, InputNumber } from 'antd' +import moment from 'moment' +import Api from '@/api' +import Utils from '@/utils/utils.js' import asyncComponent from '@/utils/asyncComponent' -// import MKEmitter from '@/utils/events.js' +import MKEmitter from '@/utils/events.js' import './index.scss' +const { confirm } = Modal +const { TextArea } = Input const VoucherTable = asyncComponent(() => import('./voucherTable')) class VoucherModule extends Component { static propTpyes = { - BID: PropTypes.any, // 鐖剁骇Id config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 } state = { BID: '', - type: '', + type: 'createVoucher', config: null, loading: false, - data: null, - searchkey: null, - disableAdd: true, - disableSave: true, - typeOptions: [] + data: [], + tbdata: [], + typeOptions: [], + charType: '', + charName: '', + charInt: '', + vouDate: null, + book: null, + username: sessionStorage.getItem('User_Name'), + remark: '', + remarkVisible: false, + attachments: 0, + title: '', + delItems: [], + status: '' // 鏂板缓鏃讹紝empty銆乧hange銆乻aved } UNSAFE_componentWillMount () { - const { config, BID } = this.props + const { config } = this.props + + let BID = '' + let BData = '' + + if (config.wrap.supModule) { + BData = window.GLOB.CacheData.get(config.wrap.supModule) + } else { + BData = window.GLOB.CacheData.get(config.$pageId) + } + if (BData) { + BID = BData.$BID || '' + } + + window.GLOB.CacheVoucher.delete(config.uuid) + let type = config.wrap.type || 'createVoucher' this.setState({ config: fromJS(config).toJS(), + type: type, BID: BID || '', - type: config.wrap.type + status: 'empty', + book: window.GLOB.CacheData.get(config.wrap.supBook) || null }, () => { - this.loadData() + this.getVoucher() }) } componentDidMount () { - + MKEmitter.addListener('resetSelectLine', this.resetParentParam) } shouldComponentUpdate (nextProps, nextState) { @@ -55,73 +85,446 @@ this.setState = () => { return } + + MKEmitter.removeListener('resetSelectLine', this.resetParentParam) + } + + resetParentParam = (MenuID, id, data) => { + const { config } = this.state + + if (config.wrap.supBook === MenuID) { + let month = data.months + let vouDate = moment() + + if (month && month < moment().format('YYYY-MM')) { + vouDate = moment(month, 'YYYY-MM').endOf('month') + } + + this.setState({ book: data, vouDate }, () => { + this.loadData() + }) + return + } + + if (!config.wrap.supModule || config.wrap.supModule !== MenuID) return + if (id !== this.state.BID || id !== '') { + this.setState({ BID: id, BData: data }, () => { + this.getVoucher() + }) + } } loadData = () => { + const { book, config } = this.state + if (!book) return + + let param = { + func: 's_get_fcc_account_data', + // account_code: book.account_code || '', + fcc_date: book.months ? book.months + '-01' : moment().format('YYYY-MM-DD'), + BID: book.id + } + + Api.genericInterface(param).then(res => { + if (!res.status) { + notification.warning({ + top: 92, + message: res.message, + duration: 5 + }) + return + } + + let typeOptions = res.char || [] + + this.setState({ + typeOptions: typeOptions, + charType: typeOptions[0] ? typeOptions[0].voucher_class : '', + charName: typeOptions[0] ? typeOptions[0].voucher_char : '', + charInt: typeOptions[0] ? typeOptions[0].voucher_char_int : '', + }) + + let names = {} + let supplier = [] + let customer = [] + let department = [] + let project = [] + let inventory = [] + let employee = [] + let cash_flow = [] + + res.sup && res.sup.forEach(item => { + names[item.sup_type_code] = item.sup_type_name + }) + + res.supplier && res.supplier.forEach(item => { + supplier.push({value: item.suppliercode, label: item.suppliername}) + }) + + res.customer && res.customer.forEach(item => { + customer.push({value: item.customercode, label: item.customername}) + }) + + res.co_pro && res.co_pro.forEach(item => { + department.push({value: item.co_pro_code, label: item.co_pro_name}) + }) + + res.pm && res.pm.forEach(item => { + project.push({value: item.projectcode, label: item.projectname}) + }) + + res.materiel && res.materiel.forEach(item => { + inventory.push({value: item.productcode, label: item.productname}) + }) + + res.workers && res.workers.forEach(item => { + employee.push({value: item.workercode, label: item.workername}) + }) + + res.cash_flow && res.cash_flow.forEach(item => { + cash_flow.push({value: item.cash_flow_code, label: item.cash_flow_name}) + }) + + let message = { + subjects: res.subjects || [], + names: names, + supplier: supplier, + customer: customer, + department: department, + project: project, + inventory: inventory, + currency: res.currency || [], + employee: employee, + cash_flow: cash_flow, + orgcode: res.orgcode, + orgname: res.orgname, + account_code: res.account_code, + account_year_code: res.account_year_code + } + + window.GLOB.CacheVoucher.set(config.uuid, message) + }) } - triggeradd = () => { + getVoucher = () => { + const { BID, type } = this.state + + if (!BID || type === 'createVoucher' || type === 'createTemp') return + + let param = { + func: 's_get_fcc_voucher', + BID: BID + } + + let data = [ + {remark: '鎻愮幇', subjectscode: '1001', subjectsname: '搴撳瓨鐜伴噾', debtor: 124, creditor: ''}, + {remark: '璐叆鍥哄畾璧勪骇', subjectscode: '1001', subjectsname: '搴撳瓨鐜伴噾', debtor: '', creditor: 124}, + {remark: '杞粨閿�鍞垚鏈�', subjectscode: '1001', subjectsname: '搴撳瓨鐜伴噾', debtor: -524, creditor: ''}, + {remark: '鎻愮幇', subjectscode: '1001', subjectsname: '搴撳瓨鐜伴噾', debtor: 34, creditor: '', i: Math.random()}, + ] + + Api.genericInterface(param).then(res => { + if (!res.status) { + notification.warning({ + top: 92, + message: res.message, + duration: 5 + }) + return + } + + this.setState({ + data: data, + tbdata: fromJS(data).toJS() + }) + }) + } + + triggersave = (t) => { + const { tbdata, delItems } = this.state + + let err = '' + let tip = '' + let list = [] + let _Items = [...delItems] + + tbdata.forEach((line, index) => { + if (err) return + if (line.type === 'total') { + if (line.debtor !== line.creditor) { + err = '鍊熻捶涓嶅钩琛★紒' + } + return + } + + let _index = index + 1 + + if (!line.remark && !line.subjectscode && !line.debtor && line.debtor !== 0 && !line.creditor && line.creditor !== 0) { + if (_index === 1) { + err = '绗�1琛屼笉鍙负绌恒��' + } else if (line.$origin) { + _Items.push(line) + } + + return + } + + if (!line.remark) { + err = `绗�${_index}琛岋紝鎽樿涓嶅彲涓虹┖銆俙 + } else if (!line.subjectscode) { + err = `绗�${_index}琛岋紝绉戠洰涓嶅彲涓虹┖銆俙 + } else if (!line.debtor && line.debtor !== 0 && !line.creditor && line.creditor !== 0) { + err = `绗�${_index}琛岋紝璇疯緭鍏ラ噾棰濄�俙 + } else if (line.debtor === 0 || line.creditor === 0) { + err = `绗�${_index}琛岋紝閲戦涓嶈兘涓�0銆俙 + } else if (line.foreign_currency_type === 'Y' && !line.origin) { + err = `绗�${_index}琛岋紝鍘熷竵涓嶅彲涓虹┖鎴栦负0銆俙 + } else if (line.sup_accounting) { + line.sup_accounting.split(',').forEach(item => { + if (!line[item]) { + err = `绗�${_index}琛岋紝璇烽�夋嫨杈呭姪鏍哥畻銆俙 + } + }) + } + + if (line.count_type === 'Y' && !err) { + if (!line.count) { + tip += `绗�${_index}琛岋紝鏁伴噺涓虹┖鎴栦负0锛侊紱` + } else if (line.price) { + if (line.debtor && line.debtor !== line.count * line.price) { + tip += `绗�${_index}琛岋紝鏁伴噺鍜岄噾棰濅笉鍖归厤锛侊紱` + } else if (line.creditor && line.creditor !== line.count * line.price) { + tip += `绗�${_index}琛岋紝鏁伴噺鍜岄噾棰濅笉鍖归厤锛侊紱` + } + } + } + + list.push(line) + }) + + if (!err && list.length === 0) { + err = '绗�1琛屼笉鍙负绌恒��' + } + + if (err) { + notification.warning({ + top: 92, + message: err, + duration: 5 + }) + return + } + + if (tip) { + const _this = this + confirm({ + content: tip + '纭瑕佷繚瀛樺悧锛�', + onOk() { + _this.voucherSave(list, _Items, t) + }, + onCancel() {} + }) + } else { + this.voucherSave(list, _Items, t) + } + } + + voucherSave = (list, items, t) => { + const { config, charInt, charType, vouDate, book, remark, charName, attachments, title } = this.state + + if (!book) { + notification.warning({ + top: 92, + message: '璇烽�夋嫨璐﹀锛�', + duration: 5 + }) + return + } + + let message = window.GLOB.CacheVoucher.get(config.uuid) || {} + + let param = { + func: 's_fcc_voucher_addupt', + BID: book.id, + ID: Utils.getguid(), + voucher_code: '', + voucher_text: title, + remark: remark, + account_year_code: book.account_year_code || '', + voucher_type: config.wrap.voucherType || '', + voucher_type_text: config.wrap.voucherTypeText || '', + orgcode: message.orgcode || '', + orgname: message.orgname || '', + voucher_class: charType, + years: book.years, + business_type: config.wrap.businessType || '', + voucher_sign: config.wrap.voucherSign || '', + voucher_char: charName, + voucher_char_int: charInt, + account_code: book.account_code || '', + fibvoucherdate: moment(vouDate).format('YYYY-MM-DD'), + UserName: sessionStorage.getItem('User_Name') || '', + FullName: sessionStorage.getItem('Full_Name') || '', + attachments_int: attachments, + sup_data: '', + subject_data: '' + } + + // subject_id,subject_voucher_code,voucher_lp,subject_code,subject_name + // ,subject_voucher_text,fcc_count,net_unitprice,unit,net_amount,direction_type + // ,exratecode,exratename,unitratio,sup_accounting ,direction_type_count,src_amount,deleted,local_exratecode + + // sup_id,sup_voucher_code,sup_voucher_lp,voucher_sup_lp,sup_subject_code,sup_subject_name,sup_voucher_text,sup_direction_type,sup_net_amount,customercode,customername,suppliercode,suppliername,co_pro_code,co_pro_name,workercode,workername,project_code,project_name,productcode,productname,cash_flow_code,cash_flow_name,sup_acc_code_01,sup_acc_name_01,sup_acc_code_02,sup_acc_name_02,sup_acc_code_03,sup_acc_name_03,sup_acc_code_04,sup_acc_name_04,sup_acc_code_05,sup_acc_name_05,sup_acc_code_06,sup_acc_name_06,sup_acc_code_07,sup_acc_name_07,sup_acc_code_08,sup_acc_name_08,sup_acc_code_09,sup_acc_name_09,sup_acc_code_10,sup_acc_name_10,sup_bid + + let sup_data = [] - } + let subject_data = list.map(item => { + let count = item.count_type === 'Y' + let curr = item.foreign_currency_type === 'Y' + if (item.sup_accounting) { + item.sup_accounting.split(',').forEach(n => { + + }) + } + sup_data.push(`${item.uuid},sup_voucher_code,sup_voucher_lp,voucher_sup_lp,sup_subject_code,sup_subject_name,sup_voucher_text,sup_direction_type,sup_net_amount,customercode,customername,suppliercode,suppliername,co_pro_code,co_pro_name,workercode,workername,project_code,project_name,productcode,productname,cash_flow_code,cash_flow_name,sup_acc_code_01,sup_acc_name_01,sup_acc_code_02,sup_acc_name_02,sup_acc_code_03,sup_acc_name_03,sup_acc_code_04,sup_acc_name_04,sup_acc_code_05,sup_acc_name_05,sup_acc_code_06,sup_acc_name_06,sup_acc_code_07,sup_acc_name_07,sup_acc_code_08,sup_acc_name_08,sup_acc_code_09,sup_acc_name_09,sup_acc_code_10,sup_acc_name_10,sup_bid`) + return `${item.uuid},'','','${item.subjectscode}','${item.subjectsname}','${item.remark}',${count ? item.count || 0 : 0},${count ? item.price || 0 : 0},'${item.unit}',${item.debtor || item.creditor},'${item.debtor ? 'debit' : 'credit'}','${curr ? item.exratecode : '01010001'}','${curr ? item.exratename : 'CNY'}',${curr ? item.unitratio || 0 : 0},'${item.sup_accounting}',${item.debtor ? 1 : -1},${curr ? item.origin || 0 : 0},0,'${item.local_currency || ''}'` + }) - triggersave = () => { + items.forEach(item => { + let count = item.count_type === 'Y' + let curr = item.foreign_currency_type === 'Y' + subject_data.push(`${item.uuid},'','','${item.subjectscode}','${item.subjectsname}','${item.remark}',${count ? item.count || 0 : 0},${count ? item.price || 0 : 0},'${item.unit}',${item.debtor || item.creditor},'${item.debtor ? 'debit' : 'credit'}','${curr ? item.exratecode : '01010001'}','${curr ? item.exratename : 'CNY'}',${curr ? item.unitratio || 0 : 0},'${item.sup_accounting}',${item.debtor ? 1 : -1},${curr ? item.origin || 0 : 0},1,'${item.local_currency || ''}'`) + }) + param.subject_data = window.btoa(window.encodeURIComponent(subject_data.join(';un'))) + + if (param) { + return + } + + Api.genericInterface(param).then(res => { + if (!res.status) { + notification.warning({ + top: 92, + message: res.message, + duration: 5 + }) + return + } + + if (t === 'add') { + this.setState({ + status: 'empty', + remark: '', + tbdata: [], + delItems: [], + charInt: charInt + 1 + }) + MKEmitter.emit('cleartable', config.uuid) + } else { + this.setState({ + status: 'saved', + delItems: [], + }) + } + }) } triggerprint = () => { + this.setState({remarkVisible: true}) + } + remarkSubmit = () => { + const { config } = this.state + let node = document.getElementById(config.uuid + 'remark') + let val = node.value + + if (val && val.length > 512) { + notification.warning({ + top: 92, + message: '褰撳墠鍐呭瓒呴暱锛屽娉ㄦ渶澶�512涓瓧绗︺��', + duration: 5 + }) + return + } + this.setState({remark: val, remarkVisible: false}) + } + + dataChange = (data, item) => { + if (item) { + this.setState({ + status: 'change', + tbdata: data, + delItems: [...this.state.delItems, item] + }) + } else { + this.setState({ + status: 'change', + tbdata: data + }) + } + } + + changeAttach = (val) => { + let _val = val + + if (isNaN(val) || val < 0) { + _val = 0 + } else { + _val = parseInt(val) + } + + this.setState({attachments: _val}) } render() { - const { config, disableSave, disableAdd, typeOptions, data, type } = this.state + const { type, status, loading, config, typeOptions, charType, charInt, data, vouDate, username, remark, remarkVisible, attachments, title } = this.state return ( <div className="menu-voucher-wrap" style={config.style}> - <div className="voucher-header"> - <Button className="system-background header-btn" disabled={disableAdd} onClick={this.triggeradd}>鏂板</Button> - <Button className="system-background header-btn" disabled={disableSave} onClick={this.triggersave}>淇濆瓨</Button> - <Button className="system-background header-btn" disabled={disableSave} onClick={this.triggerprint}>鎵撳嵃</Button> - <Button className="system-background header-btn" disabled={disableSave} onClick={this.triggerprint}>瀵煎叆</Button> - <Button className="system-background header-btn" disabled={disableSave} onClick={this.triggerprint}>瀵煎嚭</Button> - </div> - {type === 'edit' ? <div className="voucher-body"> - <div className="pre-wrap"> + {type === 'createVoucher' ? <div className="voucher-header"> + <Button className="add-background header-btn" disabled={status === 'empty'} onClick={() => this.triggersave('add')}>淇濆瓨骞舵柊澧�</Button> + <Button className="add-background header-btn" disabled={status === 'empty' || status === 'saved'} onClick={() => this.triggersave()}>淇濆瓨</Button> + <Button className="print-background header-btn" disabled={status !== 'saved'} onClick={this.triggerprint}>鎵撳嵃</Button> + <Button className="out-background header-btn" onClick={this.triggerprint}>鏇村</Button> + </div> : null} + <div className="voucher-body"> + {type === 'createVoucher' ? <div className="pre-wrap"> <div className="voucher-code"> - <Select> + <Select value={charType} dropdownClassName="mk-vcode-dropdown" onChange={(val, option) => this.setState({charType: val, charName: option.props.charName, charInt: option.props.charint})}> {typeOptions.map(option => - <Select.Option value={option.value}>{option.label}</Select.Option> + <Select.Option key={option.voucher_char_int} value={option.voucher_class} charName={option.voucher_char} charint={option.voucher_char_int}>{option.voucher_char}</Select.Option> )} </Select> - <Input autoComplete="off" /> 鍙� + <InputNumber precision={0} min={1} value={charInt} autoComplete="off" onChange={(val) => this.setState({charInt: val})}/> 鍙� </div> <div className="voucher-date"> - 鏃ユ湡锛�<DatePicker onChange={this.onChange}/> + 鏃ユ湡锛�<DatePicker value={vouDate} onChange={(val) => this.setState({vouDate: val})}/> + </div> + <div className="voucher-text"> + <Input value={title} placeholder="鍑瘉鏂囨湰" autoComplete="off" onChange={(e) => this.setState({title: e.target.value})}/> </div> <div className="voucher-affix"> - 闄勫崟鎹� <Input autoComplete="off" /> 寮� + 闄勫崟鎹� <InputNumber precision={0} value={attachments || 0} autoComplete="off" onChange={this.changeAttach}/> 寮� <Button type="link" className="" onClick={this.triggerprint}>闄勪欢</Button> <Button type="link" className="" onClick={this.triggerprint}>澶囨敞</Button> </div> - </div> - <VoucherTable config={config} data={data}/> - </div> : null} - {type === 'check' ? <div className="voucher-body"> - <div className="pre-wrap"> - <div className="voucher-code"> - 璁� 1 鍙� - </div> - <div className="voucher-date"> - 鏃ユ湡锛�2022-02-24 - </div> - <div className="voucher-affix"> - 闄勫崟鎹� 2 寮� - <Button type="link" className="" onClick={this.triggerprint}>闄勪欢</Button> - <Button type="link" className="" onClick={this.triggerprint}>澶囨敞</Button> - </div> - </div> - <VoucherTable config={config} data={data}/> - </div> : null} + </div> : null} + <VoucherTable config={config} loading={loading} data={data} onChange={this.dataChange}/> + </div> + <div className="user">鍒跺崟浜猴細{username}</div> + <Modal + title="澶囨敞" + visible={remarkVisible} + width={700} + maskClosable={false} + onOk={this.remarkSubmit} + onCancel={() => { this.setState({ remarkVisible: false })}} + destroyOnClose + > + <TextArea id={config.uuid + 'remark'} defaultValue={remark} rows={6}/> + </Modal> </div> ) } -- Gitblit v1.8.0