<template>
|
<div id="product">
|
<el-button type="primary" size="mini" @click="handleAdd" style="margin-bottom: 20px" v-if="stageShow">新增</el-button>
|
<el-form ref="ruleForm" :model="ruleForm" :show-message="false">
|
<el-table :data="ruleForm.tableData" stripe style="width: 100%;" size="small">
|
<el-table-column label=" " type="index" align="center"> </el-table-column>
|
<!-- :render-header="renderHeader" -->
|
<el-table-column prop="product">
|
<template slot="header">
|
<span>
|
<span class="red-star"></span>
|
<span style="padding-left:8px">产品</span>
|
</span>
|
</template>
|
<template slot-scope="scope">
|
<div v-if="!scope.row.save">{{ scope.row.productDesc }}</div>
|
<el-form-item :prop="'tableData.' + scope.$index + '.product'" :rules="rules('product')" v-if="scope.row.save">
|
<el-select v-model="scope.row.product" filterable clearable placeholder="请选择" size="mini">
|
<el-option
|
v-for="(item, index) in options.product"
|
:key="index"
|
:label="item.valueDesc"
|
:value="item.value"
|
>
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</template>
|
</el-table-column>
|
<el-table-column prop="city" >
|
<template slot="header">
|
<span>
|
<span class="red-star"></span>
|
<span style="padding-left:8px">合作城市</span>
|
</span>
|
</template>
|
<template slot-scope="scope">
|
<div v-if="!scope.row.save">{{ scope.row.cityDesc }}</div>
|
<el-form-item :prop="'tableData.' + scope.$index + '.city'" :rules="rules('city')" v-if="scope.row.save">
|
<el-select
|
v-model="scope.row.city"
|
filterable
|
remote
|
clearable
|
reserve-keyword
|
placeholder="请选择"
|
:remote-method="remoteMethod"
|
size="mini"
|
@blur="blur"
|
>
|
<el-option
|
v-for="(item, index) in options.city"
|
:key="index"
|
:label="item.itemname"
|
:value="item.itemno"
|
>
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</template>
|
</el-table-column>
|
<el-table-column prop="levermultiple" >
|
<template slot="header">
|
<span>
|
<span class="red-star"></span>
|
<span style="padding-left:8px">杠杆倍数</span>
|
</span>
|
</template>
|
<template slot-scope="scope">
|
<div v-if="!scope.row.save">{{ scope.row.levermultiple }}</div>
|
<el-form-item :prop="'tableData.' + scope.$index + '.levermultiple'" :rules="rules('levermultiple')" v-if="scope.row.save">
|
<el-input v-model.number="scope.row.levermultiple" size="mini"></el-input>
|
</el-form-item>
|
</template>
|
</el-table-column>
|
<el-table-column label="资金数据管理" width="140px" v-if="stageShow" fixed="right">
|
<template slot-scope="scope">
|
<el-button v-if="!scope.row.save" type="text" size="mini" @click="handleEdit(scope.row,scope.$index)">
|
修改
|
</el-button>
|
<el-button v-if="scope.row.save" type="text" size="mini" @click="handleSave(scope.row, scope.$index)">
|
保存
|
</el-button>
|
<el-button type="text" v-if="!scope.row.cancel" size="mini" @click="handleDelete(scope.row, scope.$index)">
|
删除
|
</el-button>
|
<el-button type="text" v-if="scope.row.cancel" size="mini" @click="handleCancel(scope.row,scope.$index)">
|
取消
|
</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
<pagination
|
v-show="total > 0"
|
:total="total"
|
:page.sync="listQuery.currentPage"
|
:limit.sync="listQuery.pageSize"
|
@pagination="initTable"
|
/>
|
</el-form>
|
</div>
|
</template>
|
|
<script>
|
import {
|
qryChannelProductList,
|
addChannelQcInfo,
|
saveChannelQcInfo,
|
delChannelQcInfo,
|
channelCode
|
} from '@/api/area/partner'
|
import {getAllCityAreaList} from '@/api/product'
|
import Pagination from '@/components/Pagination'
|
import { mapState } from 'vuex'
|
export default {
|
components: { Pagination },
|
props: ['serialno'],
|
data: function() {
|
return {
|
// 分页
|
listLoading: true,
|
total: 0,
|
listQuery: {
|
currentPage: 1,
|
pageSize: 10
|
},
|
ruleForm: {
|
tableData: []
|
},
|
form: {
|
serialno: '',
|
objectno: '',
|
product: '',
|
city: '',
|
levermultiple: '',
|
},
|
options: {
|
city: [],
|
product: []
|
},
|
row: {}
|
}
|
},
|
created() {
|
this.initTable()
|
this.initSelect()
|
},
|
computed: {
|
...mapState({
|
partnerParams: state => state.risk.partnerParams
|
}),
|
stageShow() {
|
const { phaseno } = this.partnerParams
|
if (phaseno === '0040' || phaseno === '0050' || phaseno === '0060' || phaseno === '0070' || phaseno === '0080' || phaseno === '0090') {
|
return false
|
} else {
|
return true
|
}
|
}
|
},
|
methods: {
|
async initTable() {
|
let params = {
|
serialno: this.partnerParams.serialno,
|
}
|
Object.assign(params, this.listQuery)
|
let res = await qryChannelProductList(params)
|
this.ruleForm.tableData = res.result.records
|
this.total = res.result.total
|
this.ruleForm.tableData.forEach((item, key) => {
|
item = Object.assign({}, item, { save: false })
|
})
|
this.initForm()
|
this.listLoading = false
|
},
|
async initForm() {
|
let params = {
|
serialno: this.partnerParams.serialno,
|
objectType: this.partnerParams.objectType
|
}
|
Object.assign(this.row, this.form)
|
let res = await addChannelQcInfo(params)
|
this._.merge(this.form, res.result)
|
},
|
/* initSelect() {
|
let product = { conditionName: 'product' }
|
channelCode(product).then(res => {
|
this.options.product = res.result
|
})
|
let city = { conditionName: 'AreaCode' }
|
channelCode(city).then(res => {
|
this.options.city = res.result
|
})
|
}, */
|
initSelect() {
|
let product = { conditionName: 'product' }
|
channelCode(product).then(res => {
|
this.options.product = res.result
|
})
|
let city = { queryFlag: '02' }
|
getAllCityAreaList(city).then(res => {
|
this.options.city = res.result
|
})
|
},
|
handleEdit(row, index) {
|
if (this._.find(this.ruleForm.tableData, { save: true })) {
|
this.$message.warning('请保存当前数据!')
|
return false
|
}
|
this.$set(this.ruleForm.tableData[index], 'save', true)
|
this.$set(this.ruleForm.tableData[index], 'cancel', true)
|
this.modifyRow = Object.assign({}, row)
|
},
|
handleSave(row, index) {
|
let params = {
|
objectno: this.partnerParams.serialno,
|
objecttype: this.partnerParams.objectType,
|
}
|
params = Object.assign({}, row, params)
|
this.$refs['ruleForm'].validate(valid => {
|
if (valid) {
|
saveChannelQcInfo(params).then(res => {
|
if (res.code === '00') {
|
this.$message.success('保存成功')
|
this.$set(this.ruleForm.tableData[index], 'save', false)
|
this.$set(this.ruleForm.tableData[index], 'cancel', false)
|
this.initTable()
|
}
|
})
|
} else {
|
this.$message.warning('当前页面存在必填项未录入或数据录入错误,请检查!')
|
return false
|
}
|
})
|
},
|
async handleDelete(row, index) {
|
if (row.newRow) {
|
this.ruleForm.tableData.splice(index, 1)
|
this.initTable()
|
return false
|
}
|
let confirm = await this.$confirm('此操作将永久删除该内容, 是否继续?', '删除确认', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
customClass: 'par_messages_box',
|
confirmButtonClass: 'par_messages_box_confirm',
|
cancelButtonClass: 'par_messages_box_cancel',
|
center: true
|
})
|
.then(() => {
|
return true
|
})
|
.catch(() => {
|
return false
|
})
|
let params = { serialno: row.serialno }
|
if (confirm) {
|
let res = await delChannelQcInfo(params)
|
if (res.code === '00') {
|
this.$message.success('删除成功!')
|
this.initTable()
|
}
|
}
|
},
|
handleAdd() {
|
if (this._.find(this.ruleForm.tableData, { save: true })) {
|
this.$message.warning('请保存当前数据!')
|
return false
|
}
|
Object.keys(this.form).forEach(key => {
|
this.row[key] = this.form[key].value
|
})
|
let params = {
|
save: true,
|
cancel: false,
|
newRow: true
|
}
|
Object.assign(params, this.row)
|
this.ruleForm.tableData.unshift(params)
|
},
|
rules(key) {
|
return {
|
required: this.form[key].required,
|
message: '请输入' + this.form[key].filedDescription,
|
trigger: 'blur'
|
}
|
},
|
// 输入搜索
|
remoteMethod(query) {
|
if (query !== '') {
|
setTimeout(() => {
|
this.options.city = this.options.city.filter(item => item.itemname.includes(query))
|
}, 200)
|
} else {
|
this.options.city = []
|
}
|
},
|
// 获取到焦点时
|
blur() {
|
let city = { queryFlag: '02' }
|
getAllCityAreaList(city).then(res => {
|
this.options.city = res.result
|
})
|
},
|
// 取消
|
handleCancel(row, index) {
|
for (let key in row) {
|
if (row[key] !== this.modifyRow[key]) {
|
this.saveSuccess = false // 用户修改了数据
|
break
|
}
|
}
|
if (!this.saveSuccess) {
|
// 数据修改了
|
this.$confirm('检测到未保存的内容,是否保存当行修改?', '取消确认', {
|
distinguishCancelAndClose: true,
|
confirmButtonText: '保存',
|
cancelButtonText: '放弃修改',
|
customClass: 'enp_messages_box',
|
confirmButtonClass: 'enp_messages_box_confirm',
|
cancelButtonClass: 'enp_messages_box_cancel',
|
center: true
|
})
|
.then(() => {
|
// 保存
|
row.cancel = !row.cancel
|
row.save = !row.save
|
// this.$message.success('保存成功');
|
this.handleSave(row,index)
|
this.saveSuccess = true
|
})
|
.catch(() => {
|
for (let key in row) {
|
row[key] = this.modifyRow[key]
|
}
|
row.cancel = !row.cancel
|
row.save = !row.save
|
this.saveSuccess = true
|
})
|
} else {
|
// 数据未修改
|
row.cancel = !row.cancel
|
row.save = !row.save
|
}
|
},
|
// 表格必填样式控制
|
renderHeader (h, {column}) { // h即为cerateElement的简写
|
return h(
|
'div',
|
[
|
[
|
h('span', {
|
style:'position:absolute;top:7px;left:12px;border:2px solid #FF4300;content:"";border-radius:50%;color:#FF4300;margin-right:5px;line-height:12px'
|
}),
|
h('span', column.label,
|
{
|
style: 'position:absolute;top:0px;left:0px;'
|
})
|
],
|
],
|
);
|
},
|
}
|
}
|
</script>
|
|
<style lang="stylus" scoped>
|
#product
|
>>> .el-form
|
.cell
|
div
|
&:nth-child(1)
|
line-height 18px
|
.el-form-item__content
|
.el-input--mini
|
// left 10px
|
.el-input__inner
|
// width 170px
|
font-size 14px
|
.red-star
|
display inline-block
|
width 5px
|
height 5px
|
border-radius 50%
|
vertical-align: middle;
|
// color: #F56C6C;
|
background-color #f56c66
|
margin-bottom 3px
|
</style>
|