<!--
  @description: 京能代理机构-（采购单位注册、招标代理机构注册）注册基本信息
  @author: 张慢慢/王俊楠
  @routerPath: /systemManagement/orgRegisterInfo
  @date： 2020-11-10 17:10:12
-->
<template>
  <div v-if="isShow" class="p0-16" style="position: relative;">
    <section class="title title_border">
      <i class="el-icon-s-home" />
      编辑注册材料
    </section>
    <!-- 判断是否已提交 空保存 00 已提交 01 审核通过 02 审核不通过-->
    <div v-if="formData.auditStatus !== '00' && formData.auditStatus !== '01'">
      <el-form ref="form" :model="formData" :rules="rules" :inline-message="true">
        <p class="page-title">
          1.基本信息
        </p>
        <table class="from_table mb16">
          <tr>
            <td>
              <el-form-item label="注册类型" prop="" />
            </td>
            <td colspan="3">
              {{ filterDictText(departRoleNameList,auditInfoParam.rolCode) }}
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item ref="departName" label="机构名称" prop="departName" />
            </td>
            <td colspan="3">
              <gx-input
                v-model.trim="formData.departName"
                style="width:96%"
                gx-placeholder="placeholderText500"
                gx-maxlength="varchar500"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item ref="orgCode" label="统一社会信用代码" prop="orgCode" />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.orgCode"
                gx-maxlength="varchar20"
              />
            </td>
            <td>
              <el-form-item ref="entPrpt" label="企业性质" prop="entPrpt" />
            </td>
            <td>
              <el-select v-model="formData.entPrpt" filterable placeholder="请选择" style="width: 100%">
                <el-option
                  v-for="item in entPrptList"
                  :key="item.typecode"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item ref="linkname" label="联系人" prop="linker.linkname" />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.linker.linkname"
                gx-maxlength="varchar20"
              />
            </td>
            <td>
              <el-form-item ref="linktel" label="联系电话" prop="linker.linktel" />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.linker.linktel"
                gx-maxlength="varchar20"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item ref="areaValue" label="联系地址" prop="areaValue" />
            </td>
            <td colspan="3">
              <!--地区组件-->
              <cascader
                :region-text="formData.areaValue"
                style="width:220px"
                @regionData="regionData"
              />
              <gx-input
                v-model.trim="formData.address"
                style="width:calc(100% - 270px)"
                gx-placeholder="placeholderText1000"
                gx-maxlength="varchar1000"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item
                ref="businessLicenseType"
                label="营业执照扫描件"
                prop="businessLicenseType"
              />
            </td>
            <td colspan="3">
              <upload
                :on-change="businessLicenseFile"
                :data="businessUpLoadData"
                :auto-delete="true"
                :auto-upload="true"
                :limit="1"
                title=""
                but-text="图片上传"
                file-ref="fileRef"
                accept="image/jpg,image/jpeg,image/png"
                tip-text="上传格式 (.jpg .png)"
              />
            </td>
            <!-- <td>
              <el-form-item ref="data" label="营业执照有效期" prop="data" />
            </td>
            <td>
              el-date-picker
                v-model="formData.data"
                :clearable="false"
              />
            </td> -->
          </tr>
          <p class="page-title">
            2.财务信息
          </p>
          <tr>
            <td>
              <el-form-item ref="finance.bankname" label="开户银行" prop="finance.bankname" />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.finance.bankname"
                gx-maxlength="varchar500"
              />
            </td>
            <td>
              <el-form-item ref="finance.bankaccount" label="账户" prop="finance.bankaccount" />
            </td>
            <td>
              <gx-input
                v-model.trim="formData.finance.bankaccount"
                gx-maxlength="varchar30"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item ref="finance.regcapital" label="注册资本(万元)" prop="finance.regcapital" />
            </td>
            <td>
              <money
                :thousands="true"
                :money-value="formData.finance"
                :unit-fixed="6"
                name="regcapital"
              />
            </td>
            <!--币种-->
            <td>
              <el-form-item
                ref="finance.currencies"
                label="币种"
                prop="finance.currencies"
              />
            </td>
            <td>
              <el-select v-model="formData.finance.currencies" style="width: 107%">
                <el-option
                  v-for="item in currenciesList"
                  :key="item.typecode"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </td>
          </tr>
        </table>
      </el-form>
      <!--操作按钮-->
      <div class="but_footer">
        <div class="but_footer-h">
          <div class="but_footer-but">
            <el-button
              :loading="confirmLoading"
              @click.stop="save()"
            >
              保存
            </el-button>
            <el-button type="primary" :loading="confirmLoading" @click.stop="sbumit()">
              提交
            </el-button>
          </div>
        </div>
      </div>
    </div>
    <!--审核状态图片-->
    <div class="auditStatus">
      <!-- 待审核 -->
      <img v-if="formData.auditStatus==='00'" src="@assets/img/common/audit/auditWait.png" alt="">
      <!-- 审核通过 -->
      <img v-if="formData.auditStatus==='01'" src="@assets/img/common/audit/auditOk.png" alt="">
      <!-- 审核不通过 -->
      <img v-if="formData.auditStatus==='02'" src="@assets/img/common/audit/auditNo.png" alt="">
    </div>
    <!--信息详情-->
    <!-- 判断是否已提交 空保存 00 已提交 01 审核通过 02 审核不通过-->
    <orgRegisterInfoDetail v-if="formData.auditStatus == '00' || formData.auditStatus === '01'" class="view" :audit-info-param="auditInfoParam" />
  </div>
</template>

<script>
/* api接口*/
import {
  savePurchaseInfo, // 保存采购单位基本信息
  saveAgencyInfo, // 保存机构信息
  getPurchaseInfo, // 获取采购基本信息
  getAgencyInfo // 获取机构基本信息
} from '@/api/common/user'
/* 公共方法 */
import { filterDictText } from '@/assets/js/utils'
import { checkLinktel, linkerName, validateInput, creditCode, bankCardNumber, characters1_auto } from '@/assets/js/validate'// 校验输入
/* 组件*/
import cascader from '@comp/common/cascader'// 地区三级联动
import upload from '@comp/common/updownload/upload'// 文件上传组件
import money from '@comp/common/money/money'// 金额
// 详情信息
import orgRegisterInfoDetail from './orgRegisterInfo-detail'
/* 混合方法 */
import { organizationGroupMixin } from '../mixins/organizationGroupMixin'
import { organizationCommonMixin } from '../mixins/organizationCommonMixin'
export default {
  name: 'OrgRegisterInfo',
  components: {
    cascader, // 地区三级联动
    upload, // 文件上传组件
    money, // 金额
    orgRegisterInfoDetail
  },
  mixins: [organizationGroupMixin, organizationCommonMixin],
  data() {
    return {
      isShow: false, // 是否展示 页面
      confirmLoading: false,
      formData: {
        /* 图片上传-不传给后端主要是为了校验是否上传了文件*/
        businessLicenseType: '', // 营业执照扫描件
        auditStatus: '', // 审核状态   空 保存 00 已提交 01 审核通过 02 审核不通过
        status: '', // 00保存 01提交
        userid: '', // 用户ID
        departId: '', // 部门id
        departName: '', // 机构名称
        orgCode: '', // 统一信用代码
        entPrpt: '', // 企业性质
        linker: {
          linkname: '', // 联系人
          linktel: '' // 联系电话
        },
        areaValue: '', // 联系地址
        address: '', // 详细地址
        finance: {
          bankname: '', // 开户银行
          bankaccount: '', // 银行帐号
          regcapital: '', // 注册资本（万元）
          currencies: '' // 币种
        }
      },
      rules: {
        departName: [{ required: true, validator: validateInput, trigger: 'blur' }], // 机构名称
        orgCode: [{ required: true, validator: creditCode, trigger: 'blur' }], // 统一信用代码
        entPrpt: [{ required: true, validator: validateInput, trigger: 'blur' }], // 企业性质
        'linker.linkname': [{ required: true, validator: linkerName, trigger: 'blur' }], // 联系人
        'linker.linktel': [{ required: true, validator: checkLinktel, trigger: 'blur' }], // 联系电话
        areaValue: [{ required: true, message: '请选择', trigger: 'change' }], // 联系地址
        businessLicenseType: [{ required: true, message: '请上传', trigger: 'change' }], // 营业执照扫描件
        'finance.bankname': [{ required: true, validator: validateInput, trigger: 'change' }], // 开户银行
        'finance.bankaccount': [{ required: true, validator: bankCardNumber, trigger: 'change' }], // 银行帐号
        'finance.regcapital': [{ required: true, validator: validateInput, trigger: 'change' }], // 注册资本（万元）
        'finance.currencies': [{ required: true, validator: characters1_auto, trigger: 'change' }] // 币种
      },
      auditInfoParam: {
        rolCode: '', // 注册类型
        departId: '' // 机构ID
      }
    }
  },
  created() {
    // 获取字典
    this.getGroup(['entPrpt', 'currencies', 'departRoleName'])
    // 初始化数据
    this.inintData()
  },
  methods: {
    filterDictText,
    // 初始化数据
    inintData() {
      const userInfo = this.$store.getters.info
      this.formData.departName = userInfo.currentDepart.departname// 机构名称
      this.formData.departId = userInfo.departid// 机构id
      this.formData.linker.linktel = userInfo.mobilePhone // 联系电话
      this.formData.linker.linkname = userInfo.realName // 联系人姓名
      this.formData.userid = userInfo.id // 用户id
      this.auditInfoParam.departId = userInfo.departid// 机构id
      this.auditInfoParam.rolCode = userInfo.currentRol.roleCode// 注册类型
      this.businessUpLoadData.bizId = userInfo.departid// 附件id
      // 查询接口
      this.init(userInfo.departid)
    },
    // 查询接口
    init(departId) {
      const params = {
        departId: departId
      }
      if (this.auditInfoParam.rolCode === 'TEMP_PURCHASING') {
        // 采购单位详情
        this.getPurchaseInfo(params)
      } else {
        // 代理机构详情
        this.getAgencyInfo(params)
      }
    },
    // 获取采购基本信息
    getPurchaseInfo(params) {
      getPurchaseInfo(params).then((res) => {
        this.isShow = true// 加载页面
        if (res.data.departId) {
          this.formData = res.data
        }
      })
    },
    // 获取代理机构信息详情
    getAgencyInfo(params) {
      getAgencyInfo(params).then((res) => {
        this.isShow = true// 加载页面
        if (res.data.departId) {
          this.formData = res.data
        }
      })
    },
    // 所在区域三级联动组件使用
    regionData(regionName, location) {
      this.formData.areaValue = regionName
    },
    // 保存信息
    save() {
      // 机构id
      if (this.auditInfoParam.rolCode === 'TEMP_PURCHASING') {
        this.savePurchaseInfo('00')
      } else {
        this.saveAgencyInfo('00')
      }
    },
    // 提交
    sbumit() {
      this.$refs.form.validate((valid, field) => {
        if (valid) { // 校验通过
          if (this.auditInfoParam.rolCode === 'TEMP_PURCHASING') {
            this.savePurchaseInfo('01')
          } else {
            this.saveAgencyInfo('01')
          }
        }
      })
    },
    // 数据保存或者提交接口（采购）
    savePurchaseInfo(type) {
      this.formData.status = type
      const params = this.formData// 过滤空字典
      savePurchaseInfo(params).then((res) => {
        if (res.header.ret === '0') {
          if (type === '01') {
            this.$message({
              message: '提交成功',
              type: 'success'
            })
            this.auditInfoParam.departId = res.data
            this.formData.auditStatus = '00'//  00 提交
          } else {
            this.$message({
              message: '保存成功',
              type: 'success'
            })
            // 保存成功 获取唯一键值
            this.formData.id = res.data
          }
        }
      })
    },
    // 数据保存或者提交接口（机构）
    saveAgencyInfo(type) {
      this.formData.status = type
      const params = this.formData // 过滤空字典
      saveAgencyInfo(params).then((res) => {
        if (res.header.ret === '0') {
          if (type === '01') {
            this.$message({
              message: '提交成功',
              type: 'success'
            })
            this.auditInfoParam.departId = res.data
            this.formData.auditStatus = '00' // 00 提交
          } else {
            this.$message({
              message: '保存成功',
              type: 'success'
            })
            // 保存成功 获取唯一键值
            this.formData.id = res.data
          }
        }
      })
    },
    // 营业执照扫描件
    businessLicenseFile(file, fileList) {
      if (fileList.length > 0) {
        this.$set(this.formData, 'businessLicenseType', 'true')// 上传了
      } else {
        this.$set(this.formData, 'businessLicenseType', '')// 未上传
      }
    }
  }
}
</script>

<style lang="less" scoped>
// 申报图片
.auditStatus{
  position: absolute;
  top: 10px;
  right:100px;
}
</style>

