<template>
  <div class="eibs">
    <el-form
        ref="modelForm"
        label-width="170px"
        size="small"
        label-position="right"
        :model="act"
        :rules="rules"
        :validate-on-rule-change="false"
        :disabled="operate === 'details'"
      >
      <c-col :span="12" class="col-left">
        <c-col :span="24">
          <el-form-item label="所属客户编号" prop="ptyextkey">
            <c-fullbox>
              <c-input :disabled="true" v-model="act.ptyextkey" placeholder="请输入账号"> </c-input>
              
              <template slot="footer" v-if="operate === 'add'">
                <c-button
                  style="margin: 0 0 0 10px; padding: 0 12px"
                  size="small"
                  type="primary"
                  @click="getBaseData_0208(act.ptyextkey)"
                >
                  获取
                </c-button>
              </template>
            </c-fullbox>

            <!--c-input v-model="act.ptyextkey" style="width: 100%" placeholder="请输入所属客户编号" :disabled=true> </c-input-->
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="账号" prop="extkey">
            <c-fullbox>
              <c-input :disabled="operate === 'edit'" v-model="act.extkey" placeholder="请输入账号"> </c-input>
              
              <!--template slot="footer" v-if="operate === 'add'">
                <c-button
                  style="margin: 0 0 0 10px; padding: 0 12px"
                  size="small"
                  type="primary"
                  @click="getBaseData(act.ptyextkey)"
                >
                  获取
                </c-button>
              </template-->

              <template slot="footer"  >
                <c-button
                  style="margin: 0 0 0 10px; padding: 0 12px"
                  size="small"
                  type="primary"
                  @click="getBaseData_8023_8091(act.extkey)"
                >
                  获取
                </c-button>
              </template>

            </c-fullbox>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="账号类型" prop="typ">
            <c-select v-model="act.typ" ref="typ" @change="typChange"  style="width: 100%" placeholder="请选择账号类型" dbCode="ACTTYP" :filterKey="act_typ" :isShowKeyAndLabel="true" filterable> </c-select>
          </el-form-item>
        </c-col>
        
        <c-col :span="24" v-if="operate != 'details'">
          <el-form-item label="核心业务代号" prop="acccore" v-if="operate !== 'details'">
            <c-input v-model="act.acccore" placeholder="请输入核心业务代号" :disabled=true> </c-input>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="科目类型" prop="trmtyp">
            <el-select
              v-model="act.trmtyp" clearablex
              placeholder="请选择科目类型"
              :isShowKeyAndLabel="true" 
              filterable
            >
              <el-option v-for="item in trmtyplst" :key="item.trmtyp" :label="act.typ+' - '+item.trmcod+' '+item.nam"
                        :value="item.trmtyp">
                <span >{{ act.typ+' - '+item.trmcod+' '+item.nam}}</span>
                
              </el-option>
            </el-select>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="账号性质" prop="actpro">
            <!-- :disabled="true" -->
            <c-select v-model="act.actpro" placeholder="请输入账号性质" :disabled="true" dbCode="ACTPRO" :isShowKeyAndLabel="true" filterable> </c-select>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="借记贷记" prop="dirflg">
            <c-select v-model="act.dirflg" placeholder="请输入借记贷记" dbCode="DIRFLG"> </c-select>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="头寸账户标志" prop="cvrflg">
            <c-radio-group v-model="act.cvrflg">
              <el-radio label="Y">是</el-radio>
              <el-radio label="">否</el-radio>
            </c-radio-group>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="所属客户账号" prop="holacc">
            <c-input v-model="act.holacc" placeholder="请输入所属客户账号"> </c-input>
          </el-form-item>
        </c-col>
      </c-col>
      <c-col :span="12" class="col-right">
        <c-col :span="24">
          <el-form-item label="客户名称" prop="ptynam">
            <c-input v-model="act.ptynam" style="width: 100%" placeholder="请输入客户名称" :disabled="true"> </c-input>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="账号描述" prop="nam">
            <c-input v-model="act.nam" placeholder="请输入账号描述"> </c-input>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="币种" prop="cur" >
            <c-select v-model="act.cur" ref="cur" @change="curChange" placeholder="请输入币种" dbCode="CURTXT" :isCache="false" :isShowKeyAndLabel="true" filterable :disabled="!(act.extkey.startsWith('FT') || act.extkey.startsWith('EF'))"> </c-select>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="主账户" prop="zmqacc" :required="!accflg">
            <c-input v-model="act.zmqacc" placeholder="请输入主账户" :disabled="accflg"> </c-input>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="账户类型" prop="acctyp">
            <!-- :disabled="true" -->
            <c-select v-model="act.acctyp"  :disabled="true" placeholder="请输入账户类型" dbCode="ACCTPE" :isShowKeyAndLabel="true" filterable > </c-select>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="优先级" prop="pri">
            <c-select v-model="act.pri" placeholder="请选择优先级" dbCode="ACTPRI" :isShowKeyAndLabel="true" filterable> </c-select>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="逻辑删除状态" prop="delflg">
            <c-radio-group v-model="act.delflg">
              <el-radio label="X">已删除</el-radio>
              <el-radio label="">已启用</el-radio>
            </c-radio-group>
          </el-form-item>
        </c-col>
        <c-col :span="24">
          <el-form-item label="偿付账户标志" prop="rmbflg">
            <c-radio-group v-model="act.rmbflg">
              <el-radio label="Y">是</el-radio>
              <el-radio label="">否</el-radio>
            </c-radio-group>
          </el-form-item>
        </c-col>
      </c-col>
      <c-col :span=24>
        <c-col :span=12>
          <c-col :span="24">
            <el-form-item label="一般提示信息" prop="inflev">
              <c-select v-model="act.inflev" placeholder="请选择一般提示信息" dbCode="INFLEV"> </c-select>
            </el-form-item>
          </c-col>
          <c-col :span="24">
            <el-form-item label="" prop="inftxt" v-if="act.inflev">
              <c-input 
                type="textarea" 
                :rows="4" 
                v-model="act.inftxt" 
                maxlength="150" 
                show-word-limit 
                placeholder="请输入提示信息内容"
              ></c-input>
            </el-form-item>
          </c-col>
        </c-col>
        <c-col :span=12>
          <c-col :span="24">
            <el-form-item label="停用提示信息" prop="stpinflev">
              <c-select v-model="act.stpinflev" placeholder="请选择停用提示信息" dbCode="INFLEV"> </c-select>
            </el-form-item>
          </c-col>
          <c-col :span="24">
            <el-form-item label="" prop="stpinftxt" v-if="act.stpinflev">
              <c-input 
                type="textarea" 
                :rows="4" 
                v-model="act.stpinftxt" 
                maxlength="150" 
                show-word-limit 
                placeholder="请输入停用提示信息内容"
              ></c-input>
            </el-form-item>
          </c-col>
        </c-col>
      </c-col>
    </el-form>
  </div>
</template>

<script>
import { Pattern } from "./Actjs/Act.js";
import codes from "~/config/CodeTable";
import { getWebDetail, getTrmtyp } from "~/service/manage/act.js";

export default {
  inject: ["root"],
  name: "",
  props: ['act', 'operate', 'model'],
  data() {
    return {
      rules: Pattern,
      baseList: [],
      baseDialog: false,
      trmtyplst: [],
      curLable:"",
      typLabel:"",
    };
  },
  components: {
  },
  created() {
    if(this.act.typ) {
      this.getTrmtyp(this.act.typ,this.act.ptyextkey, this.model.branchcode)
    }
    if(this.act.cur) {
      this.curChange()
    }
  },
  watch: {
    "act.typ": {
      handler(newVal){
        this.getTrmtyp(newVal,this.act.ptyextkey, this.model.branchcode)
      },
    },
    "act.cur": {
      handler(newVal) {
        console.log("newVal", newVal)
        this.curChange(newVal)
      }
    },
    "act.trmtyp": {
      handler(newVal) {
        let obj = {
          actdata: this.act,
          trmtyplist: this.trmtyplst
        }
        this.$emit("checkIllegal", obj)
      }
    }
  },
  computed: {
    accflg() {
      var acc = this.act.extkey;
      if (acc) {
        var id1 = acc.indexOf('ZMQ')
        var id2 = acc.indexOf('FT')
        var id3 = acc.indexOf('EF')
        if (id1 == 0 || id2 == 0 || id3 == 0) {
          return false
        }
      }
      return true
    },

    act_typ(){
      let typ=[];
      
        let currentOrg=this.$store.state.UserContext.currentOrg;
        if (currentOrg){
          console.log("currentOrg-->-",currentOrg)
          if (currentOrg.level !=='0' && currentOrg.level !==0){
            typ=['AS','CC','FI','LO'];
          }
        }
      
      console.log("--->--", typ)
      return typ;
    },
   


  },
  methods: {
    
    curChange(value){
      let obj = {};
      console.log("this.$refs.cur", this.$refs.cur)
      console.log("this.act.cur", this.act.cur)
      obj = this.$refs.cur.dbCodeList.find((item)=>{
        console.log(item.value)
        return item.value === this.act.cur;
      });
      
      console.log("this.act.typ", this.act.typ)
      console.log("objjjj", obj)
      this.curLabel=obj.label;
      console.log("objjjj", obj)

      obj = {};
      if (this.$refs.typ && this.act.typ) {
        obj = this.$refs.typ.dbCodeList.find((item)=>{
          return item.value === this.act.typ;
        });
        this.typLabel=obj.label;

        let actnam=(this.curLabel + this.typLabel + "," + this.act.ptyextkey);
        if (actnam.length > 40){
          this.act.nam = actnam.substring(0,40)
        }else {
          this.act.nam = actnam
        }
      } else {
        let actnam = this.curLabel + "," + this.act.ptyextkey;
        this.act.nam = actnam
      }
      
    },

    typChange(value){
      let obj = {};
      obj = this.$refs.typ.dbCodeList.find((item)=>{
        return item.value === value;
      });
      this.typLabel=obj.label;

      obj = {};
      if (this.$refs.cur && this.act.cur) {
        obj = this.$refs.cur.dbCodeList.find((item)=>{
          return item.value === this.act.cur;
        });
        this.curLabel=obj.label;

        let actnam=(this.curLabel + this.typLabel + "," + this.act.ptyextkey);
        if (actnam.length>40){
          this.act.nam=actnam.substring(0,40);
        }else {
          this.act.nam=actnam;
        }
      } else {
        let actnam = this.typLabel + "," + this.act.ptyextkey;
        this.act.nam = actnam
      }
      
    },
    getTrmtyp(typ,ptyextkey, branchcode) {
      getTrmtyp({"acctyp":typ,"ptyextkey":ptyextkey, "branchcode": branchcode}).then((res) => {
        if(res.respCode == "AAAAAA") {
          this.$set(this, "trmtyplst", res.data)
        } else {
          this.$notify.error(res.respMsg)
        }
      })
    },
    getBaseData_0208(ptyextkey) {
      if (ptyextkey === ""||ptyextkey.length<10){
        this.$message.info("请输入10位客户号!")
      }
      let parms={"ptyextkey":ptyextkey,"startnum":"1","selectnum":"80"}
      this.$emit('queryWebInfo', parms)
    },

    //修改页面--点击获取
    getBaseData_8023_8091(extkey) {
      if (extkey === ""||extkey === null){
        this.$message.info("请输入账号!")
        return 0;
      };

      let params = {
        extkey: extkey
      };

    getWebDetail(params).then((res) => {
      if (res.respCode == SUCCESS||res.respCode == "BBBBBB") {
        this.act.acccore = res.data.acccore;
        this.act.actpro = res.data.actpro;
        this.act.cur = res.data.cur;
        if ( !this.act.cur ){
          if (this.act.extkey.startsWith('FT')||this.act.extkey.startsWith('EF')){
            this.act.cur="CNY" 
          }
        }

        if(res.respCode == SUCCESS){
          this.$notify.success(res.respMsg)
        }else{
          this.$message.info(res.respMsg)
        }
      } else if(res.respCode == "BBBBBB"){
        //this.$message.info(res.respMsg);
      }else if(res.respCode == "EEEEEE"){
        this.$notify.error(res.respMsg);
      }
    })
    .catch((err) => {
      this.$notify.error("获取核心账号信息异常")
    });

},

    cancel() {
      this.handleClose();
    },
    handleClose(done) {
      this.baseDialog = false;
      if (done && typeof done === "function") {
        done();
      }
    },
  },
};
</script>

<style>
</style>