searchInput.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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: 120,
  187. defaultValue: "",
  188. getValue: value => {
  189. this.setState({
  190. orderNoSearch: value,
  191. reset: false
  192. });
  193. }
  194. },
  195. {
  196. placeholder: "合同编号",
  197. width: 120,
  198. defaultValue: "",
  199. getValue: value => {
  200. this.setState({
  201. contractNoSearch: value,
  202. reset: false
  203. });
  204. }
  205. },
  206. {
  207. placeholder: "客户名称",
  208. width: 120,
  209. defaultValue: "",
  210. getValue: value => {
  211. this.setState({
  212. userNameSearch: value,
  213. reset: false
  214. });
  215. }
  216. },
  217. {
  218. placeholder: "订单负责人",
  219. width: 120,
  220. defaultValue: "",
  221. getValue: value => {
  222. this.setState({
  223. salesmanNameSearch: value,
  224. reset: false
  225. });
  226. }
  227. }
  228. ];
  229. // 选择框数据
  230. const SearchSelectData = [
  231. {
  232. placeholder: "订单部门",
  233. width: 120,
  234. defaultValue: undefined,
  235. content: this.state.departmentArr,
  236. getValue: value => {
  237. this.setState({
  238. depIdSearch: value,
  239. reset: false
  240. });
  241. }
  242. },
  243. {
  244. placeholder: "审核状态",
  245. width: 120,
  246. defaultValue: "1",
  247. content: [
  248. {
  249. name: "所有",
  250. id: "0"
  251. },
  252. {
  253. name: "未审核",
  254. id: "1"
  255. },
  256. {
  257. name: "已审核",
  258. id: "2"
  259. },
  260. {
  261. name: "退票中",
  262. id: "3"
  263. }
  264. ],
  265. getValue: value => {
  266. this.setState({
  267. completeSearch: value,
  268. reset: false
  269. });
  270. }
  271. },
  272. {
  273. placeholder: "变更类型",
  274. width: 120,
  275. defaultValue: undefined,
  276. content: [
  277. {
  278. name: "退单退款",
  279. id: "0"
  280. },
  281. {
  282. name: "项目及金额变更",
  283. id: "1"
  284. },
  285. {
  286. name: "仅项目变更",
  287. id: "2"
  288. },
  289. {
  290. name: "仅金额变更",
  291. id: "3"
  292. },
  293. {
  294. name: "重报",
  295. id: "4"
  296. },
  297. {
  298. name: "赠送",
  299. id: "5"
  300. }
  301. ],
  302. getValue: value => {
  303. this.setState({
  304. changeSearch: value,
  305. reset: false
  306. });
  307. }
  308. },
  309. {
  310. placeholder: "时间",
  311. width: 120,
  312. defaultValue: "1",
  313. content: [
  314. {
  315. name: "提交时间",
  316. id: "0"
  317. },
  318. {
  319. name: "下单时间",
  320. id: "1"
  321. }
  322. ],
  323. getValue: value => {
  324. this.setState({
  325. timeTypeSearch: value,
  326. reset: false
  327. });
  328. }
  329. }
  330. ];
  331. // 时间框数据
  332. const SearchRangePickerData = [
  333. {
  334. defaultValue: [],
  335. getValue: value => {
  336. this.setState({
  337. releaseDate: value,
  338. reset: false
  339. });
  340. }
  341. }
  342. ];
  343. return (
  344. <div style={{ display: "inline-block", marginBottom: 10 }}>
  345. {SearchInputData.map((item, index) => {
  346. return (
  347. <PrimaryInput
  348. searchInputData={item}
  349. key={index}
  350. reset={this.state.reset}
  351. />
  352. );
  353. })}
  354. {SearchSelectData.map((item, index) => {
  355. return (
  356. <PrimarySelect
  357. searchSelectData={item}
  358. key={index}
  359. reset={this.state.reset}
  360. />
  361. );
  362. })}
  363. {SearchRangePickerData.map((item, index) => {
  364. return (
  365. <PrimaryRangePicker
  366. searchRangePickerData={item}
  367. key={index}
  368. reset={this.state.reset}
  369. />
  370. );
  371. })}
  372. <Button
  373. type="primary"
  374. style={{ marginLeft: 10 }}
  375. onClick={() => {
  376. this.props.search(this.state);
  377. }}
  378. >
  379. 搜索
  380. </Button>
  381. <Button
  382. onClick={_e => {
  383. this.setState(
  384. {
  385. reset: true
  386. },
  387. () => {
  388. this.props.search(this.state);
  389. }
  390. );
  391. }}
  392. style={{ marginLeft: 10 }}
  393. >
  394. 重置
  395. </Button>
  396. </div>
  397. );
  398. }
  399. }
  400. export { SearchInput, PrimaryInput, PrimarySelect, PrimaryRangePicker };