import React from 'react'; import ReactDom from 'react-dom'; import ajax from 'jquery/src/ajax/xhr.js'; import $ from 'jquery/src/ajax'; import moment from 'moment'; import '../content.less'; import { Form,Radio, Icon, Button, Input, Select, Spin, Table, Switch, message, DatePicker, Modal, Upload,Popconfirm,TimePicker,Tabs } from 'antd'; import {categoryState} from '../../../dataDic.js'; import {getCategoryState,splitUrl} from '../../../tools.js'; import ImgList from "../../../common/imgList"; import {ChooseList} from "../../order/orderNew/chooseList"; //图片组件 const PicturesWall = React.createClass({ getInitialState() { return { previewVisible: false, previewImage: '', fileList: [], } }, handleCancel() { this.setState({ previewVisible: false }) }, handlePreview(file) { this.setState({ previewImage: file.url || file.thumbUrl, previewVisible: true, }); }, handleChange(info) { let fileList = info.fileList; this.setState({ fileList }); this.props.fileList(fileList); }, componentWillReceiveProps(nextProps) { this.state.fileList = nextProps.pictureUrl; }, render() { const { previewVisible, previewImage, fileList } = this.state; const uploadButton = (
点击上传
); return (
{ this.handleChange(infor) }} fileList={fileList} />
); } }); const {TabPane} = Tabs const BusinessCategory=Form.create()(React.createClass({ //搜索功能和初始列表加载 loadData(pageNo, apiUrl) { this.state.data = []; this.setState({ listLoading: true, ispage:pageNo, }); let nameText=this.state.SuperArr; let superText=(this.state.superId)?nameText[parseInt(this.state.superId)].id:""; $.ajax({ method: "post", dataType: "json", crossDomain: false, url: globalConfig.context + '/api/admin/Varieties/vtList', data: { pageNo: pageNo || 1, pageSize: this.state.pagination.pageSize, cname:this.state.cname, //品类名称 superId:superText,//上级品类编号 layer:this.state.layer,//组织层级 status:this.state.status,//品类状态 }, success: function (data) { let theArr = []; if (!data.data || !data.data.list) { if (data.error && data.error.length) { message.warning(data.error[0].message); }; } else { for (let i = 0; i < data.data.list.length; i++) { let thisdata = data.data.list[i]; theArr.push({ key: i, id: thisdata.id,//品类ID sort:thisdata.sort,//品类序号 cid: thisdata.cid,//品类编号 cname: thisdata.cname,//品类名称 layer: thisdata.layer,//品类层级 superName: thisdata.superName,//上级品类 status: thisdata.status,//上级品类状态 }); }; this.state.pagination.current = data.data.pageNo; this.state.pagination.total = data.data.totalCount; }; this.setState({ dataSource: theArr, pagination: this.state.pagination }); }.bind(this), }).always(function () { this.setState({ listLoading: false }); }.bind(this)); }, getInitialState() { return { searchMore: true, selectedRowKeys: [], selectedRows: [], listLoading: false, orgCodeUrl: [], companyLogoUrl: [], pagination: { defaultCurrent: 1, defaultPageSize: 10, showQuickJumper: true, pageSize: 10, onChange: function (page) { this.loadData(page); }.bind(this), showTotal: function (total) { return '共' + total + '条数据'; } }, columns: [ { title: '品类序号', dataIndex: 'sort', key: 'sort', },{ title: '品类编号', dataIndex: 'cid', key: 'cid', }, { title: '品类名称', dataIndex: 'cname', key: 'cname', }, { title: '品类层级', dataIndex: 'layer', key: 'layer', //render: text => { return getAchievementCategory(text); } }, { title: '上级品类', dataIndex: 'superName', key: 'superName', },{ title: '品类状态', dataIndex: 'status', key: 'status', render: text => { return getCategoryState(text) } } ], dataSource: [], }; }, componentWillMount() { this.selectSuperId(); }, //获取上级品类 selectSuperId() { this.state.data = [] $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/Varieties/getSuperList", data:{ flag:1, }, success: function (data) { let theArr = []; let thedata=data.data; if (!thedata) { if (data.error && data.error.length) { message.warning(data.error[0].message); }; thedata = {}; }; var contactIds=[]; //for (let item in data.data) { for(var i=0;i{theData.cname} ); }; this.setState({ SuperArr:thedata, contactsOption: theArr, orderStatusOptions:data.data, }); }.bind(this), }).always(function () { this.loadData(this.state.ispage); this.setState({ loading: false }); }.bind(this)); }, //编辑部门,保存 edithandleSubmit(e){ e.preventDefault(); //上级组织字典 let nameText=this.state.SuperArr let superText=this.state.editSuperName; let superIdText=this.state.editSuperId; let superOne=this.state.editDataSource[0].editSuperName; let isStatus=this.state.editStatus; let theorgCodeUrl = []; if(this.state.orgCodeUrl.length) { let picArr = []; this.state.orgCodeUrl.map(function(item) { picArr.push(item.response.data); }); theorgCodeUrl = picArr.join(","); }; let thecompanyLogoUrl = []; if(this.state.companyLogoUrl.length) { let picArr = []; this.state.companyLogoUrl.map(function(item) { picArr.push(item.response.data); }); thecompanyLogoUrl = picArr.join(","); }; if(isStatus==1){ if(confirm('是否要停用该品类?')){ if(!(superOne==superText)){ let changeSuper=nameText[parseInt(this.state.editSuperName)].id; if(confirm('上级品类已修改,是否保存?')){ $.ajax({ method: "post", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/Varieties/editVarieties", data: { id: this.state.editId, //品类ID cname: this.state.editName, //品类名称 superId: changeSuper, //上级品类 status: this.state.editStatus, //品类状态 varietiesLogo: theorgCodeUrl, sort: this.state.editSort } }).done( function(data) { this.setState({ loading: false }); if (!data.error.length) { message.success("保存成功!"); this.edithandleCancel(); this.selectSuperId(); } else { message.warning(data.error[0].message); } }.bind(this) ); return false } }else { $.ajax({ method: "post", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/Varieties/editVarieties", data: { id: this.state.editId, //品类ID cname: this.state.editName, //品类名称 superId: superIdText, //上级品类 status: this.state.editStatus, //品类状态 varietiesLogo: theorgCodeUrl, sort: this.state.editSort } }).done( function(data) { this.setState({ loading: false }); if (!data.error.length) { message.success("保存成功!"); this.edithandleCancel(); this.selectSuperId(); } else { message.warning(data.error[0].message); } }.bind(this) ); } } }else{ if(!(superOne==superText)){ let changeSuper=nameText[parseInt(this.state.editSuperName)].id; if(confirm('上级组织已修改,是否保存?')){ $.ajax({ method: "post", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/Varieties/editVarieties", data: { id: this.state.editId, //品类ID cname: this.state.editName, //品类名称 superId: changeSuper, //上级品类 status: this.state.editStatus, //品类状态 varietiesLogo: theorgCodeUrl, sort: this.state.editSort } }).done( function(data) { this.setState({ loading: false }); if (!data.error.length) { message.success("保存成功!"); this.edithandleCancel(); this.selectSuperId(); } else { message.warning(data.error[0].message); } }.bind(this) ); return false } }else { $.ajax({ method: "post", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/Varieties/editVarieties", data: { id: this.state.editId, //品类ID cname: this.state.editName, //品类名称 superId: superIdText, //上级品类 status: this.state.editStatus, //品类状态 varietiesLogo: theorgCodeUrl, sort: this.state.editSort } }).done( function(data) { this.setState({ loading: false }); if (!data.error.length) { message.success("保存成功!"); this.edithandleCancel(); this.selectSuperId(); } else { message.warning(data.error[0].message); } }.bind(this) ); } } }, //整行点击 tableRowClick(record, index) { this.selectSuperId(); this.state.RowData = record; this.setState({ editvisible: true, selectedRowKeys:[], rowId:record.businessId, }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context +"/api/admin/Varieties/detailVarieties" , data: { id: record.id }, success: function (data) { let theArr = []; let thisdata = data.data; if (!data) { if (data.error && data.error.length) { message.warning(data.error[0].message); }; } else { theArr.push({ editId: thisdata.id,//每一条记录的ID editName:thisdata.cname,//品类名称 editStatus:thisdata.status,//品类状态 editSuperName:thisdata.superName,//上级品类 editlayer:thisdata.layer,//品类层级 editCid: thisdata.cid,//品类编号 editSort: thisdata.sort,//品类序号 editCreateName:thisdata.createName,//创建人 editTime:thisdata.createTimeFormattedDate,//创建时间 orgCodeUrl: thisdata.varietiesLogo ? splitUrl(thisdata.varietiesLogo, ',', globalConfig.avatarHost + '/upload') : [], }); }; this.setState({ editId: thisdata.id,//每一条记录的ID editName:thisdata.cname,//品类名称 editStatus:thisdata.status,//品类状态 editSuperName:thisdata.superName,//上级品类 editSuperId:thisdata.superId,//上级品类 editlayer:thisdata.layer,//品类层级 editCid: thisdata.cid,//品类编号 editSort: thisdata.sort,//品类序号 editCreateName:thisdata.createName,//创建人 editTime:thisdata.createTimeFormattedDate,//创建时间 orgCodeUrl: thisdata.varietiesLogo ? splitUrl(thisdata.varietiesLogo, ',', globalConfig.avatarHost + '/upload') : [], editDataSource: theArr, }); }.bind(this), }).always(function () { this.setState({ loading: false }); }.bind(this)); }, //左侧图片地址 getOrgCodeUrl(e) { this.setState({ orgCodeUrl: e }); }, //新增一个品类,保存 addhandleSubmit(e){ e.preventDefault(); if(!this.state.categoryName){ message.warning('请输入品类名称'); return false; } if(!this.state.upCategory){ message.warning('请选择上级品类'); return false; } this.props.form.validateFields((err, values) => { if (!err) { this.setState({ loading: true }); //上级组织字典 let nameText=this.state.SuperArr; let superText=nameText[parseInt(this.state.upCategory)].id; $.ajax({ method: "get", dataType: "json", crossDomain: false, url:globalConfig.context + '/api/admin/Varieties/addVarieties', data:{ cname:this.state.categoryName,//组织名称 superId:superText,//上级组织 } }).done(function (data) { this.setState({ loading: false }); if (!data.error.length) { message.success('新增品类成功!'); this.handleCancel(); this.selectSuperId(); } else { message.warning(data.error[0].message); } }.bind(this)); } }); }, //整行删除 delectRow() { let deletedIds = ''; for (let idx = 0; idx < this.state.selectedRows.length; idx++) { let rowItem = this.state.selectedRows[idx]; if (rowItem.id) { deletedIds=rowItem.id; }; }; this.setState({ selectedRowKeys: [], loading: deletedIds.length > 0 }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/Varieties/deleteState", data: { id: deletedIds } }).done(function (data) { if (!data.error.length) { message.success('删除成功!'); this.setState({ loading: false, }); } else { message.warning(data.error[0].message); }; this.selectSuperId(); }.bind(this)); }, //整行停用 blockRow() { let deletedIds = ''; for (let idx = 0; idx < this.state.selectedRows.length; idx++) { let rowItem = this.state.selectedRows[idx]; if (rowItem.id) { deletedIds=rowItem.id; }; }; this.setState({ selectedRowKeys: [], loading: deletedIds.length > 0 }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/Varieties/updateStatus", data: { id: deletedIds } }).done(function (data) { if (!data.error.length) { message.success('该品类已成功停用!'); this.setState({ loading: false, }); } else { message.warning(data.error[0].message); }; this.selectSuperId(); }.bind(this)); }, //品类上移 upClick() { let deletedIds = ''; let upSort = ''; for (let idx = 0; idx < this.state.selectedRows.length; idx++) { let rowItem = this.state.selectedRows[idx]; if (rowItem.id) { deletedIds=rowItem.id; upSort=rowItem.sort; }; }; this.setState({ selectedRowKeys: [], loading: deletedIds.length > 0 }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/Varieties/locationChange", data: { id: deletedIds, sort:upSort, flag:'1', } }).done(function (data) { if (!data.error.length) { message.success('该品类已成功上移!'); this.setState({ loading: false, }); } else { message.warning(data.error[0].message); }; this.selectSuperId(); }.bind(this)); }, //品类下移 downClick() { let deletedIds = ''; let upSort = ''; for (let idx = 0; idx < this.state.selectedRows.length; idx++) { let rowItem = this.state.selectedRows[idx]; if (rowItem.id) { deletedIds=rowItem.id; upSort=rowItem.sort; }; }; this.setState({ selectedRowKeys: [], loading: deletedIds.length > 0 }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/Varieties/locationChange", data: { id: deletedIds, sort:upSort, flag:'0', } }).done(function (data) { if (!data.error.length) { message.success('该品类已成功下移!'); this.setState({ loading: false, }); } else { message.warning(data.error[0].message); }; this.selectSuperId(); }.bind(this)); }, addClick() { this.state.RowData = {}; this.addReset(); this.setState({ visible: true }); }, editClick() { this.state.RowData = {}; this.setState({ editvisible: true }); }, handleCancel() { this.setState({ visible: false }) }, edithandleCancel() { this.setState({ editvisible: false }) }, search() { this.loadData(); }, reset() { this.state.cname = '';//品类名称清零 this.state.layer = undefined;//品类层级清零 this.state.status = undefined;//品类状态清零 this.state.superId = undefined;//上级品类清零 this.loadData(); }, addReset() { this.state.categoryName = '';//品类名称清零 this.state.upCategory = undefined;//上级品类清零 }, searchSwitch() { this.setState({ searchMore: !this.state.searchMore }); }, changeList(arr) { const newArr = []; this.state.columns.forEach(item => { arr.forEach(val => { if (val === item.title) { newArr.push(item); } }); }); this.setState({ changeList: newArr }); }, render() { const FormItem = Form.Item const rowSelection = { selectedRowKeys: this.state.selectedRowKeys, onChange: (selectedRowKeys, selectedRows) => { this.setState({ selectedRows: selectedRows.slice(-1), selectedRowKeys: selectedRowKeys.slice(-1) }); } }; const formItemLayout = { labelCol: { span: 8 }, wrapperCol: { span: 14 }, }; const { getFieldDecorator } = this.props.form; const hasSelected = this.state.selectedRowKeys.length > 0; const { RangePicker } = DatePicker; return (
{ this.setState({ cname: e.target.value }); }} /> 更多搜索
{this.setState({categoryName:e.target.value})}} required="required"/> *
*
{this.setState({editName:e.target.value})}}/>
{/* {this.state.editSort} */} { this.setState({ editSort: e.target.value }); } } />
{this.state.editlayer}
{this.state.editCid}
{this.state.editCreateName}
{this.state.editTime}
); } })); export default BusinessCategory;