outputValueDialog.vue
8.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<template>
<d2-dialog :title="'单店目标产值'"
:isVisible="outputVisible"
:width="'880px'"
@closeDialog="handleImport"
@confirmDialog="handleConfirmImport">
<slot>
<div class="searchWrap">
<el-col :span="13">
<el-date-picker v-model="search.targetDate"
:clearable="false"
type="month"
format="yyyy 年 MM 月"
value-format="yyyy-MM"
:picker-options="pickerOptions"
placeholder="选择月">
</el-date-picker>
</el-col>
<el-col :span="9">
<el-input v-model="search.keyword"
clearable
placeholder="输入门店名称搜索"></el-input>
</el-col>
<el-col :span="2"
class="btnContainer">
<el-button type="primary"
@click="getList"
class="searchBtn">搜索</el-button>
</el-col>
<!-- <div class="searchInput">
</div> -->
</div>
<div class="yqdTableContainer">
<!-- border -->
<el-table :data="tableData"
stripe
max-height="450"
:header-cell-style="rowClass"
style="width: 100%">
<el-table-column label="序号"
type="index"
width="50">
</el-table-column>
<el-table-column prop="yqMerchantName"
label="园区店列表"
width="300">
</el-table-column>
<el-table-column prop="merchantName"
label="门店列表"
width="300">
</el-table-column>
<!-- <el-table-column prop="outputValue"
label="门店列表">
</el-table-column> -->
<!-- width="260" -->
<el-table-column prop="outputValue"
label="产值目标">
<template slot-scope="scope">
<!-- <div>slot-scope="scope"</div> &&item.isEdit-->
<span v-if="!scope.row['isEdit']">{{scope.row['outputValue']}}</span>
<!-- @input="input($event,item)" -->
<el-input v-else
style="width: 140px"
@input="handleInput($event,scope)"
v-model="scope.row['outputValue']"
placeholder=""></el-input>
<!-- <div></div> -->
</template>
</el-table-column>
</el-table>
<div class="tips">填写后不支持修改,请谨慎输入。</div>
</div>
</slot>
</d2-dialog>
</template>
<script>
import { limitPrice } from '@/common/constants'
// import moment from 'moment'
import dayjs from 'dayjs'
import { getMerchantOutputValueTarget, setMerchantOutputValueTarget } from '@api/index'
export default {
props: {
isShow: {
// 弹窗是否展示
type: Boolean,
default: true
}
},
data() {
return {
pickerOptions: {
disabledDate: (time) => {
const maxMonth = dayjs().subtract(-1, 'months').endOf('month')
const minMonth = dayjs().subtract(5, 'months').startOf('month')
// console.log(minMonth.valueOf())
// console.log(time.getTime())
// time.getTime() > minMonth.valueOf() ||
return time.getTime() > maxMonth.valueOf() || time.getTime() < minMonth.valueOf()
}
},
nowMonth: dayjs().subtract(0, 'months').startOf('month').format('YYYY-MM'),
nextMonth: dayjs().subtract(-1, 'months').startOf('month').format('YYYY-MM'),
search: {
keyword: '',
targetDate: ''
},
// tableLabel: [],
tableData: [
// {
// date: '2016-05-02',
// name: '王小虎',
// address: '上海市普陀区金沙江路 1518 弄'
// }
// , {
// date: '2016-05-04',
// name: '王小虎',
// address: '上海市普陀区金沙江路 1517 弄'
// }, {
// date: '2016-05-04',
// name: '王小虎',
// address: '上海市普陀区金沙江路 1517 弄'
// }, {
// date: '2016-05-04',
// name: '王小虎',
// address: '上海市普陀区金沙江路 1517 弄'
// }, {
// date: '2016-05-04',
// name: '王小虎',
// address: '上海市普陀区金沙江路 1517 弄'
// }, {
// date: '2016-05-04',
// name: '王小虎',
// address: '上海市普陀区金沙江路 1517 弄'
// }, {
// date: '2016-05-01',
// name: '王小虎',
// address: '上海市普陀区金沙江路 1519 弄'
// }, {
// date: '2016-05-01',
// name: '王小虎',
// address: '上海市普陀区金沙江路 1519 弄'
// }, {
// date: '2016-05-01',
// name: '王小虎',
// address: '上海市普陀区金沙江路 1519 弄'
// }, {
// date: '2016-05-01',
// name: '王小虎',
// address: '上海市普陀区金沙江路 1519 弄'
// }, {
// date: '2016-05-01',
// name: '王小虎',
// address: '上海市普陀区金沙江路 1519 弄'
// }, {
// date: '2016-05-03',
// name: '王小虎',
// address: '上海市普陀区金沙江路 1516 弄'
// }
]
// outputVisible: true
}
},
computed: {
outputVisible: {
get() {
return this.isShow
},
set(val) {
this.$emit('update:isShow', false)
}
}
},
mounted() {
// console.log(this.nowMonth)
this.search.targetDate = this.nowMonth
this.getList()
// console.log(moment().subtract(-1, 'months').endOf('month').format('YYYY-MM-DD'))
// console.log(moment().subtract(5, 'months').startOf('month').format('YYYY-MM-DD'))
},
methods: {
getList() {
getMerchantOutputValueTarget(this.search).then((result) => {
const monthCheck = [this.nowMonth, this.nextMonth].includes(this.search.targetDate)
// console.log(monthCheck)
// 处理值能否编辑的问题
const listFilter = result
// 要单月或者下月并且值为0才可以编辑
this.tableData = listFilter.map((item) => {
item.dataMonth = this.search.targetDate
item.isEdit = monthCheck && !item.outputValue
return item
})
// console.log(result)
this.tableData = result
// console.log(this.tableData)
}).catch((err) => {
console.log(err)
})
},
handleInput(newValue, item) {
// console.log(newValue, item)
// let limitNum = limitPrice
// console.log(limitPrice(newValue, item.row.outputValue, 6))
newValue = newValue.replace(/[^\d.]/g, '') // 清除“数字”和“.”以外的字符
// console.log(newValue)
this.tableData[item.$index]['outputValue'] = limitPrice(newValue, item.row.outputValue, 6, 0, 1)
// console.log(this.tableData[item.$index]['name'])
},
// 设置表头的颜色
rowClass({ row, rowIndex }) {
// console.log(rowIndex) // 表头行标号为0
return 'background:#F4F6FC'
},
async handleConfirmImport() {
const filterList = this.tableData.filter((item) => {
// 删除无需字段 避免后台类型报错
delete item.createdDate
delete item.updatedDate
return item.isEdit && item.outputValue
})
if (filterList.length) {
// console.log('请求修改')
// const result =
await setMerchantOutputValueTarget({ list: filterList })
// console.log(result)
}
// else {
// console.log('没有能修改的')
// }
this.handleImport()
},
handleImport() {
this.outputVisible = false
}
}
}
</script>
<style lang="scss" scoped>
::v-deep.searchWrap {
height: 30px;
margin-bottom: 10px;
.el-input__inner {
height: 30px;
}
.el-input__icon {
line-height: 30px;
}
.btnContainer {
text-align: right;
padding-right: 10px;
}
.searchBtn {
font-size: 12px;
padding: 8px 10px;
}
}
::v-deep.yqdTableContainer {
.el-table .cell {
padding: 0 10px;
}
// padding-right: 3px;
.el-table__body-wrapper {
.el-table__row td:nth-child(1) {
border-left: 1px solid #ebeef5;
}
.el-table__row td:nth-last-child(1) {
border-right: 1px solid #ebeef5;
}
}
}
.tips {
margin-top: 10px;
font-size: 12px;
text-align: right;
color: #f46967;
}
</style>