| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 | import React, { Component } from "react";import { Input, Button, Select, DatePicker } from "antd";import moment from "moment";import $ from "jquery/src/ajax";// 搜索输入框class PrimaryInput extends Component {  constructor(props) {    super(props);    this.state = {      value: this.props.searchInputData.defaultValue    };    this.reset = this.reset.bind(this);  }  componentWillReceiveProps(nextProps) {    if (nextProps.reset) {      this.reset();    }  }  reset() {    this.setState(      {        value: this.props.searchInputData.defaultValue      },      () => {        this.props.searchInputData.getValue(this.state.value);      }    );  }  render() {    const Datas = this.props.searchInputData;    return (      <Input        style={{ width: Datas.width, marginRight: 10 }}        placeholder={Datas.placeholder}        value={this.state.value}        onChange={e => {          Datas.getValue(e.target.value);          this.setState({ value: e.target.value });        }}      />    );  }}// 搜索选择框class PrimarySelect extends Component {  constructor(props) {    super(props);    this.state = {      value: this.props.searchSelectData.defaultValue    };    this.reset = this.reset.bind(this);  }  componentWillReceiveProps(nextProps) {    if (nextProps.reset) {      this.reset();    }  }  reset() {    this.setState(      {        value: this.props.searchSelectData.defaultValue      },      () => {        this.props.searchSelectData.getValue(this.state.value);      }    );  }  render() {    const Datas = this.props.searchSelectData;    return (      <Select        style={{ width: Datas.width, marginRight: 10 }}        placeholder={Datas.placeholder}        value={this.state.value}        onChange={e => {          Datas.getValue(e);          this.setState({            value: e          });        }}      >        {Datas.content.map((item, index) => {          return (            <Option value={item.id} key={index}>              {item.name}            </Option>          );        })}      </Select>    );  }}// 时间搜索框class PrimaryRangePicker extends Component {  constructor(props) {    super(props);    this.state = {      value: this.props.searchRangePickerData.defaultValue    };    this.reset = this.reset.bind(this);  }  componentWillReceiveProps(nextProps) {    if (nextProps.reset) {      this.reset();    }  }  reset() {    this.setState(      {        value: this.props.searchRangePickerData.defaultValue      },      () => {        this.props.searchRangePickerData.getValue(this.state.value);      }    );  }  render() {    const { RangePicker } = DatePicker;    const Datas = this.props.searchRangePickerData;    return (      <RangePicker        value={[          this.state.value[0] ? moment(this.state.value[0]) : null,          this.state.value[1] ? moment(this.state.value[1]) : null        ]}        onChange={(_data, dataString) => {          Datas.getValue(dataString);          this.setState({            value: dataString          });        }}      />    );  }}// 搜索重置组件class SearchInput extends Component {  constructor(props) {    super(props);    this.state = {      reset: false,      departmentArr: [],      releaseDate: [],      timeTypeSearch: "1",      completeSearch: "1"    };    this.departmentList = this.departmentList.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)    });  }  componentWillMount() {    this.departmentList();  }  render() {    // 输入框数据    const SearchInputData = [      {        placeholder: "客户名称",        width: 160,        defaultValue: "",        getValue: value => {          this.setState({            userNameSearch: value,            reset: false          });        }      },      {        placeholder: "订单负责人",        width: 160,        defaultValue: "",        getValue: value => {          this.setState({            salesmanNameSearch: value,            reset: false          });        }      }    ];    // 选择框数据    const SearchSelectData = [      {        placeholder: "订单部门",        width: 160,        defaultValue: undefined,        content: this.state.departmentArr,        getValue: value => {          this.setState({            depIdSearch: value,            reset: false          });        }      },      {        placeholder: "审核状态",        width: 160,        defaultValue: "1",        content: [          {            name: "所有",            id: "0"          },          {            name: "未审核",            id: "1"          },          {            name: "已审核",            id: "2"          },          {            name: "退票中",            id: "3"          }        ],        getValue: value => {          this.setState({            completeSearch: value,            reset: false          });        }      },      {        placeholder: "时间",        width: 160,        defaultValue: "1",        content: [          {            name: "提交时间",            id: "0"          },          {            name: "下单时间",            id: "1"          }        ],        getValue: value => {          this.setState({            timeTypeSearch: value,            reset: false          });        }      }    ];    // 时间框数据    const SearchRangePickerData = [      {        defaultValue: [],        getValue: value => {          this.setState({            releaseDate: value,            reset: false          });        }      }    ];    return (      <div style={{ display: "inline-block", marginBottom: 10 }}>        {SearchInputData.map((item, index) => {          return (            <PrimaryInput              searchInputData={item}              key={index}              reset={this.state.reset}            />          );        })}        {SearchSelectData.map((item, index) => {          return (            <PrimarySelect              searchSelectData={item}              key={index}              reset={this.state.reset}            />          );        })}        {SearchRangePickerData.map((item, index) => {          return (            <PrimaryRangePicker              searchRangePickerData={item}              key={index}              reset={this.state.reset}            />          );        })}        <Button          type="primary"          style={{ marginLeft: 10 }}          onClick={() => {            this.props.search(this.state);          }}        >          搜索        </Button>        <Button          onClick={_e => {            this.setState(              {                reset: true              },              () => {                this.props.search(this.state);              }            );          }}          style={{ marginLeft: 10 }}        >          重置        </Button>      </div>    );  }}export { SearchInput, PrimaryInput, PrimarySelect, PrimaryRangePicker };
 |