Authored by lzhy

优化代码

@@ -117,52 +117,48 @@ export default { @@ -117,52 +117,48 @@ export default {
117 this.search(); 117 this.search();
118 }, 118 },
119 methods: { 119 methods: {
  120 + //组织当前的搜索条件
120 filterValues() { 121 filterValues() {
121 - const values = {  
122 - pageNo: 1,  
123 - pageSize: 10,  
124 - };  
125 - const fields = this.filters;  
126 - const keysMap = {  
127 - beginTime: 'beginTime',  
128 - endTime: 'endTime',  
129 - timeFlag: 'timeFlag',  
130 - targetAccount: 'targetAccount',  
131 - orderCode: 'orderCode',  
132 - clearingType: 'clearingType',  
133 - subClearingType: 'subClearingType',  
134 - status: 'status',  
135 - };  
136 - _.each(keysMap, (val, key) => {  
137 - values[key] = fields[val].model; 122 + const _this = this;
  123 + _.each(this.filters, (value, key) => {
  124 + _this.currentSearchParams[key] = value.model;
138 }); 125 });
139 - return values; 126 + const { current, pageSize } = this.pageData;
  127 + this.currentSearchParams.pageNo = current;
  128 + this.currentSearchParams.pageSize = pageSize;
140 }, 129 },
141 - search() {  
142 - let params = {};  
143 - this.filters.timeFlag.model = '';  
144 - params = this.filterValues();  
145 - this.list(params);  
146 - this.pageData.current = 1;  
147 - },  
148 - reset() {  
149 - let params = {}; 130 + //重置筛选条件
  131 + resetFilter() {
  132 + //重置筛选框中的数据
150 _.each(this.filters, value => { 133 _.each(this.filters, value => {
151 if (value.hasOwnProperty('model')) { 134 if (value.hasOwnProperty('model')) {
152 value.model = ''; 135 value.model = '';
153 } 136 }
154 }); 137 });
155 - params = this.filterValues();  
156 - this.list(params); 138 + },
  139 + //点击搜索按钮动作
  140 + search() {
  141 + this.filters.timeFlag.model = '';
  142 + this.pageData.current = 1;
  143 + this.filterValues();
  144 + this.list();
  145 + },
  146 + //点击全部操作
  147 + reset() {
157 this.pageData.current = 1; 148 this.pageData.current = 1;
  149 + this.resetFilter();
  150 + this.filterValues();
  151 + this.list();
158 }, 152 },
  153 + //点击快速查询操作
159 timeFlag(flag) { 154 timeFlag(flag) {
160 - let params = {}; 155 + this.resetFilter();
161 this.filters.timeFlag.model = flag; 156 this.filters.timeFlag.model = flag;
162 - params = this.filterValues();  
163 - this.list(params);  
164 this.pageData.current = 1; 157 this.pageData.current = 1;
  158 + this.filterValues();
  159 + this.list();
165 }, 160 },
  161 + //格式化时间
166 createTimeChange(time) { 162 createTimeChange(time) {
167 if (!_.isArray(time)) { 163 if (!_.isArray(time)) {
168 time = time.split(' - '); 164 time = time.split(' - ');
@@ -175,16 +171,17 @@ export default { @@ -175,16 +171,17 @@ export default {
175 this.filters.endTime.model = ''; 171 this.filters.endTime.model = '';
176 } 172 }
177 }, 173 },
  174 + //点击分页
178 pageChange(page) { 175 pageChange(page) {
179 - const params = this.filterValues();  
180 - params.pageNo = page;  
181 this.pageData.current = page; 176 this.pageData.current = page;
182 - this.list(params); 177 + this.currentSearchParams.pageNo = page;
  178 + this.list();
183 }, 179 },
184 - list(params) { 180 + //获取列表数据
  181 + list() {
185 Promise.all([ 182 Promise.all([
186 - this.financeService.shopWithdrawFreightList(params),  
187 - this.financeService.queryFreightBillSummary(params), 183 + this.financeService.shopWithdrawFreightList(this.currentSearchParams),
  184 + this.financeService.queryFreightBillSummary(this.currentSearchParams),
188 ]).then(result => { 185 ]).then(result => {
189 this.tableData = _.get(result[0], 'data.records', []); 186 this.tableData = _.get(result[0], 'data.records', []);
190 this.pageData.total = _.get(result[0], 'data.totalCount', 0); 187 this.pageData.total = _.get(result[0], 'data.totalCount', 0);
@@ -202,8 +199,9 @@ export default { @@ -202,8 +199,9 @@ export default {
202 }, 199 },
203 }); 200 });
204 }, 201 },
  202 + //导出列表
205 exportList() { 203 exportList() {
206 - const queryString = { ...this.filterValues(), excelConf: 'shopFreightList' }; 204 + const queryString = { ...this.currentSearchParams, excelConf: 'shopFreightList' };
207 const params = qs.stringify(queryString, true); 205 const params = qs.stringify(queryString, true);
208 const href = `${baseExportApi}${params}`; 206 const href = `${baseExportApi}${params}`;
209 window.open(href, '_blank'); 207 window.open(href, '_blank');
@@ -61,23 +61,6 @@ @@ -61,23 +61,6 @@
61 }}</Option> 61 }}</Option>
62 </Select> 62 </Select>
63 </div> 63 </div>
64 - <!-- <div class="select-container">-->  
65 - <!-- <Input v-model.trim="filters.targetAccount.model" :placeholder="filters.targetAccount.label" />-->  
66 - <!-- </div>-->  
67 - <!-- <div class="select-container">-->  
68 - <!-- <Select v-model.trim="filters.clearingType.model" :placeholder="filters.clearingType.label">-->  
69 - <!-- <Option v-for="option in filters.clearingType.options" :key="option.value" :value="option.value">{{-->  
70 - <!-- option.label-->  
71 - <!-- }}</Option>-->  
72 - <!-- </Select>-->  
73 - <!-- </div>-->  
74 - <!-- <div class="select-container">-->  
75 - <!-- <Select v-model.trim="filters.subClearingType.model" :placeholder="filters.subClearingType.label">-->  
76 - <!-- <Option v-for="option in filters.subClearingType.options" :key="option.value" :value="option.value">{{-->  
77 - <!-- option.label-->  
78 - <!-- }}</Option>-->  
79 - <!-- </Select>-->  
80 - <!-- </div>-->  
81 <div class="select-container"> 64 <div class="select-container">
82 <Input v-model.trim="filters.orderCode.model" :placeholder="filters.orderCode.label" /> 65 <Input v-model.trim="filters.orderCode.model" :placeholder="filters.orderCode.label" />
83 </div> 66 </div>
@@ -119,53 +102,48 @@ export default { @@ -119,53 +102,48 @@ export default {
119 this.search(); 102 this.search();
120 }, 103 },
121 methods: { 104 methods: {
  105 + //组织当前的搜索条件
122 filterValues() { 106 filterValues() {
123 - const values = {  
124 - pageNo: 1,  
125 - pageSize: 10,  
126 - };  
127 - const fields = this.filters;  
128 - const keysMap = {  
129 - beginTime: 'beginTime',  
130 - endTime: 'endTime',  
131 - timeFlag: 'timeFlag',  
132 - status: 'status',  
133 - orderCode: 'orderCode',  
134 - productSku: 'productSku',  
135 - targetAccount: 'targetAccount',  
136 - clearingType: 'clearingType',  
137 - subClearingType: 'subClearingType',  
138 - };  
139 - _.each(keysMap, (val, key) => {  
140 - values[key] = fields[val].model; 107 + const _this = this;
  108 + _.each(this.filters, (value, key) => {
  109 + _this.currentSearchParams[key] = value.model;
141 }); 110 });
142 - return values; 111 + const { current, pageSize } = this.pageData;
  112 + this.currentSearchParams.pageNo = current;
  113 + this.currentSearchParams.pageSize = pageSize;
143 }, 114 },
144 - search() {  
145 - let params = {};  
146 - this.filters.timeFlag.model = '';  
147 - params = this.filterValues();  
148 - this.list(params);  
149 - this.pageData.current = 1;  
150 - },  
151 - reset() {  
152 - let params = {}; 115 + //重置筛选条件
  116 + resetFilter() {
  117 + //重置筛选框中的数据
153 _.each(this.filters, value => { 118 _.each(this.filters, value => {
154 if (value.hasOwnProperty('model')) { 119 if (value.hasOwnProperty('model')) {
155 value.model = ''; 120 value.model = '';
156 } 121 }
157 }); 122 });
158 - params = this.filterValues();  
159 - this.list(params); 123 + },
  124 + //点击搜索按钮动作
  125 + search() {
  126 + this.filters.timeFlag.model = '';
  127 + this.pageData.current = 1;
  128 + this.filterValues();
  129 + this.list();
  130 + },
  131 + //点击全部操作
  132 + reset() {
160 this.pageData.current = 1; 133 this.pageData.current = 1;
  134 + this.resetFilter();
  135 + this.filterValues();
  136 + this.list();
161 }, 137 },
  138 + //点击快速查询操作
162 timeFlag(flag) { 139 timeFlag(flag) {
163 - let params = {}; 140 + this.resetFilter();
164 this.filters.timeFlag.model = flag; 141 this.filters.timeFlag.model = flag;
165 - params = this.filterValues();  
166 - this.list(params);  
167 this.pageData.current = 1; 142 this.pageData.current = 1;
  143 + this.filterValues();
  144 + this.list();
168 }, 145 },
  146 + //格式化时间
169 createTimeChange(time) { 147 createTimeChange(time) {
170 if (!_.isArray(time)) { 148 if (!_.isArray(time)) {
171 time = time.split(' - '); 149 time = time.split(' - ');
@@ -178,16 +156,17 @@ export default { @@ -178,16 +156,17 @@ export default {
178 this.filters.endTime.model = ''; 156 this.filters.endTime.model = '';
179 } 157 }
180 }, 158 },
  159 + //点击分页
181 pageChange(page) { 160 pageChange(page) {
182 - const params = this.filterValues();  
183 - params.pageNo = page;  
184 this.pageData.current = page; 161 this.pageData.current = page;
185 - this.list(params); 162 + this.currentSearchParams.pageNo = page;
  163 + this.list();
186 }, 164 },
187 - list(params) { 165 + //获取列表数据
  166 + list() {
188 Promise.all([ 167 Promise.all([
189 - this.financeService.shopWithdrawServiceList(params),  
190 - this.financeService.queryBillSummary(params), 168 + this.financeService.shopWithdrawServiceList(this.currentSearchParams),
  169 + this.financeService.queryBillSummary(this.currentSearchParams),
191 ]).then(result => { 170 ]).then(result => {
192 this.tableData = _.get(result[0], 'data.records', []); 171 this.tableData = _.get(result[0], 'data.records', []);
193 this.pageData.total = _.get(result[0], 'data.totalCount', 0); 172 this.pageData.total = _.get(result[0], 'data.totalCount', 0);
@@ -197,8 +176,9 @@ export default { @@ -197,8 +176,9 @@ export default {
197 this.summaryInfo.push({ ...summaryInfo, summaryName: '汇总' }); 176 this.summaryInfo.push({ ...summaryInfo, summaryName: '汇总' });
198 }); 177 });
199 }, 178 },
  179 + //导出列表
200 exportList() { 180 exportList() {
201 - const queryString = { ...this.filterValues(), excelConf: 'shopServiceList' }; 181 + const queryString = { ...this.currentSearchParams, excelConf: 'shopServiceList' };
202 const params = qs.stringify(queryString, true); 182 const params = qs.stringify(queryString, true);
203 const href = `${baseExportApi}${params}`; 183 const href = `${baseExportApi}${params}`;
204 window.open(href, '_blank'); 184 window.open(href, '_blank');
@@ -10,6 +10,8 @@ const withdrawStatus = { @@ -10,6 +10,8 @@ const withdrawStatus = {
10 10
11 export default function() { 11 export default function() {
12 return { 12 return {
  13 + //当前的搜索条件
  14 + currentSearchParams: {},
13 filters: { 15 filters: {
14 createTime: { 16 createTime: {
15 label: '创建时间', 17 label: '创建时间',
@@ -87,8 +89,6 @@ export default function() { @@ -87,8 +89,6 @@ export default function() {
87 }, 89 },
88 ], 90 ],
89 }, 91 },
90 - pageNo: 1,  
91 - pageSize: 10,  
92 }, 92 },
93 tableCols: [ 93 tableCols: [
94 { 94 {
@@ -10,6 +10,8 @@ const withdrawStatus = { @@ -10,6 +10,8 @@ const withdrawStatus = {
10 10
11 export default function() { 11 export default function() {
12 return { 12 return {
  13 + //当前的搜索条件
  14 + currentSearchParams: {},
13 filters: { 15 filters: {
14 createTime: { 16 createTime: {
15 label: '创建时间', 17 label: '创建时间',
@@ -95,8 +97,6 @@ export default function() { @@ -95,8 +97,6 @@ export default function() {
95 label: '提现账户', 97 label: '提现账户',
96 model: '', 98 model: '',
97 }, 99 },
98 - pageNo: 1,  
99 - pageSize: 10,  
100 }, 100 },
101 tableCols: [ 101 tableCols: [
102 { 102 {