searchInput.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. name: "已完成",
  266. id: "4"
  267. },
  268. {
  269. name: "已驳回",
  270. id: "5"
  271. }
  272. ],
  273. getValue: value => {
  274. this.setState({
  275. completeSearch: value,
  276. reset: false
  277. });
  278. }
  279. },
  280. {
  281. placeholder: "变更类型",
  282. width: 120,
  283. defaultValue: undefined,
  284. content: [
  285. {
  286. name: "退单退款",
  287. id: "0"
  288. },
  289. {
  290. name: "项目及金额变更",
  291. id: "1"
  292. },
  293. {
  294. name: "仅项目变更",
  295. id: "2"
  296. },
  297. {
  298. name: "仅金额变更",
  299. id: "3"
  300. },
  301. {
  302. name: "重报",
  303. id: "4"
  304. },
  305. {
  306. name: "赠送",
  307. id: "5"
  308. }
  309. ],
  310. getValue: value => {
  311. this.setState({
  312. changeSearch: value,
  313. reset: false
  314. });
  315. }
  316. },
  317. {
  318. placeholder: "时间",
  319. width: 120,
  320. defaultValue: "1",
  321. content: [
  322. {
  323. name: "提交时间",
  324. id: "0"
  325. },
  326. {
  327. name: "下单时间",
  328. id: "1"
  329. }
  330. ],
  331. getValue: value => {
  332. this.setState({
  333. timeTypeSearch: value,
  334. reset: false
  335. });
  336. }
  337. }
  338. ];
  339. // 时间框数据
  340. const SearchRangePickerData = [
  341. {
  342. defaultValue: [],
  343. getValue: value => {
  344. this.setState({
  345. releaseDate: value,
  346. reset: false
  347. });
  348. }
  349. }
  350. ];
  351. return (
  352. <div style={{ display: "inline-block", marginBottom: 10 }}>
  353. {SearchInputData.map((item, index) => {
  354. return (
  355. <PrimaryInput
  356. searchInputData={item}
  357. key={index}
  358. reset={this.state.reset}
  359. />
  360. );
  361. })}
  362. {SearchSelectData.map((item, index) => {
  363. if(this.props.isYxy) {
  364. if(item.placeholder == "审核状态") {
  365. item.content.splice(item.content.length - 1, 1)
  366. }
  367. }
  368. return (
  369. <PrimarySelect
  370. searchSelectData={item}
  371. key={index}
  372. reset={this.state.reset}
  373. />
  374. );
  375. })}
  376. {SearchRangePickerData.map((item, index) => {
  377. return (
  378. <PrimaryRangePicker
  379. searchRangePickerData={item}
  380. key={index}
  381. reset={this.state.reset}
  382. />
  383. );
  384. })}
  385. <Button
  386. type="primary"
  387. style={{ marginLeft: 10, marginTop: 10 }}
  388. onClick={() => {
  389. this.props.search(this.state);
  390. }}
  391. >
  392. 搜索
  393. </Button>
  394. <Button
  395. onClick={_e => {
  396. this.setState(
  397. {
  398. reset: true
  399. },
  400. () => {
  401. this.props.search(this.state);
  402. }
  403. );
  404. }}
  405. style={{ marginLeft: 10 }}
  406. >
  407. 重置
  408. </Button>
  409. </div>
  410. );
  411. }
  412. }
  413. export { SearchInput, PrimaryInput, PrimarySelect, PrimaryRangePicker };