<template>
  <div class="app-container">
    <el-card shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
      </div>
      <div style="margin-top: 15px">
        <el-form
          size="small"
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          @submit.native.prevent
        >
          <el-form-item label="企业名称">
            <el-input
              v-model="queryParams.companyName"
              @input="e => (queryParams.companyName = stripscript(e))"
              placeholder="请输入"
              style="min-width:270px"
            />
          </el-form-item>
          <el-form-item label="评估状态">
            <el-select
              v-model="queryParams.assessResult"
              clearable
              placeholder="请选择"
            >
              <el-option
                v-for="item in statusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleSearchList" size="small">
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
      <!-- <el-button
        style="margin-left:10px"
        class="btn-add"
        @click="upload.open = true"
        size="mini"
        type="primary"
      >
        导入
      </el-button> -->
      <el-button
        class="btn-add"
        @click="handlePage(null)"
        size="mini"
        type="primary"
      >
        添加企业
      </el-button>
    </el-card>
    <el-table
      style="width: 100%"
      class="table-container"
      :data="unscrambleList"
    >
      <el-table-column
        label="序号"
        align="center"
        type="index"
      ></el-table-column>
      <el-table-column label="企业全称" prop="companyName" align="center">
        <!-- <template slot-scope="scope">
          <el-link type="primary" :underline="false">{{
            scope.row.companyName
          }}</el-link>
        </template> -->
      </el-table-column>
      <el-table-column label="头像" align="center" prop="icon">
        <template slot-scope="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="scope.row.icon"
            fit="cover"
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="企业地址" align="center" prop="addressType">
        <template slot-scope="scope">
          <div v-if="scope.row.addressType == 4">
            {{
              optionList1.filter(item => item.value == scope.row.addressType)[0]
                .label
            }}
          </div>
          <div v-else>
            {{
              optionList1.filter(item => item.value == scope.row.addressType)[0]
                .label
            }}——{{ scope.row.cityName }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="用户姓名"
        align="center"
        prop="nickName"
      ></el-table-column>
      <el-table-column
        label="登录手机号"
        align="center"
        prop="username"
      ></el-table-column>
      <el-table-column label="评估状态" align="center" prop="assessResult">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.assess">已评估</el-tag>
          <el-tag v-else type="info">未评估</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <p>
            <el-button
              @click="handlePage(scope.row.id)"
              type="text"
              size="small"
              >编辑</el-button
            >
            <el-button
              @click="handleStatus(scope.row.id, false)"
              type="text"
              size="small"
              v-if="scope.row.deleteStatus != 1"
              >禁用</el-button
            >
            <el-button
              @click="handleStatus(scope.row.id, true)"
              type="text"
              size="small"
              v-else
              >启用</el-button
            >
            <el-button
              @click="handleDelete(scope.row.id)"
              type="text"
              size="small"
              >删除</el-button
            >
          </p>
          <p>
            <el-button
              @click="handleCollecDialog(scope.row)"
              type="text"
              size="small"
              >收藏统计</el-button
            >
            <el-button
              @click="handleDialog(scope.row)"
              type="text"
              size="small"
              :disabled="!scope.row.assess ? true : false"
              >评估结果</el-button
            >
          </p>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 用户导入对话框 -->
    <!-- <el-dialog
      title="导入"
      :visible.sync="upload.open"
      width="400px"
      append-to-body
    >
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-link type="primary" style="font-size:12px" @click="importTemplate"
            >下载模板</el-link
          >
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">
          提示：仅允许导入“xls”或“xlsx”格式文件！
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog> -->
    <!-- 收藏列表弹框 -->
    <el-dialog title="收藏列表" :visible.sync="openDialog" width="78%">
      <el-table :data="dialogData">
        <el-table-column
          property="id"
          label="序号"
          width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          property="method"
          label="产生"
          width="150"
          align="center"
        >
          <template slot-scope="scope">
            {{
              methodOptions.filter(item => item.value == scope.row.method)[0]
                .label
            }}
          </template>
        </el-table-column>
        <el-table-column
          property="title"
          label="政策标题"
          align="center"
        ></el-table-column>
        <el-table-column property="level" label="级别" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.level == 1">安徽省</span>
            <span v-if="scope.row.level == 2">地级市</span>
            <span v-if="scope.row.level == 3">合肥区县</span>
          </template>
        </el-table-column>
        <el-table-column property="attribute" label="归口" align="center">
          <template slot-scope="scope">
            {{
              attributeOptions.filter(
                item => item.value == scope.row.attribute
              )[0].label
            }}
          </template>
        </el-table-column>
        <el-table-column
          property="listDate"
          label="发布日期"
          align="center"
        ></el-table-column>
        <el-table-column
          property="source"
          label="来源"
          align="center"
        ></el-table-column>
      </el-table>
      <pagination
        v-show="dialogTotal > 0"
        :total="dialogTotal"
        :page.sync="query.pageNum"
        :limit.sync="query.pageSize"
        @pagination="getCollecList"
      />
    </el-dialog>
    <!-- 评估结果弹框 -->
    <el-dialog
      class="result-dialog"
      title="评估结果"
      :visible.sync="dialogVisible"
      width="55%"
    >
      <el-row :gutter="20">
        <el-col :span="24">
          <el-card class="box-card">
            <el-form ref="formA" :model="formA" disabled>
              <h3>A 高企认定门槛</h3>
              <section class="padding-left">
                <h4>一、企业基本情况</h4>
                <el-form-item label="企业名称">
                  <el-input
                    v-model.trim="formA.companyName"
                    style="max-width: 420px"
                  ></el-input>
                </el-form-item>
                <el-form-item label="成立时间">
                  <el-date-picker
                    v-model="formA.regTime"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    type="datetime"
                    placeholder="选择日期时间"
                  >
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="所属领域">
                  <el-col :span="6">
                    <el-form-item>
                      <el-select v-model="formA.territoryIName"> </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item>
                      <el-select v-model="formA.territoryIIName"> </el-select>
                    </el-form-item>
                  </el-col>
                </el-form-item>
                <el-form-item label="拥有在所属领域发挥核心作用的知识产权？">
                  <el-select
                    v-model="formA.hasIntellectualProperty"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in propertyOption"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <h4>二、财务数据（单位：万元）</h4>
                <el-form-item label="上一年企业总收入">
                  <el-input-number
                    v-model="formA.lastYearTotalRevenue"
                  ></el-input-number>
                </el-form-item>
                <el-form-item label="上一年主营业务部分收入">
                  <el-input-number
                    v-model="formA.lastYearBusinessRevenue"
                  ></el-input-number>
                </el-form-item>
                <el-form-item label="上一年研发总支出">
                  <el-input-number
                    v-model="formA.lastYearResearchExpend"
                  ></el-input-number>
                </el-form-item>
                <h4>三、人力资源</h4>
                <el-form-item label="上一年企业总员工数">
                  <el-input-number
                    v-model="formA.totalEmployee"
                  ></el-input-number>
                </el-form-item>
                <el-form-item label="上一年企业入职满183天的科技员工数">
                  <el-input-number
                    v-model="formA.scienceEmployee"
                  ></el-input-number>
                </el-form-item>
                <h4>四、其他</h4>
                <el-form-item
                  label="企业上一年内未发生重大安全、重大质量事故或严重环境违法行为。 "
                >
                  <el-select v-model="formA.hasBad" placeholder="请选择">
                    <el-option
                      v-for="item in propertyOption"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </section>
            </el-form>
          </el-card>
          <el-card class="box-card" style="margin-top:15px">
            <el-form ref="formA" :model="formA" disabled>
              <section class="padding-left">
                <h3>B 创新指标评分</h3>
                <h4>一、知识产权</h4>
                <el-form-item
                  label="自主研发的Ⅰ类（发明专利、植物新品种、国家新药、集成电路布图等）数量："
                >
                  <el-input-number
                    class="w120"
                    v-model="formA.propertyNumI"
                  ></el-input-number>
                  <!-- <el-input v-model="formA.name" class="w120"></el-input> -->
                </el-form-item>
                <el-form-item
                  label="自主研发的Ⅱ类（实用新型专利、外观设计专利、软件著作权等（不含商标））数量："
                >
                  <el-input-number
                    class="w120"
                    v-model="formA.propertyNumII"
                  ></el-input-number>
                </el-form-item>
                <el-form-item
                  label="企业参与过编制国家标准、行业标准、检测方法、技术规范？"
                >
                  <el-select v-model="formA.hasStandard" placeholder="请选择">
                    <el-option
                      v-for="item in propertyOption"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <h4>二、科技成果转化</h4>
                <el-form-item label="近三年年均成果转化数量：">
                  <el-input-number
                    class="w120"
                    v-model="formA.achievementNum"
                  ></el-input-number>
                </el-form-item>
                <h4>三、组织管理水平（多选）</h4>
                <el-checkbox-group v-model="formA.management">
                  <el-checkbox :label="1">
                    制定了企业研究开发的组织管理制度，建立了研发投入核算体系，编制了研发费用辅助账。
                  </el-checkbox>
                  <el-checkbox :label="2">
                    设立了内部科学技术研究开发机构并具备相应的科研条件，与国内外研究开发机构开展多种形式产学研合作
                  </el-checkbox>
                  <el-checkbox :label="3">
                    建立了科技成果转化的组织实施与激励奖励制度，建立开放式的创新创业平台。
                  </el-checkbox>
                  <el-checkbox :label="4">
                    建立了科技人员的培养进修、职工技能培训、优秀人才引进，以及人才绩效评价奖励制度。
                  </el-checkbox>
                  <br />
                  <el-checkbox :label="5">
                    以上选项都不匹配。
                  </el-checkbox>
                </el-checkbox-group>
                <h4>四、企业成长性</h4>
                <el-form-item
                  label="净资产增长率赋值（其中合肥市高新区企业，政策兑现要求上一年度净资产达40万元以上） "
                >
                  <el-select
                    style="max-width: 95px"
                    v-model="formA.assetGrowth"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in assetOption"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="销售收入增长率赋值">
                  <el-select v-model="formA.sellGrowth" placeholder="请选择">
                    <el-option
                      v-for="item in assetOption"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </section>
            </el-form>
          </el-card>
        </el-col>
        <!-- <el-col :span="14">
          
        </el-col> -->
      </el-row>
    </el-dialog>
  </div>
</template>
<script>
import {
  getCategoryList,
  handleCompanyUser,
  deleteCompanyUser,
  resetPw,
  getPolicyCollect
} from '@/api/customer';
import { parseTime } from '@/utils/ruoyi';
import { getToken } from '@/utils/auth';
export default {
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      total: 0,
      unscrambleList: [],
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: '',
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: 'Bearer ' + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + '/system/user/importData'
      },
      // 产出选项
      methodOptions: [
        {
          value: 1,
          label: '爬虫'
        },
        {
          value: 2,
          label: '手动添加'
        }
      ],
      // 归口选项
      attributeOptions: [
        {
          value: 'KJJ',
          label: '科技'
        },
        {
          value: 'JXJ',
          label: '经信'
        },
        {
          value: 'FGW',
          label: '发改'
        },
        {
          value: 'OTHER',
          label: '其他'
        }
      ],
      optionList1: [
        {
          value: '2',
          label: '地级市'
        },
        {
          value: '3',
          label: '合肥区县'
        },
        {
          value: '4',
          label: '其它'
        }
      ],
      statusOptions: [
        {
          value: 1,
          label: '已评估'
        },
        {
          value: 0,
          label: '未评估'
        }
      ],
      openDialog: false,
      dialogVisible: false,
      query: {
        pageNum: 1,
        pageSize: 10
      },
      rouId: null,
      dialogTotal: 0,
      dialogData: [],
      formA: {},
      oneMenuList: [], // 所属领域一级菜单
      twoMenuList: [], // 所属领域二级菜单
      propertyOption: [
        {
          value: 0,
          label: '否'
        },
        {
          value: 1,
          label: '是'
        }
      ], // 核心领域发挥作用知识产权 0->否 1->是   和   四、其他
      assetOption: [
        {
          value: 35,
          label: '>=35%'
        },
        {
          value: 25,
          label: '>=25%'
        },
        {
          value: 15,
          label: '>=15%'
        },
        {
          value: 5,
          label: '>=5%'
        },
        {
          value: 1,
          label: '>0%'
        },
        {
          value: 0,
          label: '<=0%'
        }
      ]
    };
  },
  methods: {
    handleSearchList() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getList() {
      getCategoryList(this.queryParams).then(({ data }) => {
        this.unscrambleList = data.list;
        this.total = data.total;
      });
    },
    handleStatus(companyId, isOpen) {
      handleCompanyUser({ companyId, isOpen }).then(({ message }) => {
        this.msgSuccess(message);
        this.getList();
      });
    },
    // 跳转页面
    handlePage(id) {
      this.$router.push({ path: '/addCustomer', query: { id } });
    },
    /** 删除按钮操作 */
    handleDelete(companyId) {
      this.$confirm('确认删除该数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(function() {
          return deleteCompanyUser({ companyId });
        })
        .then(() => {
          this.getList();
          this.msgSuccess('删除成功');
        });
    },
    handleDialog(row) {
      if (!row.assess || row.assess == '') return this.msgError('暂未评估');
      this.dialogVisible = true;
      const data = JSON.parse(row.assess);
      data.regTime = parseTime(data.regTime);
      this.formA = data;
    },
    handleCollecDialog(row) {
      this.openDialog = true;
      this.rouId = row.userId
      this.getCollecList();
    },
    getCollecList() {
      getPolicyCollect(Object.assign({},this.query,{userId:this.rouId})).then(({data})=>{
        this.dialogData = data.list
        this.dialogTotal = data.total
      })
    },
    /** 下载模板操作 */
    importTemplate() {
      // importTemplate().then(response => {
      //   this.download(response.msg);
      // });
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, '导入结果', { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  },
  created() {
    this.getList();
  }
};
</script>
<style lang="scss" scoped>
.w120 {
  width: 120px;
}
@media screen and (min-width: 1440px) {
  /deep/.el-dialog {
    // width: 55% !important;
    .el-form-item {
      margin-bottom: 12px;
    }
  }
}
// /deep/.el-checkbox__inner {
//   background-color: black !important;
//   border-color: black !important;
//   &::after {
//     border-color: white !important;
//   }
// }
</style>
