<template>
  <el-dialog
    :title="modalTitle"
    :visible.sync="modalVisible"
    :width="formLabelWidth"
    top="2vh"
    @close="handleCancel">
    <div class="mobile">
        <div class="hc-box-wrap">
            <el-form label-width="90px" :model="form" :rules="rules" ref="from" class="from">
                <el-form-item label="清分账户:" prop="account">
                    <el-input type="text" v-model="form.account" :disabled="limit.isRead"></el-input>
                </el-form-item>
                <el-form-item label="账户密码:" prop="password">
                    <el-input type="password" v-model="form.password" placeholder="请输入清分账户密码"></el-input>
                </el-form-item>
                <el-form-item label="清分类型:" prop="clearType">
                    <el-radio-group v-model="form.clearType">
                      <el-radio v-for="(item,index) in clearTypeList" :label="item.id">{{item.name}}</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="业务类型:" v-if="form.clearType == 1" prop="businessType">
                    <el-radio-group v-model="form.businessType">
                      <el-radio v-for="(item,index) in businessTypeList" :label="item.id">{{item.name}}</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="操作方式:" v-if="form.clearType == 1" prop="op">
                    <el-radio-group v-model="form.op">
                      <el-radio v-for="(item,index) in opList" :label="item.id">{{item.name}}</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-form>
        </div>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleCancel">取 消</el-button>
      <el-button type="primary" @click="submit" :loading="submitLoading">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { sendApply } from "@/api/bankCheck/bank";
export default {
  name: 'addMobiel',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: 'title'
    },
    action: {
      type: String,
      default: 'add'
    },
    selectRow: {
      type: Object,
      default:null
    }
  },
  watch: {
    visible(newVal, oldVal) {
      this.modalVisible = newVal;
    },
    title(newVal, oldVal) {
      this.modalTitle = newVal;
    },
    action(newVal, oldVal) {
      this.modalAction = newVal;
    },
    selectRow(newVal, oldVal) {
      this.modalSelectRow = newVal;
    }
  },
  data() {
    return {
      modalTitle: this.title,
      modalVisible: this.visible,
      modalAction: this.action,
      modalSelectRow: this.selectRow,
      formLabelWidth: '624px',
      submitLoading:false,
      //窗口权限
      limit: {
        isRead: false, //是否只读
        isAdd: false //是否可写
      },
      //清分类型
      clearTypeList:[
         {
           id:0,
           name:'行内/行外转账'
         },
         {
           id:1,
           name:'代发工资/代报销'
         }
      ],
      //业务类型
      businessTypeList:[
        {
          id:101,
          name:'待发'
        },
        {
          id:102,
          name:'待报销'
        }
      ],
      //操作方式
      opList:[
        {
          id:0,
          name:'账务处理'
        },
        {
          id:1,
          name:'数据校验'
        },
      ],
      //验证
      rules: {
        account: [{ required: true, message: '清分账户不能为空!', trigger: 'blur' }],
        password: [{ required: true, message: '账户密码不能为空!', trigger: 'blur' }],
        clearType: [{ required: true, message: '清分类型不能为空!', trigger: 'blur' }],
        businessType: [{ required: true, message: '业务类型不能为空!', trigger: 'blur' }],
        op: [{ required: true, message: '操作方式不能为空!', trigger: 'blur' }],
      },
      //表单
      form: {
        clearType:0
      }
    };
  },
  created() {
    this.form.transferId = this.modalSelectRow.guid
    switch (this.modalAction) {
      case 'add':
        this.limit.isAdd = true;
        break;
    }
  },
  methods: {
    //表单提交
    submit() {
      this.$refs.from.validate(valid => {
        if (valid) {
          this.submitLoading = true
          let params = Object.assign({},this.form)
          sendApply(params).then(res => {
              if (res.retHead.errCode === 0) {
                this.msgSuccess("操作成功");
                this.modalVisible = false
               	this.$emit('closeapplymodal', true);
                this.submitLoading = false
              }
          }).catch(res=>{
            this.submitLoading = false
          })
        } else {
          return false;
        }
      });
    },
    //窗口关闭
    handleCancel() {
      this.$emit('closeapplymodal', false);
    }
  }
};
</script>

<style lang="scss" scoped>


</style>
