<!-- 基本信息 -->
<template>
  <list-item :item-height="44">
    <div>
      <div slot="name" class="section-title" style="">基本信息</div>
      <item v-for="(ele, i) of baseInfo_A" :key="ele.title">
        <div slot="name" class="font-color">{{ ele.title }}</div>
        <span v-if="ele.type === 'date'" slot="content">{{ baseInfo[ele.prop] | dateFormat }}</span>
        <span v-else-if="ele.type === 'currency'" slot="content">{{ baseInfo[ele.prop] | currency }}</span>
        <span v-else-if="ele.type === 'bool'" slot="content">{{ baseInfo[ele.prop] === 'Y' ? '是' : '否' }}</span>
        <Checkbox v-else-if="ele.type === 'checkbox'" :value="baseInfo[ele.prop]==='Y'" shape="square"/>
        <span v-else slot="content">{{ baseInfo[ele.prop] }}</span>
      </item>
      <Field
        v-model="baseInfo.customer_nature_n"
        :required="true" :is-link="true" input-align="right"
        label="客户性质选择" @click="showPicker()" placeholder="请选择"/>
    </div>

    <div v-if="['FACTORY'].indexOf(baseInfo.bp_type)===-1" class="baseinfo-supp">
      <div slot="name" class="section-title" style="">基本信息补录</div>
      <item v-for="(ele, i) of baseInfo_B" :key="ele.title">
        <!-- <div slot="name" class="font-color">{{ ele.title }}</div> -->
        <Field
          :label="ele.title" v-model="baseInfo[ele.prop]" rows="1" autosize
          type="textarea" input-align="right" required placeholder="请输入"/>
      </item>
    </div>
    <div>
      <div slot="name" class="section-title" style="">法人代表信息</div>
      <item v-for="(ele, i) of orgInfo" :key="ele.title">
        <div slot="name" class="font-color">{{ ele.title }}</div>
        <span v-if="ele.type === 'date'" slot="content">{{ baseInfo[ele.prop] | dateFormat }}</span>
        <span v-else-if="ele.type === 'currency'" slot="content">{{ baseInfo[ele.prop] | currency }}</span>
        <Checkbox v-else-if="ele.type === 'checkbox'" :value="baseInfo[ele.prop]==='Y'" shape="square"/>
        <span v-else-if="ele.type === 'bool'" slot="content">{{ baseInfo[ele.prop] === 'Y' ? '是' : '否' }}</span>
        <span v-else slot="content">{{ baseInfo[ele.prop] }}</span>
      </item>
    </div>
    <div>
      <div slot="name" class="section-title" style="">实际控制人信息</div>
      <item v-for="(ele, i) of ctrlInfo" :key="ele.title">
        <div slot="name" class="font-color">{{ ele.title }}</div>
        <span v-if="ele.type === 'date'" slot="content">{{ baseInfo[ele.prop] | dateFormat }}</span>
        <span v-else-if="ele.type === 'currency'" slot="content">{{ baseInfo[ele.prop] | currency }}</span>
        <Checkbox v-else-if="ele.type === 'checkbox'" :value="baseInfo[ele.prop]==='Y'" shape="square"/>
        <span v-else-if="ele.type === 'bool'" slot="content">{{ baseInfo[ele.prop] === 'Y' ? '是' : '否' }}</span>
        <span v-else slot="content">{{ baseInfo[ele.prop] }}</span>
      </item>
    </div>
    <div v-if="baseInfo.auth_flag==='Y'">
      <div slot="name" class="section-title" style="">法人授权信息</div>
      <item v-for="(ele, i) of authInfo" :key="ele.title">
        <div slot="name" class="font-color">{{ ele.title }}</div>
        <span v-if="ele.type === 'date'" slot="content">{{ baseInfo[ele.prop] | dateFormat }}</span>
        <span v-else-if="ele.type === 'currency'" slot="content">{{ baseInfo[ele.prop] | currency }}</span>
        <Checkbox v-else-if="ele.type === 'checkbox'" :value="baseInfo[ele.prop]==='Y'" shape="square"/>
        <span v-else-if="ele.type === 'bool'" slot="content">{{ baseInfo[ele.prop] === 'Y' ? '是' : '否' }}</span>
        <span v-else slot="content">{{ baseInfo[ele.prop] }}</span>
      </item>
    </div>
    <div v-if="['TENANT', 'GUTA'].indexOf(baseInfo.bp_type)!==-1">
      <div slot="name" class="section-title" style="">资质信息</div>
      <item v-for="(ele, i) of formdata_quality" :key="ele.title">
        <div slot="name" class="font-color">{{ ele.title }}</div>
        <span v-if="ele.type === 'date'" slot="content">{{ baseInfo[ele.prop] | dateFormat }}</span>
        <span v-else-if="ele.type === 'currency'" slot="content">{{ baseInfo[ele.prop] | currency }}</span>
        <span v-else-if="ele.type === 'bool'" slot="content">{{ baseInfo[ele.prop] === 'Y' ? '是' : '否' }}</span>
        <span v-else slot="content">{{ baseInfo[ele.prop] }}</span>
      </item>
    </div>
    <div class="foot-bottom">
      <button class="success" style=" border: 1px solid #e6b500;background-color: white;color: #e6b500;" @click="signAuth">签署认证</button>
      <button class="success" @click="save">保存</button>
    </div>
    <ActionSheet
      v-model="picker_show" :actions="actions" :close-on-click-action="true" :closeable="false"
      title="客户性质选择" @select="onSelect" />
  </list-item>
</template>

<script>
import { Checkbox, Field, ActionSheet } from 'vant'
import 'vant/lib/checkbox/style'
import 'vant/lib/field/style'
import 'vant/lib/action-sheet/style'

export default {
  components: {
    Checkbox,
    Field,
    ActionSheet,
  },
  props: ['baseInfo'],
  data () {
    return {
      actions: [], // 下拉框
      customerType: [], // 客户性质下拉框
      picker_show: false,
    }
  },
  computed: {
    baseInfo_A () {
      return this.createFormA()
    },
    baseInfo_B () {
      return this.createFormB()
    },
    orgInfo () {
      return this.createFormOrg()
    },
    ctrlInfo () {
      return this.createFormCtrl()
    },
    authInfo () {
      return this.createFormAuth()
    },
    formdata_quality () {
      return this.createForm_quality()
    },
  },
  created () {
    this.getDropBox()
  },
  methods: {
    onSelect (value) {
      let val = value.name
      this.$set(this.baseInfo, 'customer_nature_n', val)
      let arr = this.customerType.filter(item => item.code_name === val)
      this.$set(this.baseInfo, 'customer_nature', arr[0].code)
    },
    showPicker () {
      this.actions = this.customerType.map(item => ({name: item.code_name}))
      this.picker_show = true
    },
    // 下拉框数据获取
    async  getDropBox () {
      let url = process.env.basePath + 'app_get_syscode'
      let param = {
        'CUSTOMER_NATURE': 'CUSTOMER_NATURE',
      }
      // hlsPopup.showLoading('请稍候')
      let res = await this.$post(url, param)
      // this.hlsPopup.hideLoading()
      if (res.return_status === 'S') {
        this.customerType = res.CUSTOMER_NATURE
      }
    },
    async signAuth () {
      let vm = this
      // console.log('qianshu renzhneg ', this.baseInfo)
      let url = process.env.basePath + 'auth_company_noauth'
      let param = {
        'bp_id': this.baseInfo.bp_id,
      }
      hlsPopup.showLoading('请稍候')
      let res = await this.$post(url, param)
      this.hlsPopup.hideLoading()
      // console.log(res)
      if (res.result.info.code === 0 && res.result.code !== 700) {
        cordova.plugins.IdCardPlugin.webSignNotary(
          function (suc) {
            hlsPopup.showLongCenter(suc.message)
          },
          function (reason) {
            hlsPopup.showLongCenter('错误信息:' + '【' + reason.code + '】' + reason.message)
          },
          res.result.info.data.authUrl
        )
      } else if (res.result.code === 700) {
        hlsPopup.showLongCenter(res.result.msg)
      } else {
        hlsPopup.showLongCenter(res.result.info.msg)
      }
    },
    async save () {
      let flag = false
      let obj = {
        'bp_id': this.baseInfo['bp_id'],
      }
      this.baseInfo_B.forEach(item => {
        obj[item.prop] = this.baseInfo[item.prop]
      })
      obj['customer_nature_n'] = this.baseInfo['customer_nature_n']
      obj['customer_nature'] = this.baseInfo['customer_nature']

      Object.keys(obj).map(key => {
        if (obj[key] === undefined || obj[key] === null || obj[key] === '') {
          flag = true
        }
      })
      console.log(obj)
      if (flag) {
        hlsPopup.showLongCenter('请将必填字段填写完整')
        return
      }
      // 财务部联系电话校验
      let financeContactReg = /^\d{11}$/
      if (!financeContactReg.test(obj.finance_contact)) {
        hlsPopup.showLongCenter('财务部联系电话错误！')
        return
      }
      // 身份证校验
      if (!this.hlsUtil.isCardNo(obj.contact_card_no)) {
        hlsPopup.showLongCenter('联系人身份证格式错误！')
        return
      }
      let url = process.env.basePath + 'bp_access_info_save'
      let param = {
        'master': obj,
      }
      hlsPopup.showLoading('请稍候')
      let res = await this.$post(url, param)
      this.hlsPopup.hideLoading()
      if (res.result === 'S') {
        hlsPopup.showLongCenter('保存成功')
      } else {
        hlsPopup.showLongCenter('保存失败')
      }
    },
    factory (arr) {
      let outArr = []
      if (arr.length) {
        arr.forEach(ele => {
          let [title, prop, type] = ele
          outArr.push({
            title: title || '',
            prop: prop || 'fdf',
            type: type || 'text',
          })
        })
      }
      return outArr
    },
    createFormA () {
      let baseInfo_A = [// 基本信息 经销商
        ['公司名称', 'bp_name', 'text'],
        ['企业类型', 'enterprise_type', 'text'],
        ['注册地址', 'registered_place', 'text'],
        ['经营地址', 'business_address', 'text'],
        ['纳税人识别号', 'organization_code', 'text'],
        ['固定电话', 'phone', 'text'],
        ['已缴纳保证金', 'paid_deposit', 'text'],
        ['评级结果', 'rating_result', 'text'],
        ['注册资本(万元)', 'registered_capital', 'text'],
        ['业务办理地（省）', 'province_n', 'text'],
        ['业务办理地（市）', 'city_n', 'text'],
        ['业务办理地（区/县）', 'district_n', 'text'],
        ['联系人', 'contact_name', 'text'],
        ['联系人手机', 'contact_tel', 'text'],
        ['QQ号', 'qq_code', 'text'],
        ['微信号', 'wechat_code', 'text'],
        ['是否授权', 'auth_flag', 'checkbox'],
      ]
      let baseInfo_A2 = [// 基本信息 主承租人/担保人
        ['公司名称', 'bp_name', 'text'],
        ['企业类型', 'enterprise_type', 'text'],
        ['注册地址', 'registered_place', 'text'],
        ['营业期限从', 'business_term_from', 'text'],
        ['营业期限到', 'business_term_to', 'text'],
        ['营业期限', 'business_term_type_n', 'text'],
        ['经营地址', 'business_address', 'text'],
        ['法定代表人', 'legal_person', 'text'],
        ['纳税人识别号', 'organization_code', 'text'],
        ['注册资本(万元)', 'registered_capital', 'text'],
        ['业务办理地（省）', 'province_n', 'text'],
        ['业务办理地（市）', 'city_n', 'text'],
        ['业务办理地（区/县）', 'district_n', 'text'],
        ['固定电话', 'phone', 'text'],
        ['QQ号', 'qq_code', 'text'],
        ['微信号', 'wechat_code', 'text'],
        ['是否授权', 'auth_flag', 'checkbox'],
      ]
      let baseInfo_A3 = [// 基本信息 主机厂
        ['公司名称', 'bp_name', 'text'],
        ['企业类型', 'enterprise_type', 'text'],
        ['注册地址', 'registered_place', 'text'],
        ['营业期限从', 'business_term_from', 'text'],
        ['营业期限到', 'business_term_to', 'text'],
        ['营业期限', 'business_term_type_n', 'text'],
        ['经营地址', 'business_address', 'text'],
        ['纳税人识别号', 'organization_code', 'text'],
        ['注册资本(万元)', 'registered_capital', 'text'],
        ['固定电话', 'phone', 'text'],
        ['业务办理地（省）', 'province_n', 'text'],
        ['业务办理地（市）', 'city_n', 'text'],
        ['业务办理地（区/县）', 'district_n', 'text'],
        ['租赁系统编号', 'xcmg_id_n', 'text'],
        ['logo上传的超链接', 'logo_upload', 'text'],
        ['是否授权', 'auth_flag', 'checkbox'],
      ]
      let info = []
      let bp_type = this.baseInfo.bp_type
      if (['TENANT', 'GUTA'].indexOf(bp_type) !== -1) {
        info = baseInfo_A2
      } else if (bp_type === 'AGENT') {
        info = baseInfo_A
      } else {
        info = baseInfo_A3
      }
      if (this.baseInfo.business_term_type_n !== '长期') {
        info.push(
          ['营业期限从', 'business_term_from', 'date'],
          ['营业期限到', 'business_term_to', 'date'],
        )
      } else {
        info.push(['营业期限', 'business_term_type_n', 'text'])
      }
      return this.factory(info)
    },
    createFormB () {
      let baseInfo_B = [// 基本信息补录 经销商
        ['财务部联系电话', 'finance_contact', 'text'],
        ['联系人', 'contact_name', 'text'],
        ['联系人身份证', 'contact_card_no', 'text'],
        ['联系人手机', 'contact_tel', 'text'],
        ['联系人地址', 'contact_adds', 'text'],
        ['资产信息', 'capital', 'text'],
        ['经营业务（范围）', 'business_scope', 'text'],
      ]
      return this.factory(baseInfo_B)
    },
    createFormOrg () {
      let orgInfo = [// 法人代表信息
        ['姓名', 'legal_person', 'text'],
        ['身份证号', 'id_card_no', 'text'],
        ['证件有效期从', 'id_card_date_from', 'date'],
        ['证件有效期到', 'id_card_date_to', 'date'],
        ['手机号', 'cell_phone', 'text'],
        ['联系地址', 'living_address', 'text'],
      ]
      return this.factory(orgInfo)
    },
    createFormCtrl () {
      let orgInfo = [// 实际控制人信息
        ['姓名', 'bp_control_name', 'text'],
        ['身份证号', 'id_card_no_c', 'text'],
        ['证件有效期从', 'id_card_date_from_c', 'date'],
        ['证件有效期到', 'id_card_date_to_c', 'date'],
        ['手机号', 'cell_phone_c', 'text'],
        ['联系地址', 'living_address_c', 'text'],
      ]
      return this.factory(orgInfo)
    },
    createFormAuth () {
      let authInfo = [// 法人授权信息
        ['姓名', 'auth_person_name', 'text'],
        ['身份证号', 'auth_person_id_card', 'text'],
        ['证件有效期从', 'auth_id_card_date_from', 'date'],
        ['证件有效期到', 'auth_id_card_date_to', 'date'],
        ['联系电话', 'auth_cell_phone', 'text'],
        ['公司职务', 'auth_person_position', 'text'],
        ['授权事项', 'auth_person_matter', 'text'],
      ]
      return this.factory(authInfo)
    },
    createForm_quality () {
      let qualificationInfo = [// 资质信息
        ['是否黑名单', 'blackList_flag', 'bool'],
        ['征信是否异常', 'credit_normal_flag', 'bool'],
        ['评级结果', 'rating_result', 'text'],
      ]
      return this.factory(qualificationInfo)
    },
  },
}
</script>

  <style lang="less" scoped>
  .section-title{
    padding: 0 0 0 0.3rem;
    font-size: 0.3rem;
    color: #385880;
    line-height: 0.5rem;
    margin-top: 12px;
    position: relative;
  }
  .baseinfo-supp{
    /deep/ .hls-item{
      padding-left:5px
    }
  }
  /deep/ #contract-details .van-cell{
    background-color: white;
  }
</style>
