<template>
  <!--最后一步-->
  <div class="section" style="overflow-y: auto;position: absolute;height: 100%;">
    <div class="step-last">
      <!--<h4 class="h4">免费开店</h4>
      <p class="title">申请开店完全免费，一个企业只能开一家店，申请到正式开通预计需1-3个工作日。了解更多请看《开店规则》</p>-->
    </div>
    <!--<div class="radioCheck">-->
      <!--<label for="1" class="radioLabel">-->
        <!--<input type="radio" v-model="selectFlag" name="role" value="open" id="1"/>-->
        <!--<label for="1" class="txtContact"></label>-->
        <!--<span>免费开店</span>-->
      <!--</label>-->
      <!--<label for="2" class="radioLabel">-->
        <!--<input type="radio" v-model="selectFlag" name="role" value="seller" id="2" checked/>-->
        <!--<label for="2" class="txtContact"></label>-->
        <!--<span>暂不开店直接寄售</span>-->
      <!--</label>-->
    <!--</div>-->
    <!--导入店铺模板-->
    <div class="mobile-vendor_store_apply" v-show="selectFlag == 'open'">
        <div>
          <!-- Nav tabs -->
          <ul class="nav nav-tabs" v-show="false">
            <li><div style="height: 39px;line-height: 39px;font-size: 14px;">店铺类型：</div></li>
            <li class="custom_tab" :class="{active: tab == 'ORIGINAL_FACTORY'}" @click="toggleTab('ORIGINAL_FACTORY')">
              <a href="javascript:void(0)">原厂</a>
            </li>
            <li class="custom_tab" :class="{active: tab == 'AGENCY'}" @click="toggleTab('AGENCY')">
              <a href="javascript:void(0)">代理商</a>
            </li>
            <li class="custom_tab" :class="{active: tab == 'DISTRIBUTION'}" @click="toggleTab('DISTRIBUTION')">
              <a href="javascript:void(0)">经销商</a>
            </li>
          </ul>
          <!-- Tab panes -->
          <div class="mobile-tab-content">
            <!-- 原厂 -->
            <div role="tabpanel" class="tab-pane" v-if="tab == 'ORIGINAL_FACTORY'" :class="{active: tab == 'ORIGINAL_FACTORY'}">
              <div class="row com_row">
                <div class="custom_col">
                  <div class="wrap-title"><span class="line"></span>营业执照</div>
                  <div class="clearfix" style="margin: 0 0.25rem">
                    <div class="show_image_area show_image pull-left">
                      <upload ref="Pom" :typeData="'BUSINESS_LICENSE'" :url="businessLicenseUrl" @uploadAction="onUpload"></upload>
                    </div>
                    <div class="pull-left infoTextMobile" style="width: 5.1rem;margin-left: 0.2rem">
                      <em style="color: #FF0000;">*</em>如已上传最新版营业执照（三证合一），则其他两证无需上传；仅支持上传JPG、PNG、GIF、PDF格式，每张大小不超过3M
                    </div>
                    <!--<div class="col-md-5" style="padding: 0;">-->
                      <!--<span style="margin-top: 50%;padding-right: 20px;">营业执照<em style="color: #FF0000;">*</em></span>-->
                    <!--</div>-->
                  </div>
                </div>
                <div class="custom_col">
                  <div class="wrap-title"><span class="line"></span>纳税人证明</div>
                  <div class="" style="margin: 0 0.25rem">
                    <div class="show_image_area show_image">
                      <upload ref="Pom"  :typeData="'TAX_PAYER'" @uploadAction="onUpload"></upload>
                    </div>
                  </div>
                </div>
                <div class="custom_col">
                  <div class="wrap-title"><span class="line"></span>税务登记证</div>
                  <div class="" style="margin: 0 0.25rem">
                    <div class="show_image_area show_image">
                      <upload ref="Pom" :typeData="'TAX_REGISTRATION'" @uploadAction="onUpload"></upload>
                    </div>
                    <!--<div class="col-md-5" style="padding: 0;">-->
                      <!--<span style="margin-top: 50%;padding-right: 20px;">税务登记证</span>-->
                    <!--</div>-->
                  </div>
                </div>
                <!--<div class="col-md-12"><em>* </em>如已上传最新版营业执照（三证合一），则其他两证无需上传 ； 仅支持JPG、PNG、GIF、PDF格式，每张大小不超过3M</div>-->
              </div>
              <!--增加品牌-->
              <div class="custom_col brand-type" v-for="(brand, index) in brands" style="margin-top: 0px">
                <div class="wrap-title"><span class="line"></span>品牌{{index+1}}</div>
                <!--<div class="col-md-1">品牌{{index+1}}<em v-if="index == 0">*</em></div>-->
                <div class="" style="margin: 0px 0.25rem;position: relative">
                  <div class="mobile-register-brand-name">品牌名称：<input @input="onBrandInput(brand, index)"
                                   @blur.stop.prevent="onBrandChanged(brand, index)"
                                   type="text" v-model="brand.name"
                                   placeholder="请输入英文品牌或中文品牌"
                                   name="brandName" />
                  </div>
                  <!--<input type="text" v-model="brand.name"-->
                         <!--@input="onBrandInput(brand, index)"-->
                         <!--@blur.stop.prevent="onBrandChanged(brand, index)"-->
                         <!--class="form-control" name="brandName"  autocomplete="off" placeholder="请输入英文品牌或中文品牌，如：松下; panasonic等"/>-->
                  <ul class="dropdown-menu"
                      v-show="showSimilarKey.flag && showSimilarKey.index == index"
                      @mouseenter="showFlag = true"
                      @mouseleave="showFlag = false">
                    <li @mouseenter="setKeyActive"
                        @mouseleave="setKeyDefault"
                        @click.stop.prevent="changedName(brand, index, key_index)"
                        v-for="(key, key_index) in similarKeys[index]">
                      <a v-text="key.nameCn">
                        <!--<strong>C</strong>apital Advan<strong>c</strong>ed-->
                      </a>
                    </li>
                  </ul>
                </div>
                <div class="brand-small-upload clearfix" style="margin: 0.1rem 0.25rem 0 0.25rem">
                  <div class="brand-small-img">
                    <upload ref="Pom" :typeData="index" @uploadAction="onUpload" :NopassThree="true"></upload>
                  </div>
                  <div class="file-text">品牌logo/商标注册原件/授权说明书</div>
                  <div v-show="brands.length > 1" @click="deleteBrand(index)" class="delete" title="删除" style="float: right;text-align: center;line-height: 1.09rem;height: 1.09rem;padding-top: 0.36rem;"><i class="fa fa-trash"></i></div>
                  <!--<div class="col-md-12"><em v-if="index == 0">*</em>仅支持JPG、PNG、GIF、PDF格式，大小不超过3M</div>-->
                </div>
              </div>
              <div class="add-brand" @click="addBrand">
                <i class="fa fa-plus-circle"></i>增加品牌
                <!--<a href="javascript:void(0)" title="增加品牌" @click="addBrand"><em><i class="fa fa-plus-circle"></i>增加品牌</em></a>-->
              </div>
              <div class="unpass-reason row" style="display: none">
                原因：<span style="color: #d32526;">原因</span>
              </div>
            </div>
            <!--原厂end-->
            <!--代理商 begin-->
            <div role="tabpanel" class="tab-pane" v-if="tab == 'AGENCY'" :class="{active: tab == 'AGENCY'}">
              <div class="row com_row">
                <div class="custom_col">
                  <div class="wrap-title"><span class="line"></span>营业执照</div>
                  <div class="clearfix" style="margin: 0 0.25rem">
                    <div class="show_image_area show_image pull-left">
                      <upload ref="Pom" :typeData="'BUSINESS_LICENSE'" :url="businessLicenseUrl" @uploadAction="onUpload" :NopassThree="true"></upload>
                    </div>
                    <div class="pull-left infoTextMobile" style="width: 5.1rem;margin-left: 0.2rem">
                      <em style="color: #FF0000;">*</em>如已上传最新版营业执照（三证合一），则其他两证无需上传；仅支持上传JPG、PNG、GIF、PDF格式，每张大小不超过3M
                    </div>
                    <!--<div class="" style="padding: 0;">-->
                      <!--<span style="margin-top: 50%;padding-right: 20px;">营业执照<em style="color: #FF0000;">*</em></span>-->
                    <!--</div>-->
                  </div>
                </div>
                <div class="custom_col">
                  <div class="wrap-title"><span class="line"></span>纳税人证明</div>
                  <div class="" style="margin: 0 0.25rem">
                    <div class="show_image_area show_image">
                      <upload  ref="Pom" :typeData="'TAX_PAYER'" @uploadAction="onUpload" :NopassThree="true"></upload>
                  </div>
                  </div>
                </div>
                <div class="custom_col">
                  <div class="wrap-title"><span class="line"></span>税务登记证</div>
                  <div class="" style="margin: 0 0.25rem">
                    <div class="show_image_area show_image">
                      <upload ref="Pom" :typeData="'TAX_REGISTRATION'" @uploadAction="onUpload" :NopassThree="true"></upload>
                    </div>
                    <!--<div class="col-md-5" style="padding: 0;">-->
                      <!--<span style="margin-top: 50%;padding-right: 20px;">税务登记证</span>-->
                    <!--</div>-->
                  </div>
                </div>
                <!--<div class=""><em>* </em>如已上传最新版营业执照（三证合一），则其他两证无需上传 ； 仅支持JPG、PNG、GIF、PDF格式，每张大小不超过3M</div>-->
              </div>
              <!--增加品牌-->
              <div class="custom_col brand-type" v-for="(brand, index) in brands" style="margin-top: 0px">
                <!--<div class="col-md-1">品牌{{index+1}}<em>*</em></div>-->
                <div class="wrap-title"><span class="line"></span>品牌{{index+1}}</div>
                <div class="" style="margin: 0px 0.25rem;position: relative">
                  <div class="mobile-register-brand-name">品牌名称：<input type="text" v-model="brand.name"
                                                                      @input="onBrandInput(brand, index)"
                                                                      @blur.stop.prevent="onBrandChanged(brand, index)"
                                                                      placeholder="请输入英文品牌或中文品牌"
                                                                      name="brandName" />
                  </div>
                  <!--<input type="text" v-model="brand.name"-->
                         <!--@input="onBrandInput(brand, index)"-->
                         <!--@blur.stop.prevent="onBrandChanged(brand, index)"-->
                         <!--class="form-control" name="brandName"  autocomplete="off" placeholder="请输入英文品牌或中文品牌，如：松下; panasonic等"/>-->
                  <ul class="dropdown-menu"
                      v-show="showSimilarKey.flag && showSimilarKey.index == index"
                      @mouseenter="showFlag = true"
                      @mouseleave="showFlag = false">
                    <li @mouseenter="setKeyActive"
                        @mouseleave="setKeyDefault"
                        v-for="(key, key_index) in similarKeys[index]">
                      <a v-text="key.nameCn"  @click.stop.prevent="changedName(brand, index, key_index)">
                        <!--<strong>C</strong>apital Advan<strong>c</strong>ed-->
                      </a>
                    </li>
                  </ul>
                </div>
                <div class="brand-small-upload clearfix"  style="margin: 0.1rem 0.25rem 0 0.25rem">
                  <div class="brand-small-img">
                    <upload  ref="Pom" :typeData="index" @uploadAction="onUpload" :NopassThree="true"></upload>
                  </div>
                  <div class="file-text">代理资格证/代理授权书</div>
                  <div v-show="brands.length > 1" @click="deleteBrand(index)" class="delete" title="删除"><i class="fa fa-trash"></i></div>
                  <!--<div class="col-md-12"> <em>*</em>仅支持JPG、PNG、GIF、PDF格式，大小不超过3M</div>-->
                </div>
              </div>
              <div class="add-brand" @click="addBrand">
                <i class="fa fa-plus-circle"></i>增加品牌
                <!--<a href="javascript:void(0)" title="增加品牌" @click="addBrand"><em><i class="fa fa-plus-circle"></i>增加品牌</em></a>-->
              </div>
              <!--<div class="add-brand row">-->
                <!--<a href="javascript:void(0)" title="增加品牌" @click="addBrand"><em><i class="fa fa-plus-circle"></i>增加品牌</em></a>-->
              <!--</div>-->
              <div class="unpass-reason row" style="display: none">
                原因：<span style="color: #d32526;">原因</span>
              </div>
            </div>
            <!--代理商 end-->
            <!--经销商 begin-->
            <div role="tabpanel" class="tab-pane" v-if="tab == 'DISTRIBUTION'" :class="{active: tab == 'DISTRIBUTION'}">
              <div class="row com_row">
                <div class="custom_col">
                  <div class="wrap-title"><span class="line"></span>营业执照</div>
                  <div class="clearfix" style="margin: 0 0.25rem">
                    <div class="show_image_area show_image pull-left">
                      <upload ref="Pom" :typeData="'BUSINESS_LICENSE'" :url="businessLicenseUrl" @uploadAction="onUpload" :NopassThree="true"></upload>
                    </div>
                    <div class="pull-left infoTextMobile" style="width: 5.1rem;margin-left: 0.2rem">
                      <em style="color: #FF0000;">*</em>如已上传最新版营业执照（三证合一），则其他两证无需上传；仅支持上传JPG、PNG、GIF、PDF格式，每张大小不超过3M
                    </div>
                    <!--<div class="col-md-5" style="padding: 0;">-->
                      <!--<span style="margin-top: 50%;padding-right: 20px;">营业执照<em style="color: #FF0000;">*</em></span>-->
                    <!--</div>-->
                  </div>
                </div>
                <div class="custom_col">
                  <div class="wrap-title"><span class="line"></span>纳税人证明</div>
                  <div class="" style="margin: 0 0.25rem">
                    <div class="show_image_area show_image">
                      <upload ref="Pom" :typeData="'TAX_PAYER'" @uploadAction="onUpload" :NopassThree="true"></upload>
                    </div>
                  </div>
                </div>
                <div class="custom_col">
                  <div class="wrap-title"><span class="line"></span>税务登记证</div>
                  <div class="" style="margin: 0 0.25rem">
                    <div class="show_image_area show_image">
                      <upload ref="Pom" :typeData="'TAX_REGISTRATION'" @uploadAction="onUpload" :NopassThree="true"></upload>
                    </div>
                    <!--<div class="col-md-5" style="padding: 0;">-->
                      <!--<span style="margin-top: 50%;padding-right: 20px;">税务登记证</span>-->
                    <!--</div>-->
                  </div>
                </div>
                <!--<div class="col-md-12"><em>* </em>如已上传最新版营业执照（三证合一），则其他两证无需上传 ； 仅支持JPG、PNG、GIF、PDF格式，每张大小不超过3M</div>-->
              </div>
            </div>
            <!--经销商 end-->
            <!--主营产品 begin-->
            <div role="tabpanel" class="tab-pane">
              <div class="row com_row">
                <div class="custom_col">
                  <div class="wrap-title"><span class="line"></span>主营产品</div>
                  <div class="" style="margin: 0 0.25rem">
                    <textarea v-model="description"
                              rows="5"
                              maxlength="500"
                              class="form-control"
                              placeholder="例：本店主营Panasonic、IT、三星等知名品牌的触控IC、显示驱动IC、液晶屏、功率模块类、电源芯片、高压熔断、被动器件等产品。"></textarea>
                  </div>
                </div>
              </div>
            </div>
            <!--主营产品 end-->
          </div>
          <!-- Submit button -->
         <!-- <div style="padding: 28px 40px;">
            <button type="button" class="btn btn-primary" style="float: right" @click="submitApply">提交申请</button>
            <div class="clear-fix"></div>
          </div>-->
        </div>
        <!--删除上传图片-->
        <div class="com-del-box" style="display: none">
          <div class="title">
            <a><i class="fa fa-close fa-lg"></i></a>
          </div>
          <div class="content">
            <p><i class="fa fa-exclamation-circle"></i>是否删除选中信息</p>
            <div><a>取消</a><a>确认</a></div>
          </div>
        </div>
        <!--删除品牌图片-->
        <div class="com-del-box" style="display: none">
          <div class="title">
            <a><i class="fa fa-close fa-lg"></i></a>
          </div>
          <div class="content">
            <p><i class="fa fa-exclamation-circle"></i>品牌信息为重要信息，确定删除吗？</p>
            <div><a>取消</a><a>确认</a></div>
          </div>
        </div>
        <!--提示框-->
        <div class="com-del-box" v-if="false">
          <div class="title">
            <a @click="showBrandNameInvalid = false"><i class="fa fa-close fa-lg"></i></a>
          </div>
          <div class="content">
            <p style="line-height: 20px;margin-top: 10px;padding:0 10px">非常抱歉，目前暂无此品牌！<br>若直接前往“品牌申请”，我们将为您先开通寄售功能，待申请通过后再提交开店申请。</p>
            <p style="line-height: 20px;">前往<a @click="goBrandApply()"  target="_blank" style="color: #5078CB">品牌申请&nbsp;<i class="fa fa-arrow-right"></i></a></p>
          </div>
        </div>
      </div>
    <!--<div class="step-last">
      <h4 class="h4">库存寄售</h4>
      <p class="title">无需开店，即可发布贵司仓库里的滞销产品，优软商城代为销售，匿名清仓无压力<button class="no-apply" @click="goProduct">暂不开店，直接寄售</button></p>
    </div>-->
    <div class="btn-area">
      <span @click="sectionChange(3)" style="background: #c1c1c1;border:#c1c1c1">上一步</span>
      <!--<span @click="btnDisabled?'':selectFlag == 'open'?submitApply():goProduct()" :class="btnDisabled?'btn-disabled':''">提交申请</span>-->
    </div>
    <div class="btn-area">
      <!--<span @click="sectionChange(2)">上一步</span>-->
      <span @click="btnDisabled?'':selectFlag == 'open'?submitApply():goProduct()" :class="btnDisabled?'btn-disabled':''">提交申请</span>
    </div>

    <div class="loading" v-show="showLoading">
      <!--<img src="/images/all/loading.gif" alt="">-->
    </div>
    <remind-box :title="collectResult" :timeoutCount="timeoutCount"></remind-box>
  </div>
</template>
<script>
  import { RemindBox } from '~components/mobile/common'
  import Upload from '~components/common/upload/upload.vue'
  export default {
    // props: {
    //   tab: {
    //     default: 'ORIGINAL_FACTORY'
    //   }
    // },
    data () {
      return {
        // tab: 'AGENCY',
        collectResult: '',
        timeoutCount: 0,
        brands: [{
          type: 'BRAND',
          name: '',
          url: '',
          isPdf: false,
          brandUuid: ''
        }],
        businessLicenseUrl: '',
        taxPayerUrl: '',
        taxRegistrationUrl: '',
//        defaultBusinessUrl: '',
        showBrandNameInvalid: false,
        similarKeys: [[]],
        showSimilarKey: {
          flag: false,
          index: 0
        },
        showFlag: false,
        isSelfRegisterSuccess: true,
        selectFlag: 'open',
        showLoading: false,
        btnDisabled: false,
        description: ''
      }
    },
    props: [
      'checkData',
      'registerData',
      'loginData',
      'enterpriseData',
      'businessImgUrl',
      'tab'
    ],
    watch: {
      enterpriseData: function (val, oldVal) {
        if (val !== {}) {
          console.log(1)
          this.businessLicenseUrl = val.url || val.businessCodeImage || ''
//          this.defaultBusinessUrl = val.enBussinessCodeImage || ''
        }
      },
      businessImgUrl: function (val, oldVal) {
        console.log(2)
        this.businessLicenseUrl = val
      }
    },
    components: {
      Upload,
      RemindBox
    },
    computed: {
      user () {
        return this.$store.state.option.user
      }
    },
    methods: {
      clearInfo() {
        this.brands = [{
          type: 'BRAND',
          name: '',
          url: '',
          isPdf: false,
          brandUuid: ''
        }]
        this.businessLicenseUrl = ''
        this.taxPayerUrl = ''
        this.taxRegistrationUrl = ''
        console.log('clear')
        // for (let i = 0; i < this.$refs.Pom.length; i++) {
        //   this.$refs.Pom[i].clearInfo()
        // }
      },
      sectionChange: function (type) {
        this.$emit('sectionEvent', type)
      },
      toggleTab (t) {
        this.tab = t
        this.brands = [{
          type: 'BRAND',
          name: '',
          url: '',
          isPdf: false,
          brandUuid: ''
        }]
      },
      onUpload: function (obj) {
        if (obj.type === 'BUSINESS_LICENSE') {
    //      this.businessLicenseUrl = obj.url
          this.businessLicenseUrl = obj.url
          if (obj.url !== '') {
            this.$emit('businessImgUrlAction', this.businessLicenseUrl)
          }
        } else if (obj.type === 'TAX_PAYER') {
          this.taxPayerUrl = obj.url
        } else if (obj.type === 'TAX_REGISTRATION') {
          this.taxRegistrationUrl = obj.url
        } else if (typeof obj.type === 'number') {
          this.brands[obj.type].url = obj.url
        }
      },
      onBrandChanged: function (item, index) {
        this.showSimilarKey.flag = this.showFlag
        if (!this.showFlag) {
          this.onCheck(item)
        }
      },
      onCheck: function (item, index) {
        if (item.name && item.name !== '') {
          this.$http.get('/api/product/brand', {params: {name: item.name, op: 'by_name'}})
            .then(response => {
              item.brandUuid = response.data.uuid
              item.isPdf = item.url.substring(item.url.length - 4, item.url.length) === '.pdf'
              this.$set(item, 'status', true)
            }, err => {
              console.log(err)
              this.$set(item, 'status', false)
              this.showBrandNameInvalid = true
            })
        }
      },
      onBrandInput: function (brand, index) {
        this.showSimilarKey.flag = false
        this.$http.get('/search/similarBrands?keyword=' + brand.name)
          .then(response => {
            if (response.data.length > 0 && response.data instanceof Array) {
              this.similarKeys[index] = response.data
            }
            if (response.data.length > 0 && response.data instanceof Array) {
              this.showSimilarKey.flag = true
              this.showSimilarKey.index = index
            }
          })
      },
      changedName: function (brand, index, keyIndex) {
        brand.name = this.similarKeys[index][keyIndex].nameCn
        this.showSimilarKey.flag = false
        this.onCheck(brand)
      },
      setKeyActive: function (e) {
        e.target.setAttribute('class', 'active')
      },
      setKeyDefault: function (e) {
        e.target.setAttribute('class', '')
      },
      submitApply: function () {
        // 个人
        if (this.loginData.isSelf) {
          if (!this.registerData.isValidRegister) {
            // this.$message.error('请输入正确的注册信息')
            this.collectResult = '请输入正确的注册信息'
            this.timeoutCount++
          } else if (!this.checkData.checked) {
            // this.$message.error('您还没有勾选相关条款')
            this.collectResult = '您还没有勾选相关条款'
            this.timeoutCount++
          } else {
            // 注册企业，并提交申请
            this.registerSelf()
          }
        } else {
          // 企业
          if (!this.checkData.checked) {
            // this.$message.error('您还没有勾选相关条款')
            this.collectResult = '您还没有勾选相关条款'
            this.timeoutCount++
          } else {
            // 提交申请
            this.storeApply(this.loginData.enterprise.uu)
          }
        }
      },
      // 个人用户，先注册企业，成功后，提交开店申请
      registerSelf: function () {
        this.showLoading = true
        this.$http.post('/basic/enterprise/register?filePath=' + this.registerData.url, this.registerData.enterprise)
          .then(response => {
            if (response.data.success) {
              this.isSelfRegisterSuccess = true
              // 删除保存的缓存企业信息
              this.$http.delete('/basic/user/userCacheEnterprise')
              // 把当前用户登录企业信息切换为注册的企业
              this.$http.get(`/user/authentication/` + response.data.data.enuu).then(() => {
                // 重新获取登录用户信息
                this.$store.dispatch('loadUserInfo')
                this.loginData.isSelf = false
                this.loginData.enterprise.uu = response.data.data.enuu
                // 提交开店申请
                this.storeApply(response.data.data.enuu)
//                    window.location.reload()
                this.showLoading = false
              })
            } else {
              this.isSelfRegisterSuccess = false
              this.showLoading = false
              // this.$message.error(response.data.message || '企业注册失败，请重新填写信息')
              this.collectResult = response.data.message || '企业注册失败，请重新填写信息'
              this.timeoutCount++
            }
          }, err => {
            console.log(err)
            this.isSelfRegisterSuccess = false
            this.showLoading = false
            this.collectResult = '企业注册失败，请重新填写信息'
            this.timeoutCount++
            // this.$message.error('企业注册失败，请重新填写信息')
          })
      },
      storeApply: function (enuu) {
        this.showLoading = true
        let validCode = 0
        let _brandFlg = true
        let _brandName = ''
        for (let i = 0; i < this.brands.length; i++) {
          if (this.brands[i].status !== undefined && !this.brands[i].status) {
            _brandFlg = false
            _brandName = this.brands[i].name
          }
        }
        if (this.businessLicenseUrl === '') {
          // this.$message.error('请上传营业执照')
          this.collectResult = '请上传营业执照'
          this.timeoutCount++
          this.showLoading = false
        } else if (this.description === '') {
          this.collectResult = '请填写主营产品信息'
          this.timeoutCount++
          this.showLoading = false
        } else if (!_brandFlg) {
          this.collectResult = `品牌${_brandName}不存在，请申请此品牌`
          this.showLoading = false
        } else {
          if (this.brands[0].name === '') {
            validCode = 1
          } else if (this.brands[0].url === '') {
            validCode = 2
          }
          if (validCode === 0 || this.tab === 'DISTRIBUTION') {
            let qualifications = []
            qualifications.push({
              type: 'BUSINESS_LICENSE',
              resourceUrl: this.businessLicenseUrl,
              isPdf: this.isPdf(this.businessLicenseUrl)
            })
            if (this.taxPayerUrl !== '') {
              qualifications.push({
                type: 'TAX_PAYER',
                resourceUrl: this.taxPayerUrl,
                isPdf: this.isPdf(this.taxPayerUrl)
              })
            }
            if (this.taxPayerUrl !== '') {
              qualifications.push({
                type: 'TAX_REGISTRATION',
                resourceUrl: this.taxRegistrationUrl,
                isPdf: this.isPdf(this.taxRegistrationUrl)
              })
            }
//            console.log(qualifications)
            let tmpBrands = []
            this.brands.forEach(function (item) {
              if (item.name !== '' && item.url !== '') {
                tmpBrands.push(item)
              }
            })
            // 申请开店
            this.$http.post('/store-service/applications', {
              applyDescription: this.description,
              brands: tmpBrands,
              qualifications: qualifications,
              type: this.tab
            }).then(response => {
              this.showLoading = false
              if (response.data.success) {
                this.btnDisabled = true
                this.collectResult = '感谢您对优软商城的支持，我们会尽快对您提交的信息进行审核，预计审核时间为3个工作日，审核结果将以站内消息及邮件形式通知您！'
                this.timeoutCount++
                // this.push('/mobile/')
                // this.$message.success('感谢您对优软商城的支持，我们会尽快对您提交的信息进行审核，预计审核时间为3个工作日，审核结果将以站内消息及邮件形式通知您！')
              } else {
                this.btnDisabled = true
                this.collectResult = '开通店铺异常，请前往PC端，我的店铺查看店铺开通进度'
                this.timeoutCount++
                // this.$message.error('开通店铺异常，请前往我的店铺查看店铺开通进度')
              }
              this.$http.post('/basic/enterprise/openVendor/' + enuu)
                .then(() => {
                  setTimeout(() => {
                    window.location.href = '/mobile/user'
                    // this.$router.push('/mobile/user')
                  }, 1500)
                })
            }, err => {
              console.log(err)
              this.$http.post('/basic/enterprise/openVendorSetRead/' + enuu)
              this.collectResult = '开通店铺失败'
              this.timeoutCount++
              // this.$message.error('开通店铺失败')
              this.showLoading = false
            })
          } else {
            if (validCode === 1) {
              this.collectResult = '请添加品牌信息'
              this.timeoutCount++
              // this.$message.error('请添加品牌信息')
              this.showLoading = false
            } else if (validCode === 2) {
              this.collectResult = '请上传品牌图片'
              this.timeoutCount++
              // this.$message.error('请上传品牌图片')
              this.showLoading = false
            }
          }
        }
      },
      addBrand: function () {
        this.brands.push({
          type: 'BRAND',
          name: '',
          url: '',
          isPdf: false,
          brandUuid: ''
        })
        this.similarKeys.push([])
      },
      deleteBrand: function (index) {
        this.brands.splice(index, 1)
        this.similarKeys.splice(index, 1)
      },
      isPdf: function (url) {
        return url.substring(url.length - 4, url.length) === '.pdf'
      },
      reflashEnterprise: function (enuu, url) {
        this.$http.post('/basic/enterprise/openVendor/' + enuu)
          .then(() => {
            this.$http.get('/user/authentication/reflash')
              .then(() => {
                this.$http.get(`/user/authentication/` + enuu).then(() => {
                  this.$store.dispatch('loadUserInfo')
                  // window.location.href = url
                  this.$router.push('/mobile/user')
                })
              }
              )
          })
      },
      goProduct: function (baseUrl) {
        if (this.loginData.isSelf) {
          if (!this.registerData.isValidRegister) {
            this.collectResult = '请输入正确的注册信息'
            this.timeoutCount++
            // this.$message.error('请输入正确的注册信息')
          } else if (!this.checkData.checked) {
            this.collectResult = '您还没有勾选相关条款'
            this.timeoutCount++
            // this.$message.error('您还没有勾选相关条款')
          } else {
            this.showLoading = true
            this.$http.post('/basic/enterprise/register?filePath=' + this.registerData.url, this.registerData.enterprise)
              .then(response => {
                if (response.data.success) {
                  this.isSelfRegisterSuccess = true
                  this.$http.delete('/basic/user/userCacheEnterprise')
                  this.reflashEnterprise(response.data.data.enuu, baseUrl || '/vendor#/vendor_upload')
                } else {
                  this.isSelfRegisterSuccess = false
                  this.collectResult = response.data.message || '企业注册失败，请重新填写信息'
                  this.timeoutCount++
                  // this.$message.error(response.data.message || '企业注册失败，请重新填写信息')
                }
                this.showLoading = false
              }, err => {
                console.log(err)
                this.isSelfRegisterSuccess = false
                this.showLoading = false
                this.collectResult = '企业注册失败，请重新填写信息'
                this.timeoutCount++
                // this.$message.error('企业注册失败，请重新填写信息')
              })
          }
        } else {
          if (!this.checkData.checked) {
            this.collectResult = '您还没有勾选相关条款'
            this.timeoutCount++
            // this.$message.error('您还没有勾选相关条款')
          } else {
            this.reflashEnterprise(this.loginData.enterprise.uu, baseUrl || '/vendor#/vendor_upload')
          }
        }
      },
      goBrandApply: function () {
        this.showBrandNameInvalid = false
        this.goProduct('/vendor#/brand/apply/')
      }
    }
  }
</script>
<style lang="scss">
  .mobile-vendor_store_apply{
    #image-box{
      overflow:visible;
      height:95vh;
      margin-top:0;
      top:2%;
      padding:1rem;
      .x-close-wrap{
        right:-.15rem;
        top:-.15rem;
        width:.35rem;
        height:.35rem;
        line-height: .3rem;
        a{
          font-size: .35rem;
        }
      }
    }
    .wrap-title {
      color: #333;
      font-size: 0.28rem;
      border-bottom: 1px solid #d3d3d3;
      height: 0.5rem;
      text-align: left;
      padding: 0 0 0.1rem 0.05rem;
      margin: 0.17rem 0.25rem 0.13rem 0.25rem;
      line-height: 0.5rem;
      .line{
        width: 0.05rem;
        background: #3f84f6;
        display: inline-block;
        vertical-align: top;
        margin-right: 0.08rem;
        height: 0.28rem;
        margin-top: 0.09rem;
      }
    }
  }
</style>
