<!--
  @description: 范本库管理
  @Modifier: sunxinman
  @routerPath: /systemManagement/templateLibrary
  @date: 2020/04/10-10:45
-->
<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="{ SearchContent_show: toggleSearchStatus }" class="clearfix SearchContent">
        <div class="SearchContent_leftInput fl">
          <el-form
            ref="searchForm"
            :model="searchForm"
            inline
          >
            <!-- 文件名称 -->
            <el-form-item ref="templateName" label="文件名称" prop="templateName">
              <el-input v-model="searchForm.templateName" placeholder="请输入文件名称" />
            </el-form-item>
          </el-form>
        </div>
        <div class="fr">
          <el-button type="primary" size="small" @click="onSearch">
            搜 索
          </el-button>
          <el-button
            plain
            type="info"
            size="small"
            @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" plain @click="add">
          新 增
        </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
            prop="templateName"
            label="文件名称"
            min-width="180"
          />
          <!-- 模板类型 -->
          <el-table-column
            header-align="center"
            label="模板类型"
            prop="templateType"
            min-width="160"
          >
            <template slot-scope="scope">
              <span
                v-for="(item, index) in templateTypeList"
                v-if="scope.row.templateType === item.typecode"
                :key="index"
              >{{ item.typename }}</span>
            </template>
          </el-table-column>
          <!-- 专业类型 -->
          <el-table-column
            header-align="center"
            prop="industryType"
            label="专业类型"
            min-width="150"
          >
            <template slot-scope="scope">
              <span
                v-for="(item, index) in projectClassificationList"
                v-if="scope.row.industryType === item.typecode"
                :key="index"
              >{{ item.typename }}</span>
            </template>
          </el-table-column>
          <!-- 说明 -->
          <el-table-column
            header-align="center"
            prop="remark"
            label="说明"
            min-width="100"
            align="center"
          />
          <!-- 模板状态 -->
          <el-table-column
            header-align="center"
            prop="templateStatus"
            label="模板状态"
            align="center"
            width="100"
          >
            <template slot-scope="scope">
              <span
                v-for="(item, index) in templateStatusList"
                v-if="scope.row.templateStatus === item.typecode"
                :key="index"
              >{{ item.typename }}</span>
            </template>
          </el-table-column>
          <!-- 版本号 -->
          <el-table-column
            header-align="center"
            label="版本号"
            prop="versionNumber"
            width="90"
          />
          <el-table-column
            header-align="center"
            label="操作"
            fixed="right"
            width="150"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                @click.stop="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" />
      </section>
    </section>
    <!-- 新增/编辑范本弹框 -->
    <tempalteAdd v-if="dialogDataAdd.dialog" :dialog-data="dialogDataAdd" @watchChild="watchChild" />
    <!-- 查看范本详情弹框 -->
    <tempalteDetail v-if="dialogDataDetail.dialog" :dialog-data="dialogDataDetail" />
  </div>
</template>
<script>
/* 接口*/
import { getTemplateLibraryList, deleteTemplateLibraryById } from '@/api/common/tools.js' // 项目列表 项目删除
/* 公用方法*/
import { filterObj } from '@/assets/js/utils' // 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'
import { templateGroupMixin } from './mixins/templateGroupMixin'
/* 组件*/
import pagination from '@comp/common/pagination/pagination' // 分页
import tempalteAdd from './templateAdd-dialog' // 新增、编辑范本弹框
import tempalteDetail from './templateDetail-dialog' // 查看范本详情弹框
export default {
  name: 'TemplateLibraryList',
  components: {
    pagination, // 分页
    tempalteAdd, // 新增范本
    tempalteDetail // 范本详情
  },
  mixins: [ListMixin, templateGroupMixin],
  data() {
    return {
      loading: true,
      // 搜索
      searchForm: {
        templateName: '' // 文件名称
      },
      tableData: [],
      dialogDataAdd: {
        dialog: false, // 新增范本弹框
        type: '00' // 00新增；01编辑
      },
      dialogDataDetail: {
        dialog: false // 范本弹框详情
      }
    }
  },
  created() {
    // 获取列表信息
    this.loadData()
  },
  methods: {
    // 获取数据
    loadData() {
      const params = this.getQueryParams() // 查询条件
      getTemplateLibraryList(params)
        .then(response => {
          this.loading = false
          this.tableData = response.data.records
          this.paginationData.total = response.data.total
        })
        .catch(() => {})
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 编辑
    edit(row) {
      this.dialogDataAdd = {
        dialog: true,
        type: '01',
        id: row.id
      }
    },
    // 查看
    view(row) {
      this.dialogDataDetail.dialog = true
      this.dialogDataDetail.id = row.id
    },
    // 搜索
    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()
    },
    // 新增
    add() {
      this.dialogDataAdd = {
        dialog: true,
        type: '00'
      }
    },
    // 删除
    del(row) {
      this.$confirm('确认删除该条记录吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        deleteTemplateLibraryById(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>
.SearchContent_leftInput {
  width: calc(100% - 300px) !important;
}
</style>
