<template >
  <div class="ls-comment">
    <div class="approval-wrap">
      <p class="title">审批操作</p>
<!--      <div v-if="taskShow.isAddress">-->
<!--        <el-row :gutter="20">-->
<!--          <el-col :span="8">-->
<!--            <div class="tips">-->
<!--              <span class="star">*</span>-->
<!--              <span >税率代码:</span>-->
<!--            </div>-->
<!--            <el-select v-model="rateId" placeholder="请选择"  size="mini" @change="setRate">-->
<!--              <el-option-->
<!--                v-for="item in rateList"-->
<!--                :key="item.NAME"-->
<!--                :label="item.NAME"-->
<!--                :value="item.NAME">-->
<!--              </el-option>-->
<!--            </el-select>-->
<!--          </el-col>-->
<!--        </el-row>-->
<!--      </div>-->
      <div v-if="taskShow.isBusesss">
        <el-row :gutter="20">
          <el-col :span="8">
            <div class="tips">
              <span >客户等级:</span>
            </div>
            <el-select v-model="processForm.gradeId" placeholder="请选择"  size="mini">
              <el-option
                v-for="item in gradeList"
                :key="item.key"
                :label="item.key"
                :value="item.key">
              </el-option>
            </el-select>
          </el-col>
        </el-row>
      </div>
      <div v-if="taskShow.isFinancial">
        <el-row :gutter="20">
          <el-col :span="8">
            <div class="tips">
              <span class="star">*</span>
              <span >收款银行:</span>
            </div>
          <el-select v-model="bankId" placeholder="请选择"  filterable clearable size="mini" @change="setBankVal">
                <el-option
                  v-for="item in bankList"
                  :key="item.vaule"
                  :label="item.key"
                  :value="item.vaule">
                </el-option>
              </el-select>
          </el-col>
        </el-row>
<!--        <div class="table-wrap">-->
<!--          <el-table :data="addressData"  highlight-current-row  size="mini" stripe border >-->
<!--            <el-table-column type="index" label="序号" width="50"  >-->
<!--            </el-table-column>-->
<!--            <el-table-column  v-for="(item, index) in colunms" :key="index"-->
<!--                :prop="item.prop"-->
<!--                :label="item.label"-->
<!--                :fixed="item.fixed"-->
<!--                :formatter="formatter"-->
<!--                :min-width="item.width"-->
<!--                :show-overflow-tooltip="item.tooltip"-->
<!--                >-->
<!--            </el-table-column>-->
<!--            <el-table-column prop="rateName" label="税率代码" min-width="120">-->
<!--              <template slot-scope="scope">-->
<!--                <el-select-->
<!--                  v-model="scope.row.rateName"-->
<!--                  placeholder="请选择"  size="mini">-->
<!--                  <el-option-->
<!--                    v-for="item in rateList"-->
<!--                    :key="item.NAME"-->
<!--                    :label="item.NAME"-->
<!--                    :value="item.NAME">-->
<!--                  </el-option>-->
<!--                  </el-select>-->
<!--              </template>-->
<!--            </el-table-column>-->
<!--          </el-table>-->
<!--        </div>-->
      </div>
      <div style="padding-top: 10px">
        <el-input
          v-model="msg"
          type="textarea"
          placeholder="请输入处理说明"
          maxlength="300"
          show-word-limit
        />
      </div>
    </div>
  </div>
</template>
<script>
  import commonSelectList from '@/common/commonSelectList.js'
  export default {
    name: 'approval-comment',
    props:{
      moduleId:{
          type: String,
          default: '3110',
          required: true
      },
      addressData: {
        type: Array,
        default: () => []
      },
      isVisid:{
        type: Boolean,
        default:true,
        required: false
      },
      isApply:{
        type: Boolean,
        default:true,
      },
      errmsg:{
        type: String,
        required:false
      }
    },
    created(){
      let $this=this;
      parent.window.doSubmit = function(param){
        if(!$this.isProccess){
          $this.approve(param);
          return false;
        }else{
          return true;
        }
      };
      this.bid=this.$common.getUrlParams('bid');
      this.taskRefId=this.$common.getUrlParams('taskRefId');
      this.processId=this.$common.getUrlParams('processId');
      this.setTaskShow();
    },
    mounted () {
    },
    methods: {
      setBusess(val){
          this.processForm.gradeId=val;
      },
      setBankVal(val){
        this.bankList.forEach(item=>{
          if(val===item.vaule){
              let bank={
                company:item.key,
                ac:item.vaule,
                swiftCode:item.ext1,
                address:item.ext2,
                bankCode:item.ext3,
                bankName:item.ext4,
                status:'Y'
              };
           this.processForm.bank=bank;
          }
        });
      },
      // setRate(val){
      //   let rate={
      //     rateId:val,
      //     id:this.bid,
      //     rateName:val
      //   };
      //   this.processForm.rate.push(rate);
      // },
      async initDictData(){
        //我司收款银行
        this.bankList = await commonSelectList.dictDataGet(this, 'CRM_MY_RECEIVING_BANK') || [];
        this.gradeList = await commonSelectList.dictDataGet(this, 'Crm_Customer_Rank') || [];
      },
      // getErpRate(){
      //   let th=this;
      //   this.$ajax.get({
      //     domain: 'dataQueryUrl',
      //     url: 'dataQuery.queryErpRate',
      //     showLoad: false,
      //     data: {},
      //     requestType: 'form',
      //     success: function(res) {
      //       if (res.errorCode === 200) {
      //         let data = res.data || [];
      //         th.rateList=data;
      //       }
      //     },
      //     error: function(err) {
      //       console.log(err);
      //     }
      //   });
      // },

      setTaskShow(){
        // //obj_c9c8b3a341100001f1321ce45dc317b7
        // //地址申请，财务审批环境
        // if(this.taskRefId=='obj_c9ca9897863000011a7b17c3aef02dd0'){
        //     this.getErpRate();
        //     this.taskShow.isAddress=true;
        // //客户申请，财务审批
        // }else
        if(this.taskRefId=='obj_c9c8b3a341100001f1321ce45dc317b7'){
         // this.getErpRate();
          this.initDictData();
          this.taskShow.isFinancial=true;
        }else if(this.taskRefId=='obj_c9c8b3a126b000014787189be1c0af90' || this.taskRefId=='obj_c9c80bffebc00001cc5e559b19ee3740'){
          this.taskShow.isBusesss=true;
          this.initDictData();
        }
      },
      approve(param){
        if(param.actionName!=null && param.actionName=='驳回' && !this.msg){
          this.$message({type: 'warning', message: '请填写驳回理由'});
          return false;
        }
        if(this.isApply){
          this.$emit('apply',param);
        }
        if(!this.isVisid){
          this.$message.error(this.errmsg)
          return false;
        }
        //财务环节，校验是否填写税率代码
        if(this.taskShow.isFinancial){
          this.processForm.rate = [];
          if(!this.processForm.bank){
            this.$message("请选择收款银行！");
            return;
          }
          // for(let i=0; i<this.addressData.length; i++){
          //   let item = this.addressData[i];
          //   if(!item.rateName && param.actionName!='驳回'){
          //     this.$message("请选择税率代码！");
          //     return;
          //   }
          //   item.rateId=item.rateName;
          //   this.processForm.rate.push(item);
          // };
        }
        param = Object.assign(param,this.processForm);
        this.$ajax.post({
          domain: 'crmCmUrl',
          url: 'cmProcess.approve',
          data: param,
          requestType: 'body',
          showLoad: true,
          success: function (res) {
            if (res.errorCode === 200) {
              this.isProccess=true;
              parent.FormToolBarAction.BTN_TRANSACT();
            }else {
              this.$message.error(res.msg)
            }
          }.bind(this),
          error: function (res) {
            this.$message({
              type: 'error',
              message: res.body.msg || res.msg
            })
          }.bind(this)
        });
      },
      formatter(row, column, cellValue, index){
        if(column.property == 'status'){
          if(row.status == 'Y'){
            return '有效';
          }else if(row.status == 'N'){
            return '无效';
          }else {
            return '未生效';
          }
        } else if( column.property  == 'isDefault'){
          return row.isDefault == 1 ? '是' : '否'
        } else if(column.property  == 'edi'){
          return row.edi == 1 ? '是' : '否'
        }else if(column.property == 'cmOrg'){
          return row.cmOrg.orgName;
        }
        else {
          return cellValue;
        }
      },
      getMsg: function () {
        return this.msg;
      },
      setParentValue: function (id, value) {
        try {
          if (parent) {
            parent.$('#' + id).val(value);
          }
        } catch (err) { }
      }
    },
    data: function () {
      return {
        msg: '',
        bid:'',
        rateList:[],
        gradeList:[],
        taskShow:{
          isFinancial :false,
          isAddress:false,
          isBusesss:false
        },
        bankList:[],//收款银行
        isProccess:false,
        processId:'',
        taskRefId:'',
        rateId:'',
        rateName:'',
        bankId:'',
        processForm: {
          moduleId: this.moduleId,//所属模块
          bank: {},
          rate:[],
          gradeId:''
        },
        colunms: [//表格列
          { prop: 'shortAddress', label: '地址简称', width: 100, fixed: false, tooltip: true},
          { prop: 'area', label: '大洲', width: 100, fixed: false, tooltip: true},
          { prop: 'country', label: '所有国家或地区', width: 120, fixed: false, tooltip: true},
          { prop: 'porridge', label: '省(州)', width: 100, fixed: false, tooltip: true},
          { prop: 'city', label: '城市', width: 100, fixed: false, tooltip: true},
          { prop: 'address1', label: '地址1', width: 120, fixed: false, tooltip: true},
          { prop: 'address2', label: '地址2', width: 120, fixed: false, tooltip: true},
          { prop: 'postalCode', label: '邮编', width: 100, fixed: false, tooltip: true},
          { prop: 'cmOrg', label: '应用组织', width: 100, fixed: false, tooltip: true}
        ],
      }
    },
    watch: {
      'msg': function (val) {
        if(val){
          this.setParentValue('msg',val);
        }
      }
    }
  }
</script>
<style type="text/css" scoped lang="scss">
 .ls-comment{
    .tips{
      margin: 5px 0;
    }
    .star{
      color: #FF0000;
    }
    .approval-wrap{
      margin-top: 10px;
      padding: 20px;
      background: #F8F8F8;
      border-radius: 5px;
      .table-wrap{
        margin: 15px 0;
      }
      .el-col{
        display: flex;
        align-items: center;
        margin-top: 10px;
      }
      .el-select, .el-date-editor{
        flex: 1;
        margin-left: 10px;
      }
      .tips{
        margin: 5px 0;
      }
    }
    .title{
      font-size: 14px;
      font-weight: bold;
      color: #0077FA;
      // margin: 15px 0;
    }
 }
</style>
