customers.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. import React from "react";
  2. import $ from "jquery/src/ajax";
  3. import "react-quill/dist/quill.bubble.css";
  4. import moment from "moment";
  5. import {
  6. Form,
  7. Icon,
  8. Button,
  9. Input,
  10. Table,
  11. message,
  12. Modal,
  13. Select,
  14. DatePicker,
  15. Popconfirm,
  16. } from "antd";
  17. import SpinContainer from '../../SpinContainer';
  18. const { Option } = Select;
  19. const { TextArea } = Input;
  20. const { RangePicker } = DatePicker;
  21. //主体
  22. const Customers = Form.create()(
  23. React.createClass({
  24. loadData(pageNo = 1) {
  25. this.state.data = [];
  26. this.setState({
  27. loading: true,
  28. });
  29. $.ajax({
  30. method: "get",
  31. dataType: "json",
  32. crossDomain: false,
  33. url:
  34. globalConfig.context +
  35. "/api/admin/visitingCustomers/listVisitingCustomers",
  36. data: {
  37. pageNo: pageNo,
  38. pageSize: this.state.pagination.pageSize,
  39. name: this.state.name,
  40. startTime: this.state.time[0],
  41. endTime: this.state.time[1],
  42. status:this.state.statusView
  43. },
  44. success: function(data) {
  45. let theArr = [];
  46. if (!data.data || !data.data.list) {
  47. if (data.error && data.error.length) {
  48. message.warning(data.error[0].message);
  49. }
  50. } else {
  51. for (let i = 0; i < data.data.list.length; i++) {
  52. let thisdata = data.data.list[i];
  53. theArr.push({
  54. key: i + 1,
  55. id: thisdata.id,
  56. name: thisdata.name,
  57. mobile: thisdata.mobile,
  58. status: thisdata.status,
  59. remark: thisdata.remark,
  60. createTimes: thisdata.createTimes,
  61. });
  62. }
  63. this.state.pagination.current = data.data.pageNo;
  64. this.state.pagination.total = data.data.totalCount;
  65. }
  66. this.setState({
  67. dataSource: theArr,
  68. pagination: this.state.pagination,
  69. page: data.data.pageNo
  70. });
  71. }.bind(this)
  72. }).always(
  73. function() {
  74. this.setState({
  75. loading: false
  76. });
  77. }.bind(this)
  78. );
  79. },
  80. getInitialState() {
  81. return {
  82. //数据类型
  83. loading: false,
  84. visible: false,
  85. time: [],
  86. pagination: {
  87. defaultCurrent: 1,
  88. defaultPageSize: 10,
  89. showQuickJumper: true,
  90. pageSize: 10,
  91. onChange: function(page) {
  92. this.loadData(page);
  93. this.setState({
  94. selectedRowKeys: []
  95. });
  96. }.bind(this),
  97. showTotal: function(total) {
  98. return "共" + total + "条数据";
  99. }
  100. },
  101. columns: [
  102. {
  103. title: "序号",
  104. dataIndex: "id",
  105. key: "id"
  106. },
  107. {
  108. title: "姓名",
  109. dataIndex: "name",
  110. key: "name"
  111. },
  112. {
  113. title: "联系方式",
  114. dataIndex: "mobile",
  115. key: "mobile"
  116. },
  117. {
  118. title: "提交时间",
  119. dataIndex: "createTimes",
  120. key: "createTimes"
  121. },
  122. {
  123. title: "是否查看",
  124. dataIndex: "status",
  125. key: "status",
  126. render: text => {
  127. if (text == 0) {
  128. return "未读";
  129. } else if (text == 1) {
  130. return "已读";
  131. }
  132. }
  133. },
  134. {
  135. title: "回复备注",
  136. dataIndex: "remark",
  137. key: "remark"
  138. },
  139. {
  140. title: "操作",
  141. dataIndex: "aab",
  142. key: "aab",
  143. render: (text, record) => {
  144. return (
  145. <div>
  146. <Button
  147. type="primary"
  148. onClick={(e) => {
  149. this.addRemarks(record);
  150. }}
  151. >
  152. 添加备注
  153. </Button>
  154. <Popconfirm
  155. placement="top"
  156. title={"是否确认删除?"}
  157. onConfirm={e => {
  158. this.delete(record);
  159. }}
  160. okText="确认"
  161. cancelText="取消"
  162. >
  163. <Button
  164. type="primary"
  165. style={{ marginLeft: 10 }}
  166. >
  167. 删除
  168. </Button>
  169. </Popconfirm>
  170. </div>
  171. );
  172. }
  173. }
  174. ],
  175. //数据列表
  176. dataSource: []
  177. };
  178. },
  179. componentWillMount() {
  180. this.loadData();
  181. },
  182. stopPropagation(e) {
  183. e.stopPropagation();
  184. e.nativeEvent.stopImmediatePropagation();
  185. },
  186. addRemarks(record) {
  187. let status = record.status + ""
  188. this.setState({
  189. visible: true,
  190. id: record.id,
  191. status,
  192. remark: record.remark
  193. })
  194. },
  195. cancel() {
  196. this.setState({
  197. visible: false,
  198. remarks: undefined,
  199. status: []
  200. })
  201. },
  202. // 导出
  203. exportExec() {
  204. message.config({
  205. duration: 20,
  206. });
  207. let loading = message.loading("下载中...");
  208. this.setState({
  209. exportPendingLoading: true,
  210. });
  211. let data = {
  212. name: this.state.name || undefined,
  213. startTime: this.state.time[0] || undefined,
  214. endTime: this.state.time[1] || undefined,
  215. status:this.state.statusView || undefined
  216. };
  217. for (let i of Object.keys(data)) {
  218. if (i === "status" || i === "clockIn") {
  219. if (isNaN(parseInt(data[i]))) {
  220. delete data[i];
  221. }
  222. } else if (!data[i]) {
  223. delete data[i];
  224. }
  225. }
  226. // console.log(data);
  227. // debugger
  228. // let obj1 = JSON.parse(JSON.stringify(this.state.columns));
  229. // console.log(obj1);
  230. // data = Object.assign(data, obj1);
  231. // if (this.props.exportExecProcessing) {
  232. // data = this.props.exportExecProcessing(data);
  233. // }
  234. // console.log(data);
  235. $.ajax({
  236. method: "get",
  237. dataType: "json",
  238. crossDomain: false,
  239. url: globalConfig.context +'/api/admin/visitingCustomers/listVisitingCustomers/export',
  240. data,
  241. success: function (data) {
  242. if (data.error.length === 0) {
  243. this.download(data.data.data);
  244. // console.log(data.data.data);
  245. } else {
  246. message.warning(data.error[0].message);
  247. }
  248. }.bind(this),
  249. }).always(
  250. function () {
  251. loading();
  252. this.setState({
  253. exportPendingLoading: false,
  254. });
  255. }.bind(this)
  256. );
  257. },
  258. download(fileName) {
  259. window.location.href =
  260. globalConfig.context + "/open/download?fileName=" + fileName+"&delete=true";
  261. },
  262. delete(record) {
  263. this.setState({
  264. loading: true
  265. });
  266. $.ajax({
  267. method: "post",
  268. dataType: "json",
  269. crossDomain: false,
  270. url:
  271. globalConfig.context +
  272. "/api/admin/visitingCustomers/updateVisitingCustomers",
  273. data: {
  274. id: record.id,
  275. status: 2,
  276. remark: record.remark
  277. },
  278. success: function(data) {
  279. let theArr = [];
  280. if (data.error && data.error.length) {
  281. message.warning(data.error[0].message);
  282. } else {
  283. message.success("删除成功!");
  284. this.loadData();
  285. }
  286. }.bind(this)
  287. }).always(
  288. function() {
  289. this.setState({
  290. loading: false
  291. });
  292. }.bind(this)
  293. );
  294. },
  295. tijiao() {
  296. this.setState({
  297. loading: true
  298. })
  299. $.ajax({
  300. method: "post",
  301. dataType: "json",
  302. crossDomain: false,
  303. url:
  304. globalConfig.context +
  305. "/api/admin/visitingCustomers/updateVisitingCustomers",
  306. data: {
  307. id: this.state.id,
  308. status: this.state.status,
  309. remark: this.state.remark
  310. },
  311. success: function(data) {
  312. let theArr = [];
  313. if (data.error && data.error.length) {
  314. message.warning(data.error[0].message);
  315. }else {
  316. this.loadData()
  317. this.cancel()
  318. message.success("提交成功!");
  319. }
  320. }.bind(this)
  321. }).always(
  322. function() {
  323. this.setState({
  324. loading: false
  325. });
  326. }.bind(this)
  327. );
  328. },
  329. reset() {
  330. this.state.time = []
  331. this.state.name = undefined
  332. this.state.statusView = undefined
  333. this.loadData()
  334. },
  335. render() {
  336. const FormItem = Form.Item;
  337. return (
  338. <div className="user-content">
  339. <div className="content-title">
  340. <span>客户访问列表</span>
  341. <div className="user-search">
  342. <Input
  343. placeholder="请输入客户名称"
  344. style={{
  345. width: "150px",
  346. marginRight: "20px",
  347. marginBottom: "10px"
  348. }}
  349. value={this.state.name}
  350. onChange={e => {
  351. this.setState({ name: e.target.value });
  352. }}
  353. />
  354. {/* 互链 */}
  355. <Select
  356. placeholder="是否查看"
  357. style={{ width: 150 }}
  358. value={this.state.statusView}
  359. onChange={(e) => {
  360. this.setState({
  361. statusView: e,
  362. });
  363. }}
  364. >
  365. <Option value="1">是,已查看</Option>
  366. <Option value="0">否,待查看</Option>
  367. </Select>
  368. <span style={{ fontSize: 14 }} >提交日期:</span>
  369. <RangePicker
  370. value={[
  371. this.state.time[0] ? moment(this.state.time[0]) : null,
  372. this.state.time[1] ? moment(this.state.time[1]) : null
  373. ]}
  374. onChange={(data, dataString) => {
  375. this.setState({ time: dataString });
  376. }}
  377. />
  378. <Button
  379. type="primary"
  380. onClick={()=>{this.loadData()}}
  381. style={{ marginRight: "10px",marginLeft: 10 }}
  382. >
  383. 搜索
  384. </Button>
  385. <Button onClick={this.reset} style={{ marginRight: "10px" }}>
  386. 重置
  387. </Button>
  388. <Button loading={this.state.exportPendingLoading} onClick={this.exportExec} style={{ marginRight: "10px" }}>
  389. 导出
  390. </Button>
  391. </div>
  392. <div className="patent-table">
  393. <SpinContainer spinning={this.state.loading}>
  394. <Table
  395. columns={this.state.columns}
  396. dataSource={this.state.dataSource}
  397. pagination={this.state.pagination}
  398. onRowClick={this.tableRowClick}
  399. size="small"
  400. bordered
  401. />
  402. </SpinContainer>
  403. </div>
  404. </div>
  405. <div className="patent-desc">
  406. <Modal
  407. className="customeDetails"
  408. title={"备注信息"}
  409. width="350"
  410. visible={this.state.visible}
  411. onOk={this.tijiao}
  412. okText={"保存"}
  413. onCancel={this.cancel}
  414. >
  415. <SpinContainer spinning={this.state.loading}>
  416. <div className="clearfix">
  417. <FormItem
  418. labelCol={{ span: 6 }}
  419. wrapperCol={{ span: 14 }}
  420. label="客户备注"
  421. >
  422. <TextArea
  423. placeholder="请输入备注"
  424. value={this.state.remark}
  425. onChange={e => {
  426. this.setState({
  427. remark: e.target.value
  428. });
  429. }}
  430. />
  431. </FormItem>
  432. <FormItem
  433. labelCol={{ span: 6 }}
  434. wrapperCol={{ span: 14 }}
  435. label="是否已读"
  436. >
  437. <Select
  438. defaultValue="0"
  439. style={{ width: 120 }}
  440. value={this.state.status}
  441. placeholder="是否阅读"
  442. onChange={e => {
  443. this.setState({
  444. status: e
  445. });
  446. }}
  447. >
  448. <Option value="0">未读</Option>
  449. <Option value="1">已读</Option>
  450. </Select>
  451. </FormItem>
  452. </div>
  453. </SpinContainer>
  454. </Modal>
  455. </div>
  456. </div>
  457. );
  458. }
  459. })
  460. );
  461. export default Form.create()(Customers);