<template>
  <div>
    <el-dialog
      v-loading="qysdsLoading"
      :visible.sync="visible"
      :before-close="handleCancel"
      :append-to-body="true"
      :close-on-click-modal="false"
      title="企业画像"
      width="70%">
      <el-tabs v-model="tabValue" type="border-card">
        <el-tab-pane name="qygdxx" label="企业详情信息">
          <sections
            :title="'纳税人资格认定信息'"
            :size="'18px'"
            class="b-cells"
            style="padding-bottom: 20px"
            content-height="auto"/>
          <el-descriptions
            style="padding-left: 30px">
            <el-descriptions-item
              v-for="xx in qynsrzgxx"
              :key="xx.name"
              :label="xx.name">{{ xx.value }}
            </el-descriptions-item>
          </el-descriptions>
          <sections
            :title="'企业参保人数'"
            :size="'18px'"
            class="b-cells"
            style="padding-bottom: 20px"
            content-height="auto"/>
          <div style="padding-bottom: 20px">
            月份：
            <el-date-picker
              v-model="xyDjyf"
              format="yyyy-MM" value-format="yyyyMM"
              type="month"
              placeholder="选择月份"
              @change="getqyCbrsData"/>
            <el-button style="margin-left: 10px" type="primary" @click="getDetail">查询</el-button>
          </div>
          <el-table ref="refCbrs" :data="qycbrs" border>
            <el-table-column label="登记序号" prop="djxh"/>
            <el-table-column label="月份" prop="yf"/>
            <el-table-column label="参保人数" prop="cbrs"/>
          </el-table>
          <sections
            :title="'信用等级'"
            :size="'18px'"
            class="b-cells"
            style="padding-bottom: 20px"
            content-height="auto"/>
          <div style="padding-bottom: 20px">
            年度：
            <el-date-picker
              v-model="xyDjnd"
              format="yyyy" value-format="yyyy "
              type="year"
              placeholder="选择年度"
              @change="getQypjData"/>
            <el-button style="margin-left: 10px" type="primary" @click="getQypjData">查询</el-button>
          </div>
          <el-table ref="ref" :data="pjdjList" border>
            <el-table-column label="登记序号" prop="djxh"/>
            <el-table-column label="年度" prop="pjnd"/>
            <el-table-column label="信用等级" prop="pjjg"/>
          </el-table>
        </el-tab-pane>
        <el-tab-pane name="qygsxx" label="企业工商信息">
          <sections
            :title="'企业工商信息'"
            :size="'18px'"
            class="b-cells"
            style="padding-bottom: 20px"
            content-height="auto"/>
          <el-descriptions
            style="padding-left: 30px">
            <el-descriptions-item
              v-for="xx in qygsxx"
              :key="xx.name"
              :label="xx.name">{{ xx.value }}
            </el-descriptions-item>
          </el-descriptions>
        </el-tab-pane>
        <el-tab-pane name="qyfxxx" label="企业风险信息">
          <sections
            :title="'企业风险信息'"
            :size="'18px'"
            class="b-cells"
            style="padding-bottom: 20px"
            content-height="auto"/>
          <div style="padding-bottom: 20px">
            年度：
            <el-date-picker
              v-model="fxDjnd"
              format="yyyy" value-format="yyyy"
              type="year"
              placeholder="选择年度"
              @change="getQyfxxxData"/>
            <el-button style="margin-left: 10px" type="primary" @click="getQyfxxxData">查询</el-button>
          </div>
          <el-table ref="refFx" :data="qyFxList" border>
            <el-table-column label="登记序号" prop="djxh"/>
            <el-table-column label="指标代码" prop="fxzbDm"/>
            <el-table-column label="风险描述" prop="fxmx"/>
          </el-table>
        </el-tab-pane>
        <el-tab-pane name="qysdsndsb" label="企业所得税年度申报">
          <div style="padding-bottom: 20px">
            年度：
            <el-date-picker
              v-model="ndsbTime"
              format="yyyy" value-format="yyyy"
              type="year"
              placeholder="选择年度"
              @change="getQysdsndsbData()"/>
            <el-button style="margin-left: 10px" type="primary" @click="getQysdsndsbData">查询</el-button>
          </div>
          <sections
            :title="'企业所得税年度申报'"
            :size="'18px'"
            class="b-cells"
            style="padding-bottom: 20px"
            content-height="auto"/>
          <el-table ref="refQysds" :data="qysdsList" border>
            <el-table-column v-for="item in QysdsFieldList" :label="item.name" :prop="item.value"/>
            <el-table-column
              fixed="right"
              label="操作"
              width="60">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  @click="openQysds(scope.row)"
                >详 情
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
        <el-tab-pane name="qyfphz" label="企业发票汇总">
          <sections
            :title="'销项发票汇总'"
            :size="'18px'"
            class="b-cells"
            style="padding-bottom: 20px"
            content-height="auto"/>
          <el-table ref="refFx" :data="xxFpList" border>
            <el-table-column label="年度" prop="nd"/>
            <el-table-column label="销项不含税金额" prop="xxbhsje"/>
            <el-table-column label="销项税额" prop="xxse"/>
            <el-table-column label="销项价税合计" prop="xxjshj"/>
            <el-table-column label="项年开票数量" prop="xxkpsl"/>
            <el-table-column label="销项年最大开票额" prop="xxzdkpe"/>
          </el-table>
          <sections
            :title="'进项发票汇总'"
            :size="'18px'"
            class="b-cells"
            style="padding-bottom: 20px"
            content-height="auto"/>
          <el-table ref="refFx" :data="jxFpList" border>
            <el-table-column label="年度" prop="nd"/>
            <el-table-column label="进项不含税金额" prop="jxbhsje"/>
            <el-table-column label="进项税额" prop="jxse"/>
            <el-table-column label="进项价税合计" prop="jxjshj"/>
          </el-table>
        </el-tab-pane>
      </el-tabs>
      <el-dialog
        :visible.sync="visibleQysds"
        :before-close="cancelQysds"
        :append-to-body="true"
        :close-on-click-modal="false"
        title="企业所得税年度申报"
        width="70%">
        <el-form
          v-loading="qysdsLoading"
          ref="editForm"
          class="el-form--flex"
          label-position="left"
          label-width="100px">
          <el-form-item
            v-for="item in QysdsFieldList"
            :key="item.value"
            :label="item.name"
            label-width="160px"
          >
            <template>
              {{ getQysdsValue(item.value) }}
            </template>
          </el-form-item>
        </el-form>
      </el-dialog>
    </el-dialog>
  </div>
</template>
<script type="text/javascript">
import Qynsrzg from './EnterpriseProfile/qynsrzg.vue'
import qynsrzg from './EnterpriseProfile/qynsrzg.vue'
import Sections from './Sections.vue'
import {
  getNsrzg,
  getQyCbrs,
  getQyFpxx,
  getQyFxmx,
  getQyFxndsb, getQygsxx,
  getQynsrXyDj,
  getQySfl
} from '../../../api/crm/EnterpriseProfile'

export default {
  name: 'EnterpriseProfile',
  components: { Sections, Qynsrzg },
  mixins: [],
  props: {
    qyjbxx: {
      type: Object,
      default: () => {
        return {}
      }
    },
    id: [String, Number],
    poolId: [String, Number],
    visible: {
      type: Boolean,
      required: true,
      default: false
    }
  },
  data() {
    return {
      qysdsLoading: false,
      visibleQysds: false,
      xyDjyf: '',
      fpTime: '',
      ndsbTime: '',
      qysdsData: {},
      tabValue: 'qygdxx',
      qynsrzgxx: [],
      formList: [],
      pjdjList: [],
      xyDjnd: '',
      qygsxx: [],
      qycbrs: [],
      qysflList: [],
      qyFxList: [],
      fxDjnd: '',
      qysdsList: [],
      qyFpList: [],
      jxFpList: [],
      xxFpList: [],
      QysdsFieldList: [
        {
          index: 1,
          name: 'uuid',
          value: 'uuid'
        },
        {
          index: 2,
          name: '申报UUID',
          value: 'sbuuid'
        }, {
          index: 3,
          name: '税款所属期起',
          value: 'skssqq'
        }, {
          index: 4,
          name: '税款所属期止',
          value: 'skssqz'
        }, {
          index: 5,
          name: '凭证序号',
          value: 'pzxh'
        }, {
          index: 6,
          name: '营业收入',
          value: 'yysr'
        }, {
          index: 7,
          name: '营业成本',
          value: 'yycb'
        }, {
          index: 8,
          name: '营业税金及附加',
          value: 'yysjFj'
        }, {
          index: 9,
          name: '销售费用',
          value: 'xsfy'
        }, {
          index: 10,
          name: '管理费用',
          value: 'glfy'
        }, {
          index: 11,
          name: '财务费用',
          value: 'cwfy'
        }, {
          index: 12,
          name: '资产减值损失',
          value: 'zcjzss'
        }, {
          index: 13,
          name: '公允价值变动收益',
          value: 'gyjzbdsy'
        }, {
          index: 14,
          name: '投资收益',
          value: 'tzsy'
        }, {
          index: 15,
          name: '营业利润',
          value: 'yylr'
        }, {
          index: 16,
          name: '营业外收入',
          value: 'yywsr'
        }, {
          index: 17,
          name: '营业外支出',
          value: 'yywzc'
        }, {
          index: 18,
          name: '利润总额',
          value: 'lrze'
        }, {
          index: 19,
          name: '境外所得金额',
          value: 'jwsdje'
        }, {
          index: 20,
          name: '纳税调整增加额',
          value: 'nstzzje'
        }, {
          index: 21,
          name: '纳税调整减少额',
          value: 'nstzjse'
        }, {
          index: 22,
          name: '减：免税、减计收入及加计扣除',
          value: 'msjjsrjjjkc'
        }, {
          index: 23,
          name: '加：境外应税所得抵减境内亏损',
          value: 'jwyssddjjnks'
        }, {
          index: 24,
          name: '纳税调整后所得',
          value: 'nstzhsd'
        }, {
          index: 25,
          name: '减：所得减免',
          value: 'sdjm'
        }, {
          index: 26,
          name: '抵扣应纳税所得额',
          value: 'dkynssde'
        }, {
          index: 27,
          name: '弥补以前年度亏损',
          value: 'mbyqndks'
        }, {
          index: 28,
          name: '应纳税所得额',
          value: 'ynssde'
        }, {
          index: 29,
          name: '税率',
          value: 'sl1'
        }, {
          index: 30,
          name: '应纳所得税额',
          value: 'ynsdse'
        }, {
          index: 31,
          name: '减、免所得税额',
          value: 'jmsdse'
        }, {
          index: 32,
          name: '抵免所得税额',
          value: 'dmsdse'
        }, {
          index: 33,
          name: '应纳税额',
          value: 'ynse'
        }, {
          index: 34,
          name: '境外所得应纳所得税额',
          value: 'jwsdynsdse'
        }, {
          index: 35,
          name: '减：境外所得抵免所得税额',
          value: 'jwsddmsdse'
        }, {
          index: 36,
          name: '实际应纳所得税额',
          value: 'sjynsdse'
        }, {
          index: 37,
          name: '本年累计实际已预缴的所得税额',
          value: 'bnljsjyyjSdse'
        }, {
          index: 38,
          name: '本年应补退的所得税额',
          value: 'bnybtSdse'
        }, {
          index: 39,
          name: '总机构分摊本年应补（退）所得税额',
          value: 'zjgftbnybtsdse'
        }, {
          index: 40,
          name: '财政集中分配本年应补（退）所得税额',
          value: 'czjzfpbnybtsdse'
        }, {
          index: 41,
          name: '总机构主体生产经营部门分摊本年应补（退）所得税额',
          value: 'zjgztscjybmftbnybtsdse'
        }, {
          index: 42,
          name: '以前年度多缴的所得税额在本年抵减额',
          value: 'yqnddjSdseBndje'
        }, {
          index: 43,
          name: '以前年度应缴未缴在本年入库所得税额',
          value: 'yqndYjwjzbnrksdse'
        }
      ]
    }
  },
  computed: {
    qynsrzg() {
      return qynsrzg
    }
  },
  watch: {
    'tabValue'(newVal, oldVal) {
      if (newVal === 'qygdxx') {
        this.getForm()
      } else if (newVal === 'qysfl') {
        this.getQySflData()
      } else if (newVal === 'qyfxxx') {
        this.getQyfxxxData()
      } else if (newVal === 'qysdsndsb') {
        this.getQysdsndsbData()
      } else if (newVal === 'qyfphz') {
        this.getQyfphzData()
      } else if (newVal === 'nsrzgrz') {
        this.getNsrzgData()
      } else if (newVal === 'cbrs') {
        this.getqyCbrsData()
      } else if (newVal === 'qyxydj') {
        this.getQypjData()
      } else if (newVal === 'qygsxx') {
        this.getQygsxxData()
      }
    }
  },
  mounted() {
    this.getForm()
  },
  methods: {
    getForm() {
      this.getNsrzgData()
      this.getqyCbrsData()
      this.getQypjData()
    },
    openQysds(data) {
      this.qysdsData = data
      this.visibleQysds = true
    },
    cancelQysds() {
      this.visibleQysds = false
    },
    handleCancel() {
      console.log(this.id)
      this.$emit('update:visible', false)
    },
    getQysdsValue(data) {
      if (this.qysdsData) {
        return this.qysdsData[data]
      }
      return '无'
    },
    getQyfphzData() {
      this.qysdsLoading = true
      const param = this.qyjbxx.shxydm ? this.qyjbxx.shxydm : this.qyjbxx.djxh
      console.log(this.qyjbxx)
      const qyfp = {
        param: param
      }
      getQyFpxx(qyfp).then(res => {
        console.log(res.data)
        this.qyFpList = res.data
        this.jxFpList = res.data.jxfpList
        this.xxFpList = res.data.xxfpList
        console.log(this.jxFpList)
        this.qysdsLoading = false
      })
    },
    getQysdsndsbData() {
      this.qysdsLoading = true
      const qysds = {
        param: this.qyjbxx.djxh,
        time: this.ndsbTime
      }
      getQyFxndsb(qysds).then(res => {
        this.qysdsList = res.data
        this.qysdsLoading = false
      })
    },
    getQyfxxxData() {
      this.qysdsLoading = true
      const dqyfxYf = {
        time: this.fxDjnd,
        param: this.qyjbxx.djxh
      }
      getQyFxmx(dqyfxYf).then(res => {
        this.qyFxList = res.data
        this.qysdsLoading = false
      })
    },
    getQySflData() {
      this.qysdsLoading = true
      const djxhNYf = {
        param: this.qyjbxx.djxh
      }
      getQySfl(djxhNYf).then(res => {
        this.qysflList = res.data
        this.qysdsLoading = false
      })
    },
    getqyCbrsData() {
      this.qysdsLoading = true
      const djxhNYf = {
        time: this.xyDjyf,
        param: this.qyjbxx.djxh
      }
      getQyCbrs(djxhNYf).then(res => {
        this.qycbrs = res.data
        console.log(res.data)
        this.qysdsLoading = false
      })
    },
    getQypjData() {
      this.qysdsLoading = true
      const djxhNd = {
        time: this.xyDjnd,
        param: this.qyjbxx.djxh
      }
      getQynsrXyDj(djxhNd).then(res => {
        this.pjdjList = res.data
        this.qysdsLoading = false
      })
    },
    getNsrzgData() {
      this.qysdsLoading = true
      const data = this.qyjbxx.djxh
      getNsrzg(data).then(res => {
        this.qynsrzgxx = [
          {
            name: '认定凭证UUID',
            value: res.data.rdpzuuid
          },
          {
            name: '登记序号',
            value: res.data.djxh
          },
          {
            name: '流程实例ID',
            value: res.data.lcslid
          },
          {
            name: '纳税人资格类型代码',
            value: res.data.nsrzglxDm
          },
          {
            name: '有效期起',
            value: res.data.yxqq
          },
          {
            name: '有效期止',
            value: res.data.yxqz
          },
          {
            name: '数据中止日期',
            value: res.data.sjzzrq
          }
        ]
        this.qysdsLoading = false
      })
    },
    getQygsxxData() {
      this.qysdsLoading = true
      const nsrmc = this.qyjbxx.nsrmc
      getQygsxx(nsrmc).then(res => {
        this.qygsxx = [
          {
            name: '统一社会信用代码',
            value: res.data.tyshxydm
          },
          {
            name: '企业名称',
            value: res.data.nsrmc
          },
          {
            name: '登记注册类型',
            value: res.data.djzclxDm
          },
          {
            name: '开业日期',
            value: res.data.kyrq
          },
          {
            name: '证照号码',
            value: res.data.zzhm
          },
          {
            name: '法人姓名',
            value: res.data.fddbrxm
          },
          {
            name: '法人证件类型',
            value: res.data.fddbrsfzjlxDm
          },
          {
            name: '法人证件号码',
            value: res.data.fddbrsfzjhm
          },
          {
            name: '法人固定电话',
            value: res.data.fddbrgddh
          },
          {
            name: '法人移动电话',
            value: res.data.fddbryddh
          },
          {
            name: '财务姓名',
            value: res.data.cwfzrxm
          },
          {
            name: '财务证件号码',
            value: res.data.cwfzrsfzjhm
          },
          {
            name: '财务固定电话',
            value: res.data.cwfzrgddh
          },
          {
            name: '财务移动电话',
            value: res.data.cwfzryddh
          },
          {
            name: '生产经营地址',
            value: res.data.scjydz
          },
          {
            name: '生产经营地行政区划代码',
            value: res.data.scjydzxzqhszDm
          },
          {
            name: '生产经营地 联系电话',
            value: res.data.scjydlxdh
          },
          {
            name: '生产经营地 邮政编码',
            value: res.data.scjydyzbm
          },
          {
            name: '国标行业',
            value: res.data.hyDm
          },
          {
            name: '从业人数',
            value: res.data.cyrs
          },
          {
            name: '批准设立机构名称',
            value: res.data.pzsljgmc
          },
          {
            name: '经营范围',
            value: res.data.jyfw
          }
        ]
        this.qysdsLoading = false
      })
    }
  }
}
</script>
