<!--
  @description: 采购人/代理机构-建设项目-列表
  @author: 肖文龙
  @routerPath:/buildingProject/buildingProjectList
  @date： 2019-12-4 09:35:58
-->
<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>
        <span class="fr pointer" @click="handleToggleSearch">
          <el-link
            :underline="false"
            :class="toggleSearchStatus?'arrow-is-active':''"
            type="primary"
            class="toggleSearchStatus icon el-icon-arrow-down"
          />
          {{ toggleSearchStatus?'收起高级查询' :'展开高级查询' }}
        </span>
      </div>
      <section :class="{'SearchContent_show':toggleSearchStatus}" class="clearfix SearchContent">
        <div class="SearchContent_leftInput fl">
          <el-form
            ref="searchForm"
            :model="searchForm"
            inline
            label-position="right"
          >
            <!--批准文号-->
            <el-form-item ref="approvalNo" label="批准文号" prop="approvalNo">
              <el-input
                v-model.trim="searchForm.approvalNo"
                placeholder="批准文号"
                width="228px"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!--建设项目编码-->
            <el-form-item ref="projectNo" label="建设项目编码" prop="projectNo">
              <el-input
                v-model.trim="searchForm.projectNo"
                placeholder="建设项目编码"
                width="228px"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!--创建人-->
            <el-form-item ref="createUser" label="创建人" prop="createUser">
              <el-input
                v-model.trim="searchForm.createUser"
                placeholder="创建人"
                width="228px"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!--建设项目名称-->
            <el-form-item ref="projectName" label="建设项目名称" prop="projectName">
              <el-input
                v-model.trim="searchForm.projectName"
                placeholder="建设项目名称"
                width="228px"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!--状态-->
            <el-form-item ref="auditStatus" label="状态" prop="auditStatus">
              <el-select v-model="auditStatus" placeholder="请选择" @change="selectAudit">
                <el-option
                  v-for="item in buildingProjectStatusList"
                  :key="item.typecode"
                  :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="consignContractAdd()">
          新 增
        </el-button>
      </div>
      <section>
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
        >
          <el-table-column
            type="index"
            label="序号"
            align="center"
            width="60"
            fixed="left"
            header-align="center"
          />
          <el-table-column

            prop="approvalNo"
            width="160"
            fixed="left"
            label="批准文号"
            header-align="center"
          />
          <el-table-column
            prop="projectNo"
            label="建设项目编码"
            width="165"
            header-align="center"
            align="center"
          />
          <el-table-column

            header-align="center"
            prop="projectName"
            align="left"
            min-width="300"
            label="建设项目名称"
          />
          <el-table-column
            header-align="center"
            prop="constructionProjectType"
            align="left"
            width="100"
            label="建设项目类型"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.constructionProjectType==='00'">基本建设项目</span>
              <span v-if="scope.row.constructionProjectType==='01'">生产运维项目</span>
            </template>
          </el-table-column>
          <el-table-column

            prop="createUser"
            label="创建人"
            align="center"
            header-align="center"
          />
          <el-table-column
            prop="createTime"
            label="创建时间"
            align="center"
            width="150"
            header-align="center"
          >
            <template slot-scope="scope">
              {{ scope.row.createTime && $Moment(scope.row.createTime).format(momentDateTime) }}
            </template>
          </el-table-column>
          <el-table-column
            prop="auditStatus"
            label="状态"
            align="center"
            header-align="center"
          >
            <template slot-scope="scope">
              <span
                v-for="(item,index) in buildingProjectStatusList"
                v-if="scope.row.auditStatus===item.typecode"
                :key="index"
              >{{ item.typename }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            header-align="center"
            align="left"
            fixed="right"
            width="230"
          >
            <template slot-scope="scope">
              <el-link type="primary" @click.stop="intoContract(scope.row)">
                [查看]
              </el-link>
              <el-link
                v-if="scope.row.useStatus==='01' && buildingProjectConfigType"
                type="primary"
                @click.stop="handleDetail(scope.row.id)"
              >
                [流程追踪]
              </el-link>
              <el-link
                v-if="scope.row.auditStatus === '' || scope.row.auditStatus === '02'"
                size="mini"
                type="primary"
                plain
                @click.stop="modificationContract(scope.row.id)"
              >
                [修改]
              </el-link>
              <el-link
                v-if="scope.row.auditStatus === '' || scope.row.auditStatus === '02'"
                type="primary"
                @click.stop="deleteContract(scope.row.id)"
              >
                [删除]
              </el-link>
              <el-link
                v-if="scope.row.auditStatus === '01'"
                type="primary"
                @click.stop="intoProject(scope.row)"
              >
                [招标项目]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
      </section>
    </section>
    <!--流程追踪查看弹框-->
    <flow-detail-dialog ref="tracingFlow" />
  </div>
</template>

<script>
/* api接口*/
import { getConstructionProjectByPage, removeConstructionProjectById } from '@/api/purchasePlan/taskplan'
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { buildingProjectGroupMixin } from '../../mixins/buildingProjectGroupMixin'// 字典信息
import { filterObj } from '@/assets/js/utils'
/* 组件*/
import pagination from '@comp/common/pagination/pagination' // 分页组件
import flowDetailDialog from '@views/work/process/flowDetail-dialog' //  流程追踪组件
export default {
  name: 'BuildingProjectList',
  components: {
    pagination,
    flowDetailDialog
  },
  mixins: [ListMixin, buildingProjectGroupMixin],
  data() {
    return {
      loading: true,
      date: '',
      auditStatus: null, // 下拉框
      searchForm: {
        auditStatus: '', // 审核状态
        approvalNo: '', // 批准文号
        projectNo: '', // 建设项目编码
        projectName: '', // 建设项目名称
        createUser: '' // 创建人
      },
      tableData: []
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    // 状态下拉框
    selectAudit(audit) {
      if (audit) {
        delete this.searchForm.useStatus
        this.searchForm.auditStatus = audit
      } else {
        delete this.searchForm.auditStatus
        this.searchForm.useStatus = '00'
      }
    },
    // 获取数据
    loadData() {
      const params = this.getQueryParams()// 查询条件
      getConstructionProjectByPage(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {
        this.loading = false
      })
    },
    // 查询条件
    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() {
      Object.keys(this.searchForm).forEach(val => {
        this.searchForm[val] = ''
      })
      this.auditStatus = null
      this.searchForm.pageNo = 1
      this.searchForm.pageSize = 10
      this.loadData()
    },
    // 新增建设项目
    consignContractAdd() {
      this.$router.push({ name: 'BuildingProjectAdd' })
    },
    // 修改
    modificationContract(id) {
      this.$router.push({
        name: 'BuildingProjectAdd',
        params: { id }
      })
    },
    // 删除
    deleteContract(id) {
      this.$confirm('是否确定删除，删除后信息将无法恢复！', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        removeConstructionProjectById(id).then(() => {
          this.$message({
            type: 'success',
            message: '删除成功'
          })
          this.loadData()
        }).catch()
      }).catch(() => {
      })
    },
    // 查看
    intoContract(row) {
      this.$router.push({
        path: '/buildingProject/buildingProjectDetail',
        name: 'BuildingProjectDetail',
        params: {
          detailType: '00', // 委托合同标题展示 00 查看建设项目 01 台账查看建设项目 02 审批建设项目
          id: row.id
        }
      })
    },
    // 招标项目
    intoProject(row) {
      // 进入二级列表页
      this.$router.push({
        path: '/buildingProject/buildingProjectCorrelationList',
        name: 'BuildingProjectCorrelationList',
        params: { id: row.id }
      })
    },
    // 流程追踪详情
    handleDetail(id) {
      this.$refs.tracingFlow.openDialogInitData(id)
    }
  }
}
</script>

<style lang="less" scoped>
  .SearchContent_leftInput{
    width: calc(100% - 300px) !important;
  }
</style>
