Преглед изворни кода

增加从购物车选择商品

zhanghe пре 7 година
родитељ
комит
e71297f288

+ 19 - 1
src/models/mproduct/mproduct.js

@@ -1,4 +1,4 @@
-import { query, update, createMerchantProduct } from '../../services/mproduct';
+import { query, update, createMerchantProduct, queryFromShopCart } from '../../services/mproduct';
 import modelExtend from 'dva-model-extend';
 import queryString from 'query-string';
 import { message } from 'antd';
@@ -44,6 +44,24 @@ export default modelExtend(pageModel, {
       }
       yield put({ type: 'changeLoading', payload: { listLoading: false }});
     },
+    * queryBuyMsg({payload}, {call, put}) {
+      yield put({ type: 'changeLoading', payload: { listLoading: true }});
+      const { data, success } = yield call(queryFromShopCart, payload);
+      if (success) {
+        yield put({
+          type: 'querySuccess',
+          payload: {
+            list: data || [],
+            pagination: {
+              current: Number(payload.pageNo) || 1,
+              pageSize: Number(payload.pageSize) || pageSize,
+              total: data.totalSize,
+            }
+          }
+        });
+      }
+      yield put({ type: 'changeLoading', payload: { listLoading: false }});
+    },
     // 商品上架 - {status: NORMAL, merchantId: 'xxx', pid: 'xxx'}
     * putOnSale ({ payload, callback }, { call, put }) {
       const { data, success } = yield call(createMerchantProduct, { ...payload, status: Codes.CODE_NORMAL });

+ 9 - 1
src/models/order/detail.js

@@ -1,6 +1,14 @@
 import pathToRegexp from 'path-to-regexp';
 import { message } from 'antd';
-import { queryOne, querySubOrder, create, remove, confirmPay, confirmSend, confirmReceive } from '../../services/order';
+import {
+  queryOne,
+  querySubOrder,
+  create,
+  remove,
+  confirmPay,
+  confirmSend,
+  confirmReceive
+} from '../../services/order';
 
 export default {
   namespace: 'orderDetail',

+ 1 - 1
src/models/ware/detail.js

@@ -94,7 +94,7 @@ export default {
     saveSortResult(state, action) {
       return {
         ...state,
-        currentItem: { ...state.currentItem, resourceList },
+        currentItem: { ...state.currentItem, resourceList: action.payload },
         modalVisible: false,
       };
     },

+ 5 - 5
src/routes/Course/Edit/index.js

@@ -337,11 +337,6 @@ export default class CourseDetail extends PureComponent {
                   initialValue: code,
                 })(<Input />)}
               </Form.Item>
-              <Form.Item label="课程名称:" hasFeedback {...formItemLayout}>
-                {getFieldDecorator('name', {
-                  initialValue: name,
-              })(<Input disabled={true} placeholder="根据标题及副标题自动生成"/>)}
-              </Form.Item>
               <Form.Item label="课程标题:" hasFeedback {...formItemLayout}>
                 {getFieldDecorator('title', {
                   rules: [{ required: true, type: 'string', message: "标题为必填项!" }],
@@ -353,6 +348,11 @@ export default class CourseDetail extends PureComponent {
                   initialValue: subTitle,
                 })(<Input />)}
               </Form.Item>
+              <Form.Item label="课程名称:" hasFeedback {...formItemLayout}>
+                {getFieldDecorator('name', {
+                  initialValue: name,
+              })(<Input disabled={true} placeholder="根据标题及副标题自动生成"/>)}
+              </Form.Item>
               <Form.Item label="面包屑导航:" hasFeedback {...formItemLayout}>
                 {getFieldDecorator('breadCrumb', {
                   initialValue: breadCrumb,

+ 84 - 52
src/routes/Order/Add/index.js

@@ -10,6 +10,7 @@ import {
   Form,
   Table,
   Button,
+  Radio,
   Input,
   InputNumber,
   Select,
@@ -33,6 +34,7 @@ export default class CreateOrder extends Component {
     userInfo: {}, // 记录终端用户信息
     products: [], // 记录选择的产品
     tableDatas: [], // 记录选择的商品
+    isFromCart: false, // 记录商品从哪里选择的<购物车?产品库>
   };
 
   // 终端选择弹框,显示 -> 加载数据
@@ -102,39 +104,56 @@ export default class CreateOrder extends Component {
   }
 
   // 产品选择弹框
-  handleProductSelectBtnClick = () => {
+  handleProductSelectBtnClick = (isFromCart) => {
     const { userInfo } = this.state;
-    const { merchantId } = userInfo;
+    const { merchantId, uid } = userInfo;
+    this.setState({ isFromCart });
     this.props.dispatch({ type: 'orderDetail/showProductModal' });
-    this.props.dispatch({
-      type: 'mproduct/query',
-      payload: {
-        pageNo: 1,
-        pageSize,
-        merchantId,
-      },
-    });
+    if (isFromCart) {
+      this.props.dispatch({
+        type: 'mproduct/queryBuyMsg',
+        payload: {
+          pageSize,
+          userId: uid,
+          pageNo: 1,
+        }
+      });
+    } else {
+      this.props.dispatch({
+        type: 'mproduct/query',
+        payload: {
+          pageNo: 1,
+          pageSize,
+          merchantId,
+        },
+      });
+    }
   }
 
   handleProductModalSearch = (data) => {
-    const { userInfo } = this.state;
-    const { merchantId } = userInfo;
+    const { userInfo, isFromCart } = this.state;
+    const { merchantId, id } = userInfo;
     const newData = { ...data };
     if (newData.keyword) {
       newData[newData.field] = newData.keyword;
     }
     delete newData.field;
     delete newData.keyword;
-    this.props.dispatch({
-      type: 'mproduct/query',
-      payload: { ...newData, merchantId, pageNo: 1, pageSize },
-    });
+    if (isFromCart) {
+      console.log('购物车内商品暂不支持查找...');
+    } else {
+      this.props.dispatch({
+        type: 'mproduct/query',
+        payload: { ...newData, merchantId, pageNo: 1, pageSize },
+      });
+    }
   }
 
   handleProductModalTableChange = (pagination, filterArgs, filters) => {
-    const { userInfo } = this.state;
+    const { userInfo, isFromCart } = this.state;
     const { merchantId } = userInfo;
     const newFilters = { ...filters };
+    if (isFromCart) {return;}
     if (newFilters.keyword) {
       newFilters[newFilters.field] = newFilters.keyword;
     }
@@ -259,7 +278,7 @@ export default class CreateOrder extends Component {
 
   handlePageSubmit = () => {
     const { form, dispatch, orderDetail } = this.props;
-    const { userInfo, tableDatas } = this.state;
+    const { userInfo, tableDatas, isFromCart } = this.state;
     const { getFieldsValue, validateFields } = form;
     const { filters } = orderDetail;
     const { uid } = userInfo;
@@ -277,6 +296,7 @@ export default class CreateOrder extends Component {
       postData.goods = detailList;
       postData.adjustPrice = 0;
       postData.orderStatus = Codes.CODE_UNPAID;
+      postData.isFromCart = isFromCart;
       dispatch({
         type: 'orderDetail/create',
         payload: postData,
@@ -299,7 +319,10 @@ export default class CreateOrder extends Component {
     let rowSort = 1;
     const formatedData = [];
     const rowDataMaker = (item) => {
-      const first = item.goods[0];
+      let first = item.goods[0]; //默认选中第一个
+      if (item.goods.filter(a => a.isInCart)[0]) {
+        first = item.goods.filter(a => a.isInCart)[0];
+      }
       return {
         name: item.name,
         code: item.code,
@@ -310,6 +333,7 @@ export default class CreateOrder extends Component {
         price3: first.terminalPrice,
         rowSum: first.merchantPrice,
         chargeUnit: first.chargeUnit,
+        isFromCart: this.state.isFromCart,
       };
     };
     data.map((item) => {
@@ -543,22 +567,23 @@ export default class CreateOrder extends Component {
           <Form>
             <Form.Item label="选择终端" {...formItemLayout}>
               <Button onClick={this.handleTerminalSelectBtnClick} type="primary" size="small" icon="plus-circle-o">选择</Button>
-              {userInfo.userCode ?
+              {
+                userInfo.userCode ?
                 (
                   <List
-  size="small"
-  bordered
-  style={{ width: '50%' }}
-  dataSource={[
-                    `终端编号: ${userInfo.userCode}`,
-                    `终端名称: ${userInfo.userName}`,
-                    `所属校区: ${userInfo.campusName}`,
-                    `所属渠道: ${userInfo.merchantName}`,
-                  ]}
-  renderItem={item => <List.Item>{item}</List.Item>}
-/>
-)
-              : null}
+                    size="small"
+                    bordered
+                    style={{ width: '50%' }}
+                    dataSource={[
+                      `终端编号: ${userInfo.userCode}`,
+                      `终端名称: ${userInfo.userName}`,
+                      `所属校区: ${userInfo.campusName}`,
+                      `所属渠道: ${userInfo.merchantName}`,
+                    ]}
+                    renderItem={item => <List.Item>{item}</List.Item>}
+                  />
+                ) : null
+              }
             </Form.Item>
             <Form.Item label="收货人" {...formItemLayout}>
               {getFieldDecorator('name', {
@@ -591,25 +616,32 @@ export default class CreateOrder extends Component {
                 <Input.TextArea style={{ width: '50%' }} placeholder="请输入(选填)" />
               )}
             </Form.Item>
-            <Form.Item label="添加商品" {...formItemLayout}>
-              {userInfo.merchantId ?
-                <Button onClick={this.handleProductSelectBtnClick} type="primary" size="small" icon="plus-circle-o">添加</Button>
-              :
-                (
-                  <Tooltip title="先选择终端">
-                    <Button onClick={this.handleProductSelectBtnClick} disabled type="primary" size="small" icon="plus-circle-o">添加</Button>
-                  </Tooltip>
-                )
-              }
-              <Table
-                bordered
-                scroll={{ x: 1250 }}
-                pagination={false}
-                columns={columns}
-                dataSource={listData}
-                footer={() => <strong>{`价格总计:  ${total}元`}</strong>}
-              />
-            </Form.Item>
+            {userInfo.merchantId &&
+              <Form.Item label="添加商品" {...formItemLayout}>
+                <Button.Group size="small">
+                  <Button
+                    type={this.state.isFromCart ? 'default' : 'primary'}
+                    onClick={() => this.handleProductSelectBtnClick(false)}
+                    >
+                    产品库
+                  </Button>
+                  <Button
+                    type={this.state.isFromCart? 'primary' : 'default'}
+                    onClick={() => this.handleProductSelectBtnClick(true)}
+                  >
+                    购物车
+                  </Button>
+                </Button.Group>
+                <Table
+                  bordered
+                  scroll={{ x: 1250 }}
+                  pagination={false}
+                  columns={columns}
+                  dataSource={listData}
+                  footer={() => <strong>{`价格总计:  ${total}元`}</strong>}
+                />
+              </Form.Item>
+            }
           </Form>
           {/* 终端选择弹框 */}
           <TerminalSelectModal

+ 4 - 14
src/routes/Order/Add/product.js

@@ -42,23 +42,18 @@ export default class MerchantProductSelectModal extends PureComponent {
         title: '产品编号',
         dataIndex: 'code',
         key: 1,
-        width: '27%',
+        width: '35%',
       },{
         title: '产品名称',
         dataIndex: 'name',
         key: 2,
-        width: '28%'
+        width: '35%'
       },{
         title: '产品类型',
         dataIndex: 'type',
         key: 3,
         render: (text, record) => productType[text],
         width: '15%'
-      },{
-        title: '渠道名称',
-        dataIndex: 'merchantName',
-        key: 4,
-        width: '15%',
       }],
     };
 
@@ -67,23 +62,18 @@ export default class MerchantProductSelectModal extends PureComponent {
         title: '产品编号',
         dataIndex: 'code',
         key: 1,
-        width: '27%',
+        width: '35%',
       },{
         title: '产品名称',
         dataIndex: 'name',
         key: 2,
-        width: '28%',
+        width: '35%',
       },{
         title: '产品类型',
         dataIndex: 'type',
         key: 3,
         render: (text, record) => productType[text],
         width: '15%',
-      },{
-        title: '渠道名称',
-        dataIndex: 'merchantName',
-        key: 4,
-        width: '15%',
       }],
       ...fsTableOpts,
     }

+ 15 - 2
src/routes/Support/Edit/index.js

@@ -182,13 +182,13 @@ export default class SupportDetail extends PureComponent {
       }
 
       // 取出名称name值作为标题title字段值
-      const { title } = getFieldsValue();
+      const { title, subTitle } = getFieldsValue();
 
       // 最终提交的数据
       const data = {
         ...rest,
         ...getFieldsValue(),
-        name: title,
+        name: `${title}${subTitle}`,
         imgList: newImgList,
         supportList: newSupportList,
       };
@@ -246,7 +246,9 @@ export default class SupportDetail extends PureComponent {
     const {
       cpId,
       title,
+      subTitle,
       code,
+      name,
       digest,
       detail,
       coverUrl,
@@ -322,6 +324,17 @@ export default class SupportDetail extends PureComponent {
                   initialValue: title,
                 })(<Input />)}
               </Form.Item>
+              <Form.Item label="配套副标题:" hasFeedback {...formItemLayout}>
+                {getFieldDecorator('subTitle', {
+                  rules: [{ required: true, type: 'string', message: "副标题为必填项!" }],
+                  initialValue: subTitle,
+                })(<Input />)}
+              </Form.Item>
+              <Form.Item label="配套名称:" hasFeedback {...formItemLayout}>
+                {getFieldDecorator('name', {
+                  initialValue: name,
+              })(<Input disabled={true} placeholder="根据标题及副标题自动生成"/>)}
+              </Form.Item>
               <Form.Item label="配套概要:" hasFeedback {...formItemLayout}>
                 {getFieldDecorator('digest', {
                   initialValue: digest,

+ 1 - 1
src/routes/Ware/Edit/index.js

@@ -41,7 +41,7 @@ export default class WareDetail extends PureComponent {
     const { dispatch } = this.props;
     dispatch({
       type: 'wareDetail/saveSortResult',
-      payload: { resourceList: data }
+      payload: data,
     });
   }
 

+ 5 - 1
src/services/mproduct.js

@@ -1,6 +1,6 @@
 import { stringify } from 'qs';
 import request from '../utils/request';
-import { merchantProducts, merchantProduct, merchantProductCreate } from '../utils/api';
+import { merchantProducts, merchantProduct, merchantProductCreate, shopCartProducts } from '../utils/api';
 
 export async function query(params) {
   return request(`${merchantProducts}?${stringify(params)}`);
@@ -10,6 +10,10 @@ export async function queryOne(params) {
   return request(`${merchantProduct}?${stringify(params)}`);
 }
 
+export async function queryFromShopCart(params){
+  return request(`${shopCartProducts}?${stringify(params)}`);
+}
+
 export async function createMerchantProduct(params) {
   const options = {
     method: 'PUT',

+ 1 - 0
src/utils/api.js

@@ -27,6 +27,7 @@ module.exports = {
   merchantProducts: `${config.apiHost}/merchant/product`,
   merchantProduct: `${config.apiHost}/merchant/product/detail`,
   merchantProductCreate: `${config.apiHost}/merchant/product/status`,
+  shopCartProducts: `${config.apiHost}/buymsg/list`,
   bundleTag: `${config.apiHost}/merchant/product/tags`,
   goods: `${config.apiHost}/goods`,
   order: `${config.apiHost}/order`,

+ 1 - 1
src/utils/config.js

@@ -44,7 +44,7 @@ Codes.CODE_SEASON = '季';
 Codes.CODE_ITEM = '件';
 
 module.exports = {
-  apiHost: '/api/v1',
+  apiHost: 'http://192.168.1.40:8500',
   ossHost: 'http://efunimgs.oss-cn-beijing.aliyuncs.com',
   // 每页返回数据量
   pageSize: 20,