<!--
@description: 系统共享文档管理
@Modifier: zhuyanchao
@routerPath: /systemManagement/systemZipDoc-list
@date: 2020-7-11-15:23
-->
<template>
  <div>
    <!--标题-->
    <div class="title title_border p0-16">
      <i class="el-icon-s-home" />共享文档管理
    </div>
    <section class="p0-16">
      <!--查询条件-->
      <div class="crud_menu_title clearfix">
        <span class="icon-line fl">查询条件</span>
      </div>
      <section class="clearfix SearchContent">
        <div class="SearchContent_leftInput fl">
          <el-form
                  ref="searchForm"
                  :model="searchForm"
                  inline
                  label-width="98px"
                  label-position="left"
          >
            <!-- key键值 -->
            <el-form-item ref="fileName" label="文件名" prop="fileName">
              <el-input v-model.trim="searchForm.fileName" placeholder="文件名" style="width: 200px" />
            </el-form-item>
            <!-- 文档类别 -->
            <el-form-item ref="docType" label="文档类型" prop="docType">
              <el-select v-model="searchForm.docType" filterable placeholder="请选择" style="width: 120px">
                <el-option
                        v-for="(item,index) in docTypeList"
                        :key="index"
                        :label="item.typename"
                        :value="item.typecode"
                />
              </el-select>
            </el-form-item>
            <el-form-item ref="roleType" label="角色类型" prop="roleType">
              <el-select v-model="searchForm.roleType" filterable placeholder="请选择" style="width: 120px">
                <el-option
                        v-for="(item,index) in docRoleTypeList"
                        :key="index"
                        :label="item.typename"
                        :value="item.typecode"
                />
              </el-select>
            </el-form-item>
          </el-form>
        </div>
        <div class="fr">
          <el-button type="primary" @click="onSearch">
            搜索
          </el-button>
          <el-button plain type="info" @click="resetForm('searchForm')">
            重置
          </el-button>
        </div>
      </section>
      <!--查询结果-->
      <div class="crud_menu_title">
        <span class="icon-line">查询结果</span>
      </div>
      <div class="mb10">
        <el-button type="primary" @click="addConfig">
          新增共享文档
        </el-button>
      </div>
      <section>
        <el-table
                ref="smallTable"
                v-loading="loading"
                :data="tableData"
        >
          <el-table-column
                  type="index"
                  label="序号"
                  width="60px"
                  align="center"
          />
          <!-- 文件名 -->
          <el-table-column
                  align="center"
                  prop="fileName"
                  label="文件名"
                  min-width="50"
          />
          <!-- 角色类型 -->
          <el-table-column
                  align="center"
                  prop="docType"
                  label="角色类型"
                  min-width="50"
          >
            <template slot-scope="scope">
              <span
                      v-for="(item, index) in docRoleTypeList"
                      v-if="scope.row.roleType === item.typecode"
                      :key="index"
              >{{ item.typename }}</span>
            </template>
          </el-table-column>
          <!-- 文档类型 -->
          <el-table-column
                  align="center"
                  prop="docType"
                  label="文档类型"
                  min-width="50"
          >
            <template slot-scope="scope">
              <span
                      v-for="(item, index) in docTypeList"
                      v-if="scope.row.docType === item.typecode"
                      :key="index"
              >{{ item.typename }}</span>
            </template>
          </el-table-column>
          <!-- 上传时间 -->
          <el-table-column
                  align="center"
                  label="上传时间"
                  prop="createTime"
                  min-width="50"
          />
          <!-- 创建人 -->
          <el-table-column
                  prop="createUserName"
                  label="创建人"
                  align="center"
                  min-width="50"
          />
          <!-- 备注 -->
          <el-table-column
                  prop="memo"
                  label="备注"
                  align="center"
                  min-width="100"
          />
          <el-table-column
                  header-align="center"
                  label="操作"
                  align="center"
                  width="160"
          >
            <template slot-scope="scope">
              <el-link
                      :underline="false"
                      size="mini"
                      type="primary"
                      @click="edit(scope.row)"
              >
                [下载]
              </el-link>
              <el-link
                      type="primary"
                      @click.stop="view(scope.row)"
              >
                [查看]
              </el-link>
              <el-link
                      type="primary"
                      @click.stop="del(scope.row)"
              >
                [删除]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
        <!-- 新增/编辑系统配置弹框 -->
        <systemZipDocAdd v-if="dialogDataAdd.dialog" :dialog-data="dialogDataAdd" @watchChild="watchChild" />
        <!-- 查看共享文档详情弹框 -->
        <systemZipDocDetail v-if="dialogDataDetail.dialog" :dialog-data="dialogDataDetail" />
      </section>
    </section>
</div>
</template>

<script>
/* 接口*/
import { listSystemDocZipPages, delSystemZipDocById } from '@/api/common/systemConfigCenter'// 共享文档
import { systemZipDocMixin } from './mixins/systemZipDocMixin'
import { downLoadFile } from '@/api/common/uploadCenter'
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 常用方法
/* 组件*/
import upload from '@comp/common/updownload/upload'
import { download } from '@/assets/js/utils'
import { ListMixin } from '@/mixins/ListMixin'// 分页
import pagination from '@comp/common/pagination/pagination'// 分页
import systemZipDocAdd from './systemZipDocAdd-dialog' // 新增、编辑系统配置弹框
import systemZipDocDetail from './systemZipDocDetail-dialog' // 查看共享文档弹框
import downloadFile from '@comp/common/updownload/downloadFile'
import Cookies from 'js-cookie'
export default {
  name: 'SystemDocList',
  components: {
    pagination, // 分页
    systemZipDocAdd, // 新增系统配置
    upload,
    downloadFile,
    systemZipDocDetail // 查看共享文档
  },
  mixins: [ListMixin, systemZipDocMixin],
  data() {
    return {
      action: '/bidprocurement/common-tools/systemConfig/uploadSystemDocZip',
      importHeaders: {}, // cookit
      upLoadData: {
        fileType: 'system_doc_zip_attachment '// 文件类型
      },
      loading: true,
      // 搜索
      searchForm: {
        fileName: '', // key键值
        docType: '',
        roleType: '',
        createUserName: ''
      },
      tableData: [],
      dialogDataAdd: {
        dialog: false, // 新增共享文档弹框
        useStatus: '01' // 00禁用；01启用
      },
      dialogDataDetail: {
        dialog: false // 共享文档弹框详情
      }
    }
  },
  created() {
    this.importHeaders['X-AUTH-TOKEN'] = Cookies.get('X-AUTH-TOKEN')
    this.loadData()
  },
  methods: {
    // 获取数据
    loadData() {
      const params = this.getQueryParams()// 查询条件
      listSystemDocZipPages(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 新增配置
    addConfig() {
      this.dialogDataAdd = {
        dialog: true,
        id: null
      }
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 获取列表信息
      this.loadData()
    },
    // 重置
    resetForm(formName) {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.$refs[formName].resetFields()
      // 获取列表信息
      this.loadData()
    },
    // 瞎子啊
    edit(row) {
      const data = {
        fileId: row.fileId, // row.fileId, // 附件id
        fileType: 'system_doc_zip_attachment' // 附件类型
      }
      downLoadFile(data).then(res => {
        download(res, row.fileName)
      })
    },
    // 查看共享文档
    view(row) {
      this.dialogDataDetail.dialog = true
      this.dialogDataDetail.id = row.id
    },
    // 删除
    del(row) {
      this.$confirm('确认删除该条记录吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        delSystemZipDocById(row.id).then(res => {
          if (res.header.ret === '0') {
            this.$message({
              type: 'success',
              message: '删除成功'
            })
            this.loadData()
          }
        })
      })
    },
    // 监听子组件
    watchChild(val) {
      if (val) {
        this.loadData()
      }
    }
  }

}
</script>

<style lang="less" scoped>

</style>
