123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824 |
- import React from 'react';
- import $ from 'jquery/src/ajax';
- import {
- Form, Icon, Button, Input, Select, AutoComplete, Spin, Table,
- message, DatePicker, Modal, Tabs
- } from 'antd';
- import moment from 'moment';
- import { ShowModal, splitUrl } from '../../../tools.js';
- import { ChooseList } from "../../order/orderNew/chooseList";
- import "./index.less";
- import ImgList from "../../../common/imgList";
- const PicturesWall = React.createClass({
- getInitialState() {
- return {
- previewVisible: false,
- previewImage: "",
- fileList: this.props.pictureUrl,
- };
- },
- getDefaultProps() {
- return {
- changeClick: this.modifyChange,
- };
- },
- 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 { fileList } = this.state;
- return (
- <div style={{ display: "inline-block" }}>
- <ImgList
- isSupportPDF={true}
- limitation={false}
- domId={this.props.domId}
- uploadConfig={{
- action: globalConfig.context + "/api/admin/standard/uploadPicture",
- data: { sign: "standard_document" },
- multiple: true,
- listType: "picture-card",
- }}
- onChange={(infor) => {
- this.handleChange(infor);
- }}
- fileList={fileList}
- />
- </div>
- );
- },
- });
- const { TabPane } = Tabs
- const FormItem = Form.Item;
- const Standard = Form.create()(React.createClass({
- getInitialState() {
- return {
- searchValues: {},
- loading: false,
- changeList: undefined, // 更改后的表格显示数据
- dataSource: [],
- departmentArr: [],
- typeList: [
- { key: "国家标准", value: 0, },
- { key: "行业标准", value: 1, },
- { key: "地方标准", value: 2, },
- { key: "团体标准", value: 3, },
- { key: "国际标准", value: 4, },
- { key: "企业标准", value: 5, },
- ],
- pagination: {
- defaultCurrent: 1,
- defaultPageSize: 10,
- showQuickJumper: true,
- pageSize: 20,
- onChange: function (page) {
- this.loadData(page);
- }.bind(this),
- showTotal: function (total) {
- return '共' + total + '条数据';
- }
- },
- columns: [
- {
- title: '标准编号',
- dataIndex: 'serialNumber',
- key: 'serialNumber',
- },
- {
- title: '标准名称',
- dataIndex: 'name',
- key: 'name',
- },
- {
- title: '参考',
- dataIndex: 'reference',
- key: 'reference',
- render: (text, record) => <span>{['国家 ', '行业 ', '地方 ', '团体 ', '国际 ', '企业 '][record.type]}{text}</span>
- },
- {
- title: '部门',
- dataIndex: 'depName',
- key: 'depName',
- },
- {
- title: '负责人',
- dataIndex: 'adminName',
- key: 'adminName',
- },
- {
- title: '标准状态',
- dataIndex: 'status',
- key: 'status',
- render: text => <span style={{ color: ["red", "green"][text] }}>{["关闭", "开启"][text]}</span>
- },
- {
- title: '更新时间',
- dataIndex: 'updateTime',
- key: 'updateTime',
- },
- {
- title: '附件',
- dataIndex: 'url',
- key: 'url',
- render: (text, record, index) =>
- <div className='selStandard'>
- <ImgList
- fileList={text ? splitUrl(text, ',', globalConfig.avatarHost + '/upload') : []}
- domId={"selStandard" + index}
- />
- </div>
- },
- ],
- visible: "",
- data: {},
- orgCodeUrl: [],
- };
- },
- componentWillMount() {
- this.loadData();
- this.departmentList();
- },
- // 列表接口
- loadData(pageNo) {
- const { searchValues, pagination } = this.state;
- this.setState({
- loading: true,
- });
- let datas = Object.assign(searchValues, {
- pageNo: pageNo || 1,
- pageSize: pagination.pageSize,
- });
- $.ajax({
- method: "get",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/standard/list",
- data: datas,
- success: function (data) {
- ShowModal(this);
- this.setState({
- loading: false,
- });
- if (data.error && data.error.length === 0) {
- if (data.data.list) {
- pagination.current = data.data.pageNo;
- pagination.total = data.data.totalCount;
- if (data.data && data.data.list && !data.data.list.length) {
- pagination.current = 0;
- pagination.total = 0;
- }
- this.setState({
- dataSource: data.data.list,
- pagination: this.state.pagination,
- pageNo: data.data.pageNo,
- });
- } else {
- this.setState({
- dataSource: data.data,
- pagination: false,
- });
- }
- } else {
- message.warning(data.error[0].message);
- }
- }.bind(this),
- }).always(
- function () {
- this.setState({
- loading: false,
- });
- }.bind(this)
- );
- },
- //部门
- departmentList() {
- $.ajax({
- method: "get",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/organization/selectSuperId",
- data: {},
- success: function (data) {
- let thedata = data.data;
- let theArr = [];
- if (!thedata) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- }
- } else {
- thedata.map(function (item, index) {
- theArr.push({
- key: index,
- name: item.name,
- id: item.id
- });
- });
- }
- this.setState({
- departmentArr: theArr
- });
- }.bind(this)
- }).always(
- function () {
- }.bind(this)
- );
- },
- search() {
- this.loadData();
- },
- reset() {
- this.setState({
- searchValues: {}
- }, () => {
- this.loadData();
- })
- },
- changeList(arr) {
- const newArr = [];
- this.state.columns.forEach(item => {
- arr.forEach(val => {
- if (val === item.title) {
- newArr.push(item);
- }
- });
- });
- this.setState({
- changeList: newArr
- });
- },
- addClick() {
- this.setState({
- visible: "add"
- })
- },
- tableRowClick(e) {
- if (!adminData.isSuperAdmin) {
- return
- }
- this.setState({
- visible: "edit",
- })
- this.getDetails(e.id)
- // const orgCodeUrl = e.url ? splitUrl(e.url, ',', globalConfig.avatarHost + '/upload') : []
- // this.setState({
- // visible: "edit",
- // data: e,
- // orgCodeUrl,
- // adminName: e.adminName,
- // })
- },
- getDetails(id) {
- this.setState({
- loading: true
- });
- $.ajax({
- method: "get",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/standard/get",
- data: {
- id,
- },
- success: function (data) {
- let thedata = data.data || {};
- let orgCodeUrl = []
- if (!thedata) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- };
- } else {
- orgCodeUrl = thedata.url ? splitUrl(thedata.url, ',', globalConfig.avatarHost + '/upload') : []
- }
- this.setState({
- data: thedata,
- orgCodeUrl,
- adminName: thedata.adminName,
- })
- }.bind(this),
- }).always(function () {
- this.setState({
- loading: false
- });
- }.bind(this));
- },
- getOrgCodeUrl(e) {
- this.setState({
- orgCodeUrl: e
- });
- },
- handleCancel() {
- this.setState({
- visible: "",
- adminName: undefined,
- data: {},
- orgCodeUrl: [],
- })
- },
- handleSubmit() {
- const { data } = this.state
- if (!data.serialNumber) {
- message.warning('标准编号不能为空!');
- return;
- }
- if (!data.name) {
- message.warning('标准名称不能为空!');
- return;
- }
- if (!data.depId) {
- message.warning('部门不能为空!');
- return;
- }
- if (!data.status && data.status != 0) {
- message.warning('请选择状态!');
- return;
- }
- let pictureUrl = "";
- if (this.state.orgCodeUrl.length) {
- let picArr = [];
- this.state.orgCodeUrl.map(function (item) {
- if (
- item.response &&
- item.response.data &&
- item.response.data.length
- ) {
- picArr.push(item.response.data);
- }
- });
- pictureUrl = picArr.join(",");
- }
- $.ajax({
- method: "POST",
- dataType: "json",
- crossDomain: false,
- url:
- data.id
- ? globalConfig.context + '/api/admin/standard/update'
- : globalConfig.context + '/api/admin/standard/add',
- data: Object.assign(data, {
- url: pictureUrl,
- }),
- }).done(function (data) {
- this.setState({
- loading: false
- });
- if (!data.error.length) {
- message.success('保存成功!');
- this.handleCancel();
- this.loadData(this.state.pageNo);
- } else {
- message.warning(data.error[0].message);
- }
- }.bind(this));
- },
- followUp(e) {
- this.setState({
- adminName: e
- });
- $.ajax({
- method: "get",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/customer/listAdminByName",
- data: {
- adminName: e,
- },
- success: function (data) {
- let thedata = data.data || [];
- if (!thedata) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- }
- thedata = {};
- }
- this.setState({
- fjlist: thedata,
- });
- }.bind(this),
- }).always(
- function () {
- this.setState({
- loading: false,
- });
- }.bind(this)
- );
- },
- selectF(value) {
- const { data, fjlist } = this.state;
- const newdataSources = JSON.stringify(fjlist) == "{}" ? [] : fjlist;
- this.setState({
- data: Object.assign(data, {
- aid: newdataSources.find((item) => item.name == value).id,
- }),
- });
- },
- render() {
- const { RangePicker } = DatePicker;
- let departmentArr = this.state.departmentArr || [];
- const { searchValues, data } = this.state
- const dataSources = this.state.fjlist || [];
- const options = dataSources.map((group) => (
- <Select.Option key={group.id} value={group.name}>
- {group.name}
- </Select.Option>
- ));
- const formItemLayout = {
- labelCol: { span: 8 },
- wrapperCol: { span: 14 },
- };
- return (
- <div className="user-content">
- <div className="content-title">
- <Tabs defaultActiveKey="1" className="test">
- <TabPane tab="搜索" key="1">
- <div className="user-search" style={{ marginLeft: 10 }}>
- <Input
- placeholder="请输入标准名称"
- value={searchValues["name"]
- ? searchValues["name"]
- : ""}
- onChange={(e) => {
- searchValues["name"] = e.target.value;
- this.setState({
- searchValues: searchValues,
- });
- }}
- />
- <Select
- placeholder="请输入部门名称"
- style={{ width: 230 }}
- value={searchValues["depId"]
- ? searchValues["depId"]
- : undefined}
- onChange={e => {
- searchValues["depId"] = e;
- this.setState({
- searchValues: searchValues,
- });
- }}
- >
- {departmentArr.map(function (item) {
- return (
- <Select.Option key={item.id}>{item.name}</Select.Option>
- );
- })}
- </Select>
- <Select
- placeholder="状态"
- style={{ width: 140 }}
- value={searchValues["status"]}
- onChange={(e) => {
- searchValues["status"] = e;
- this.setState({
- searchValues: searchValues,
- });
- }}
- >
- <Select.Option value={null}>全部</Select.Option>
- <Select.Option value={0}>关闭</Select.Option>
- <Select.Option value={1}>开启</Select.Option>
- </Select>
- <Select
- placeholder="标准类型"
- style={{ width: 140 }}
- value={searchValues["type"]}
- onChange={(e) => {
- searchValues["type"] = e;
- this.setState({
- searchValues: searchValues,
- });
- }}
- >
- {this.state.typeList.map(function (item) {
- return (
- <Select.Option key={item.value} value={item.value}>
- {item.key}
- </Select.Option>
- );
- })}
- </Select>
- <span>时间:</span>
- <RangePicker
- style={{ width: 300 }}
- value={[
- searchValues.startTime ? moment(searchValues.startTime) : null,
- searchValues.endTime ? moment(searchValues.endTime) : null,
- ]}
- onChange={(data, dataString) => {
- this.setState({
- searchValues: Object.assign(searchValues, {
- startTime: dataString[0],
- endTime: dataString[1],
- }),
- });
- }}
- />
- <Button
- type="primary"
- onClick={this.search}
- style={{ margin: "0 10px" }}
- >搜索</Button>
- <Button onClick={this.reset}>重置</Button>
- </div>
- </TabPane>
- <TabPane tab="更改表格显示数据" key="2">
- <div style={{ marginLeft: 10 }}>
- <ChooseList
- columns={this.state.columns}
- changeFn={this.changeList}
- changeList={this.state.changeList}
- top={55}
- margin={11}
- />
- </div>
- </TabPane>
- {adminData.isSuperAdmin ?
- <TabPane tab="新增" key="3">
- <Button
- type="primary"
- className="addButton"
- style={{ float: "left", marginBottom: 10, marginTop: 12 }}
- onClick={this.addClick}
- >
- 新增
- </Button>
- </TabPane> : ""}
- </Tabs>
- <div className="patent-table">
- <Spin spinning={this.state.loading}>
- <Table
- bordered
- columns={
- this.state.changeList
- ? this.state.changeList
- : this.state.columns
- }
- style={{
- cursor: 'pointer',
- }}
- dataSource={this.state.dataSource}
- pagination={this.state.pagination}
- onRowDoubleClick={this.tableRowClick}
- />
- </Spin>
- </div>
- </div>
- {
- this.state.visible != "" &&
- <Modal
- title={!!data.id ? "编辑标准" : "新增标准"}
- visible={this.state.visible != ""}
- width="600px"
- onCancel={this.handleCancel}
- maskClosable={false}
- footer=""
- className="admin-desc-content"
- >
- <Form
- layout="horizontal"
- // onSubmit={this.handleSubmit}
- id="demand-form"
- >
- <Spin spinning={this.state.loading}>
- <div className="clearfix">
- <FormItem
- className="half-middle"
- {...formItemLayout}
- label="标准编号"
- >
- <Input
- placeholder="标准编号"
- value={data["serialNumber"]
- ? data["serialNumber"]
- : ""}
- style={{ width: "230px" }}
- onChange={(e) => {
- data["serialNumber"] = e.target.value;
- this.setState({
- data: data
- });
- }}
- />
- <span className="mandatory">*</span>
- </FormItem>
- <FormItem
- className="half-middle"
- {...formItemLayout}
- label="标准名称"
- >
- <Input
- placeholder="标准名称"
- value={data["name"]
- ? data["name"]
- : ""}
- style={{ width: "230px" }}
- onChange={(e) => {
- data["name"] = e.target.value;
- this.setState({
- data: data
- });
- }}
- />
- <span className="mandatory">*</span>
- </FormItem>
- <FormItem
- className="half-middle"
- {...formItemLayout}
- label="参考"
- >
- <Select
- placeholder="请选择"
- style={{ width: "80px" }}
- value={data.type}
- onChange={(e) => {
- data["type"] = e;
- this.setState({
- data: data
- });
- }}
- >
- {this.state.typeList.map(function (item) {
- return (
- <Select.Option key={item.value} value={item.value}>
- {item.key}
- </Select.Option>
- );
- })}
- </Select>
- <Input
- placeholder="请输入参考网址"
- value={data["reference"]
- ? data["reference"]
- : ""}
- style={{ width: "140px", marginLeft: "10px" }}
- onChange={(e) => {
- data["reference"] = e.target.value;
- this.setState({
- data: data
- });
- }}
- />
- </FormItem>
- <FormItem
- className="half-middle"
- {...formItemLayout}
- label="部门"
- >
- <Select
- placeholder="请选择部门"
- style={{ width: 230 }}
- value={data["depId"]
- ? data["depId"]
- : undefined}
- onChange={e => {
- data["depId"] = e;
- this.setState({
- data: data,
- });
- }}
- >
- {departmentArr.map(function (item) {
- return (
- <Select.Option key={item.id}>{item.name}</Select.Option>
- );
- })}
- </Select>
- <span className="mandatory">*</span>
- </FormItem>
- <FormItem
- className="half-middle"
- {...formItemLayout}
- label="负责人"
- >
- <AutoComplete
- className="certain-category-search"
- dropdownClassName="certain-category-search-dropdown"
- dropdownMatchSelectWidth={false}
- style={{ width: 230 }}
- dataSource={options}
- placeholder="负责人名称"
- value={this.state.adminName}
- onChange={this.followUp.bind(this)}
- filterOption={true}
- onSelect={this.selectF.bind(this)}
- >
- <Input />
- </AutoComplete>
- </FormItem>
- <FormItem
- className="half-middle"
- {...formItemLayout}
- label="状态"
- >
- <Select
- placeholder=""
- style={{ width: "80px" }}
- value={data.status}
- onChange={(e) => {
- data["status"] = e;
- this.setState({
- data: data,
- });
- }}
- >
- {[
- { key: "关闭", value: 0 },
- { key: "开启", value: 1 },
- ].map(function (item) {
- return (
- <Select.Option key={item.value} value={item.value}>
- {item.key}
- </Select.Option>
- );
- })}
- </Select>
- <span className="mandatory">*</span>
- </FormItem>
- <FormItem
- className="half-middle"
- {...formItemLayout}
- label="上附件"
- >
- <PicturesWall
- domId={'standard'}
- fileList={this.getOrgCodeUrl}
- pictureUrl={this.state.orgCodeUrl}
- />
- </FormItem>
- <span className="mandatory" style={{ marginLeft: 210 }}>支持图片,pdf</span>
- </div>
- <FormItem className="half-middle">
- <Button
- className="set-submit"
- type="primary"
- onClick={this.handleSubmit}
- style={{ marginLeft: "150px" }}
- >
- 保存
- </Button>
- <Button
- className="set-submit"
- type="ghost"
- onClick={this.handleCancel}
- >
- 取消
- </Button>
- </FormItem>
- </Spin>
- </Form>
- </Modal>
- }
- </div>
- );
- }
- }));
- export default Standard;
|