index.js 5.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/*
 * @Title:
 * @Author: hongmye
 * @Date: 2023-12-26 18:34:42
 */
import { Image, Tooltip, message } from 'antd';
import React, { useMemo, useEffect, useState } from 'react';
import classNames from 'classnames';
import DataCarousel from '../DataCarousel';
import styles from './index.less';
const BottomItem = props => {
12
  const { projectConfig, listData = [], configData = [], onLineUrl, handToPage, handlePage, industries = [] } = props;
13 14 15 16 17 18 19 20 21 22 23 24 25
  const isJump = industries.includes('项目案例');
  const [list, setList] = useState([]);
  const [infoData, setInfoData] = useState({});
  const renderNum = (num, type) => {
    const numStr = num ? num.toString() : '0';
    const arr = numStr.split('');

    return arr.map(a => (
      <div className={styles.l_item_num_item} type={type}>
        {a}
      </div>
    ));
  };
26
  const toPage = (url, col) => {
27
    if (!isJump) return message.warning('该用户没有权限!');
28
    if (!url.includes('https')) return;
29 30 31 32
    if (!url.includes('user/noscret') || projectConfig[col['平台名称']]) {
      return handToPage(url);
    }
    handToPage(url.split('user/noscret')[0]);
33 34 35 36 37 38 39 40 41 42
  };
  const toMore = (e, url) => {
    if (!isJump) return message.warning('该用户没有权限!');
    handlePage(e, '项目案例');
  };
  const renderCol = (row, rindex) => {
    if (!Array.isArray(row)) return null;
    return (
      <div className={styles.list_item_col}>
        {row.map((col, cIndex) => (
43 44
          <div
            key={`${rindex}-${cIndex}`}
45
            type={col['项目环境'] && col['项目环境'].includes('https') && isJump ? 'jump' : 'none'}
46
            onClick={() => toPage(col['项目环境'], col)}
47 48 49 50 51 52 53 54 55 56 57
            alt="点击体验"
            className={styles.list_item}
          >
            <div className={styles.list_item_img_wrap}>
              <div className={classNames(styles.list_item_img, 'list_item_img')}>
                <Image
                  src={`${onLineUrl}CityInterface/rest/services/filedownload.svc/download/${col['项目图片']}`}
                  style={{ height: '100px', width: '100%', overflow: 'hidden' }}
                  preview={false}
                />
              </div>
58

59 60 61 62
              {col['重要程度'] === '样板' ? <div className={styles.list_item_img_tip} /> : null}
            </div>
            <div className={styles.list_item_info_wrap}>
              <div className={styles.list_item_info_tip} type={col['所属行业']}>
周宏民's avatar
周宏民 committed
63
                {col['所属行业'] === '能源' ? '节水' : col['所属行业'] === '农饮水' ? '农水' : col['所属行业']}
64
              </div>
65
              <div className={styles.list_item_info_name}>
66 67
                <Tooltip title={col['平台名称']} color="#1685FF">
                  {col['平台名称']}
68
                </Tooltip>
69
              </div>
70
              <div className={styles.list_item_info_address}>{col['城市']}</div>
71
            </div>
72
          </div>
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
        ))}
      </div>
    );
  };
  const spliceArr = (arr, num) => {
    const reArr = [];
    arr.map(item => {
      if (!reArr[reArr.length - 1] || reArr[reArr.length - 1].length === num) {
        // 新行添加
        reArr.push([]);
      }
      if (reArr[reArr.length - 1].length !== num) {
        // 长度不够则直接添加
        reArr[reArr.length - 1].push(item);
      }
      return null;
    });
    return reArr;
  };
  useEffect(() => {
    const arr = [];
    listData.forEach(i => {
95 96 97
      let str = i['所属省份'];
      if (i['所属省份']) {
        if (str[str.length - 1] === '省') {
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
          str = str.slice(0, str.length - 1);
        }
      }
      i['城市'] = str;
      arr.push(i);
    });
    setList(spliceArr(arr, 2));
  }, [listData]);
  useEffect(() => {
    const obj = {
      项目数量: '',
      服务客户: '',
      覆盖省份: '',
    };
    configData.forEach(c => {
      if (obj[c['名称']] === '') {
        obj[c['名称']] = c['数值'];
      }
    });

    setInfoData(obj);
  }, [configData]);
  return (
    <div className={classNames(styles.bottom_item, 'demo_bottom_item')}>
      <div className={styles.left}>
        <div className={styles.l_title_wrap}>
          <div className={styles.l_title_sub}>熊猫智慧水务</div>
          <div className={styles.l_title}>项目落地保障:</div>
        </div>
        <div className={styles.l_list}>
          <div className={styles.l_item}>
            <div className={styles.l_item_title} type="项目数量">
              项目数量:
            </div>
            <div className={styles.l_item_num_list}>{renderNum(infoData['项目数量'], '项目数量')}</div>
            <div className={styles.l_item_num_unit}></div>
          </div>
          <div className={styles.l_item}>
            <div className={styles.l_item_title} type="服务客户">
              服务客户:
            </div>
            <div className={styles.l_item_num_list}>{renderNum(infoData['服务客户'], '服务客户')}</div>
140
            <div className={styles.l_item_num_unit}></div>
141 142 143 144 145 146
          </div>
          <div className={styles.l_item}>
            <div className={styles.l_item_title} type="覆盖省份">
              覆盖省份:
            </div>
            <div className={styles.l_item_num_list}>{renderNum(infoData['覆盖省份'], '覆盖省份')}</div>
147
            <div className={styles.l_item_num_unit}></div>
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
          </div>
        </div>
      </div>

      <div className={styles.center}>
        <DataCarousel
          gap={1}
          autoplay={5000}
          itemHeight={270}
          list={list}
          renderItem={renderCol}
          config={{
            direction: 'horizontal',
            width: 1520,
            loop: false,
            slidesPerView: 7,
          }}
        />
      </div>
      <div className={styles.right} onClick={e => toMore(e)}>
        查看全部
      </div>
    </div>
  );
};
export default BottomItem;