<!--
  @description: 财务信息
  @author: change by sunxinman
  @routerPath: /systemManagement/addOrganization/financialInformation
  @date:  2019/11/16-23:33
-->
<template>
  <div>
    <el-form ref="form" :model="formData" :rules="rules" label-width="160px">
      <el-row>
        <el-col :span="24">
          <el-form-item ref="bankname" label="开户银行" prop="bankname">
            <el-input v-model="formData.bankname" placeholder="请输入开户银行全称" style="width:85%" />
            <el-popover
              placement="top-start"
              popper-class="hint"
              width="420"
              offset="5"
              trigger="hover"
              content="银行全称+开户支行名称"
            >
              <el-button slot="reference" class="prompt">
                <i class="iconfont icon-qm" />
              </el-button>
            </el-popover>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item ref="bankaccount" label="基本账户账号" prop="bankaccount">
            <el-input v-model="formData.bankaccount" placeholder="基本存款账户" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item ref="regcapital" label="注册资金" prop="regcapital">
            <el-row>
              <el-input v-model="formData.regcapital" placeholder="0.00" type="number" min="0" step="1" class="input-with-select">
                <el-button slot="prepend">
                  人民币
                </el-button>
                <el-select slot="append" v-model="formData.currenciesUnit" placeholder="请选择">
                  <el-option
                    v-for="item in options"
                    :key="item.index"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-input>
            </el-row>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button @click="lastStep">
            上一步
          </el-button>
          <el-button type="primary" @click="submit">
            提交
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getDepartInfo, saveFinance } from '@/api/rolemanagment/organization'
import { characters1_50, checkNum, checkMoney } from '@/assets/js/validate'

export default {
  data() {
    return {
      formData: {
        bankaccount: '', // 基本账户账号
        bankname: '', // 开户银行
        createBy: '',
        createDate: '',
        createName: '',
        currencies: '人民币', // 注册资金币种
        currenciesUnit: '00', // 注册资金单位
        departId: '', // 机构ID
        departName: '',
        id: '',
        regcapital: '', // 注册资金
        status: ''// (00:保存,01:提交)
      },
      rules: {
        regcapital: [
          { required: true, validator: characters1_50, trigger: 'blur' },
          { validator: checkMoney, trigger: 'blur' }
        ],
        bankaccount: [
          { required: true, validator: characters1_50, trigger: 'blur' },
          { validator: checkNum, trigger: 'blur' }
        ],
        bankname: [{ required: true, validator: characters1_50, trigger: 'blur' }]
      },
      options: [{
        value: '00',
        label: '元'
      }, {
        value: '01',
        label: '万元'
      }]
    }
  },
  created() {
    this.departId = this.$route.query.departId
  },
  mounted() {
    const data = {
      departId: this.departId
    }
    getDepartInfo(data).then(response => {
      this.formData.id = response.data.finance.id
      this.formData = response.data.finance
    }).catch(res => {

    })
  },
  methods: {
    // 保存
    save() {
      this.$confirm('确定保存？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.formData.status = '00'
        this.formData.departId = this.departId
        saveFinance(this.formData).then(response => {
          this.$message({
            type: 'success',
            message: '保存成功!'
          })
          const data = {
            departId: this.departId
          }
          getDepartInfo(data).then(res => {
            this.formData.id = response.data.finance.id
          })
        })
      }).catch(() => {
      })
    },
    // 提交
    submit() {
      this.$confirm('确定提交？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.formData.status = '01'
        this.formData.departId = this.departId
        saveFinance(this.formData).then(response => {
          this.$message({
            type: 'success',
            message: '提交成功!'
          })
          this.$router.push({ path: '/systemManagement/organization' })
        })
      }).catch(() => {
      })
    },
    // 上一步
    lastStep() {
      const pathData = {
        departId: this.$route.query.departId
      }
      this.$emit('stepPage', 1, pathData)
    }
  }
}
</script>
<style lang="less" scoped>
.clearBorder {
  & .el-input__inner {
    border-right: 0;
  }
}
.hasInfo {
  & .el-input__inner {
    width: 100px;
  }
}
/deep/.el-form-item--small .el-form-item__error {
  padding-left: 77px !important;
}
/deep/.el-select .el-input {
  width: 100px;
}
/deep/.input-with-select .el-input-group__append {
  background-color: #fff;
}
</style>
