From 0f7c6320bc66ac7fb8f2b670d8833032d136c17a Mon Sep 17 00:00:00 2001 From: MustangDeng <670124965@qq.com> Date: Thu, 3 Mar 2022 15:28:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E7=A8=8E=E7=A8=8E=E7=8E=87=E8=A1=A8?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=8A=9F=E8=83=BD=E7=BB=93=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pc4mobx/hrmSalary/apis/taxrate.js | 18 ++++- .../hrmSalary/components/EditTable/index.js | 20 ++++-- .../components/slideModalTitle/index.js | 9 ++- .../pages/taxRate/editSlideContent.js | 14 +++- pc4mobx/hrmSalary/pages/taxRate/index.js | 70 ++++++++++++++----- pc4mobx/hrmSalary/stores/taxRate.js | 48 ++++++++++++- 6 files changed, 149 insertions(+), 30 deletions(-) diff --git a/pc4mobx/hrmSalary/apis/taxrate.js b/pc4mobx/hrmSalary/apis/taxrate.js index 6be047c0..6457fc1c 100644 --- a/pc4mobx/hrmSalary/apis/taxrate.js +++ b/pc4mobx/hrmSalary/apis/taxrate.js @@ -8,7 +8,14 @@ export const getTaxRateList = params => { //删除税率表 export const deleteTaxRate = params => { - return WeaTools.callApi('/api/bs/hrmsalary/taxrate/del', 'POST', params); + return fetch('/api/bs/hrmsalary/taxrate/delete', { + method: 'POST', + mode: 'cors', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(params) + }).then(res => res.json()) } //获取新建或者详情表单 @@ -30,5 +37,12 @@ export const saveTaxRate = params => { //编辑税率表 export const updateTaxRate = params => { - return WeaTools.callApi('/api/bs/hrmsalary/taxrate/update', 'POST', params); + return fetch('/api/bs/hrmsalary/taxrate/update', { + method: 'POST', + mode: 'cors', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(params) + }).then(res => res.json()) } diff --git a/pc4mobx/hrmSalary/components/EditTable/index.js b/pc4mobx/hrmSalary/components/EditTable/index.js index 761c519a..06611a74 100644 --- a/pc4mobx/hrmSalary/components/EditTable/index.js +++ b/pc4mobx/hrmSalary/components/EditTable/index.js @@ -12,15 +12,18 @@ export class EditableCell extends React.Component { this.props.onChange(value); } render() { - const { value, editable } = this.state; + const { value } = this.state; + const { editable } = this.props; return (
- + { + editable ? : value + }
@@ -40,6 +43,7 @@ export default class EditableTable extends React.Component { value={text} record={record} onChange={this.onCellChange(record.indexNum, item.dataIndex)} + editable={this.props.editable} /> ) } @@ -64,6 +68,7 @@ export default class EditableTable extends React.Component { ) } @@ -93,11 +98,14 @@ export default class EditableTable extends React.Component { } render() { const columns = this.columns; + const { editable } = this.props; return (
-
+ { + editable &&
{ this.props.addItem() }} />
+ } ); diff --git a/pc4mobx/hrmSalary/components/slideModalTitle/index.js b/pc4mobx/hrmSalary/components/slideModalTitle/index.js index d3245b13..dbf7d256 100644 --- a/pc4mobx/hrmSalary/components/slideModalTitle/index.js +++ b/pc4mobx/hrmSalary/components/slideModalTitle/index.js @@ -3,6 +3,11 @@ import { Button } from 'antd'; import "./index.less" export default class SlideModalTitle extends React.Component { + componentWillMount() { // 初始化渲染页面 + this.state = { + editable: this.props.editable === undefined ? "true": this.props.editable + } + } render() { return
@@ -12,7 +17,9 @@ export default class SlideModalTitle extends React.Component {
{this.props.subtitle}
- + { + this.state.editable && + }
diff --git a/pc4mobx/hrmSalary/pages/taxRate/editSlideContent.js b/pc4mobx/hrmSalary/pages/taxRate/editSlideContent.js index 47641c3a..74c4a182 100644 --- a/pc4mobx/hrmSalary/pages/taxRate/editSlideContent.js +++ b/pc4mobx/hrmSalary/pages/taxRate/editSlideContent.js @@ -19,9 +19,14 @@ let emptyItem = { @inject('taxRateStore') @observer export default class EditSlideContent extends React.Component { - constructor(props) { - super(props); - } + + componentWillMount() { // 初始化渲染页面 + this.state = { + editable: this.props.editable === undefined ? "true": this.props.editable + } + } + + addItem() { const { taxRateStore: {setDataSource}} = this.props; @@ -51,6 +56,7 @@ export default class EditSlideContent extends React.Component { onChange={value => { setNameValue(value) }} + viewAttr={this.props.editable ? 2: 1} /> @@ -66,6 +72,7 @@ export default class EditSlideContent extends React.Component { onChange={value => { setRemarkValue(value) }} + viewAttr={this.props.editable ? 2: 1} /> @@ -77,6 +84,7 @@ export default class EditSlideContent extends React.Component { bordered addItem={() => {this.addItem()}} onDataSourceChange={setDataSource} + editable={this.state.editable} /> diff --git a/pc4mobx/hrmSalary/pages/taxRate/index.js b/pc4mobx/hrmSalary/pages/taxRate/index.js index cec1c81e..af6c117e 100644 --- a/pc4mobx/hrmSalary/pages/taxRate/index.js +++ b/pc4mobx/hrmSalary/pages/taxRate/index.js @@ -2,7 +2,7 @@ import React from 'react'; import { inject, observer } from 'mobx-react'; import { toJS } from 'mobx'; -import { Button, Table, DatePicker } from 'antd'; +import { Button, Table, DatePicker, Modal } from 'antd'; import { WeaTop, WeaTab, WeaRightMenu, WeaRangePicker, WeaInputSearch, WeaSlideModal } from 'ecCom'; import { WeaTableNew } from 'comsMobx'; @@ -26,7 +26,9 @@ export default class TaxRate extends React.Component { super(props); this.state = { value: "", - selectedKey: "0" + selectedKey: "0", + currentOperate: "add", + editable: false, } } @@ -44,7 +46,7 @@ export default class TaxRate extends React.Component { let valueSpan = record[newColumn.dataIndex + "span"] !== undefined ? record[newColumn.dataIndex + "span"] : record[newColumn.dataIndex]; switch(newColumn.dataIndex) { case "name": - return {this.onEdit(record)}} + return {this.onEdit(record, false)}} dangerouslySetInnerHTML={{ __html: valueSpan }} /> default: return
@@ -55,28 +57,60 @@ export default class TaxRate extends React.Component { return newColumns; } - onEdit = (record) => { + onEdit = (record, editable) => { + this.setState({currentOperate: "update", editable: editable}) const {taxRateStore: {setSlideVisiable, emptyForm, getItemInform }} = this.props; emptyForm(); setSlideVisiable(true); getItemInform(record.id) } + handleInsertBtnClick = () => { + const {taxRateStore: {setSlideVisiable, emptyForm }} = this.props; + this.setState({ + currentOperate: "add", + editable: true + }) + emptyForm(); + setSlideVisiable(true) + } + + onOperatesClick = (record, index, operate, flag) => { + const {taxRateStore : {doDelete}} = this.props; + switch(operate.index.toString()){ + case '0': // 编辑 + this.onEdit(record, true); + break; + case "1": // 删除 + Modal.confirm({ + title: "信息确认", + content: "确定删除吗", + onOk() { + doDelete([record.id]) + }, + onCancel() {} + }); + break; + } + }; + render() { const { taxRateStore } = this.props; const { loading, hasRight, form, condition, tableStore, showSearchAd, getTableDatas, doSearch, setShowSearchAd } = taxRateStore; - const { doSave, slideVisiable, setSlideVisiable, emptyForm } = taxRateStore + const { doSave, slideVisiable, setSlideVisiable, emptyForm, doUpdate, doBatchDelete } = taxRateStore + const selectedRowKeys = toJS(tableStore.selectedRowKeys) || []; // tableStore 右侧选中数组 if (!hasRight && !loading) { // 无权限处理 return renderNoright(); } const rightMenu = [// 右键菜单 - { - key: 'BTN_COLUMN', - icon: , - content: '显示列定制', - onClick: this.showColumn - }, + { + key: 'BTN_DEL', + icon: , + content : '批量删除', + disable: selectedRowKeys.length === 0, // 没有选中禁用 + onClick : doBatchDelete, + } ]; const collectParams = { // 收藏功能配置 favname: '个税税率表', @@ -97,8 +131,7 @@ export default class TaxRate extends React.Component { const renderSearchOperationItem = () => { return
{' '}
- } + + return (
@@ -151,12 +186,13 @@ export default class TaxRate extends React.Component { measure={'%'} title={ {doSave()}} + onSave={() => {this.state.currentOperate == "add" ? doSave() : doUpdate()}} + editable={this.state.editable} /> } - content={()} + content={()} onClose={() => setSlideVisiable(false)} showMask={true} closeMaskOnClick={() => setSlideVisiable(false)} /> diff --git a/pc4mobx/hrmSalary/stores/taxRate.js b/pc4mobx/hrmSalary/stores/taxRate.js index e0f3c22b..9cbf3fd7 100644 --- a/pc4mobx/hrmSalary/stores/taxRate.js +++ b/pc4mobx/hrmSalary/stores/taxRate.js @@ -18,6 +18,8 @@ export class taxRateStore { @observable remarkValue = ""; @observable slideVisiable = false; // 侧边划入是否展示 + currentId = ""; // 当前编辑的数据id + @action setSlideVisiable = slideVisiable => this.slideVisiable = slideVisiable; @@ -88,8 +90,8 @@ export class taxRateStore { // 获取表单数据 @action getItemInform = (id) => { + this.currentId= id; API.getTaxRateForm({id}).then(res => { - if(res.status) { let { taxRateBatch, taxRateRecords } = res.data.form this.setNameValue(taxRateBatch.name); @@ -101,4 +103,48 @@ export class taxRateStore { }) } + @action doUpdate = () => { + let params = { + taxRateBatch: { + name: this.nameValue, + description: this.remarkValue, + id: this.currentId + }, + taxRateRecords: this.dataSource + } + API.updateTaxRate(params).then(res => { + if(res.status) { + message.success("保存成功"); + this.getTableDatas(); + this.showSearchAd = false; + this.setSlideVisiable(false); + } else { + message.warning("保存失败: " + res.errormsg ? res.errormsg: ""); + } + }) + } + + @action doDelete = (ids) => { + API.deleteTaxRate(ids).then(res => { + if(res.status) { + message.success("删除成功"); + this.getTableDatas(); + this.showSearchAd = false; + } else { + message.warning("删除失败: " + res.errormsg ? res.errormsg: ""); + } + }) + } + + // 批量删除 + @action + doBatchDelete = () => { + let ids = toJS(this.tableStore.selectedRowKeys) + if(ids.length == 0) { + message.warning("未选择任何条目"); + return + } + this.doDelete(toJS(this.tableStore.selectedRowKeys)) + } + } \ No newline at end of file