index.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. import React, { PureComponent } from 'react';
  2. import { Divider, Modal, Table, Form, Card, Button, Tag } from 'antd';
  3. import { connect } from 'dva';
  4. import { routerRedux } from 'dva/router';
  5. import queryString from 'query-string';
  6. import PageHeaderLayout from '../../../layouts/PageHeaderLayout';
  7. import FooterToolbar from '../../../components/FooterToolbar';
  8. import DescriptionList from '../../../components/DescriptionList';
  9. import NewPriceModal from './price';
  10. import TagSelectModal from './tags';
  11. import { pageSize, productType, Codes } from '../../../utils/config';
  12. const { Description } = DescriptionList;
  13. const confirm = Modal.confirm;
  14. @Form.create()
  15. @connect(state => ({
  16. mproductDetail: state.mproductDetail,
  17. goodsModel: state.goodsModel,
  18. tagModel: state.tagModel,
  19. }))
  20. export default class MerchantProductEdit extends PureComponent {
  21. handleAddPriceClick = () => {
  22. this.props.dispatch({
  23. type: 'goodsModel/showModal',
  24. payload: { operation: 'createItem' },
  25. });
  26. }
  27. handleEditPriceClick = (record) => {
  28. this.props.dispatch({
  29. type: 'goodsModel/showModal',
  30. payload: {
  31. operation: 'updateItem',
  32. goodsItem: record,
  33. },
  34. });
  35. }
  36. handleDelPriceClick = (record) => {
  37. const { dispatch, location } = this.props;
  38. const { search } = location;
  39. confirm({
  40. title: `您确定要删除此定价?`,
  41. onOk () {
  42. dispatch({
  43. type: 'goodsModel/removeItem',
  44. payload: { id: record.id },
  45. callback: () => {
  46. dispatch(routerRedux.push({
  47. pathname: '/goods/edit',
  48. search,
  49. }));
  50. }
  51. });
  52. },
  53. });
  54. }
  55. handleEditTagClick = () => {
  56. const { location } = this.props;
  57. const { search } = location;
  58. const { merchantId, pid } = queryString.parse(search);
  59. this.props.dispatch({
  60. type: 'goodsModel/showTagModal',
  61. });
  62. this.props.dispatch({
  63. type: 'tagModel/query',
  64. payload: {
  65. pageNo: 1,
  66. pageSize,
  67. merchantId,
  68. }
  69. });
  70. }
  71. handleTagModalCancel = () => {
  72. this.props.dispatch({
  73. type: 'goodsModel/hideTagModal',
  74. });
  75. }
  76. handleTagModalOk = (data) => {
  77. const { location } = this.props;
  78. const { search } = location;
  79. const { merchantId, pid } = queryString.parse(search);
  80. this.props.dispatch({
  81. type: 'goodsModel/bundleTags',
  82. payload: { pid, merchantId, tags: data.map(item => item.id) },
  83. callback: () => {
  84. this.props.dispatch(routerRedux.push({
  85. pathname: '/goods/edit',
  86. search,
  87. }));
  88. }
  89. });
  90. }
  91. handleTagModalSearch = (data) => {
  92. const { location } = this.props;
  93. const { search } = location;
  94. const { merchantId, pid } = queryString.parse(search);
  95. const newData = { ...data };
  96. if (newData.keyword) {
  97. newData[newData.field] = newData.keyword;
  98. }
  99. delete newData.field;
  100. delete newData.keyword;
  101. this.props.dispatch({
  102. type: 'tagModel/query',
  103. payload: {
  104. ...newData,
  105. pageNo: 1,
  106. pageSize,
  107. merchantId,
  108. }
  109. });
  110. }
  111. handlePageExit = () => {
  112. const { dispatch, mproductDetail } = this.props;
  113. const { filters } = mproductDetail;
  114. dispatch(routerRedux.push({
  115. pathname: '/goods',
  116. search: queryString.stringify(filters),
  117. }));
  118. }
  119. handleTagModalTableChange = (pagination) => {
  120. const { location, dispatch, mproductDetail } = this.props;
  121. const { filters } = mproductDetail;
  122. const { search } = location;
  123. const { merchantId, pid } = queryString.parse(search);
  124. const newFilters = { ...filters };
  125. if (newFilters.keyword) {
  126. newFilters[newFilters.field] = newFilters.keyword;
  127. }
  128. delete newFilters.field;
  129. delete newFilters.keyword;
  130. const data = {
  131. ...newFilters,
  132. pageNo: pagination.current,
  133. pageSize: pagination.pageSize,
  134. merchantId,
  135. };
  136. Object.keys(data).map(key => data[key] ? null : delete data[key]);
  137. dispatch({ type: 'tagModel/query', payload: { ...data } });
  138. }
  139. render(){
  140. const { mproductDetail, goodsModel, tagModel, location } = this.props;
  141. const { currentItem } = mproductDetail;
  142. const { modalShow, tagModalShow, operation, goodsItem } = goodsModel;
  143. const { list, listLoading, pagination } = tagModel;
  144. const { goods, tags, type, code, name, merchantName } = currentItem;
  145. const { search } = location;
  146. const { merchantId, pid } = queryString.parse(search);
  147. const priceModalProps = {
  148. data: operation === 'createItem' ? {} : goodsItem,
  149. title: operation === 'createItem' ? '添加价格' : '编辑价格',
  150. visible: modalShow,
  151. maskClosable: false,
  152. onCancel: () => {
  153. this.props.dispatch({ type: 'goodsModel/hideModal' });
  154. },
  155. onSubmit: (data) => {
  156. const newData = { ...data, merchantId, pid, productType: type };
  157. this.props.dispatch({
  158. type: `goodsModel/${operation}`,
  159. payload: newData,
  160. callback: () => {
  161. this.props.dispatch(routerRedux.push({
  162. pathname: '/goods/edit',
  163. search,
  164. }));
  165. }
  166. });
  167. },
  168. };
  169. const listTableProps = {
  170. simple: true,
  171. bordered: true,
  172. pagination: false,
  173. rowKey: (record) => record.id,
  174. dataSource: goods,
  175. columns: [{
  176. title: '计价单位',
  177. dataIndex: 'chargeUnit',
  178. key: 'chargeUnit',
  179. },{
  180. title: '供应商价格(¥)',
  181. dataIndex: 'cpPrice',
  182. key: 'cpPrice',
  183. },{
  184. title: '渠道方价格(¥)',
  185. dataIndex: 'merchantPrice',
  186. key: 'merchantPrice',
  187. },{
  188. title: '终端价格(¥)',
  189. dataIndex: 'terminalPrice',
  190. key: 'terminalPrice',
  191. },{
  192. title: '操作',
  193. key: 'action',
  194. render: (text, record) => (
  195. <span>
  196. <a onClick={() => this.handleEditPriceClick(record)}>编辑</a>
  197. <Divider type="vertical" />
  198. <a onClick={() => this.handleDelPriceClick(record)}>删除</a>
  199. </span>
  200. ),
  201. }],
  202. };
  203. return (
  204. <PageHeaderLayout>
  205. <Card
  206. bordered={false}
  207. title="详情"
  208. style={{ marginBottom: 15 }}
  209. >
  210. <DescriptionList size="large" col={2} style={{ marginBottom: 32 }}>
  211. <Description term="商品编号">{code}</Description>
  212. <Description term="商品名称">{name}</Description>
  213. <Description term="商品类型">{productType[type]}</Description>
  214. <Description term="渠道名称">{merchantName}</Description>
  215. </DescriptionList>
  216. </Card>
  217. <Card
  218. bordered={false}
  219. title={
  220. <div>定价
  221. <Divider type="vertical" />
  222. <Button onClick={this.handleAddPriceClick} size="small" type="primary">添加</Button>
  223. </div>
  224. }
  225. style={{ marginBottom: 15 }}
  226. >
  227. <Table { ...listTableProps }/>
  228. <NewPriceModal { ...priceModalProps } />
  229. </Card>
  230. <Card
  231. bordered={false}
  232. title={
  233. <div>标签
  234. <Divider type="vertical" />
  235. <Button onClick={this.handleEditTagClick} size="small" type="primary">选择</Button>
  236. </div>
  237. }
  238. style={{ marginBottom: 15 }}
  239. >
  240. {/*标签的模态选择框*/}
  241. <TagSelectModal
  242. rowKeyName="id"
  243. modalVisible={tagModalShow}
  244. selTableData={tags || []}
  245. style={{ top: 20 }}
  246. fsTableDataSource={list}
  247. fsTableLoading={listLoading}
  248. fsTablePagination={pagination}
  249. onOk={this.handleTagModalOk}
  250. onCancel={this.handleTagModalCancel}
  251. onSearch={this.handleTagModalSearch}
  252. fsTableOnChange={this.handleTagModalTableChange}
  253. />
  254. {tags ? tags.map(item => <Tag key={item.id} color="#f50">{item.name}</Tag>) : null}
  255. </Card>
  256. <FooterToolbar>
  257. <Button onClick={this.handlePageExit} type="primary">
  258. 完成
  259. </Button>
  260. </FooterToolbar>
  261. </PageHeaderLayout>
  262. );
  263. }
  264. }