<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\enterprise\controller;

use app\enterprise\common\EnterpriseController;
use app\enterprise\api\TalentApi;
use app\common\api\DictApi;
use app\common\api\VerifyApi;

/**
 * Description of TalentLibrary
 *
 * @author sgq
 */
class TalentLibrary extends EnterpriseController {

    public function index() {
        return view("", ["type" => $this->user["type"]]);
    }

    public function list() {
        $res = TalentApi::getList($this->request, 3);
        return json($res);
    }

    public function export() {
        $setting = [];

        $params = $this->request->param();
        $fields = $params["export"];
        if (!$fields)
            return json(["msg" => "请选择要导出的数据"]);
        $names = DictApi::getTalentFields(4, in_array("isMatchZhiren", $fields));
        $names["industryFieldNew"] = "产业领域";
        $names["enterpriseName"] = "单位名称";
        $names["enterpriseTag"] = "单位标签";
        $names["street"] = "所属镇街";
        $names["breakFaithName"] = "曾被相关主管部门列为失信个人";
        $names["identifyMonth"] = "公布入选月份";
        $names["certificateNo"] = "人才编号";
        $names["activeName"] = "离职状态";
        $names["cur_quit_time"] = "离职时间";
        $names["first_submit_time"] = "首次确认提交时间";
        $names["new_submit_time"] = "最新确认提交时间";
        $list = VerifyApi::getExportDatas(7, $params);
        foreach ($fields as $field) {
            $columns[] = $names[$field];
        }
        $datas = [];
        for ($i = 0; $i < count($list); $i++) {

            if(count((array)$list[$i]) > 0){
                $data = [];
                for ($n = 0; $n < count($fields); $n++) {
                    $cellValue = $list[$i][$fields[$n]];
                    $data[] = $cellValue;
                }
                $datas[] = $data;
            }

        }
        $setting["freeze"] = "A2";
        $setting["filter"] = sprintf("A1:%s1", getExcelColumnByIndex(count($columns) - 1));
        if ($datas) {
            export($columns, $datas, "人才认定申报列表导出", $setting);
            exit();
        }
        echo "<script>parent.layer.alert('没有可以导出的数据');window.history.go(-1);</script>";
    }

}
