diff --git a/src/components/gird/main.js b/src/components/gird/main.js index 83f3b4f1..03581977 100644 --- a/src/components/gird/main.js +++ b/src/components/gird/main.js @@ -1,658 +1,581 @@ import React from 'react' -import ReactDom from 'react-dom'; -import "./main.css" -import { - Icon, - Menu, - Checkbox, - Switch, - Sweetalert, - Notify -} from 'zent'; -import _ from "lodash"; -import Pagination from "../pagination/main.js" -import GridEdit from "../gridEdit/main.js" -import Input from "../input/main.js" -import GridCheckBar from "../gridCheckBar/main.js" - - +import ReactDom from 'react-dom' +import './main.css' +import { Icon, Menu, Checkbox, Switch, Sweetalert, Notify } from 'zent' +import _ from 'lodash' +import Pagination from '../pagination/main.js' +import GridEdit from '../gridEdit/main.js' +import Input from '../input/main.js' +import GridCheckBar from '../gridCheckBar/main.js' //tabbar组件机构{title:"",index:""} //props {} // type : normal slot -//tableColumn 表格列属性结构 type width,label,background,textAlign - +//tableColumn 表格列属性结构 type width,label,background,textAlign export default class menu extends React.Component { + static defaultProps = { + isShowPageBar: true, //是否显示页码 + isMultiple: true, + isSwitch: true, + page: '', + headBackgroud: '', + spliteColor: '#f9fafc', + countbarVisible: true, + maxheight: 400, + isBorder: false, + Column: [ + { + title: '推广计划名称', + prop: 'name', + width: '300px', + textAlign: 'flex-start', + type: 'normal', + sort: false, + total: false, + valueType: 'text' + }, + { + title: '操作', + prop: 'edit', + width: '220px', + textAlign: 'flex-start', + type: 'slot', + sort: false, + total: false, + valueType: 'text' + }, + { + title: '曝光量', + prop: 'num1', + width: 'auto', + textAlign: 'left', + type: 'normal', + sort: true, + total: true, + valueType: 'number' + }, + { + title: '点击量', + prop: 'num2', + width: 'auto', + textAlign: 'left', + type: 'normal', + sort: true, + total: true, + valueType: 'number' + }, + { + title: '点击率', + prop: 'num3', + width: 'auto', + textAlign: 'left', + type: 'normal', + sort: true, + total: true, + valueType: 'percentage' + }, + { + title: '点击均价', + prop: 'price', + width: 'auto', + textAlign: 'left', + type: 'normal', + sort: true, + total: true, + valueType: 'price' + }, + { + title: '花费', + prop: 'totalprice', + width: 'auto', + textAlign: 'left', + type: 'normal', + sort: true, + total: true, + valueType: 'price' + } + ], + tableData: [ + { + id: 0, + name: '推广计划-2021-10-19 17:43', + num1: 0, + num2: 0, + num3: 0, + price: 0, + totalprice: 0 + } + ], + emptyText: '抱歉,暂无相关数据记录', + dataCount: 0, + curIndex: 0 + } - static defaultProps = { - isShowPageBar:true, //是否显示页码 - isMultiple: true, - isSwitch: true, - page:'', - headBackgroud: "", - spliteColor: "#f9fafc", - countbarVisible:true, - maxheight:400, - isBorder:false, - Column: [{ - title: "推广计划名称", - prop: "name", - width: "300px", - textAlign: "flex-start", - type: "normal", - sort: false, - total: false, - valueType: "text" - }, - { - title: "操作", - prop: "edit", - width: "220px", - textAlign: "flex-start", - type: "slot", - sort: false, - total: false, - valueType: "text" - }, - { - title: "曝光量", - prop: "num1", - width: "auto", - textAlign: "left", - type: "normal", - sort: true, - total: true, - valueType: "number" - }, - { - title: "点击量", - prop: "num2", - width: "auto", - textAlign: "left", - type: "normal", - sort: true, - total: true, - valueType: "number" - }, - { - title: "点击率", - prop: "num3", - width: "auto", - textAlign: "left", - type: "normal", - sort: true, - total: true, - valueType: "percentage" - }, - { - title: "点击均价", - prop: "price", - width: "auto", - textAlign: "left", - type: "normal", - sort: true, - total: true, - valueType: "price" - }, - { - title: "花费", - prop: "totalprice", - width: "auto", - textAlign: "left", - type: "normal", - sort: true, - total: true, - valueType: "price" - }, - ], - tableData: [{ - id: 0, - name: "推广计划-2021-10-19 17:43", - num1: 0, - num2: 0, - num3: 0, - price: 0, - totalprice: 0 - } - ], - emptyText: "抱歉,暂无相关数据记录", - dataCount:0, - curIndex:0, - - } + constructor(props) { + super(props) + let tableData = [] + // 如果是多选 + // if (props.isMultiple) { + // tableData = _.map(props.tableData, (item) => { + // return item.checked = false; + // }) + // } + // if (props.isSwitch) { + // tableData = _.map(props.tableData, (item) => { + // return item.switched = false; + // }) + // } - constructor(props) { - super(props); - let tableData = []; - // 如果是多选 - // if (props.isMultiple) { - // tableData = _.map(props.tableData, (item) => { - // return item.checked = false; - // }) - // } + this.state = { + switchLoading: false, + allChecked: false, + tableData: props.tableData, + Column: props.Column, + dataTotal: props.dataTotal, + indeterminate: false, + pageNum: 0, + pageCount: props.dataCount, + pageLoading: false, + editShow: false, + postion: null, + historyrow_id: null, + curRow: null, + emptyText: props.emptyText || '抱歉,暂无相关数据记录', + edit_title: '', + edit_column: '' + } + } - // if (props.isSwitch) { - // tableData = _.map(props.tableData, (item) => { - // return item.switched = false; - // }) - // } + scrollFunc = function (e) {} + componentDidMount() { + const dom = ReactDom.findDOMNode(this) + if (dom.attachEvent) { + dom.attachEvent('onmousewheel', this.scrollFunc) + } + //Firefox使用addEventListener添加滚轮事件 + if (dom.addEventListener) { + //firefox + dom.addEventListener('DOMMouseScroll', this.scrollFunc, false) + } + //Safari与Chrome属于同一类型 + dom.onmousewheel = this.scrollFunc + } + //多选 + AllCheckChange = (e) => { + if (this.state.tableData.length == 0) { + return + } - this.state = { - switchLoading: false, - allChecked: false, - tableData: props.tableData, - Column: props.Column, - dataTotal:props.dataTotal, - indeterminate: false, - pageNum:0, - pageCount:props.dataCount, - pageLoading:false, - editShow:false, - postion:null, - historyrow_id:null, - curRow:null, - emptyText: "抱歉,暂无相关数据记录", - edit_title:"", - edit_column:"" - } - } - - - scrollFunc = function (e) { + this.setState({ + indeterminate: false + }) + this.setState({ + allChecked: e.target.checked + }) - } - - componentDidMount() { - const dom = ReactDom.findDOMNode(this); - if(dom.attachEvent){ - dom.attachEvent('onmousewheel',this.scrollFunc); - } - //Firefox使用addEventListener添加滚轮事件 - if (dom.addEventListener) {//firefox - dom.addEventListener('DOMMouseScroll', this.scrollFunc, false); - } - //Safari与Chrome属于同一类型 - dom.onmousewheel = this.scrollFunc; - } - - //多选 - AllCheckChange = (e) => { - - if(this.state.tableData.length == 0) - { - return; - } - - this.setState({ - indeterminate: false - }) - this.setState({ - allChecked: e.target.checked - }) + let tableData = _.map(this.state.tableData, (item) => { + return (item.checked = e.target.checked) + }) + this.setState({ + tableData: this.state.tableData + }) + let selection = _.filter(this.state.tableData, (item) => { + return item.checked == true + }) + this.props.checkChange(selection) + } - let tableData = _.map(this.state.tableData, (item) => { - return item.checked = e.target.checked; - }) - this.setState({ - tableData: this.state.tableData - }) - let selection = _.filter(this.state.tableData, (item) => { - return item.checked == true; - }) - this.props.checkChange(selection) - } - - - allChecked(status) - { + allChecked(status) { + this.setState({ allChecked: status }) + let tabledata = _.map(this.state.tableData, (item) => { + item.checked = false + return item + }) + this.setState({ + indeterminate: false + }) + this.setState({ tableData: tabledata }) + } - this.setState({allChecked:status}) - let tabledata = _.map(this.state.tableData,(item)=>{ - item.checked =false - return item - }) - this.setState({ - indeterminate: false - }) - this.setState({tableData:tabledata}) - - } - - - - - checkChange(index, e){ - this.state.tableData[index].checked = e.target.checked; - this.setState({ - tableData: this.state.tableData - }) - let selection = _.filter(this.state.tableData, (item) => { - return item.checked == true; - }) - this.props.checkChange(selection) - - if (selection.length == this.state.tableData.length ) { - this.setState({ - indeterminate: false - }) - this.setState({ - allChecked: true - }) - } - else if(selection.length == 0) - { - this.setState({ - indeterminate: false - }) - this.setState({ - allChecked: false - }) - } - else { - this.setState({ - indeterminate: true - }) - } + checkChange(index, e) { + this.state.tableData[index].checked = e.target.checked + this.setState({ + tableData: this.state.tableData + }) + let selection = _.filter(this.state.tableData, (item) => { + return item.checked == true + }) + this.props.checkChange(selection) - } - - getCellValue(column,rowData){ - let value = _.get(rowData,column) - return value||value==0 ? value : "-" - } - - switchChange(index,e) { + if (selection.length == this.state.tableData.length) { + this.setState({ + indeterminate: false + }) + this.setState({ + allChecked: true + }) + } else if (selection.length == 0) { + this.setState({ + indeterminate: false + }) + this.setState({ + allChecked: false + }) + } else { + this.setState({ + indeterminate: true + }) + } + } - this.state.tableData[index].switched = e; - this.setState({ - tableData: this.state.tableData - }) + getCellValue(column, rowData) { + let value = _.get(rowData, column) + return value || value == 0 ? value : '-' + } - - } + switchChange(index, e) { + this.state.tableData[index].switched = e + this.setState({ + tableData: this.state.tableData + }) + } - editRow(e,column, row) { - this.setState({edit_title:column.title}) - this.setState({edit_column:column.prop}) - - this.setState({curRow:row}) - - let pos = {} - pos.x = e.clientX; - pos.y = e.clientY; - - this.setState({postion:pos}); - - if(this.state.historyrow_id == row.id) - { - this.setState({editShow:!this.state.editShow}) - } - else{ - this.setState({editShow:true}) - this.setState({historyrow_id:row.id}) - } - + editRow(e, column, row) { + this.setState({ edit_title: column.title }) + this.setState({ edit_column: column.prop }) - } - - componentWillReceiveProps(nextProps) { - - if(this.state.tableData != nextProps.tableData) - { + this.setState({ curRow: row }) - this.setState({tableData: nextProps.tableData}); - this.setState({page: nextProps.page}); - this.setState( {dataCount:nextProps.dataCount}) - } - } + let pos = {} + pos.x = e.clientX + pos.y = e.clientY - onConfirm = () => { - - } + this.setState({ postion: pos }) - - onCancel = () => { - - } - total = (e) => { - let sum = 0 - if (e.total) { - for (let i = 0; i < this.state.tableData.length; i++) { + if (this.state.historyrow_id == row.id) { + this.setState({ editShow: !this.state.editShow }) + } else { + this.setState({ editShow: true }) + this.setState({ historyrow_id: row.id }) + } + } - let row = this.state.tableData[i] - let num = row[e.prop] == "" ? 0 : row[e.prop]; - sum += num; - } - if (e.valueType == "percentage") { - return sum <= 0 ? "0.00%" : sum.toFixed(2) + "%"; - } - if (e.valueType == "price") { - return sum <= 0 ? "0.00" : sum.toFixed(2); - } + componentWillReceiveProps(nextProps) { + if (this.state.tableData != nextProps.tableData) { + this.setState({ tableData: nextProps.tableData }) + this.setState({ page: nextProps.page }) + this.setState({ dataCount: nextProps.dataCount }) + } + } - } else { - return ""; - } - return sum; - } - //当前页码条数 - onCountChange(e){ - this.props.countChange(e) - this.setState({pageCount:e}) - } - gridPageLoad(){ - this.setState({pageLoading:true}) - setTimeout(()=>{ - this.setState({pageLoading:false}) - },500) - } - pageShow(e){ - - } - gridEditChange(e){ - - } - getSelectData(){ - - let selectList = this.state.tableData.filter((o)=>{return o.checked == true}) - selectList = _.map(selectList, o => _.omit(o, ['checked'])); - return selectList - - } - rowItemClick(index){ - console.log(index) - - this.setState({curIndex:index}) - } + onConfirm = () => {} - - render() { - const { - data, - ComponentHandler - } = this.props; - var column_width = 0; - - let auto_column_width = this.state.Column.length > 12 ? "100px" : 100 / (this.state.Column.length - 2) + "%"; - - - return (