<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
     width="70%"
    :visible.sync="visible">

    <el-tabs v-model="activeName" :title="title" type="border-card" style="margin: -20px -10px -20px -10px;">
      <el-tab-pane label="基础信息" name="jc">
        <span slot="label"><i class="el-icon-tickets" style="font-size: 16px;"></i> <span style="font-size: 16px;font-weight: 600;">基础信息</span></span>

          <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
                   label-width="195px">
            <el-row  :gutter="15">
              <el-col :span="8">
                  <el-form-item label="企业名称" prop="name"
                      :rules="[
                        {required: true, message:'企业名称不能为空', trigger:'blur'}
                       ]">
                    <el-input v-model="inputForm.name" placeholder="请填写企业名称"     ></el-input>
                 </el-form-item>
              </el-col>
              <el-col :span="8">
                  <el-form-item label="属地" prop="des1"
                      :rules="[
                        {required: true, message:'属地不能为空', trigger:'blur'}
                       ]">
                    <el-input v-model="inputForm.des1" placeholder="请填写属地"     ></el-input>
                 </el-form-item>
              </el-col>

              <el-col :span="8">
                  <el-form-item label="所属行业" prop="industry"
                      :rules="[
                        {required: true, message:'所属行业不能为空', trigger:'blur'}
                       ]">
                    <el-input v-model="inputForm.industry" placeholder="请填写所属行业"     ></el-input>
                 </el-form-item>
              </el-col>

              <el-col :span="8">
                  <el-form-item label="销售规模" prop="des3"
                      :rules="[
                        {required: true, message:'销售规模不能为空', trigger:'blur'}
                       ]">
                    <el-input v-model="inputForm.des3" placeholder="请填写销售规模"     ></el-input>
                 </el-form-item>
              </el-col>

              <el-col :span="8">
                  <el-form-item label="主导产品一" prop="bz1"
                      :rules="[
                        {required: true, message:'主导产品一不能为空', trigger:'blur'}
                       ]">
                    <el-input v-model="inputForm.bz1" placeholder="请填写主导产品一"     ></el-input>
                 </el-form-item>
              </el-col>

              <el-col :span="8">
                  <el-form-item label="产业链上下游" prop="bz2"
                      :rules="[
                       ]">
                    <el-input v-model="inputForm.bz2" placeholder="请填写产业链上下游"     ></el-input>
                 </el-form-item>
              </el-col>

              <el-col :span="8">
                  <el-form-item label="主导产品二" prop="bz3"
                      :rules="[

                       ]">
                    <el-input v-model="inputForm.bz3" placeholder="请填写主导产品二"     ></el-input>
                 </el-form-item>
              </el-col>

              <el-col :span="8">
                  <el-form-item label="产业链上下游" prop="bz4"
                      :rules="[
                       ]">
                    <el-input v-model="inputForm.bz4" placeholder="请填写产业链上下游"     ></el-input>
                 </el-form-item>
              </el-col>

              <el-col :span="8">
                  <el-form-item label="工信局联系人" prop="bz5"
                      :rules="[

                       ]">
                    <el-input v-model="inputForm.bz5" placeholder="请填写工信局联系人"     ></el-input>
                 </el-form-item>
              </el-col>
              <el-col :span="8">
                  <el-form-item label="联系人手机" prop="bz6"
                      :rules="[

                       ]">
                    <el-input v-model="inputForm.bz6" placeholder="请填写联系人手机"     ></el-input>
                 </el-form-item>
              </el-col>

              <el-col :span="8">
                  <el-form-item label="企业联系人" prop="lxr"
                      :rules="[
                        {required: true, message:'企业联系人不能为空', trigger:'blur'}
                       ]">
                    <el-input v-model="inputForm.lxr" placeholder="请填写企业联系人"     ></el-input>
                 </el-form-item>
              </el-col>
              <el-col :span="8">
                  <el-form-item label="联系人手机" prop="phone"
                      :rules="[
                        {required: true, message:'联系人手机不能为空', trigger:'blur'},
                        {validator: validator.isMobile, trigger:'blur'}
                       ]">
                    <el-input v-model="inputForm.phone" placeholder="请填写联系人手机"     ></el-input>
                 </el-form-item>
              </el-col>

              <el-col :span="8">
                  <el-form-item label="挂钩干部" prop="des14"
                      :rules="[
                        {required: true, message:'挂钩干部不能为空', trigger:'blur'}
                       ]">
                    <el-input v-model="inputForm.des14" placeholder="请填写挂钩干部"     ></el-input>
                 </el-form-item>
              </el-col>
              <el-col :span="8">
                  <el-form-item label="挂钩干部手机" prop="des13"
                      :rules="[
                        {required: true, message:'挂钩干部手机不能为空', trigger:'blur'},
                        {validator: validator.isMobile, trigger:'blur'}
                       ]">
                    <el-input v-model="inputForm.des13" placeholder="请填写挂钩干部手机"     ></el-input>
                 </el-form-item>
              </el-col>


              </el-row>

              <div style=" padding-left: 80px;padding-top: 20px;"> </div>

          </el-form>
      </el-tab-pane>



    </el-tabs>

    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>

  </el-dialog>

  <EnterpriseElectricityForm  ref="enterpriseElectricityForm" @refreshDataList="warnrefreshList"></EnterpriseElectricityForm>
  <EnterpriseWaterForm  ref="enterpriseWaterForm" @refreshDataList="sfrefreshList"></EnterpriseWaterForm>
  <EnterprisePropertyForm  ref="enterprisePropertyForm" @refreshDataList="wyfrefreshList"></EnterprisePropertyForm>
</div>
</template>

<script>
  import EnterpriseElectricityForm from '../enterpriseelectricity/EnterpriseElectricityForm.vue'
  import EnterpriseWaterForm from '../enterprisewater/EnterpriseWaterForm.vue'
  import EnterprisePropertyForm from '../enterpriseproperty/EnterprisePropertyForm.vue'
  import GridSelect from '@/components/gridSelect'
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  import enterpriseElectricityService from '@/api/enterpriseelectricity/enterpriseElectricityService'
  import enterpriseWaterService from '@/api/enterprisewater/enterpriseWaterService'
  import enterprisePropertyService from '@/api/enterpriseproperty/enterprisePropertyService'
  import enterpriseInfoService from '@/api/enterpriseinfo/enterpriseInfoService'
  export default {
    data () {
      return {
        activeName: 'jc',
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          name: '',
          industry: '',
          des1: '',
          des2: '',
          des3: '',
          des5: '',

          des7: 0,
          des8: 0,
          des9: 0,

          entryTime: '',
          officeArea: '',
          annualRent: '',
          floor: '',
          lxr: '',
          phone: '',
          htStime: '',
          htEtime: '',
          qyDes: '',
          businessContent: '',
          totalNumber: 0,
          securityNumber: 0,
          belowUndergraduate: 0,
          undergraduate: 0,
          postgraduate: 0,
          doctoralStudent: 0,
          qyDes: '',
          num2: '',
          num3: '',
          softWritingNumbers: '',
          bz1: '',
          bz2: '',
          bz3: '',
          bz4: '',
          bz5: '',
          bz6: '',
          des10: '',
          des11: '',
          des13: '',
          des14: '',
        },

        electdataList: [],
        warntablePage: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          orders: [{
            column: 'a.create_date',
            asc: false
          }]
        },

        sfdataList: [],
        sftablePage: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          orders: [{
            column: 'a.create_date',
            asc: false
          }]
        },

        wyfdataList: [],
        wyftablePage: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          orders: [{
            column: 'a.create_date',
            asc: false
          }]
        },

      }
    },
    components: {
      GridSelect,
      SelectTree,
      EnterpriseElectricityForm,
      EnterpriseWaterForm,
      EnterprisePropertyForm
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建企业基本信息`
        } else if (method === 'edit') {
          this.title = '修改企业基本信息'
        } else if (method === 'view') {
          this.title = '查看企业基本信息'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            enterpriseInfoService.queryById(this.inputForm.id).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data)
              this.inputForm.industry = this.inputForm.industry.split(',')
              this.loading = false
            })

          }
        })
      },


      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {

            this.inputForm.industry = this.inputForm.industry.toString()
            this.loading = true
            enterpriseInfoService.save(this.inputForm).then(({data}) => {
              this.visible = false
              this.$message.success(data)
              this.$emit('refreshDataList')
              this.loading = false
            }).catch(() => {
              this.loading = false
            })


          }
        })
      }
    }
  }
</script>
