Authored by 陈峰

supplement

@@ -3,13 +3,15 @@ @@ -3,13 +3,15 @@
3 class="in-store" 3 class="in-store"
4 width="700" 4 width="700"
5 v-model="showModal" 5 v-model="showModal"
  6 + @on-cancel="modalCancel"
6 title="添加到入库单"> 7 title="添加到入库单">
7 <div class="in-store-content"> 8 <div class="in-store-content">
8 <p class="notice">* 请选择要添加的入库单</p> 9 <p class="notice">* 请选择要添加的入库单</p>
9 <Table 10 <Table
10 ref="table" 11 ref="table"
11 v-if="loadingOk" 12 v-if="loadingOk"
12 - height="300" 13 + height="300"
  14 + no-data-text="正在加载..."
13 :data="tableData" 15 :data="tableData"
14 :columns="tableColumn" 16 :columns="tableColumn"
15 @on-row-click="tableRowClick"></Table> 17 @on-row-click="tableRowClick"></Table>
@@ -86,7 +88,6 @@ export default { @@ -86,7 +88,6 @@ export default {
86 show() { 88 show() {
87 this.loadingData(); 89 this.loadingData();
88 this.showModal = true; 90 this.showModal = true;
89 - this.loadingOk = true;  
90 }, 91 },
91 loadingData() { 92 loadingData() {
92 return supplierService.listOrder({ 93 return supplierService.listOrder({
@@ -134,6 +135,8 @@ export default { @@ -134,6 +135,8 @@ export default {
134 .in-store-content { 135 .in-store-content {
135 .notice { 136 .notice {
136 color: #f30; 137 color: #f30;
  138 + font-size: 14px;
  139 + line-height: 30px;
137 } 140 }
138 } 141 }
139 </style> 142 </style>
1 import {CellImage, CellInfo, CellPrice} from 'components/cell'; // eslint-disable-line 1 import {CellImage, CellInfo, CellPrice} from 'components/cell'; // eslint-disable-line
  2 +import timeFormat from 'filters/time-format';
2 3
3 export default function() { 4 export default function() {
4 return { 5 return {
@@ -22,55 +23,15 @@ export default function() { @@ -22,55 +23,15 @@ export default function() {
22 sknFactoryCode: '', 23 sknFactoryCode: '',
23 skuFactoryCode: '', 24 skuFactoryCode: '',
24 prodName: '', 25 prodName: '',
25 - brandId: -1, 26 + brandId: '',
26 stockStatus: '' 27 stockStatus: ''
27 }, 28 },
28 pageData: { 29 pageData: {
29 total: 0, 30 total: 0,
30 - current: 1, 31 + pageNo: 1,
31 pageSize: 20 32 pageSize: 20
32 }, 33 },
33 - tableData: [{  
34 - id: 1,  
35 - picImgUrl: 'http://img12.static.yhbimg.com/goodsimg/2017/05/09/09/028f8f329a40386d5cdbd966a92d0aaa0a.jpg?imageView2/0/w/78/h/78',  
36 - productSkn: '123',  
37 - productName: '123',  
38 - brandName: '123',  
39 - maxSortName: '123',  
40 - middleSortName: '123',  
41 - smallSortName: '123',  
42 - retailPrice: '123',  
43 - salesPrice: '123',  
44 - saleStatus: '已上架',  
45 - stock: '123',  
46 - day: '123',  
47 - buhuo: '123',  
48 - time: 1492531200,  
49 - store: '南京1号仓库',  
50 - brandId: 248,  
51 - _checked: false,  
52 - num: 0  
53 - }, {  
54 - id: 2,  
55 - picImgUrl: 'http://img12.static.yhbimg.com/goodsimg/2017/05/09/09/028f8f329a40386d5cdbd966a92d0aaa0a.jpg?imageView2/0/w/78/h/78',  
56 - productSkn: '123',  
57 - productName: '123',  
58 - brandName: '1232',  
59 - maxSortName: '123',  
60 - middleSortName: '123',  
61 - smallSortName: '123',  
62 - retailPrice: '123',  
63 - salesPrice: '123',  
64 - saleStatus: '已上架',  
65 - stock: '123',  
66 - day: '123',  
67 - buhuo: '123',  
68 - time: 1492531200,  
69 - store: '南京1号仓库',  
70 - brandId: 249,  
71 - _checked: false,  
72 - num: 0  
73 - }], 34 + tableData: [],
74 tableCols: [{ 35 tableCols: [{
75 type: 'selection', 36 type: 'selection',
76 width: 60, 37 width: 60,
@@ -81,14 +42,13 @@ export default function() { @@ -81,14 +42,13 @@ export default function() {
81 align: 'center', 42 align: 'center',
82 render: (h, params) => { 43 render: (h, params) => {
83 return ( 44 return (
84 - <CellImage  
85 - imageSrc={params.row.picImgUrl}  
86 - productUrl={params.row.productUrl}></CellImage> 45 + <img v-prod-img={params.row.productSkn}/>
87 ); 46 );
88 } 47 }
89 }, { 48 }, {
90 title: '商品信息', 49 title: '商品信息',
91 align: 'center', 50 align: 'center',
  51 + width: '15%',
92 render: (h, params) => { 52 render: (h, params) => {
93 return ( 53 return (
94 <CellInfo items={[ 54 <CellInfo items={[
@@ -111,6 +71,7 @@ export default function() { @@ -111,6 +71,7 @@ export default function() {
111 }, { 71 }, {
112 title: '价格(元)', 72 title: '价格(元)',
113 align: 'center', 73 align: 'center',
  74 + width: '13%',
114 render: (h, params) => { 75 render: (h, params) => {
115 return ( 76 return (
116 <CellInfo items={[ 77 <CellInfo items={[
@@ -119,34 +80,29 @@ export default function() { @@ -119,34 +80,29 @@ export default function() {
119 value: params.row.retailPrice 80 value: params.row.retailPrice
120 }, { 81 }, {
121 label: '销售价', 82 label: '销售价',
122 - value: params.row.salesPrice 83 + value: params.row.salePrice
123 } 84 }
124 ]}></CellInfo> 85 ]}></CellInfo>
125 ); 86 );
126 } 87 }
127 }, { 88 }, {
128 - title: '销售状态',  
129 - key: 'saleStatus'  
130 - }, {  
131 title: '仓库库存', 89 title: '仓库库存',
132 key: 'stock' 90 key: 'stock'
133 }, { 91 }, {
134 title: '库存可售天数', 92 title: '库存可售天数',
135 - key: 'day' 93 + key: 'saleDays'
136 }, { 94 }, {
137 title: '建议补货数', 95 title: '建议补货数',
138 - key: 'buhuo' 96 + key: 'supplementNums'
139 }, { 97 }, {
140 title: '最近一次补货时间', 98 title: '最近一次补货时间',
  99 + width: 150,
141 render: (h, params) => { 100 render: (h, params) => {
142 return ( 101 return (
143 - <span>{params.row.time}</span> 102 + <span>{timeFormat(params.row.lastTime)}</span>
144 ); 103 );
145 } 104 }
146 }, { 105 }, {
147 - title: '仓库',  
148 - key: 'store'  
149 - }, {  
150 title: '补货数', 106 title: '补货数',
151 render: (h, params) => { 107 render: (h, params) => {
152 return ( 108 return (
@@ -154,6 +110,7 @@ export default function() { @@ -154,6 +110,7 @@ export default function() {
154 max={999} 110 max={999}
155 min={0} 111 min={0}
156 value={params.row.num} 112 value={params.row.num}
  113 + style={{width: '60px'}}
157 onInput={val => (params.row.num = val)} 114 onInput={val => (params.row.num = val)}
158 onOn-change={val => (this.numChange(params.row, val))}></Input-number> 115 onOn-change={val => (this.numChange(params.row, val))}></Input-number>
159 ); 116 );
@@ -43,9 +43,9 @@ @@ -43,9 +43,9 @@
43 @on-selection-change="selectChange"></Table> 43 @on-selection-change="selectChange"></Table>
44 <Page 44 <Page
45 :total="pageData.total" 45 :total="pageData.total"
46 - :current="pageData.current" 46 + :current="pageData.pageNo"
47 @on-change="pageChange" 47 @on-change="pageChange"
48 - :page-size="20" 48 + :page-size="pageData.pageSize"
49 show-total></Page> 49 show-total></Page>
50 </LayoutList> 50 </LayoutList>
51 <ModalInvoice ref="modalInvoice" @save="saveInvoice" :brand="selectBrand.brandId"></ModalInvoice> 51 <ModalInvoice ref="modalInvoice" @save="saveInvoice" :brand="selectBrand.brandId"></ModalInvoice>
@@ -56,7 +56,7 @@ @@ -56,7 +56,7 @@
56 import _ from 'lodash'; 56 import _ from 'lodash';
57 import {SelectBrand, SelectCategory} from 'components/select'; 57 import {SelectBrand, SelectCategory} from 'components/select';
58 import {ModalInvoice} from './components'; 58 import {ModalInvoice} from './components';
59 -import supplierService from 'supplier-service'; 59 +import invoiceService from 'invoice-service';
60 import store from './store'; 60 import store from './store';
61 61
62 export default { 62 export default {
@@ -64,19 +64,31 @@ export default { @@ -64,19 +64,31 @@ export default {
64 return store.apply(this); 64 return store.apply(this);
65 }, 65 },
66 created() { 66 created() {
  67 + return this.search();
67 }, 68 },
68 methods: { 69 methods: {
69 search() { 70 search() {
70 - return supplierService.supplementProductList(this.getQuery()).then(res => {  
71 - console.log(res); 71 + this.$Loading.start();
  72 + return invoiceService.supplementProductList(this.getQuery()).then(res => {
  73 + this.$Loading.finish();
  74 + this.tableData = res.records;
  75 + this.pageData.total = res.totalCount;
  76 + }, () => {
  77 + this.$Loading.finish();
72 }); 78 });
73 }, 79 },
  80 + pageChange(page) {
  81 + this.pageData.pageNo = page;
  82 + return this.search();
  83 + },
74 getQuery() { 84 getQuery() {
75 - return Object.assign(this.query, { 85 + let params = _.toPairs(Object.assign(this.query, {
76 maxSortId: _.get(this.category, '[0].value'), 86 maxSortId: _.get(this.category, '[0].value'),
77 middleSortId: _.get(this.category, '[1].value'), 87 middleSortId: _.get(this.category, '[1].value'),
78 smallSortId: _.get(this.category, '[2].value') 88 smallSortId: _.get(this.category, '[2].value')
79 - }); 89 + }, this.pageData));
  90 +
  91 + return _.fromPairs(params.filter(item => item[1]));
80 }, 92 },
81 reset() { 93 reset() {
82 this.category = []; 94 this.category = [];
@@ -84,26 +96,34 @@ export default { @@ -84,26 +96,34 @@ export default {
84 this.search(); 96 this.search();
85 }, 97 },
86 selectChange(selection) { 98 selectChange(selection) {
87 - _.each(this.tableData, row => { 99 + _.each(this.$refs.table.rebuildData, row => { // 更新rebuildData不会导致页面重新刷新
88 if (_.some(selection, item => item.id === row.id)) { 100 if (_.some(selection, item => item.id === row.id)) {
89 if (row.num <= 0) { 101 if (row.num <= 0) {
90 row.num = 1; 102 row.num = 1;
91 } 103 }
92 row._checked = true; 104 row._checked = true;
93 } else { 105 } else {
94 - row._checked = false;  
95 row.num = 0; 106 row.num = 0;
  107 + row._checked = false;
96 } 108 }
97 }); 109 });
98 this.validBrand(); 110 this.validBrand();
99 }, 111 },
100 numChange(row, num) { 112 numChange(row, num) {
101 - this.syncData();  
102 - row._checked = num > 0;  
103 - this.validBrand(); 113 + if ((row.num > 0 && !row._checked) ||
  114 + (row.num === 0 && row._checked)) {
  115 + if (row.brandId !== this.selectBrand.brandId && this.selectBrand.brandId) { // 如果品牌不同就直接操作table的rebuilddata不会导致表格刷新
  116 + row.num = 0;
  117 + this.$Message.warning(`请选择品牌为:${this.selectBrand.brandName}的商品补货`);
  118 + return;
  119 + }
  120 + this.syncData();
  121 + row._checked = num > 0;
  122 + this.validBrand();
  123 + }
104 }, 124 },
105 validBrand() { 125 validBrand() {
106 - let selection = _.filter(this.tableData, row => row._checked); 126 + let selection = _.filter(this.$refs.table.rebuildData, row => row._checked);
107 127
108 if (selection.length > 0) { 128 if (selection.length > 0) {
109 if (!this.selectBrand.brandId) { 129 if (!this.selectBrand.brandId) {
@@ -113,7 +133,12 @@ export default { @@ -113,7 +133,12 @@ export default {
113 let rmRows = _.remove(selection, row => row.brandId !== this.selectBrand.brandId); 133 let rmRows = _.remove(selection, row => row.brandId !== this.selectBrand.brandId);
114 134
115 if (rmRows.length) { 135 if (rmRows.length) {
116 - _.each(rmRows, row => { 136 + this.syncData(); // 重新建立table的data和数据data的引用关系然后修改_checked重新渲染表格
  137 + let rowDatas = _.map(rmRows, row => {
  138 + return _.find(this.tableData, item => item.id === row.id);
  139 + });
  140 +
  141 + _.each(rowDatas, row => {
117 row._checked = false; 142 row._checked = false;
118 row.num = 0; 143 row.num = 0;
119 }); 144 });
@@ -135,14 +160,36 @@ export default { @@ -135,14 +160,36 @@ export default {
135 this.tableData = this.$refs.table.rebuildData; 160 this.tableData = this.$refs.table.rebuildData;
136 }, 161 },
137 saveInvoice(invoiceId) { 162 saveInvoice(invoiceId) {
138 - let skus = this.tableData.filter(row => row._checked).map(row => { 163 + this.syncData();
  164 + let goodsList = this.tableData.filter(row => row._checked).map(row => {
139 return { 165 return {
140 productSku: row.productSku, 166 productSku: row.productSku,
141 num: row.num 167 num: row.num
142 }; 168 };
143 }); 169 });
144 170
145 - console.log(skus, invoiceId); 171 + if (goodsList.length && invoiceId) {
  172 + this.$Loading.start();
  173 + return invoiceService.addGoods({
  174 + proRequisitionFormId: invoiceId,
  175 + goodsList
  176 + }).then(res => {
  177 + this.$Loading.finish();
  178 + if (res.code === 200) {
  179 + this.$Notice.success({
  180 + title: '保存成功'
  181 + });
  182 + this.search();
  183 + } else {
  184 + this.$Notice.error({
  185 + title: res.message
  186 + });
  187 + }
  188 + }, () => {
  189 + this.$Loading.finish();
  190 + });
  191 + }
  192 + this.$Message.warning('请选择商品和入库单');
146 } 193 }
147 }, 194 },
148 components: { 195 components: {
1 /** 1 /**
2 * Created by TaoHuang on 2017/5/25. 2 * Created by TaoHuang on 2017/5/25.
3 */ 3 */
4 - 4 +import _ from 'lodash';
5 import request from 'axios'; 5 import request from 'axios';
6 6
7 const apiUrl = { 7 const apiUrl = {
@@ -18,7 +18,8 @@ const apiUrl = { @@ -18,7 +18,8 @@ const apiUrl = {
18 listAvailableProduct: '/erp/invoiceGoodsAvailable', 18 listAvailableProduct: '/erp/invoiceGoodsAvailable',
19 addGoods: '/erp/invoiceGoodsAdd', 19 addGoods: '/erp/invoiceGoodsAdd',
20 updateGoods: '/erp/invoiceGoodsUpdate', 20 updateGoods: '/erp/invoiceGoodsUpdate',
21 - deleteGoods: 'erp/invoiceGoodsDelete' 21 + deleteGoods: 'erp/invoiceGoodsDelete',
  22 + supplementProductList: '/erp/supplementProductList'
22 }; 23 };
23 24
24 function listOrder(params) { 25 function listOrder(params) {
@@ -100,6 +101,22 @@ function deleteGoods(params) { @@ -100,6 +101,22 @@ function deleteGoods(params) {
100 .then(res => res.data); 101 .then(res => res.data);
101 } 102 }
102 103
  104 +function supplementProductList(params) {
  105 + return request.post(apiUrl.supplementProductList, params)
  106 + .then(res => {
  107 + if (res.data.code === 200) {
  108 + let records = _.get(res, 'data.data.records', []);
  109 +
  110 + _.each(records, item => {
  111 + item.num = 0;
  112 + item._checked = false;
  113 + });
  114 + return res.data.data;
  115 + }
  116 + return {};
  117 + });
  118 +}
  119 +
103 export default { 120 export default {
104 listProduct, 121 listProduct,
105 listOrder, 122 listOrder,
@@ -114,5 +131,6 @@ export default { @@ -114,5 +131,6 @@ export default {
114 listAvailableProduct, 131 listAvailableProduct,
115 addGoods, 132 addGoods,
116 updateGoods, 133 updateGoods,
117 - deleteGoods 134 + deleteGoods,
  135 + supplementProductList
118 }; 136 };