index.js 11 KB

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