text: /*
   * @Author: lbb 
   * @Date: 2018-05-18 18:56:24 
   * @Last Modified by: zouwendi
   * @Last Modified time: 2018-06-11 17:56:23
   * @Description:子库管理
   */
  import React, { Component } from 'react';
  import { Form, Row, Col, Input, Button, Modal, Card, Select } from 'antd';
  import { connect } from 'dva';
  import { Link, routerRedux } from 'dva/router';
  import Debounce from 'lodash-decorators/debounce';
  import Bind from 'lodash-decorators/bind';
  
  import styles from '../../styles/list.less';
  
  import List from '../../components/List';
  import Operate from '../../components/Oprs';
  
  const FormItem = Form.Item;
  const { Option } = Select;
  const url = 'subware';
  const routerUrl = '/subware';
  
  @connect(({ base }) => ({
    base,
  }))
  @Form.create()
  @List.create()
  export default class SubwareList extends Component {
    state = {
      scrollY: document.body.clientHeight > 768 ? 430 + document.body.clientHeight - 800 : 430,
    };
  
    componentDidMount() {
      window.addEventListener('resize', this.resize);
    }
    componentWillUnmount() {
      window.removeEventListener('resize', this.resize);
    }
  
    @Bind()
    @Debounce(200)
    resize() {
      this.setState({
        scrollY: document.body.clientHeight > 768 ? 430 + document.body.clientHeight - 768 : 430,
      });
    }
  
    handleSearch = e => {
      e.preventDefault();
      const { form, list } = this.props;
      const { setList } = list;
      form.validateFieldsAndScroll((err, values) => {
        setList({
          current: 1,
          queryMap: { ...values } || {},
        });
      });
    };
  
    handleFormReset = () => {
      const { form, list } = this.props;
      const { setList } = list;
      setList({
        current: 1,
        queryMap: {},
      });
      form.resetFields();
    };
  
    // 删除后调用list
    hanleDelete = info => {
      const { dispatch, list } = this.props;
      const { setList } = list;
      dispatch({
        type: `${url}/delete`,
        payload: {
          id: info.subware_code, //主键
        },
        callback: () => setList(),
        url,
      });
    };
  
    render() {
      const { form, base } = this.props;
      const { getFieldDecorator } = form;
      const { hanleDelete } = this;
      const showConfirm = record => {
        Modal.confirm({
          title: '确定想要删除吗?',
          okType: 'danger',
          okText: '是',
          cancelText: '否',
          onOk() {
            hanleDelete(record);
          },
        });
      };
  
      const columns = [
        {
          title: '操作',
          key: 'action',
          align: 'center',
          width: 240,
          render: (text, record) => (
            <Row type="flex" justify="space-around">
              <Operate operateName="UPDATE">
                <Link
                  to={{
                    pathname: `${routerUrl}/info`,
                    state: { id: record.subware_code }, //主键
                  }}
                >
                  <Button type="primary" icon="edit" ghost size="small">
                    编辑
                  </Button>
                </Link>
              </Operate>
              <Operate operateName="DELETE">
                <Button
                  type="danger"
                  icon="delete"
                  ghost
                  size="small"
                  onClick={() => showConfirm(record)}
                >
                  删除
                </Button>
              </Operate>
            </Row>
          ),
        },
        {
          title: '子库编码',
          dataIndex: 'subware_code',
          width: 100,
          sorter: true,
        },
        {
          title: '子库名称',
          dataIndex: 'subware_name',
          width: 200,
          sorter: true,
        },
        {
          title: '子库类型',
          dataIndex: 'subware_type_name',
          width: 100,
          sorter: true,
        },
        {
          title: '主库编码',
          dataIndex: 'warehouse_name',
          width: 150,
          sorter: true,
        },
        {
          title: '主库描述',
          dataIndex: 'warehouse_desc',
          width: 150,
        },
        {
          title: '纬度',
          dataIndex: 'latitude',
          width: 100,
        },
        {
          title: '经度',
          dataIndex: 'longitude',
          width: 100,
        },
        {
          title: '地址',
          dataIndex: 'address',
        },
      ];
  
      const listConfig = {
        url: '/api/query/querySubwareList', // 必填,请求url
        scroll: { x: 1500, y: this.state.scrollY }, // 可选配置,同antd table
        rowKey: 'subware_code', // 必填,行key
        columns, // 必填,行配置
      };
  
      return (
        <div className={styles.tableListForm}>
          <Card bordered={false} style={{ marginBottom: 24 }} hoverable>
            <Form onSubmit={this.handleSearch} layout="inline">
              <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
                <Col md={8} sm={24}>
                  <FormItem label="子库编码">
                    {getFieldDecorator('subware_code', {
                      initialValue: this.props.list.queryMap.subware_code,
                    })(<Input placeholder="请输入" />)}
                  </FormItem>
                </Col>
                <Col md={8} sm={24}>
                  <FormItem label="主库编码">
                    {getFieldDecorator('warehouse_name', {
                      initialValue: this.props.list.queryMap.warehouse_name,
                    })(
                      <Select
                        showSearch
                        placeholder="选择"
                        optionFilterProp="children"
                        filterOption={(input, option) =>
                          option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                        }
                      >
                        {Array.isArray(base.WareHouse)
                          ? base.WareHouse.map(item => (
                              <Option key={item.dic_code} value={item.dic_code}>
                                {`${item.dic_name}(${item.dic_code})`}
                              </Option>
                            ))
                          : null}
                      </Select>
                    )}
                  </FormItem>
                </Col>
                <Col md={8} sm={24}>
                  <FormItem label="子库类型">
                    {getFieldDecorator('subware_type', {
                      initialValue: this.props.list.queryMap.subware_type,
                    })(
                      <Select
                        showSearch
                        placeholder="选择"
                        optionFilterProp="children"
                        filterOption={(input, option) =>
                          option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                        }
                      >
                        {Array.isArray(base.WareHouseType)
                          ? base.WareHouseType.map(item => (
                              <Option key={item.dic_code} value={item.dic_code}>
                                {`${item.dic_name}(${item.dic_code})`}
                              </Option>
                            ))
                          : null}
                      </Select>
                    )}
                  </FormItem>
                </Col>
                <Col md={12} sm={24}>
                  <span className={styles.submitButtons}>
                    <Button icon="search" type="primary" htmlType="submit">
                      查询
                    </Button>
                    <Button icon="sync" style={{ marginLeft: 8 }} onClick={this.handleFormReset}>
                      重置
                    </Button>
                    <Operate operateName="NEW">
                      <Button
                        icon="plus"
                        type="primary"
                        style={{ marginLeft: 8 }}
                        onClick={() => this.props.dispatch(routerRedux.push(`${routerUrl}/info`))}
                      >
                        新建
                      </Button>
                    </Operate>
                  </span>
                </Col>
              </Row>
            </Form>
          </Card>
          <List {...listConfig} />
        </div>
      );
    }
  }
  