index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. * 多选组件——左右布局,这样能看到更多的数据
  3. * 用于装修商品选择
  4. * */
  5. import { connect } from 'dva/index';
  6. import React, { Component, Fragment } from 'react';
  7. import {
  8. Empty,
  9. Form, Modal,
  10. } from 'antd';
  11. import {
  12. failTip,
  13. list_com_page_size_16,
  14. sldComLanguage,
  15. } from '@/utils/utils';
  16. import global from '@/global.less';
  17. import styles from './index.less';
  18. import Search from '@/components/Search/Search';
  19. import ALibbSvg from '@/components/ALibbSvg';
  20. import { Scrollbars } from 'react-custom-scrollbars';
  21. import defaultSettings from '@/defaultSettings';
  22. let pageSize = list_com_page_size_16;
  23. @connect(({ pc_home, project }) => ({
  24. pc_home,
  25. project,
  26. }))
  27. @Form.create()
  28. export default class SldSelMoreLeftRightGoods extends Component {
  29. constructor(props) {
  30. super(props);
  31. this.state = {
  32. selectedRows: [],
  33. selectedRowKeys: [],//selectedRows的key
  34. modalVisible: false,
  35. loading: false,
  36. data: {},
  37. title: '',
  38. params: { pageSize: pageSize },
  39. search_data: [{
  40. type: 'input',
  41. label: `${sldComLanguage('商品名称')}`,
  42. name: 'goodsName',
  43. placeholder: `${sldComLanguage('请输入商品名称')}`,
  44. },
  45. // {
  46. // type: 'input',
  47. // label: `店铺名称`,//店铺名称
  48. // name: 'store_name',
  49. // placeholder: `请输入店铺名称`,//请输入店铺名称
  50. // },
  51. // {
  52. // type: 'select',
  53. // label: `促销活动`,
  54. // name: 'activity_type',
  55. // placeholder: `请选择促销活动`,
  56. // sel_data: [
  57. // { key: '', name: `全部` },
  58. // { key: '1', name: `手机专享` },
  59. // { key: '2', name: `拼团` },
  60. // { key: '3', name: `团购` },
  61. // { key: '4', name: `限时` },
  62. // { key: '5', name: `预售` },
  63. // { key: '6', name: `阶梯团` },
  64. // ],
  65. // }
  66. ],
  67. formValues: {},//搜索条件
  68. };
  69. }
  70. init_flag = true;
  71. loading_pagination_flag = false;//分页加载标识,防止分页重复加载
  72. componentDidMount() {
  73. }
  74. componentWillReceiveProps(nextProps, nextContext) {
  75. if (nextProps.modalVisible) {
  76. this.get_list({ pageSize: pageSize });
  77. this.setState({
  78. selectedRows: [...nextProps.selectedRows],
  79. selectedRowKeys: [...nextProps.selectedRowKeys],
  80. });
  81. }
  82. }
  83. componentWillUnmount() {
  84. }
  85. //获取数据列表
  86. get_list = (params) => {
  87. this.setState({ loading: true });
  88. const { dispatch } = this.props;
  89. let { data } = this.state;
  90. let dis_type = '';
  91. let new_params = { ...params,};
  92. dis_type = 'project/get_spreader_goods_lists';
  93. dispatch({
  94. type: dis_type,
  95. payload: new_params,
  96. callback: (res) => {
  97. this.setState({ loading: false });
  98. if (res.state == 200) {
  99. if (res.data.pagination != undefined) {
  100. if (res.data.pagination.current == 1) {
  101. data = res.data;
  102. } else {
  103. data.list = data.list.concat(res.data.list);
  104. data.pagination = res.data.pagination;
  105. }
  106. }
  107. this.setState({
  108. data: data,
  109. });
  110. this.loading_pagination_flag = false;
  111. }
  112. },
  113. });
  114. };
  115. //搜索事件
  116. search = (data) => {
  117. for (let i in data) {
  118. if (data[i] == '') {
  119. delete data[i];
  120. }
  121. }
  122. this.setState({
  123. formValues: data,
  124. params: { pageSize: pageSize }
  125. });
  126. this.get_list({ pageSize: pageSize, ...data });
  127. };
  128. //搜索重置事件
  129. seaReset = () => {
  130. //搜索条件置为空
  131. this.setState({
  132. formValues: {},
  133. params: { pageSize: pageSize }
  134. });
  135. this.get_list({ pageSize: pageSize });
  136. };
  137. //取消事件
  138. sldCancle = () => {
  139. this.setState({
  140. selectedRows: [],
  141. selectedRowKeys: [],//selectedRows的key
  142. params: { pageSize: pageSize },
  143. });
  144. this.props.sldHandleSeleMoreModalCancle();
  145. };
  146. sldConfirm = () => {
  147. let { selectedRows, selectedRowKeys } = this.state;
  148. if (selectedRowKeys.length > 0) {
  149. if (this.props.extra.min_num != undefined && this.props.extra.min_num > 0 && selectedRowKeys.length < this.props.extra.min_num) {
  150. failTip(`${sldComLanguage('该模块至少需要选择')}${this.props.extra.min_num}${sldComLanguage('个商品')}`);//该模块至少需要选择 个商品
  151. return false;
  152. }
  153. if (this.props.extra.total_num != undefined && this.props.extra.total_num > 0 && selectedRowKeys.length != this.props.extra.total_num) {
  154. failTip(`${sldComLanguage('该模块需要选择')}${this.props.extra.total_num}${sldComLanguage('个商品')}`);//该模块需要选择 个商品
  155. return false;
  156. }
  157. if (this.props.extra.max_num != undefined && this.props.extra.max_num > 0 && selectedRowKeys.length > this.props.extra.max_num) {
  158. failTip(`${sldComLanguage('该模块最多选择')}${this.props.extra.max_num}${sldComLanguage('个商品')}`);//该模块至少需要选择 个商品
  159. return false;
  160. }
  161. this.props.seleSvideo(selectedRows, selectedRowKeys);
  162. this.setState({
  163. selectedRows: [],
  164. selectedRowKeys: [],
  165. });
  166. } else {
  167. failTip(`${sldComLanguage('请选择商品')}`);//请选择商品
  168. }
  169. this.setState({ params: { pageSize: pageSize } });
  170. };
  171. //关闭modal之后重置数据
  172. closeReset = () => {
  173. this.init_flag = true;
  174. };
  175. //滚动条滚动到底部事件
  176. handleScrollLeft = (e) => {
  177. const { height } = this.props;
  178. let { data } = this.state;
  179. // //当滚动到距离底部50px的时候请求分页
  180. // if (e.scrollTop < (height * (data.pagination.current * 1 - 1) + 50) && e.scrollTop > height * (data.pagination.current * 1 - 1)) {
  181. //
  182. // }
  183. //是否还有数据
  184. if (data.pagination.current * pageSize < data.pagination.total && !this.loading_pagination_flag) {
  185. //请求分页数据
  186. this.loading_pagination_flag = true;
  187. this.get_list({ pageSize: pageSize, current: data.pagination.current * 1 + 1 });
  188. }
  189. };
  190. //左侧数据点击事件(将选中的数据添加到右侧,左侧添加选中标识)
  191. handleLeftItem = (item) => {
  192. let { selectedRows, selectedRowKeys } = this.state;
  193. if (selectedRowKeys.indexOf(item.goodsId) == -1) {
  194. selectedRowKeys.push(item.goodsId);
  195. selectedRows.push(item);
  196. }
  197. this.setState({
  198. selectedRowKeys,
  199. selectedRows,
  200. });
  201. };
  202. //右侧数据点击事件(移除选中数据,右侧将不显示,左侧的选中标识去掉)
  203. handleRightItem = (item) => {
  204. let { selectedRows, selectedRowKeys } = this.state;
  205. selectedRows = selectedRows.filter(items => items.goodsId != item.goodsId);
  206. selectedRowKeys = selectedRowKeys.filter(items => items != item.goodsId);
  207. this.setState({
  208. selectedRowKeys,
  209. selectedRows,
  210. });
  211. };
  212. render() {
  213. const { modalVisible, width, title, height } = this.props;
  214. const { selectedRows, search_data, data, selectedRowKeys } = this.state;
  215. return (
  216. <Modal destroyOnClose={true}
  217. onOk={this.sldConfirm}
  218. afterClose={this.closeReset}
  219. onCancel={this.sldCancle}
  220. visible={modalVisible}
  221. width={width}
  222. title={title}>
  223. <div className={`${styles.component_sele_more} ${global.flex_column_start_start}`}>
  224. <div className={global.tableListForm}>
  225. <div style={{ position: 'relative' }}>
  226. <Search search_data={search_data} top={0} seaSubmit={(data) => this.search(data)}
  227. seaReset={() => this.seaReset()}/>
  228. </div>
  229. </div>
  230. <div className={`${styles.content} ${global.flex_row_start_start}`} style={{ height: height }}>
  231. <div style={{ height: height, background: defaultSettings.primaryCommonColor }}>
  232. <Scrollbars
  233. onScrollFrame={(e) => this.handleScrollLeft(e)}
  234. style={{ width: 438, zIndex: 1 }}>
  235. <div className={`${styles.left} ${global.flex_row_start_start}`} style={{ height: height }}>
  236. {data.list != undefined && data.list.length > 0 &&
  237. data.list.map((item, index) => {
  238. return <a key={index}
  239. className={`${styles.item} ${global.flex_row_start_start}`}
  240. onClick={(e) => {e.preventDefault(); this.handleLeftItem(item) }}
  241. style={{ marginBottom: index == data.list.length - 1 ? 10 : 0 }}>
  242. <div className={`${styles.item_left} ${global.flex_row_center_center}`}>
  243. <img className={styles.live_img} src={item.goodsImage}/>
  244. </div>
  245. <div className={`${styles.item_right} ${global.flex_column_start_start}`}>
  246. <span className={`${styles.svideo_name}`}>{item.goodsName}</span>
  247. <span className={`${styles.svideo_label}`}>{sldComLanguage('¥')}{item.productPrice}</span>
  248. {selectedRowKeys.indexOf(item.goodsId) > -1 &&
  249. <div className={`${styles.sele_svideo_flag}`}>
  250. <ALibbSvg fill={defaultSettings.primaryColor} width={19} height={19} type={'yixuan'}/>
  251. </div>
  252. }
  253. </div>
  254. </a>;
  255. })
  256. }
  257. {data.list == undefined||data.list.length ==0 &&
  258. <div className={global.flex_column_center_center} style={{width:'100%',height:'100%'}}>
  259. <Empty image={Empty.PRESENTED_IMAGE_SIMPLE}/>
  260. </div>
  261. }
  262. </div>
  263. </Scrollbars>
  264. </div>
  265. <div className={`${styles.center} ${global.flex_row_center_center}`}>
  266. <ALibbSvg fill={'#FFE3D5'} width={39} height={32} type={'move-up1'}/>
  267. </div>
  268. <div style={{ height: height, background: defaultSettings.primaryCommonColor }}>
  269. <Scrollbars
  270. style={{ width: 438, zIndex: 1 }}>
  271. <div className={`${styles.right} ${global.flex_row_start_start}`} style={{ height: height }}>
  272. {selectedRows.length > 0 ?
  273. selectedRows.map((item, index) => {
  274. return <a key={index}
  275. className={`${styles.item} ${global.flex_row_start_start}`}
  276. onClick={(e) => {e.preventDefault(); this.handleRightItem(item) }}
  277. style={{ marginBottom: index == selectedRows.length - 1 ? 10 : 0 }}>
  278. <div className={`${styles.item_left} ${global.flex_row_center_center}`}>
  279. <img className={styles.live_img} src={item.goodsImage}/>
  280. </div>
  281. <div className={`${styles.item_right} ${global.flex_column_start_start}`}>
  282. <span className={`${styles.svideo_name}`}>{item.goodsName}</span>
  283. <span className={`${styles.svideo_label}`}>{sldComLanguage('¥')}{item.productPrice}</span>
  284. <div className={`${styles.sele_svideo_flag}`}>
  285. <ALibbSvg fill={defaultSettings.primaryColor} width={19} height={19} type={'ziyuan21'}/>
  286. </div>
  287. </div>
  288. </a>;
  289. })
  290. :<div className={global.flex_column_center_center} style={{width:'100%',height:'100%'}}>
  291. <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={`${sldComLanguage('您还未选择数据')}`}/>
  292. </div>
  293. }
  294. </div>
  295. </Scrollbars>
  296. </div>
  297. </div>
  298. </div>
  299. </Modal>
  300. );
  301. }
  302. }