searchInput.js 9.3 KB

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