import React from 'react';
import $ from 'jquery/src/ajax';
import 'react-quill/dist/quill.bubble.css';
import {
Form,
Icon,
Button,
Input,
Select,
Spin,
Table,
message,
DatePicker,
Modal,
Upload,
Popconfirm,
Cascader,
InputNumber,
Radio
} from 'antd';
import { getGameState, splitUrl, getprovince ,getReleaseStateList,getboutique,getTypeModule
} from '@/tools.js';
import { releaseStateList } from '@/dataDic.js';
//主体
const BusinessProject = Form.create()(
React.createClass({
loadData(pageNo) {
this.state.data = [];
this.setState({
loading: true,
page: pageNo
});
$.ajax({
method: 'get',
dataType: 'json',
crossDomain: false,
url: globalConfig.context + '/portal/service/jtProject/list',
data: {
pageNo: pageNo || 1,
pageSize: this.state.pagination.pageSize,
topId: this.state.typeSearch? this.state.typeSearch[0]:'',
secondId:this.state.typeSearch?this.state.typeSearch[1]:'',
name: this.state.nameSearch,
privateProject: 1,
isHot:this.state.hotSearch,
auditStatus:this.state.stateSearch
},
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],
ProvinceCityArr = [],
cname = '',
superName = '',
ProvinceS = thisdata.province, //getprovince
citys = thisdata.city,
Areas = thisdata.area;
ProvinceCityArr.push(ProvinceS, citys, Areas);
this.state.categoryList.map((item) => {
if (thisdata.categoryId == item.id) {
cname = item.name;
superName = item.superName;
}
});
theArr.push({
key: i,
id: thisdata.id, //业务名称
name: thisdata.name, //业务名称
categoryId: thisdata.categoryId, //业务品类
number: thisdata.number,
price: thisdata.price, //市场价
superName: superName,
cname: cname,
module:thisdata,module,
companyName:thisdata.companyName,
city: thisdata.city,
activityPrice: thisdata.activityPrice ? thisdata.activityPrice : '', //最低折扣
memberPrice: thisdata.memberPrice ? thisdata.memberPrice : '', //会员价
offset: thisdata.offset ? thisdata.offset : '',
activityPrice: thisdata.activityPrice ? thisdata.activityPrice : '', //活动价
activityFlag: thisdata.activityFlag, //活动生效标识
status: thisdata.status, //项目状态
province: thisdata.province,
auditStatus:thisdata.auditStatus,
introduce: thisdata.introduce,
createTime: thisdata.createTime ? new Date(thisdata.createTime).toLocaleString() : '',
value: thisdata.value,
isHot:thisdata.isHot.toString(),
applyConditions: thisdata.applyConditions
});
}
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({
loading: false
});
}.bind(this)
);
},
getInitialState() {
return {
searchMore: true,
selectedRowKeys: [],
selectedRows: [],
loading: false,
orgCodeUrl: [],
typeSearch:[],
companyLogoUrl: [],
pagination: {
defaultCurrent: 1,
defaultPageSize: 10,
showQuickJumper: true,
pageSize: 10,
onChange: function(page) {
this.loadData(page);
this.setState({
selectedRowKeys: []
});
}.bind(this),
showTotal: function(total) {
return '共' + total + '条数据';
}
},
columns: [
{
title: '项目名称',
dataIndex: 'name',
key: 'bname'
},
{
title: '发布人账户昵称',
dataIndex: 'companyName',
key: 'companyName'
},
{
title: '品类名称',
dataIndex: 'cname',
key: 'cname',
render:(text,recard)=>{
let ids =recard.categoryId,categoryList =this.state.categoryList,txt='' ;
categoryList.map(item=>{
if(item.children){
(item.children).map(atem=>{
if(atem.value==ids){
txt= atem.label
}
})
}
})
return txt;
}
},
{
title: '上级品类',
dataIndex: 'superName',
key: 'superName',
render:(text,recard)=>{
let ids =recard.categoryId,categoryList =this.state.categoryList,txt='' ;
categoryList.map(item=>{
if(item.children){
(item.children).map(atem=>{
if(atem.value==ids){
txt= item.label
}
})
}
})
return txt;
}
},
{
title: '业务地区',
dataIndex: 'area',
key: 'area',
render: (text, rocard) => {
return (
{rocard.province != 0 ? (
{getprovince(rocard.province) + '-' + getprovince(rocard.city)}
) : (
'全国'
)}
);
}
},
{
title: '发布状态',
dataIndex: 'auditStatus',
key: 'auditStatus',
render:text=>{
return getReleaseStateList(text);
}
},
{
title: '是否热门',
dataIndex: 'isHot',
key: 'isHot',
render:text=>{
return getboutique(text);
}
},
{
title: '市场价(万元)',
dataIndex: 'price',
key: 'price'
},
{
title: '最低折扣',
dataIndex: 'offset',
key: 'offset'
},
{
title: '会员价(万元)',
dataIndex: 'memberPrice',
key: 'memberPrice'
},
{
title: '活动价(万元)',
dataIndex: 'activityPrice',
key: 'activityPrice'
},
{
title: '活动生效标识',
dataIndex: 'activityFlag',
key: 'activityFlag',
render: (text) => {
return getGameState(text);
}
}
],
dataSource: []
};
},
//业务品类列表获取
topLevel() {
$.ajax({
method: 'get',
dataType: 'json',
crossDomain: false,
url: globalConfig.context + '/portal/service/jtBusiness/getCategoryList',
data: {
},
success: function(data) {
let theArr = [],thisdata=data.data;
if (!data.data) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
}
} else {
thisdata.map((item,index) => {
theArr.push({
'value':item.topLevelId,
'label':item.topLevel,
'children':[]
})
if (item.children) {
item.children.map(atem => {
(theArr[index].children).push({
'value':atem.id,
'label':atem.name
})
})
}
})
}
this.setState({
categoryList: theArr,
});
this.loadData();
}.bind(this)
}).always(
function() {
this.setState({
loading: false
});
}.bind(this)
);
},
componentWillMount() {
this.topLevel();
},
detailes(recard) {
this.setState({
loading:true
});
$.ajax({
method: 'get',
dataType: 'json',
crossDomain: false,
url: globalConfig.context + '/api/user/jtBusiness/project/detail',
data: {
id: recard.id
},
success: function(data) {
let thisData = data.data;
if (!thisData) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
}
thisData = {};
}
let categoryList = this.state.categoryList,name='';
categoryList.map(item=>{
if((item.children).length){
(item.children).map(atem=>{
if(atem.value==thisData.categoryId){
name=item.label+'/'+atem.label;
return;
}
})
}
});
document.querySelector('.txt').innerHTML='';
let eleDiv = document.createElement('div');
eleDiv.innerHTML=thisData.introduce;
document.querySelector('.txt').append(eleDiv);
this.setState({
id: thisData.id,
data: thisData,
name: name,
createTime: thisData.createTime ? new Date(thisData.createTime).toLocaleString() : '',
auditStatus: thisData.auditStatus,
orgCodeUrl: thisData.minImgUrl
? splitUrl(thisData.minImgUrl, ',', globalConfig.avatarHost + '/upload')
: [],
companyLogoUrl: thisData.maxImgUrl
? splitUrl(thisData.maxImgUrl, ',', globalConfig.avatarHost + '/upload')
: []
});
}.bind(this)
}).always(
function() {
this.setState({
loading: false
});
}.bind(this)
);
},
//项目列表整行点击
tableRowClick(record, index) {
this.state.RowData = record;
this.setState({
editvisible: true
});
this.detailes(record);
},
edithandleCancel(e) {
this.setState({
editvisible: false
});
},
delectRow(recard) {
this.setState({
loading:true
})
let deletedIds =[];
let rowItem = this.state.selectedRowKeys[0];
let data = this.state.dataSource ||[];
if (data.length) {
deletedIds.push(data[rowItem].id);
}
$.ajax({
method: "POST",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/jtBusiness/project/annul",
data: {
id: deletedIds[0]
}
}).done(function (data) {
if (!data.error.length) {
message.success('下架成功!');
this.setState({
loading: false,
selectedRowKeys:[],
});
} else {
message.warning(data.error[0].message);
};
this.loadData();
}.bind(this));
},
changeHot(recard) {
this.setState({
loading:true
})
let deletedIds =[];
let rowItem = this.state.selectedRowKeys[0];
let data = this.state.dataSource ||[];
if (data.length) {
deletedIds.push(data[rowItem].id);
deletedIds.push(data[rowItem].isHot);
}
$.ajax({
method: "POST",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/jtBusiness/project/ifHot",
data: {
id: deletedIds[0],
isHot:deletedIds[1]
}
}).done(function (data) {
if (!data.error.length) {
message.success('修改成功!');
this.setState({
loading: false,
selectedRowKeys:[],
});
} else {
message.warning(data.error[0].message);
};
this.loadData();
}.bind(this));
},
search() {
this.loadData();
},
//搜索部分的清零
reset() {
this.state.nameSearch = ''; //项目名称清零
this.state.typeSearch = undefined; //品类名称清零
this.state.ressSearch = undefined; //省市区清零
this.state.activityFlag = undefined; //活动生效清零
this.state.status = undefined; //项目状态清零
this.state.stateSearch=undefined;
this.state.hotSearch=undefined;
this.loadData();
},
//更多搜索的显示与否
searchSwitch() {
this.setState({
searchMore: !this.state.searchMore
});
},
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 theData = this.state.data || {};
const hasSelect = this.state.selectedRowKeys.length;
return (
);
}
})
);
export default BusinessProject;