templateUtil.js 18.1 KB
Newer Older
bert committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
import React, { PropTypes } from 'react';
import { Table, Pagination, Popconfirm, Row, Col } from 'antd';
import { Link } from 'react-router'

/**
 * 格式化 `caseDesc`
 * 
 * desc:
 * 服务端传来的 `caseDesc` 换行是用 `/n` 来体现的,在页面上无法显示
 * 
 * 该方法将 `caseDesc` 按 `/n` 来切割成数据
 * 遍历切割后的数据,处理换行显示
 * 
 */
const caseDescFormat = (caseDesc) => {
  return caseDesc.split("/n")
    .map((item, index, items) => {
      if ((items.length - 1) == index) {
        return <span>{item}</span>
      } else {
        return <span>{item}<br/></span>
      }
    });
};

/**
 * 处理表格左侧 `+` 扩展内容
 * 
 * desc:
 * 表格显示的字段为主要字段,扩展中显示的是附加字段及详情
 * 方便在使用case的时候,可以直接在表格上操作,减去进入详情的步骤
 * 
 */
export const expandedRowRender = (record) => {
  const caseDescElement = caseDescFormat(record.caseDesc);

  const styleTitle = { textAlign: 'right', border: '1px dotted #ccc', borderRight: 'none', borderLeft: 'none', padding: '10px', lineHeight: '1.5' };
  const styleContent = { border: '1px dotted #ccc', borderLeft: 'none', borderRight: 'none', padding: '10px', lineHeight: '1.5' };
  const styleDetail = { textAlign: 'right', padding: '0 10px 10px 10px' };
  const styleDetailCont = { textAlign: 'right', padding: '10px' };
  return <div>
    <Row>
      <Col style={styleTitle} span={2}>小区:</Col>
      <Col style={styleContent} span={3}>{record.community ? record.community : '暂无数据'}</Col>
      <Col style={styleTitle} span={2}>业主姓名:</Col>
      <Col style={styleContent} span={3}>{record.ownerName ? record.ownerName : '暂无数据'}</Col>
      <Col style={styleTitle} span={2}>单元:</Col>
      <Col style={styleContent} span={3}>{record.unit ? record.unit : '暂无数据'}</Col>
      <Col style={styleTitle} span={2}>实收金额:</Col>
      <Col style={styleContent} span={3}>{record.recoveredAmount ? record.recoveredAmount : '暂无数据'}</Col>
    </Row>
    <Row>
      <Col style={styleTitle} span={2}>楼栋:</Col>
      <Col style={styleContent} span={3}>{record.building ? record.building : '暂无数据'}</Col>
      <Col style={styleTitle} span={2}>欠费月数:</Col>
      <Col style={styleContent} span={3}>{record.arrearsMonth ? record.arrearsMonth : '暂无数据'}</Col>
      <Col style={styleTitle} span={2}>房号:</Col>
      <Col style={styleContent} span={3}>{record.room ? record.room : '暂无数据'}</Col>
      <Col style={styleTitle} span={2}>业主电话:</Col>
      <Col style={styleContent} span={3}>{record.ownerPhone ? record.ownerPhone : '暂无数据'}</Col>
    </Row>
    <Row>
      <Col style={styleTitle} span={2}>收费方式:</Col>
      <Col style={styleContent} span={2}>{record.chargeWay ? record.chargeWay : '暂无数据'}</Col>
      <Col style={styleTitle} span={3}>实收历史欠费金额:</Col>
      <Col style={styleContent} span={13}>{record.arrearsAmount ? record.arrearsAmount : '暂无数据'}</Col>
    </Row>
    <br />
    <Row>
      <Col style={styleDetail} span={2}>详情:</Col>
      <Col style={styleDetailCont} span={7} style={{ whiteSpace: 'pre-line' }}>{caseDescElement ? caseDescElement : '暂无数据'}</Col>
    </Row>
  </div>
};

/**
 * case管理表格字段配置
 */
export function caseManageTableHead(operation) {
  return [
    {
      title: '工单号',
      dataIndex: 'caseNo',
    }, {
      title: '标题',
      render: (text, record, index) => <div className="yincang" style={{ width: '300' }}>{record.caseTitle}</div>,
    },
    {
      title: '优先级',
      dataIndex: 'priority',
      key: 'priority',
      sorter: true,
      filters: [
        {
          text: '非常高',
          value: '1',
        },
        {
          text: '高',
          value: '2',
        },
        {
          text: '中',
          value: '3',
        },
        {
          text: '低',
          value: '4',
        }
      ],
      render: (text, record, index) => {
        return formatPriority(record.priority);
      }
    }
    , {
      title: '发起人',
      dataIndex: 'createUser',
      key: 'createUser'
    }, {
      title: '发起时间',
      dataIndex: 'createTime',
      key: 'createTime',
      sorter: true
    }, {
      title: '执行人',
      render: (text, record, index) => record.executorList[0] && record.executorList[0].userName,
      key: 'executorUser'
    }, {
      title: '类型',
      dataIndex: 'caseTypeName',
      key: 'caseTypeName',
      filters: operation.typeList
      // filterMultiple: false
    }, {
      title: '状态',
      render: function(text, record, index) {
        return formatStatus(record.status);
      },
      key: 'status',
    }, {
      title: '催费金额',
      dataIndex: 'amount',
      key: 'amount',
      sorter: true
    }, {
      title: '关注人',
      render: (text, record, index) => <div className="yincang" style={{ width: '400' }}>{record.focusList}</div>,
      key: 'focusUser'
    }, {
      title: '管理',
      key: 'operation',
      fixed: 'right',
      render: (record) => <Link to={{ pathname: "case_detail/" + record.id }}>详情</Link>
    }];
}

/**
 * case排名表格字段配置
 */
export function caseRankTableHead(operation) {
  return [
    {
      title: '排名',
      dataIndex: 'rownum'
    },
    {
      title: '员工姓名',
      dataIndex: 'userName',
      key: 'userName'
    },
    {
      title: '排名类型',
      render: (text, record, index) => {
        switch (record.rankType) {
          case 'remain':
            return (<div>剩余任务</div>);
          case 'create':
            return (<div>发起任务</div>);
          case 'finish':
            return (<div>完成任务</div>);
          case 'confirmfinish':
            return (<div>确认完成任务</div>);
          case 'close':
            return (<div>关闭任务</div>);
        }
      },
      key: 'rankType'
    },
    {
      title: '任务数量',
      dataIndex: 'caseNumber',
      key: 'caseNumber',
      sorter: true
    },
    {
      title: '日期',
      dataIndex: 'rankTime',
      key: 'rankTime'
    }];
}


/**
 * 我的关注表格字段配置
 */
export function myFocusTableHead(operation) {
  return [
    {
      title: '工单号',
      dataIndex: 'caseNo',
    }, {
      title: '标题',
      render: (text, record, index) => <div className="yincang" style={{ width: '300' }}>{record.caseTitle}</div>,
    },
    {
      title: '优先级',
      dataIndex: 'priority',
      key: 'priority',
      sorter: true,
      filters: [
        {
          text: '非常高',
          value: '1',
        },
        {
          text: '高',
          value: '2',
        },
        {
          text: '中',
          value: '3',
        },
        {
          text: '低',
          value: '4',
        }
      ],
      render: (text, record, index) => {
        return formatPriority(record.priority);
      }
    }
    , {
      title: '发起人',
      dataIndex: 'createUser',
      key: 'createUser'
    }, {
      title: '发起时间',
      dataIndex: 'createTime',
      key: 'createTime',
      sorter: true
    }, {
      title: '执行人',
      render: (text, record, index) => record.executorList[0] && record.executorList[0].userName,
      key: 'executorUser'
    }, {
      title: '类型',
      dataIndex: 'caseTypeName',
      key: 'caseTypeName',
      filters: operation.typeList
      // filterMultiple: false
    }, {
      title: '状态',
      render: (text, record, index) => {
        return formatStatus(record.status);
      },
      key: 'status',
    }, {
      title: '催费金额',
      dataIndex: 'amount',
      key: 'amount',
      sorter: true
    }, {
      title: '关注人',
      render: (text, record, index) => <div className="yincang" style={{ width: '400' }}>{record.focusList}</div>,
      key: 'focusUser'
    }, {
      title: '管理',
      key: 'operation',
      fixed: 'right',

      render: (record) => {
        return (
          <span>
            <Link to={{ pathname: "case_detail/" + record.id }}>详情</Link>
          </span>)
      }
    }];
}


/**
 * 我的任务表格字段配置
 */
export function myTaskTableHead(operation) {
  return [
    {
      title: '工单号',
      dataIndex: 'caseNo'
    }, {
      title: '标题',
      render: (text, record, index) => <div className="yincang" style={{ width: '300' }}>{record.caseTitle}</div>
    },
    {
      title: '优先级',
      dataIndex: 'priority',
      key: 'priority',
      sorter: true,
      filters: [
        {
          text: '非常高',
          value: '1',
        },
        {
          text: '高',
          value: '2',
        },
        {
          text: '中',
          value: '3',
        },
        {
          text: '低',
          value: '4',
        }
      ],
      render: (text, record, index) => {
        return formatPriority(record.priority);
      }
    }
    , {
      title: '发起人',
      dataIndex: 'createUser',
      key: 'createUser'
    }, {
      title: '发起时间',
      dataIndex: 'createTime',
      key: 'createTime',
      sorter: true
    }, {
      title: '执行人',
      render: (text, record, index) => record.executorList[0] && record.executorList[0].userName,
      key: 'executorUser'
    }, {
      title: '类型',
      dataIndex: 'caseTypeName',
      key: 'caseTypeName',
      // filterMultiple: false,
      filters: operation.typeList
    }, {
      title: '状态',
      render: (text, record, index) => {
        return formatStatus(record.status);
      },
      key: 'status'
    }, {
      title: '催费金额',
      dataIndex: 'amount',
      key: 'amount',
      sorter: true
    }, {
      title: '关注人',
      render: (text, record, index) => <div className="yincang" style={{ width: '400' }}>{record.focusList}</div>,
      key: 'focusUser'
    }, {
      title: '管理',
      key: 'operation',
      fixed: 'right',

      render: (record) => {
        let successDom;
        const finishtext = '确定要完成这个任务吗?';
        if (record.status != 2 && record.status != 3 && record.status != 4) {

          successDom = <span>
            <span className="ant-divider"></span>
            <Popconfirm placement="top" title={finishtext} onConfirm={() => { operation.finishCase(record.id) } }>
              <a>完成</a>
            </Popconfirm>
          </span>;
        }
        return (
          <span>
            <Link to={{ pathname: "case_detail/" + record.id }}>详情</Link>
            {successDom}
          </span>);
      }
    }];
}


/**
 * 我的case表格字段配置
 */
export function myCaseTableHead(operation) {
  return [
    {
      title: '工单号',
      dataIndex: 'caseNo',
    },
    {
      title: '标题',
      render: (text, record, index) => <div className="yincang" style={{ width: '300' }}>{record.caseTitle}</div>,
    },
    {
      title: '优先级',
      dataIndex: 'priority',
      key: 'priority',
      sorter: true,
      filters: [
        {
          text: '非常高',
          value: '1',
        },
        {
          text: '高',
          value: '2',
        },
        {
          text: '中',
          value: '3',
        },
        {
          text: '低',
          value: '4',
        }
      ],
      render: (text, record, index) => {
        return formatPriority(record.priority);
      }
    },
    {
      title: '发起人',
      dataIndex: 'createUser',
      key: 'createUser'
    }, {
      title: '发起时间',
      dataIndex: 'createTime',
      key: 'createTime',
      sorter: true
    }, {
      title: '执行人',
      render: (text, record, index) => record.executorList[0] && record.executorList[0].userName,
      key: 'executorUser'
    }, {
      title: '类型',
      dataIndex: 'caseTypeName',
      key: 'caseTypeName',
      filters: operation.typeList
      // filterMultiple: false
    }, {
      title: '状态',
      render: (text, record, index) => {
        return formatStatus(record.status);
      },
      key: 'status',
    }, {
      title: '催费金额',
      dataIndex: 'amount',
      key: 'amount',
      sorter: true
    }, {
      title: '关注人',
      render: (text, record, index) => <div className="yincang" style={{ width: '400' }}>{record.focusList}</div>,
      key: 'focusUser'
    }, {
      title: '管理',
      key: 'operation',
      fixed: 'right',

      render: (record) => {
        let ConfirmDom, CloseDom;
        const confirmFinishtext = '确定要完成这个任务吗?';
        const closetext = '确定要关闭这个任务吗?';
        if (record.status == 2) { // 已完成状态下才能操作确认完成
          ConfirmDom = <span>
            <span className="ant-divider"></span>
            <Popconfirm placement="top" title={confirmFinishtext} onConfirm={() => { operation.confirmFinishCase(record.id) } }>
              <a>确认完成</a>
            </Popconfirm>
          </span>

          // ConfirmDom = ConfirmFinisModal;
        }
        if (record.status != 3 && record.status != 4) {
          CloseDom = <span>
            <span className="ant-divider"></span>
            <Popconfirm placement="top" title={closetext} onConfirm={() => { operation.closeCase(record.id) } }>
              <a>关闭</a>
            </Popconfirm>
          </span>
          // CloseDom = CloseModal;
        }
        return (
          <span>
            <Link to={{ pathname: "case_detail/" + record.id }}>详情</Link>
            { ConfirmDom }
            { CloseDom }
          </span>)

        // return (
        //   <span>
        //     <Link to={{pathname:"case_detail/" + record.id}}>详情</Link>
        //     {record.status != 3 && record.status != 4? <CloseModal confirmFinishCase={(close_message)=>{operation.confirmFinishCase(record.id, close_message)}}/> : ''}
        //     {record.status == 2? <ConfirmFinisModal /> : ''}
        //   </span>)
      }
    }];
}

/**
 * case分组表格字段配置
 */
export function caseGroupTableHead(operation) {
  return [
    {
      title: '工单号',
      dataIndex: 'caseNo',
    }, {
      title: '标题',
      render: (text, record, index) => <div className="yincang" style={{ width: '300' }}>{record.caseTitle}</div>,
    },
    {
      title: '优先级',
      dataIndex: 'priority',
      key: 'priority',
      sorter: true,
      filters: [
        {
          text: '非常高',
          value: '1',
        },
        {
          text: '高',
          value: '2',
        },
        {
          text: '中',
          value: '3',
        },
        {
          text: '低',
          value: '4',
        }
      ],
      render: (text, record, index) => {
        return formatPriority(record.priority);
      }
    }
    , {
      title: '发起人',
      dataIndex: 'createUser',
      key: 'createUser'
    }, {
      title: '发起时间',
      dataIndex: 'createTime',
      key: 'createTime',
      sorter: true
    }, {
      title: '执行人',
      render: (text, record, index) => record.executorList[0] && record.executorList[0].userName,
      key: 'executorUser'
    }, {
      title: '类型',
      dataIndex: 'caseTypeName',
      key: 'caseTypeName',
      filters: operation.typeList
      // filterMultiple: false
    }, {
      title: '状态',
      render: function(text, record, index) {
        return formatStatus(record.status);
      },
      key: 'status',
    }, {
      title: '催费金额',
      dataIndex: 'amount',
      key: 'amount',
      sorter: true
    }, {
      title: '关注人',
      render: (text, record, index) => <div className="yincang" style={{ width: '400' }}>{record.focusList}</div>,
      key: 'focusUser'
    }, {
      title: '管理',
      key: 'operation',
      fixed: 'right',
      render: (record) => <Link to={{ pathname: "case_detail/" + record.id }}>详情</Link>
    }];
}

/**
 * 关联case 表格配置
 */
export function relatedCaseTableHead(operation) {
  return [
    {
      title: '工单号',
      dataIndex: 'caseNo',
      key: 'caseNo',
      render: (text) => <a href="#">{text}</a>,
    }, {
      title: '标题',
      dataIndex: 'title',
      key: 'title',
    }, {
      title: '类型',
      dataIndex: 'caseTypeName',
      key: 'caseTypeName',
    }, {
      title: '优先级',
      dataIndex: 'priority',
      key: 'priority',
      render: (text, record, index) => {
        return formatPriority(record.priority);
      }
    }, {
      title: '状态',
      render: function(text, record, index) {
        return formatStatus(record.status);
      },
      key: 'status',
    }, {
      title: '操作',
      key: 'operation',
      render: (text, record) => {
        
        const closetext = '确定删除该关联分组?';
        
        return (
          <span>
            <Link to={{ pathname: "case_detail/" + record.id }}>详情</Link>
            <span className="ant-divider"></span>
            
            <span>
              <span className="ant-divider"></span>
              <Popconfirm placement="top" title={closetext} onConfirm={() => { operation.delRelatedCase(record.id) } }>
                <a>删除</a>
              </Popconfirm>
            </span>
            
          </span>
        )
      },
    }];
}

function formatPriority(priority) {
  switch (priority) {
    case '1':
      return (<div><span className="case-state state-error"></span>非常高</div>);
    case '2':
      return (<div><span className="case-state state-emergency"></span>高</div>);
    case '3':
      return (<div><span className="case-state state-ongoing"></span>中</div>);
    case '4':
      return (<div><span className="case-state state-close"></span>低</div>);
      
    default:
      return '暂无数据'
  }
}

function formatStatus(status) {
  switch (status) {
    case '1':
      return (<div><span className="case-state state-error"></span>进行中</div>);
    case '2':
      return (<div><span className="case-state state-success"></span>已完成</div>);
    case '3':
      return (<div><span className="case-state state-close"></span>确认完成</div>);
    case '4':
      return (<div><span className="case-state state-close"></span>已关闭</div>);
  }
}