From 90fff0ec484bbb3a10248f389cb9c4bddeff93ed Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 31 一月 2023 18:10:44 +0800 Subject: [PATCH] 2023-01-31 --- src/tabviews/custom/components/module/voucher/index.jsx | 237 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 192 insertions(+), 45 deletions(-) diff --git a/src/tabviews/custom/components/module/voucher/index.jsx b/src/tabviews/custom/components/module/voucher/index.jsx index a36f5ef..ca3cc7b 100644 --- a/src/tabviews/custom/components/module/voucher/index.jsx +++ b/src/tabviews/custom/components/module/voucher/index.jsx @@ -1,7 +1,7 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Button, Select, Input, DatePicker, notification } from 'antd' +import { Button, Select, Input, Modal, DatePicker, notification } from 'antd' import moment from 'moment' import Api from '@/api' @@ -9,6 +9,7 @@ import MKEmitter from '@/utils/events.js' import './index.scss' +const { confirm } = Modal const VoucherTable = asyncComponent(() => import('./voucherTable')) class VoucherModule extends Component { @@ -18,18 +19,18 @@ state = { BID: '', + type: 'createVoucher', config: null, loading: false, data: [], - disableAdd: false, - disableSave: false, + tbdata: [], typeOptions: [], charType: '', charInt: '', vouDate: null, book: null, username: sessionStorage.getItem('User_Name'), - change: false + status: '' // 鏂板缓鏃讹紝empty銆乧hange銆乻aved } UNSAFE_componentWillMount () { @@ -48,13 +49,16 @@ } window.GLOB.CacheVoucher.delete(config.uuid) + let type = config.wrap.type || 'createVoucher' this.setState({ config: fromJS(config).toJS(), + type: type, BID: BID || '', + status: 'empty', book: window.GLOB.CacheData.get(config.wrap.supBook) || null }, () => { - this.loadData() + this.getVoucher() }) } @@ -97,7 +101,7 @@ if (!config.wrap.supModule || config.wrap.supModule !== MenuID) return if (id !== this.state.BID || id !== '') { this.setState({ BID: id, BData: data }, () => { - this.loadData() + this.getVoucher() }) } } @@ -185,15 +189,19 @@ } window.GLOB.CacheVoucher.set(config.uuid, message) - - setTimeout(() => { - this.getVoucher() - }, 200) }) } - 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}, @@ -201,37 +209,192 @@ {remark: '鎻愮幇', subjectscode: '1001', subjectsname: '搴撳瓨鐜伴噾', debtor: 34, creditor: '', i: Math.random()}, ] - this.setState({ - data: data + 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() + }) }) } - triggeradd = () => { - + triggersave = (t) => { + const { tbdata } = this.state + + let err = '' + let tip = '' + let list = [] + + 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琛屼笉鍙负绌恒��' + } + 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.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, t) + }, + onCancel() {} + }) + } else { + this.voucherSave(list, t) + } } - triggersave = () => { + voucherSave = (list, t) => { + const { BID, config, charInt, charType, book } = this.state + if (!book) { + notification.warning({ + top: 92, + message: '璇烽�夋嫨璐﹀锛�', + duration: 5 + }) + return + } + + let param = { + func: 's_fcc_voucher_addupt', + BID: BID, + voucher_code: '', + voucher_text: '', + remark: '', + account_year_code: '', + voucher_type: '', + voucher_type_text: '', + orgcode: '', + orgname: '', + voucher_class: '', + years: book.years, + business_type: '', + voucher_sign: '', + voucher_char: charType, + voucher_char_int: charInt, + account_code: book.account_code || '', + fibvoucherdate: '', + UserName: sessionStorage.getItem('User_Name') || '', + FullName: sessionStorage.getItem('Full_Name') || '', + sup_data: '', + subject_data: '' + } + + 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', + tbdata: [], + charInt: charInt + 1 + }) + MKEmitter.emit('cleartable', config.uuid) + } else { + this.setState({ + status: 'saved' + }) + } + }) } triggerprint = () => { } + dataChange = (data) => { + this.setState({ + status: 'change', + tbdata: data + }) + } + render() { - const { config, disableSave, disableAdd, typeOptions, charType, charInt, data, vouDate, username } = this.state + const { type, status, loading, config, typeOptions, charType, charInt, data, vouDate, username } = this.state return ( <div className="menu-voucher-wrap" style={config.style}> - <div className="voucher-header"> - <Button className="add-background header-btn" disabled={disableAdd} onClick={this.triggeradd}>鏂板</Button> - <Button className="add-background header-btn" disabled={disableSave} onClick={this.triggersave}>淇濆瓨</Button> - <Button className="print-background header-btn" disabled={disableSave} onClick={this.triggerprint}>鎵撳嵃</Button> - <Button className="system-background header-btn" disabled={disableSave} onClick={this.triggerprint}>瀵煎叆</Button> - <Button className="out-background header-btn" disabled={disableSave} onClick={this.triggerprint}>瀵煎嚭</Button> - </div> - {config.wrap.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 value={charType} dropdownClassName="mk-vcode-dropdown" onChange={(val, option) => this.setState({charType: val, charInt: option.props.charint})}> {typeOptions.map(option => @@ -248,25 +411,9 @@ <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} - {config.wrap.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> </div> ) -- Gitblit v1.8.0