import React, { useState, useEffect, useRef } from 'react'; import { PageHeaderWrapper } from '@ant-design/pro-layout'; import { Card, Table, Button, Row, DatePicker, Col, InputNumber, message } from 'antd'; import { getRetailManualList, ListItem, autoAlloctionApi, ShopTaskList, save, saveParams } from './api'; import EModal from './component/Modal'; import moment from 'moment'; import currency from 'currency.js'; import ApproveModal from '@/pages/order3/Common/ApproveModal'; const { Column } = Table; const day = new Date(); const month = day.getMonth() + 1; const year = day.getFullYear(); const strtime = year + '-' + month; let newDate = new Date(strtime); const newDay = newDate.getTime(); export default function TacklingCarModels() { const [visible, setVisible] = useState(false); const [loading, setLoading] = useState(false); const [current, setCurrent] = useState({}); const [confirmLoading, setConfirmLoading] = useState(false); const [saveLoading, setSaveLoading] = useState(false); const [date, setDate] = useState(newDay); const [edit, setEdit] = useState(false); const [list, setList] = useState({}); const [orginDara, setOrginDara] = useState({}); const index = useRef(); const [approveOpen, setApproveOpen] = useState(false); // let index; useEffect(() => { getList(newDay); }, []); function setReset() { setList({ ...orginDara }); setEdit(false); } //查询列表 function getList(date: number) { const params = { taskDate: date.valueOf(), autoAssign: true, }; getRetailManualList(params).then(res => { setLoading(false); const data = res.data; setOrginDara(data || {}); setList(data || {}); // message.success(res.result); }).catch(e => { setLoading(false); message.warning(e.message); }); } /** * 修改零售任务数量 * @param e * @param index */ function _onChange(e: number, index: number) { const data = JSON.parse(JSON.stringify(list)); data.shopTaskList![index].taskCount = e; data.shopTaskList![index].clueDealTaskCount = currency(e || 0).multiply(data.shopTaskList[index].clueDealTaskRate || 0).divide(100).value; // data.shopTaskList![index].clueDealTaskCount = Math.ceil((e || 0)*((data.shopTaskList![index].clueDealTaskRate || 0)/100)); setList({ ...data }); } /** * 修改线索到店零售数量 * @param e * @param index */ function handleChangeClue(e: number, index: number) { const data = JSON.parse(JSON.stringify(list)); if (data.shopTaskList[index].taskCount < e) { message.error("线索到店零售数量不能大于零售任务!"); return; } data.shopTaskList![index].clueDealTaskCount = e; setList({ ...data }); } function _ChangeMoth(date: any) { setLoading(true); setDate(date.valueOf()); getList(date); } //保存 function handleClick() { setLoading(true); const params = { id: list.id, shopTaskList: list.shopTaskList }; autoAllocationSave(params); } function handleOpenApprove() { setApproveOpen(true); } //提交审批 function saveClick(params?: any) { setLoading(true); setSaveLoading(true); save({...params, id: list.id}).then((res) => { setSaveLoading(false); setLoading(false); setList({ ...list, canModified: false }); message.success(res.result); }).catch(e => { setLoading(false); message.warning(e.message); setSaveLoading(false); }); } //自动提交 function autoAllocationSave(params: saveParams) { setConfirmLoading(true); setEdit(true); autoAlloctionApi(params).then((res) => { setConfirmLoading(false); getList(date); setEdit(false); message.success(res.result); }).catch(e => { message.warning(`${e.message}`); setConfirmLoading(false); setLoading(false); }); } return ( { let total = 0; pageData.forEach(({ taskCount }) => { total += taskCount || 0; }); return ( <> {total == 0 ? null : ( 合计 {total} )} ); }} > { if (edit) { return _onChange(e, index)} />; } else { return {value}; } }} /> {value}} /> ( <> )} />
{list.canModified ? ( <> {edit ? : } {edit ? null : } {edit ? : null} ) : null}
); }