tgfp.vue 11.7 KB
Newer Older
fukai committed
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
<template>
    <div class="eibs-tab">
        <el-table :data="model.recgrp.tgf" @selection-change="handleSelectionChange" ref="multipleTable"
                  style="width: 100%">
            <el-table-column :selectable="rowSelectable" type="selection" v-if="showSelection"
                             width="55"></el-table-column>
            <el-table-column label="明细主键" prop="seqno" width="100"></el-table-column>
            <el-table-column :formatter="(row) => getCodeLabel(row.listopertype, 'opertype')" label="明细操作类型"
                             prop="listopertype" width="150"></el-table-column>
            <el-table-column label="合约金额" prop="contractamt"></el-table-column>
            <el-table-column label="交易方向" prop="tradedirection"></el-table-column>
            <el-table-column label="交易日" prop="tradedate"></el-table-column>
            <el-table-column label="到期日" prop="enddate"></el-table-column>
            <el-table-column :formatter="(row) => getCodeLabel(row.sta, 'rmbsta')" fixed="right" label="状态" prop="sta"
                             v-if="showSta" width="100"></el-table-column>
            <el-table-column fixed="right" label="操作" v-if="showButton" width="150">
                <template slot-scope="scope">
                    <el-button :disabled="isButtonDisabled(scope.row)" @click="handleEdit(scope.$index,scope.row)"
                               size="mini">编辑
                    </el-button>
                    <el-button :disabled="isButtonDisabled(scope.row)" @click="handleDelete(scope.$index)"
                               size="mini" v-if="showDeleteButton(scope.row)">
                        删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <div style="margin-top: 20px" v-show="showButton">
            <el-button :disabled="!isFlgChecked" @click="addRow" type="primary">添 加</el-button>
            <!--                <el-button @click="deleteSelectedRows" type="primary">删 除</el-button>-->
        </div>


        <el-dialog :before-close="cancel" :visible.sync="showDialog" center title="明细信息" v-dialogDrag v-if="showDialog">
            <el-form :model="formData" :rules="rules" :validate-on-rule-change="false" label-width="150px" ref="formRef"
                     style="width: 100%">
                <!-- 第1行 -->
                <c-row>
                    <c-col :span="8">
                        <el-form-item label="合约金额" prop="contractamt">
                            <c-input-currency placeholder="请输入合约金额" v-model="formData.contractamt"></c-input-currency>
                        </el-form-item>
                    </c-col>
                    <c-col :span="8">
                        <el-form-item label="交易方向" prop="tradedirection">
                            <c-select dbCode="tradir" placeholder="请输入交易方向"
                                      v-model="formData.tradedirection"></c-select>
                        </el-form-item>
                    </c-col>
                    <c-col :span="8">
                        <el-form-item label="交易日" prop="tradedate">
                            <c-date-picker placeholder="请输入交易日" type="date"
                                           v-model="formData.tradedate"></c-date-picker>
                        </el-form-item>
                    </c-col>
                </c-row>

                <!-- 第2行 -->
                <c-row>
                    <c-col :span="8">
                        <el-form-item label="到期日" prop="enddate">
                            <c-date-picker placeholder="请输入到期日" type="date" v-model="formData.enddate"></c-date-picker>
                        </el-form-item>
                    </c-col>
                </c-row>

            </el-form>
            <span class="dialog-footer" slot="footer">
                <el-button @click="saveRow" type="primary">保 存</el-button>
                <el-button @click="cancel" type="primary">取 消</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import event from "../event";
    import moment from 'moment';
		import commonMixin from "../../../../../../mixin/commonMixin";
		import {checkRuleOfTGF} from "RcpmisRules"

    export default {
        props: ["model", "codes"],
        mixins: [commonMixin, event],
        data() {
            return {
                formData: {
                    contractamt: '',			//  合约金额		.recp.tgfpp.contractamt
                    tradedate: '',			//  交易日		.recp.tgfpp.tradedate
                    enddate: '',			//  到期日		.recp.tgfpp.enddate
                    tradedirection: '',			//  交易方向		.recp.tgfpp.tradedirection
                },
            };
        },
        computed: {
            rules() {
							let checks = checkRuleOfTGF().call({module:"TGFAME"}).call(this,this,moment)
              return checks
                // return {
                //     contractamt: [
                //         {required: true, message: '必输项'}
                //     ],
                //     tradedirection: [
                //         {required: true, message: '必输项'}
                //     ],
                //     enddate: [
                //         {required: true, message: '必输项'},
                //         {
                //             validator: (rule, value, callback) => {
                //                 let rq = new Date(value);
                //                 let re = new Date(this.formData.tradedate);
                //                 if (moment(rq).diff(moment(re), 'days') < 0) {
                //                     return callback(new Error("到期日需要大于等于交易日!"))
                //                 } else {
                //                     callback();
                //                 }
                //             }, trigger: 'blur'
                //         }
                //     ],
                //     tradedate: [
                //         {required: true, message: '必输项'}
                //     ]

                // }
            },
        },
        watch: {
            'model.rmbbut.flg': {
                handler(newValue) {
                    const dectyp = this.model.pblmod.dectyp;
                    const opertype = this.model.recgrp.ads.opertype;
                    if (dectyp === "D" && opertype === "1") {
                        if (newValue === "X") {
                            this.model.recgrp.tgf.forEach(row => {
                                if (row.sta !== 'D' && row.sta !== 'G' && row.acp !== 'X') {
                                    this.$refs.multipleTable.toggleRowSelection(row);
                                }
                            })
                        } else {
                            this.$refs.multipleTable.clearSelection();
                        }
                    }
                },
            },
            "model.recgrp.ads.opertype": {
                handler(newValue) {
                    const dectyp = this.model.pblmod.dectyp;
                    if (dectyp === "D") {
                        if (newValue === "3") {
                            this.model.recgrp.tgf.forEach(row => {
                                if (row.sta !== 'D' && row.sta !== 'G' && row.acp !== 'X') {
                                    this.$refs.multipleTable.toggleRowSelection(row);
                                }
                            })
                        } else {
                            this.$refs.multipleTable.clearSelection();
                        }
                    }
                }
            },
        },
        methods: {
            handleSelectionChange(selection) {
                this.selectedRows = selection;
                // 当前行被选中时,备份原始值并更新值
                selection.forEach(row => {
                    if (row.acp !== 'X') {
                        row.backupValue = row.listopertype;
                        if (row.backupValue === '2' || row.backupValue === '3' || row.sta === '8') {
                            row.listopertype = '3';
                        } else {
                            if (row.sta === 'D' || row.sta === 'G') {
                                row.listopertype = row.backupValue;
                            } else {
                                row.listopertype = '1';
                            }
                        }
                        // 添加一个标记,表示当前行已被选中
                        row.acp = 'X';
                    }
                });
                // 检查哪些行被取消选中,并恢复它们的原始值
                this.model.recgrp.tgf.forEach(row => {
                    if (!selection.includes(row) && row.acp === 'X') {
                        row.listopertype = row.backupValue;
                        // 清除选中标记
                        row.acp = '';
                    }
                })
            },
            addRow() {
                this.isEdit = false;
                let tgf = {
                    // sta: "",			//  人行报送状态		.recp.tgfpp.sta
                    seqno: this.model.recgrp.tgf.length + 1,			//  明细主键		.recp.tgfpp.seqno
                    listopertype: '1',
                    contractamt: '',			//  合约金额		.recp.tgfpp.contractamt
                    tradedate: '',			//  交易日		.recp.tgfpp.tradedate
                    enddate: '',			//  到期日		.recp.tgfpp.enddate
                    tradedirection: '',			//  交易方向		.recp.tgfpp.tradedirection
                    acp: 'X',
                };
                this.index = this.model.recgrp.tgf.push(tgf) - 1;
                this.formData = this.model.recgrp.tgf[this.index];
                // this.calcRmbbop().then((rtnmsg) => {
                //     if (rtnmsg.respCode === SUCCESS) {
                //         this.formData = this.model.recgrp.tgf[this.index];
                //     }
                // });
                this.toggleShow();
            },
            saveRow() {
                this.$refs.formRef.validate((valid) => {
                    if (valid) {
                        this.$set(this.model.recgrp.tgf, this.index, {...this.formData});
                        this.$refs.formRef.resetFields();
                        this.toggleShow();
                    } else {
                        // 前端校验失败
                        this.$notify({
                            title: '失败',
                            message: '校验失败',
                            type: 'error',
                        });
                        return false;
                    }
                })

            },
            cancel() {
                if (!this.isEdit)
                    this.model.recgrp.tgf.splice(this.index, 1);
                this.toggleShow();
            },
            handleDelete(index) {
                this.model.recgrp.tgf.splice(index, 1);
            },
            deleteSelectedRows() {
                if (this.selectedRows.length === 0) {
                    this.$message.warning('请先选择要删除的数据行');
                    return;
                }
                this.selectedRows.forEach(row => {
                    const index = this.model.recgrp.tek.indexOf(row);
                    if (index !== -1) {
                        this.model.recgrp.tek.splice(index, 1);
                    }
                });
                this.$message.success('成功删除选中行');
                this.selectedRows = [];
            },
        }

    };
</script>
<style>
</style>