<template>
  <div class="app-container">
    <div class="container-main">
      <div class="elect-cont-left">
        <div class="head-container">
          <el-select v-model="form.fondsId" placeholder="请选择" style="width: 225px;" @change="changeFondsValue($event)">
            <el-option
              v-for="(item,index) in fondsOptions"
              :key="index"
              :label="item.fondsName"
              :value="item.id"
            />
          </el-select>
        </div>
        <div class="container-left">
          <span class="right-top-line" />
          <span class="left-bottom-line" />
          <ul class="left-annual-type">
            <li class="active">本单位填报（6）</li>
            <li>下级上报（0）</li>
            <li>汇总上报（0）</li>
          </ul>
        </div>
      </div>

      <div class="elect-cont-right">
        <div class="head-container" style="position: relative;">
          <crudOperation :permission="permission">
            <template v-slot:middle>
              <el-button slot="reference" size="mini" :loading="crud.delAllLoading" :disabled="crud.selections.length === 0" @click="toDelete(crud.selections)">
                <i class="iconfont icon-shanchu" />
                删除
              </el-button>
            </template>
          </crudOperation>
          <div class="double-click-btn" style="top: 3px;"><i class="iconfont icon-zhuyi-lan" /><span>双击列表数据查看年报详情</span></div>
        </div>
        <div class="container-right">
          <span class="right-top-line" />
          <span class="left-bottom-line" />
          <el-table
            ref="table"
            v-loading="loading"
            class="archives-table"
            :data="tableData"
            @selection-change="crud.selectionChangeHandler"
            @row-click="clickRowHandler"
            @row-dblclick="handleDbClick"
          >
            <el-table-column type="selection" align="center" width="55" />
            <el-table-column label="年度" prop="year" />
            <el-table-column label="统计模板" prop="template" min-width="150px" />
            <el-table-column label="填报单位" prop="unit" />
            <el-table-column label="创建人" prop="creator" />
            <el-table-column prop="create_time" label="创建日期">
              <template slot-scope="scope">
                <div>{{ scope.row.create_time | parseTime }}</div>
              </template>
            </el-table-column>
            <el-table-column label="备注" prop="remark" />
            <el-table-column label="状态" prop="status" align="center">
              <template slot-scope="scope">
                <!-- <div>{{ scope.row.status === 0 ? '录入中' : '已汇总' }}</div> -->
                <span v-if="scope.row.status === 0" class="row-state row-physical state-active">录入中</span>
                <span v-else class="row-state row-binding state-active">已汇总</span>
              </template>
            </el-table-column>
            <!-- <el-table-column label="操作" align="center" prop="deptsStatus" /> -->
          </el-table>
          <!--分页组件-->
          <!-- <pagination v-if="crud.data.length!==0" /> -->
        </div>
      </div>
    </div>

    <el-dialog append-to-body :close-on-click-modal="false" :before-close="handleCloseDialog" :visible.sync="detailVisible" title="详情">
      <div class="setting-dialog">
        <ul class="annual-dialog-detail">
          <li class="detail-item">
            <div class="detail-item-left">年度：</div>
            <div class="detail-item-right">{{ detailContent && detailContent.year }}</div>
          </li>
          <li class="detail-item">
            <div class="detail-item-left">年报模板：</div>
            <div class="detail-item-right">2019</div>
          </li>
          <li class="detail-item">
            <div class="detail-item-left">填报单位：</div>
            <div class="detail-item-right">{{ detailContent && detailContent.unit }}</div>
          </li>
          <li class="detail-item">
            <div class="detail-item-left">报表模板：</div>
            <div class="detail-item-right">{{ detailContent && detailContent.template }}</div>
          </li>
          <li class="detail-item">
            <div class="detail-item-left">填报人：</div>
            <div class="detail-item-right">{{ detailContent && detailContent.creator }}</div>
          </li>
          <li class="detail-item">
            <div class="detail-item-left">上报至：</div>
            <div class="detail-item-right">{{ detailContent && detailContent.upToUint }}</div>
          </li>
          <li class="detail-item">
            <div class="detail-item-left">上报日期：</div>
            <div class="detail-item-right">{{ detailContent && detailContent.upToDate | parseTime }}</div>
          </li>
          <li class="detail-item">
            <div class="detail-item-left">备注：</div>
            <div class="detail-item-right">{{ detailContent && detailContent.remark }}</div>
          </li>
          <li class="detail-item">
            <div class="detail-item-left">附件列表：</div>
            <div class="detail-item-right" />
          </li>
        </ul>
        <div slot="footer" class="dialog-footer">
          <!-- <router-link to="/local-html">跳转到本地HTML文件</router-link> -->
          <el-button type="primary" @click="goToHtml">报表详情</el-button>
          <!-- <el-button type="text" @click="detailVisible=false">确定</el-button> -->
        </div>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import crudDept from '@/api/system/dept'
import { FetchFondsAll } from '@/api/system/fonds'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'

const defaultForm = { id: null, fondsId: null }
const data = [
  {
    'year': 2024,
    'template': '《档案室基本情况表》（2019版）',
    'unit': '武汉飞天智能',
    'creator': '系统管理员',
    'create_time': '1706078799000',
    'status': 1,
    'remark': '',
    'upToUint': '',
    'upToDate': null
  },
  {
    'year': 2023,
    'template': '《档案室基本情况表》（2019版）',
    'unit': '武汉飞天智能',
    'creator': '系统管理员',
    'create_time': '1706078799000',
    'status': 1,
    'remark': '',
    'upToUint': '武汉飞天智能',
    'upToDate': '1706078799000'
  },
  {
    'year': 2022,
    'template': '《档案室基本情况表》（2019版）',
    'unit': '武汉飞天智能',
    'creator': '系统管理员',
    'create_time': '1706078799000',
    'status': 1,
    'remark': '',
    'upToUint': '',
    'upToDate': null
  },
  {
    'year': 2021,
    'template': '《档案室基本情况表》（2019版）',
    'unit': '武汉飞天智能',
    'creator': '系统管理员',
    'create_time': '1706078799000',
    'status': 1,
    'remark': '',
    'upToUint': '',
    'upToDate': null
  },
  {
    'year': 2020,
    'template': '《档案室基本情况表》（2019版）',
    'unit': '武汉飞天智能',
    'creator': '系统管理员',
    'create_time': '1706078799000',
    'status': 1,
    'remark': '',
    'upToUint': '',
    'upToDate': null
  },
  {
    'year': 2019,
    'template': '《档案室基本情况表》（2019版）',
    'unit': '武汉飞天智能',
    'creator': '系统管理员',
    'create_time': '1706078799000',
    'status': 1,
    'remark': '',
    'upToUint': '',
    'upToDate': null
  }
]

export default {
  name: 'AnnualReportStatistics',
  components: { crudOperation },
  cruds() {
    return CRUD({ title: '年报统计', idField: 'deptsId', url: 'api/depts/initDeptsList', crudMethod: { ...crudDept }, optShow: {
      add: false,
      edit: false,
      del: false,
      reset: false,
      download: false,
      group: false
    },
    queryOnPresenterCreated: false
    })
  },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  data() {
    return {
      permission: {
        add: ['admin'],
        edit: ['admin'],
        del: ['admin']
      },
      fondsOptions: [],
      form: {
        'fondsId': null
      },
      loading: false,
      tableData: data,
      detailVisible: false,
      detailContent: {}
    }
  },
  mounted() {
    this.getFondsDatas()
  },
  methods: {
    getFondsDatas() {
      FetchFondsAll().then(res => {
        this.fondsOptions = res
        if (this.fondsOptions.length > 0) {
          this.form.fondsId = this.fondsOptions[0].id
        }
      })
    },
    changeFondsValue(value) {
      const obj = this.fondsOptions.find(function(item) {
        return item.id === value
      })
      console.log('obj', obj)
    },
    clickRowHandler(row) {
      this.$refs.table.clearSelection()
      this.$refs.table.toggleRowSelection(row)
    },
    handleDbClick(row) {
      this.detailVisible = true
      this.detailContent = row
    },
    handleCloseDialog() {
      this.detailVisible = false
    },
    goToHtml() {
      // 这里的 'test.html' 是你放在 public 目录下的 HTML 文件名称
      // window.location.href = 'report/annual.htm'
      window.open('report/annual.htm', '_blank')
    }
  }
}
</script>

<style lang="scss" scoped>
.left-annual-type{
  // padding: 20px 0;
  line-height: 36px;
  font-size: 14px;
  color: #0c0e1e;
  li{
    padding: 0 10px;
    &:hover,
    &.active{
      background-color: #e8f2ff;
      color: #0348f3;
      cursor: default;
    }
  }
}

.annual-dialog-detail{
  .detail-item{
    display: flex;
    justify-content: flex-start;
    line-height: 38px;
    font-size: 16px;
    .detail-item-left{
      width: 120px;
      text-align: right;
    }
    .detail-item-right{
      color: #0c0e1e;
    }
  }
}
</style>
