searchInput.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. import React, { Component } from "react";
  2. import { Input, Button, Select, DatePicker } from "antd";
  3. import moment from "moment";
  4. import $ from "jquery/src/ajax";
  5. // 搜索输入框
  6. class PrimaryInput extends Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. value: this.props.searchInputData.defaultValue
  11. };
  12. this.reset = this.reset.bind(this);
  13. }
  14. componentWillReceiveProps(nextProps) {
  15. if (nextProps.reset) {
  16. this.reset();
  17. }
  18. }
  19. reset() {
  20. this.setState(
  21. {
  22. value: this.props.searchInputData.defaultValue
  23. },
  24. () => {
  25. this.props.searchInputData.getValue(this.state.value);
  26. }
  27. );
  28. }
  29. render() {
  30. const Datas = this.props.searchInputData;
  31. return (
  32. <Input
  33. style={{ width: Datas.width, marginRight: 10 }}
  34. placeholder={Datas.placeholder}
  35. value={this.state.value}
  36. onChange={e => {
  37. Datas.getValue(e.target.value);
  38. this.setState({ value: e.target.value });
  39. }}
  40. />
  41. );
  42. }
  43. }
  44. // 搜索选择框
  45. class PrimarySelect extends Component {
  46. constructor(props) {
  47. super(props);
  48. this.state = {
  49. value: this.props.searchSelectData.defaultValue
  50. };
  51. this.reset = this.reset.bind(this);
  52. }
  53. componentWillReceiveProps(nextProps) {
  54. if (nextProps.reset) {
  55. this.reset();
  56. }
  57. }
  58. reset() {
  59. this.setState(
  60. {
  61. value: this.props.searchSelectData.defaultValue
  62. },
  63. () => {
  64. this.props.searchSelectData.getValue(this.state.value);
  65. }
  66. );
  67. }
  68. render() {
  69. const Datas = this.props.searchSelectData;
  70. return (
  71. <Select
  72. style={{ width: Datas.width, marginRight: 10 }}
  73. placeholder={Datas.placeholder}
  74. value={this.state.value}
  75. onChange={e => {
  76. Datas.getValue(e);
  77. this.setState({
  78. value: e
  79. });
  80. }}
  81. >
  82. {Datas.content.map((item, index) => {
  83. return (
  84. <Option value={item.id} key={index}>
  85. {item.name}
  86. </Option>
  87. );
  88. })}
  89. </Select>
  90. );
  91. }
  92. }
  93. // 时间搜索框
  94. class PrimaryRangePicker extends Component {
  95. constructor(props) {
  96. super(props);
  97. this.state = {
  98. value: this.props.searchRangePickerData.defaultValue
  99. };
  100. this.reset = this.reset.bind(this);
  101. }
  102. componentWillReceiveProps(nextProps) {
  103. if (nextProps.reset) {
  104. this.reset();
  105. }
  106. }
  107. reset() {
  108. this.setState(
  109. {
  110. value: this.props.searchRangePickerData.defaultValue
  111. },
  112. () => {
  113. this.props.searchRangePickerData.getValue(this.state.value);
  114. }
  115. );
  116. }
  117. render() {
  118. const { RangePicker } = DatePicker;
  119. const Datas = this.props.searchRangePickerData;
  120. return (
  121. <RangePicker
  122. value={[
  123. this.state.value[0] ? moment(this.state.value[0]) : null,
  124. this.state.value[1] ? moment(this.state.value[1]) : null
  125. ]}
  126. onChange={(_data, dataString) => {
  127. Datas.getValue(dataString);
  128. this.setState({
  129. value: dataString
  130. });
  131. }}
  132. />
  133. );
  134. }
  135. }
  136. // 搜索重置组件
  137. class SearchInput extends Component {
  138. constructor(props) {
  139. super(props);
  140. this.state = {
  141. reset: false,
  142. departmentArr: [],
  143. releaseDate: [],
  144. timeTypeSearch: "1",
  145. completeSearch: "1"
  146. };
  147. this.departmentList = this.departmentList.bind(this);
  148. }
  149. departmentList() {
  150. $.ajax({
  151. method: "get",
  152. dataType: "json",
  153. crossDomain: false,
  154. url: globalConfig.context + "/api/admin/organization/selectSuperId",
  155. data: {},
  156. success: function(data) {
  157. let thedata = data.data;
  158. let theArr = [];
  159. if (!thedata) {
  160. if (data.error && data.error.length) {
  161. message.warning(data.error[0].message);
  162. }
  163. } else {
  164. thedata.map(function(item, index) {
  165. theArr.push({
  166. key: index,
  167. name: item.name,
  168. id: item.id
  169. });
  170. });
  171. }
  172. this.setState({
  173. departmentArr: theArr
  174. });
  175. }.bind(this)
  176. });
  177. }
  178. componentWillMount() {
  179. this.departmentList();
  180. }
  181. render() {
  182. // 输入框数据
  183. const SearchInputData = [
  184. {
  185. placeholder: "客户名称",
  186. width: 160,
  187. defaultValue: "",
  188. getValue: value => {
  189. this.setState({
  190. userNameSearch: value,
  191. reset: false
  192. });
  193. }
  194. },
  195. {
  196. placeholder: "订单负责人",
  197. width: 160,
  198. defaultValue: "",
  199. getValue: value => {
  200. this.setState({
  201. salesmanNameSearch: value,
  202. reset: false
  203. });
  204. }
  205. }
  206. ];
  207. // 选择框数据
  208. const SearchSelectData = [
  209. {
  210. placeholder: "订单部门",
  211. width: 160,
  212. defaultValue: undefined,
  213. content: this.state.departmentArr,
  214. getValue: value => {
  215. this.setState({
  216. depIdSearch: value,
  217. reset: false
  218. });
  219. }
  220. },
  221. {
  222. placeholder: "审核状态",
  223. width: 160,
  224. defaultValue: "1",
  225. content: [
  226. {
  227. name: "所有",
  228. id: "0"
  229. },
  230. {
  231. name: "未审核",
  232. id: "1"
  233. },
  234. {
  235. name: "已审核",
  236. id: "2"
  237. },
  238. {
  239. name: "退票中",
  240. id: "3"
  241. }
  242. ],
  243. getValue: value => {
  244. this.setState({
  245. completeSearch: value,
  246. reset: false
  247. });
  248. }
  249. },
  250. {
  251. placeholder: "时间",
  252. width: 160,
  253. defaultValue: "1",
  254. content: [
  255. {
  256. name: "提交时间",
  257. id: "0"
  258. },
  259. {
  260. name: "下单时间",
  261. id: "1"
  262. }
  263. ],
  264. getValue: value => {
  265. this.setState({
  266. timeTypeSearch: value,
  267. reset: false
  268. });
  269. }
  270. }
  271. ];
  272. // 时间框数据
  273. const SearchRangePickerData = [
  274. {
  275. defaultValue: [],
  276. getValue: value => {
  277. this.setState({
  278. releaseDate: value,
  279. reset: false
  280. });
  281. }
  282. }
  283. ];
  284. return (
  285. <div style={{ display: "inline-block", marginBottom: 10 }}>
  286. {SearchInputData.map((item, index) => {
  287. return (
  288. <PrimaryInput
  289. searchInputData={item}
  290. key={index}
  291. reset={this.state.reset}
  292. />
  293. );
  294. })}
  295. {SearchSelectData.map((item, index) => {
  296. return (
  297. <PrimarySelect
  298. searchSelectData={item}
  299. key={index}
  300. reset={this.state.reset}
  301. />
  302. );
  303. })}
  304. {SearchRangePickerData.map((item, index) => {
  305. return (
  306. <PrimaryRangePicker
  307. searchRangePickerData={item}
  308. key={index}
  309. reset={this.state.reset}
  310. />
  311. );
  312. })}
  313. <Button
  314. type="primary"
  315. style={{ marginLeft: 10 }}
  316. onClick={() => {
  317. this.props.search(this.state);
  318. }}
  319. >
  320. 搜索
  321. </Button>
  322. <Button
  323. onClick={_e => {
  324. this.setState(
  325. {
  326. reset: true
  327. },
  328. () => {
  329. this.props.search(this.state);
  330. }
  331. );
  332. }}
  333. style={{ marginLeft: 10 }}
  334. >
  335. 重置
  336. </Button>
  337. </div>
  338. );
  339. }
  340. }
  341. export { SearchInput, PrimaryInput, PrimarySelect, PrimaryRangePicker };