<template>
  <!--金融部大区域维护-一览页面-->
  <div class="bigAreaMaintainEdit">
    <dialog-edit :visible.sync="dialogVisible" :editModel="editModel" :form="form"
                 :api="api" :width="width"
                 :title="$t('cyjg.financialRegionInfo.bigAreaMaintain')">
      <div class="organ-item">
        <search-form :componentList="searchList" :formValue.sync="queryParas" @handleFilter="handleFilter"
                     :isShowFoldBtn="false"
                     @clearParam="clearParam"></search-form>
      </div>
      <data-table :api="api" :sourceData.sync="sourceData" :operateBtnLayout="operateBtnLayout" :loadCount.sync="loadCount"
                  :menuFlag="menuFlag" :showSelection='true' :queryParas="queryParas" :type="selectionType" :store="$store"
                  @selectRowChange="selectRowChange" @onEditRow="showEdit">
        <template slot="headButton">
          <div class="floatRight">
            <auth-button type="primary" :label="$t('common.create')"
                         icon="iconfont iconxinzeng" size="medium" @click="showCreate"></auth-button>
            <auth-button type="danger" :label="$t('common.del')"
                         icon="iconfont iconshanchu" size="medium" @click="delBatch"></auth-button>
          </div>
        </template>
        <!-- 核心企业 -->
        <el-table-column align="left" :label="$t('cyjg.financialRegionInfo.coreEnterprise')" prop="coreCompanyName">
          <template slot-scope="scope">
            <el-link @click="showBusiness(scope.row)" :underline="underline" type="primary">{{scope.row.coreCompanyName}}</el-link>
          </template>
        </el-table-column>
        <!-- 大区域 -->
        <el-table-column align="left" :label="$t('cyjg.financialRegionInfo.bigArea')" prop="largeAreaName">
          <template slot-scope="scope">
            <span>{{scope.row.largeAreaName}}</span>
          </template>
        </el-table-column>
      </data-table>
      <big-area-maintain-update-edit :visible.sync="showDetail" :editModel="showModel" :form="newItem" :regMsg="regMsg" @saveSuccess="saveSuccess"></big-area-maintain-update-edit>
<!--      <business-region-company-edit :visible.sync="busVisible" :editModel="busModel" :form="busItem"></business-region-company-edit>-->
      <pro-company-info-manage-edit :visible.sync="busVisible" :editModel="busModel" :form="busItem" :regMsg="regMsg"></pro-company-info-manage-edit>
    </dialog-edit>
  </div>
</template>

<script>
// 大区域维护(金融部)
import { searchForm, DataTable, authButton, DialogEdit, SelectCoreEnterprise } from 'newepoch-components'
import BaseEdit from '@/pages/baseEditPage.js'
import BigAreaMaintainUpdateEdit from '@/pages/cyjg/financialRegionInfo/bigAreaMaintainUpdateEdit.vue'
import financialRegionInfoApi from '@/api/cyjg/financialRegionInfoApi.js'
// import storage from '@/utils/storage'
import ProCompanyInfoManageEdit from '@/pages/cyjg/financialRegionInfo/coreEnterpriseInfoManageEdit.vue'
export default {
  extends: new BaseEdit(),
  name: 'bigAreaMaintainEdit',
  components: {
    searchForm,
    DialogEdit,
    DataTable,
    authButton,
    SelectCoreEnterprise,
    BigAreaMaintainUpdateEdit,
    ProCompanyInfoManageEdit
  },
  data () {
    return {
      width: '1480px',
      sourceData: [],
      rows: [],
      menuFlag: false,
      underline: true,
      showDetail: false,
      busVisible: false,
      showModel: '',
      busModel: '',
      operateBtnLayout: 'E',
      selectionType: 'selection',
      newItem: {},
      busItem: {},
      // 查询条件
      queryParas: {
        pageIndex: 1,
        pageSize: 10,
        coreCompanyId: ''
      },
      loadCount: 0,
      searchList: [
        // 核心企业
        {
          label: this.$i18n.messages[this.$i18n.locale].cyjg.financialRegionInfo.coreEnterprise,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          labelWidth: '',
          value: 'coreCompanyId',
          componentName: SelectCoreEnterprise
        }
      ]
    }
  },
  computed: {
    api () {
      return financialRegionInfoApi.financialBigArea
    }
  },
  methods: {
    // 新增/编辑 操作成功
    saveSuccess () {
      this.handleFilter()
      this.$emit('refreshBigArea')
    },
    // 复选框勾选数据
    selectRowChange (val) {
      this.rows = val
    },
    // 查询
    handleFilter () {
      let $this = this
      $this.loadCount = $this.loadCount + 1
    },
    // 重置
    clearParam () {
      let $this = this
      $this.queryParas = {
        pageIndex: 1,
        pageSize: 10,
        coreCompanyId: ''
      }
    },
    // 批量删除
    delBatch () {
      if (this.rows.length === 0) {
        this.warning(this.$i18n.messages[this.$i18n.locale].common.delSelectedTip)
        return
      }
      let arr = this.rows.map(it => {
        return it.keyId
      })
      let $this = this
      $this.$confirm(this.$i18n.messages[this.$i18n.locale].common.confirmTip, this.$i18n.messages[this.$i18n.locale].common.warningTip, {
        type: 'warning'
      }).then(() => {
        financialRegionInfoApi.financialInfoManage.dels({ ids: arr, delType: '1' }).then(res => {
          if (res && res.data) {
            $this.success(this.$i18n.messages[this.$i18n.locale].common.delSuccess)
            $this.handleFilter()
            $this.$emit('refreshBigArea')
          } else {
            $this.error(this.$i18n.messages[this.$i18n.locale].common.delFailure)
          }
        })
      }).catch(() => {})
    },
    // 打开编辑界面
    showEdit (index, data, editModel) {
      this.newItem = Object.assign({}, data, { areaName: data.largeAreaName })
      this.showModel = editModel
      this.showDetail = true
    },
    // 打开新增界面
    showCreate () {
      this.showModel = 'C'
      this.newItem = {
        areaName: ''
      }
      this.showDetail = true
    },
    // 打开项目公司界面
    showBusiness (data) {
      this.$set(data, 'tagCode', '60')
      this.$set(data, 'enterpriseId', data.coreCompanyId)
      this.busItem = Object.assign({}, data)
      this.busModel = 'V'
      this.busVisible = true
      // storage.setLocal('params', data)
      // this.$router.push({
      //   name: 'coreEnterpriseInfoManageEdit'
      // })
    }
  },
  watch: {}
}
</script>

<style scoped lang="scss" src="@/styles/cyjg/financialRegionInfo/bigAreaMaintainEdit.scss">
</style>
