<!--
  @description:采购立项-项目管理(招标)
  @Modifier:郝定康
  @routerPath:/procurement/biDManageList
  @date:2021-01-28 10:28:06
-->
<template>
  <div>
    <table-crud
      ref="tableCrud"
      :menu="true"
      :search-form="searchForm"
      search-label-width="100px"
      @on-load="loadData"
    >
      <!--标题-->
      <!-- <div class="title title_border p0-16">
        <i class="el-icon-s-home" />采购单管理（{{ $route.meta.tenderMethodText }}）
      </div> -->
      <template v-slot:header>
        <span>采购单管理（{{ $route.meta.tenderMethodText }}）</span>
      </template>

      <!--查询条件-->
      <template v-slot:search="search">
        <el-form-item ref="tenderNo" label="采购单编号" prop="tenderNo">
          <el-input
            v-model.trim="searchForm.tenderNo"
            placeholder="请输入采购单编号"
            style="width:310px"
            @keyup.enter.native="search.onSearch"
          />
        </el-form-item>
        <el-form-item
          ref="tenderName"
          label="采购单名称"
          prop="tenderName"
        >
          <el-input
            v-model.trim="searchForm.tenderName"
            placeholder="请输入采购单名称"
            style="width:310px"
            @keyup.enter.native="search.onSearch"
          />
        </el-form-item>
        <el-form-item
          ref="tenderMethod"
          label="公开/邀请"
          class="list_seach_select"
          prop="tenderMethod"
        >
          <el-select v-model="searchForm.tenderType" placeholder="请选择" style="width:310px">
            <el-option
              v-for="item in tenderTypeList"
              :key="item.typename"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <el-form-item ref="date" label="创建日期 " prop="date">
          <el-date-picker
            v-model="searchForm.createTimeBegin"
            :value-format="elValueFormatDate"
            :clearable="false"
            type="date"
            align="right"
            placeholder="选择日期时间"
            style="width:149px"
          />
          ~
          <el-date-picker
            v-model="searchForm.createTimeEnd"
            :value-format="elValueFormatDate"
            :clearable="false"
            type="date"
            align="right"
            placeholder="选择日期时间"
            style="width:149px"
          />
        </el-form-item>
        <el-form-item
          label="采购组织形式"
          class="list_seach_select"
          prop="tenderOrgMethod"
        >
          <el-select
            v-model="searchForm.tenderOrgMethod"
            placeholder="请选择"
            style="width:310px"
          >
            <el-option
              v-for="item in plan_purchase_organizationList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
      </template>
      <template v-slot:GXTable>
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
        >
          <el-table-column
            type="index"
            label="序号"
            min-width="60px"
            align="center"
          />
          <el-table-column
            header-align="center"
            align="left"
            label="采购单编号/名称"
            min-width="230"
          >
            <template slot-scope="scope">
              <p>{{ scope.row.tenderNo }}</p>
              <p>{{ scope.row.tenderName }}</p>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="是否框架"
            width="80"
            align="center"
            prop="planType"
          />
          <el-table-column
            header-align="center"
            label="公开/邀请"
            min-width="80"
            align="center"
          >
            <template slot-scope="scope">
              {{ filterDictText(tenderTypeList,scope.row.tenderType ) }}
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="采购组织形式"
            min-width="100"
            align="center"
          >
            <template slot-scope="scope">
              {{ filterDictText(plan_purchase_organizationList,scope.row.tenderOrgMethod ) }}
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="创建日期"
            align="center"
            min-width="130"
          >
            <template slot-scope="scope">
              {{ scope.row.createTime && $Moment(scope.row.createTime).format(momentDateTime) }}
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="状态"
            align="center"
            width="110"
          >
            <template slot-scope="scope">
              <span v-if="!scope.row.auditStatus">待处理</span>
              <span v-else>{{ filterDictText(auditStatusList,scope.row.auditStatus ) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="操作"
            align="center"
            min-width="180"
          >
            <template slot-scope="scope">
              <!-- roleCode角色code 采购员11显示其他角色不显示 -->
              <template v-if="roleCode==='11'">
                <!--auditStatus 审核状态 00:待审核 01:审核通过 02:审核不通过-->
                <el-link
                  v-if="!scope.row.auditStatus || scope.row.auditStatus==='02'"
                  :underline="false"
                  type="primary"
                  size="mini"
                  plain
                  @click.stop="redactProject(scope.row)"
                >
                  [编辑]
                </el-link>
                <el-link
                  v-if="scope.row.sourceType.indexOf('01A') !== -1 && scope.row.purchaseProjectStatus==='00'"
                  :underline="false"
                  type="primary"
                  size="mini"
                  plain
                  @click="callbackfn(scope.row, '00')"
                >
                  [退回分配]
                </el-link>
              </template>
              <el-link
                :underline="false"
                type="primary"
                size="mini"
                plain
                @click.stop="intoProject(scope.row)"
              >
                [查看]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </table-crud>
    <!-- 退回分配 -->
    <projectRelease v-if="dialogProjectRelease.dialog" :dialog-data="dialogProjectRelease" @projectRelease="projectRelease" />
  </div>
</template>
<script>
/* 接口*/
import { listTenderManagementPages, cancelPurchase } from '@/api/procurement/procurementProject'// 项目列表 项目删除
/* 公用方法*/
import { filterDictText } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { initGroupMixin } from '@/mixins/initGroupMixin'// 字典信息
import { commonMxin } from '@/mixins/commonMxin'// 字典信息
/* 常用方法*/
import { procurementGroupMixins } from '@/views/procurement/mixins/procurementGrounpMixins'
import { procurementProjectMixins } from '../mixins/procurementProjectMixins'

/* 组件*/
import projectRelease from '@/views/procurement/procurementProject/procurementProjectLineItemInfo/procurementProjectRelease-dialog.vue' // 项目整单释放退回弹框

export default {
  name: 'BiDManageList',
  components: {
    projectRelease // 项目释放退回弹框
  },
  mixins: [initGroupMixin, commonMxin, procurementGroupMixins, procurementProjectMixins],
  data() {
    return {
      loading: true,
      roleCode: '', // 角色code
      date: [], // 搜索时间选择数据
      // 搜索
      searchForm: {
        tenderNo: '', // 采购项目编号
        tenderName: '', // 采购项目名称
        tenderType: '', // 公开/邀请
        createTimeBegin: '', // 创建开始时间
        createTimeEnd: '', // 创建结束时间
        quoteEndTimeBegin: '', // 报价截止时间开始时间
        quoteEndTimeEnd: '', // 报价截止时间开始结束
        tenderOrgMethod: '' // 组织形式
      },
      // 整单释放 整单退回参数字段
      releaseProject: {
        tenderId: '', // 项目id
        reason: '' // 释放说明字段
      },
      // 项目释放退回弹框
      dialogProjectRelease: {
        dialog: false,
        status: '' // 区分整单释放和退回字段 00释放 01退回
      },
      tableData: [], // 列表数据
      auditStatusList: [
        { typename: '待审核', typecode: '00' },
        { typename: '审核通过', typecode: '01' },
        { typename: '审核不通过', typecode: '02' }
      ]
    }
  },
  watch: {
    date(val) {
      this.searchForm.createTimeBegin = val[0]
      this.searchForm.createTimeEnd = val[1]
    }
  },
  created() {
    // 查询项目状态
    this.initProjectBase()
    // 字典信息
    this.initWebTypeGroup()
  },
  methods: {
    filterDictText, // 字典值替换文本
    // 获取列表数据
    loadData(params, callback, tabData) {
      // const params = this.getQueryParams()// 查询条件
      listTenderManagementPages(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        callback(response.data.total)
        this.roleCode = this.$store.getters.info.currentRol.roleCode // 角色code
      }).catch(() => {
        this.loading = false
      })
    },
    // 编辑
    redactProject(row) {
      // 判断项目id
      if (row.id) {
        this.$router.push({
          path: '/procurement/procurementBaseContentAdd',
          query: {
            tenderId: row.id, // 项目id
            tenderOrgMethod: row.tenderOrgMethod // 项目组织形式
          }
        })
      }
    },

    // 查看
    intoProject(row) {
      this.$router.push({
        path: '/procurement',
        name: 'procBidContentDetail',
        params: {
          tenderId: row.id, // 项目id
          packId: row.packId, // 标段id
          tenderType: row.tenderType // 采购类型
        }
      })
    },
    // 整单释放  整单退回
    callbackfn(row, status) {
      if (row.id) {
        this.releaseProject.tenderId = row.id // 获取项目id
        this.dialogProjectRelease.status = status // 区分整单释放或者整单退回字段 00 释放 01 退回
        this.dialogProjectRelease.dialog = true // 开启释放说明弹框
      }
    },
    // 整单释放/整单退回释放说明的弹框回调
    projectRelease(releaseData) {
      this.releaseProject.reason = releaseData.reason // 获取释放说明

      setTimeout(() => {
      // 整单释放
        this.$confirm('确认将采购单退回采购室主任重新分配？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          // 调用整单释放 整单退回请求
          this.cancelPurchaseRequest(this.releaseProject)
        }).catch(() => {
        })
      }, 500)
    },
    // 整单释放 整单说明接口请求
    cancelPurchaseRequest(data) {
      cancelPurchase(data).then(res => {
        this.$message.success('操作成功')
        // 刷新列表
        this.$refs.tableCrud.onSearchChange()
      }).catch(() => {

      })
    }
  }
}
</script>
<style lang="less" scoped>
    /deep/ .el-textarea__inner {
        padding: 1px 15px;
        line-height: 0.9;
    }
</style>
