<template>
  <div class="eibs-tab">

    <el-form
          ref="paramsForm"
          label-position="right"
          label-width="110px"
          size="small"
      >
      <c-col :span="24">
        <!---------左边------------>
          <c-col :span="11">
               <c-col :span="24">
                   <c-col :span="21">
                    <el-form-item :label="$t('ordrel.filter')" prop="usfmod.flt">
                        <c-select v-model="model.usfmod.flt" style="width:100%" :placeholder="$t('other.please_enter')+ $t('ordrel.filter')" :code="codes.flt_ordrel">
                          </c-select>
                    </el-form-item>
                   </c-col>
                   <c-col :span="3">
                    <c-button size="small" type="primary"  @click="onUsfmodShwflt">
                         {{$t('usfmod.CF000033')}}
                    </c-button>
                   </c-col>
               </c-col>

               <c-col :span="24" v-if="model.usfmod.flt ==='<SELU>'">
                <c-form-item :label="$t('ordrel.SF000050')" prop="usfmod.usr.extkey">
                    <c-input  v-model="model.usfmod.usr.extkey" maxlength="8"  :placeholder="$t('other.please_enter')+$t('ordrel.SF000050')"></c-input>
                </c-form-item>
               </c-col>

           <c-col :span="24">
               <!-- S0000075 : Between -->
               <c-col :span="12">
                    <el-form-item :label="$t('ordrel.S0000075')" prop="inidatfro">
                        <c-date-picker type="date"  v-model="model.inidatfro" style="width:100%"  :placeholder="$t('other.please_enter')+$t('ordrel.S0000075')"></c-date-picker>
                    </el-form-item>
               </c-col>

                 <!-- S0000076 : and -->
               <c-col :span="12">
                <el-form-item :label="$t('ordrel.S0000076')" prop="inidattil" label-width ="80px">
                    <c-date-picker type="date"  v-model="model.inidattil" style="width:100%"  :placeholder="$t('other.please_enter')+$t('ordrel.S0000075')"></c-date-picker>
                </el-form-item>
               </c-col>

           </c-col>

         <!-- SG000156 : 信用证标志 -->
           <c-col :span="24">
            <el-form-item :label="$t('ordrel.SG000156')" prop="dflg">
                <c-select v-model="model.dflg" style="width:100%" :placeholder="$t('other.please_enter')+$t('ordrel.SG000156')" :code="codes.dflg_ordrel">
                  </c-select>
            </el-form-item>
           </c-col>


          </c-col>
         <!---------右边------------>
          <c-col :span="11" :offset="1">
                 <!-- SF000050 : Reference -->

                   <c-col :span="24">
                    <c-form-item :label="$t('ordrel.SF000050')" prop="seltxt">
                        <c-input  v-model="model.seltxt" maxlength="32"  :placeholder="$t('other.please_enter')+$t('ordrel.SF000050')"></c-input>
                    </c-form-item>
                   </c-col>
                <!-- SG000138 : Status -->

                  <c-col :span="24">
                   <el-form-item :label="$t('ordrel.SG000138')" prop="sta">
                       <c-select v-model="model.sta" style="width:100%" :placeholder="$t('other.please_enter')+$t('ordrel.SG000138')" :code="codes.sta_ordrel">
                         </c-select>
                   </el-form-item>
                  </c-col>
                   <!-- S0000073 : Transaction Type  -->
                 <c-col :span="24">
                  <c-form-item :label="$t('ordrel.S0000073')" prop="atp.cod">
                      <c-input  v-model="model.atp.cod" maxlength="6"  :placeholder="$t('other.please_enter')+$t('ordrel.S0000073')"></c-input>
                  </c-form-item>
                 </c-col>

                <!-- S0000074 : Transaction Text -->
                   <c-col :span="24">
                    <c-form-item :label="$t('ordrel.S0000074')" prop="atptxt">
                        <c-input  v-model="model.atptxt" maxlength="37"  :placeholder="$t('other.please_enter')+$t('ordrel.S0000074')" disabled></c-input>
                    </c-form-item>
                   </c-col>
                </c-col>
             </c-col>
        <c-col :span="24" style="text-align: right; height: 36.8px;padding-right: 75px" >
             <el-button icon="el-icon-search" size="small" @click="handleOpen1" >
                {{$t('ordrel.CG000160')}}
             </el-button>
             <el-button type="primary" size="small" @click="handleOpen2" >
                复核任务
             </el-button>
            <el-button size="small" @click="handleReset">重置</el-button>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="small"
              @click="handleSearch"
              >查询</el-button>

            </c-col>
        </el-form>

        <c-col :span="24">

             <c-istream-table
                :list="stmData.data"
                :columns="stmData.columns"
                :showButtonFlg=true
                >
                 <el-table-column fixed="right" prop="op" label="操作" width="180px">
                             <template slot-scope="scope">
                                 <c-button
                                   style="margin-left: 0"
                                   size="small"
                                   type="primary"
                                   @click="getButtons2(scope.row)"
                                 >
                                   工作流程
                                 </c-button>
                                <c-button
                                  style="margin-left: 2"
                                  size="small"
                                  type="primary"
                                  @click="getButtons(scope.row)"
                                >
                                  处理
                                </c-button>
                            </template>
                        </el-table-column>
            </c-istream-table>
      </c-col>

   <el-dialog
        :visible.sync="initdialog"
        :title="'操作列表'"
        append-to-body
      >
        <div class="m-list-btns">
          <div class="busnavbar">
            <div class="busnavbar-items">
              <c-button
                style="margin-left: 7px"
                size="medium"
                type="primary"
                class="medium_bcs"
                @click.native="onOperate('relrow')"
                title="$t('ordrel.CG000158')">
                    {{$t('ordrel.CG000158')}}
                </c-button>
                <c-button
                  style="margin-left: 7px"
                  size="medium"
                  type="primary"
                  class="medium_bcs"
                  @click.native="onButRelrow"
                  :disabled = this.button
                  title="$t('ordrel.CF000069')">
                    {{$t('ordrel.CF000069')}}
                  </c-button>
                <c-button
                    style="margin-left: 7px"
                    size="medium"
                    type="primary"
                    class="medium_bcs"
                    :disabled = this.button
                    @click.native="onButReprow"
                    title="$t('ordrel.CF000070')">
                        {{$t('ordrel.CF000070')}}
                </c-button>
               <c-button
                    style="margin-left: 7px"
                    size="medium"
                    type="primary"
                    class="medium_bcs"
                    :disabled = this.button
                    @click.native="onButRejrow"
                    title="$t('ordrel.CF000071')">
                        {{$t('ordrel.CF000071')}}
                </c-button>
                   <c-button
                        style="margin-left: 7px"
                        size="medium"
                        type="primary"
                        class="medium_bcs"
                        @click.native="onOperate"
                        disabled
                        title="$t('ordrel.CF000077')">
                            {{$t('ordrel.CF000077')}}
                    </c-button>
                   <c-button
                        style="margin-left: 7px"
                        size="medium"
                        type="primary"
                        class="medium_bcs"
                        @click.native="showGridPromptDialog('events')"
                        title="$t('ordrel.CG000140')">
                            {{$t('ordrel.CG000140')}}
                    </c-button>
                   <c-button
                        style="margin-left: 7px"
                        size="medium"
                        type="primary"
                        class="medium_bcs"
                        @click.native="onOperate"
                        title="$t('ordrel.CG000152')">
                            {{$t('ordrel.CG000152')}}
                    </c-button>
            </div>
          </div>
        </div>
      </el-dialog>




  </div>
</template>
<script>
import Api from "~/service/Api"
import commonProcess from "~/mixin/commonProcess";
import CodeTable from "~/config/CodeTable"
import Event from "~/model/Ordrel/Event"

export default {
    inject: ['root'],
    props:["model","codes"],
    mixins: [commonProcess],
    data(){
        return {
             button:false,
             initdialog:false,
             stmData: {
                 columns: [
                     "1 1 \"交易代码\" 200",
                     "2 2  \"交易名称\" 150",
                      {index:3,position:3,width:160,pattern:'code',label:'交易状态',code:'sptDetSta'},
                     "4 4 \"创建时间\" 200",
                     "5 5 \"对于用户\" 200",
                     "6 6 \"工作用户\" 200",
                 ],
                 data: []
             }
        }
    },
    methods:{...Event,
        async onOperate(){
                  this.$notify.error({title: '错误',message: '开发中'});
             },
        async getButtons2(row){
               this.$emit("changeTab");
               let index = row.IDX+1;
               const selIds = [index]; //rowno选中行
               const selDst = "ordstm" //列表对应后台模型中的stream
               let params = { selDst: selDst, selIds: selIds };
               let rtnmsg = await this.executeRule("ordstm",params);
               if(rtnmsg.respCode == SUCCESS)
               {
                  this.updateModel(rtnmsg.data)
                  //TODO 处理数据逻辑
                  this.model.clmmod.wfestm = rtnmsg.data.clmmod.wfestm;
               }
               else
               {
                   if(row.交易代码){
                        const items = row.srcStr.split("\t");
                        this.model.clmmod.wfs.objtyp="ORD";
                        this.model.clmmod.wfs.objinr=items[0];
                        this.model.clmmod.wfs.objnam=row.Name;
                   }
                   this.$notify.error({title: '错误',message: rtnmsg.respMsg});
               }
        },
       async getButtons(row){
               this.index=row['IDX'];
                let status = row['交易状态'];
                //控制订单确认按钮是否可用
                let buttonflg="";
                if(status == "PUR" || status == "CMP"){
                    buttonflg = "Y";
                }else{
                    buttonflg = "N";
                }
                if(this.model.ordstm.rows.length  == 0  || buttonflg  == "N"){
                    this.button=false
                }else{
                    this.button=true
                }

               //初始化选中行
               const selIds = [row['IDX'] + 1 ]; //rowno选中行
               const selDst = "ordstm" //列表对应后台模型中的stream
               let params = { selDst: selDst, selIds: selIds };
               let rtnmsg = await this.executeRule("ordstm",params);
               if (rtnmsg.respCode == SUCCESS) {
                 this.initdialog = true
                } else {
                 this.initdialog = false
                }



         },
         onButRelrow(){
               this.$confirm('确定是否要授权此笔交易?','提示',{
                   confirmButtonText: 'Yes',
                   cancelButtonText: 'No',
                   type: 'warning',
                   showClose:false
                 }).then(async () => {//yes的执行在这里写
                          let index = this.index+1;
                          const selIds = [index]; //rowno选中行
                          const selDst = "ordstm" //列表对应后台模型中的stream
                          let params = { selDst: selDst, selIds: selIds };
                          let rtnmsg = await this.executeRule('relrow',params);
                          if (rtnmsg.respCode == SUCCESS) {
                             this.initdialog = false
                             this.stmData.data = rtnmsg.data.ordstm.rows;
                             this.model.ordstm = rtnmsg.data.ordstm;
                           } else {
                              this.initdialog = false
                           }

                 }).catch(() => {//No的功能在这里写

                 });

         },
         onButReprow(){
                this.$confirm('确定是否要退回此笔交易?','提示',{
                    confirmButtonText: 'Yes',
                    cancelButtonText: 'No',
                    type: 'warning',
                    showClose:false
                  }).then(async () => {//yes的执行在这里写
                           let index = this.index+1;
                           const selIds = [index]; //rowno选中行
                           const selDst = "ordstm" //列表对应后台模型中的stream
                           let params = { selDst: selDst, selIds: selIds };
                           let rtnmsg = await this.executeRule('reprow',params);
                           if (rtnmsg.respCode == SUCCESS) {
                              this.initdialog = false
                              this.stmData.data = rtnmsg.data.ordstm.rows;
                              this.model.ordstm = rtnmsg.data.ordstm;
                            } else {
                               this.initdialog = false
                            }

                  }).catch(() => {//No的功能在这里写

                  });

          },
          onButRejrow(){
              this.$confirm('确定是否要删除此笔交易?','提示',{
                  confirmButtonText: 'Yes',
                  cancelButtonText: 'No',
                  type: 'warning',
                  showClose:false
                }).then(async () => {//yes的执行在这里写
                         let index = this.index+1;
                         const selIds = [index]; //rowno选中行
                         const selDst = "ordstm" //列表对应后台模型中的stream
                         let params = { selDst: selDst, selIds: selIds };
                         let rtnmsg = await this.executeRule('rejrow',params);
                         if (rtnmsg.respCode == SUCCESS) {
                            this.initdialog = false
                            this.stmData.data = rtnmsg.data.ordstm.rows;
                            this.model.ordstm = rtnmsg.data.ordstm;
                          } else {
                             this.initdialog = false
                          }

                }).catch(() => {//No的功能在这里写

                });

        },
        async onButEvents(){
            let index = this.index+1;
            const selIds = [index]; //rowno选中行
            const selDst = "ordstm" //列表对应后台模型中的stream
            let params = { selDst: selDst, selIds: selIds };
            let rtnmsg = await this.executeRule('events',params);
            if (rtnmsg.respCode == SUCCESS) {
               this.initdialog = false
               this.stmData.data = rtnmsg.data.ordstm.rows;
               this.model.ordstm = rtnmsg.data.ordstm;
             } else {
                this.initdialog = false
             }

       },
        handleOpen1(){
          window.location.href="#/business/inflsb"
        },
         handleOpen2(){
          window.location.href="#/business/trnrel"
        },
    },
    created:function(){

    }
}
</script>
<style>
.m-table-search {
    padding: 20px 0px 10px 0px;
}
</style>