<!--
  @description:京能采购计划-框架计划编制
  @author: lxl
  @routerPath:/procurement/procurementPlanFrameList
  @date： 2020-8-3 13:40:01
-->
<template>
  <div>
    <table-crud
      ref="tableCrud"
      :menu="true"
      :tabs="tabList"
      :search-form.sync="searchForm"
      search-label-width="100px"
      @on-load="loadData"
    >
      <!--标题-->
      <template v-slot:header>
        <span>框架计划编制</span>
      </template>
      <!--查询条件-->

      <template v-slot:search="search">
        <!-- 采购单编号 -->
        <el-form-item
          ref="tenderNo"
          label="采购单编号"
          prop="tenderNo"
        >
          <gx-input
            v-model.trim="searchForm.tenderNo"
            @keyup.enter.native="search.onSearch"
          />
        </el-form-item>
        <!--框架计划编号-->
        <el-form-item
          ref="purchasePlanNo"
          label="框架计划编号"
          prop="purchasePlanNo"
        >
          <gx-input
            v-model.trim="searchForm.purchasePlanNo"
            @keyup.enter.native="search.onSearch"
          />
        </el-form-item>
        <!--采购方式-->
        <el-form-item ref="tenderMethod" label="采购方式" prop="tenderMethod">
          <el-select v-model="searchForm.tenderMethod" filterable placeholder="请选择">
            <el-option
              v-for="item in tenderMethodList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <!--公开/邀请-->
        <el-form-item ref="tenderType" label="公开/邀请" prop="tenderType">
          <el-select v-model="searchForm.tenderType" filterable placeholder="请选择">
            <el-option
              v-for="item in tenderTypeList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <!--审核状态-->
        <el-form-item ref="bizAuditStatus" label="审核状态" prop="bizAuditStatus">
          <el-select v-model="searchForm.bizAuditStatus" filterable placeholder="请选择">
            <el-option
              v-for="item in bizAuditStatusList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <!--供应商属性-->
        <el-form-item ref="supplierAttribute" label="供应商属性" prop="supplierAttribute">
          <el-select v-model="searchForm.supplierAttribute" filterable placeholder="请选择">
            <el-option
              v-for="item in supplierAttributeList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <!--供应商分类-->
        <el-form-item ref="supplierCategory" label="供应商分类" prop="supplierCategory">
          <el-select v-model="searchForm.supplierCategory" filterable placeholder="请选择">
            <el-option
              v-for="item in supplierCategoryList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
      </template>
      <template v-slot:menuLeft>
        <div class="mb10">
          <el-button type="primary" @click="implementPurchase">
            录入框架计划
          </el-button>
        </div>
      </template>
      <template v-slot:GXTable>
        <!-- 待提交 -->
        <framePurchaseTable v-if="searchForm.framePlanStatus==='00'" :table-data="tableData" :loading="loading" @orderData="onOrderData" @checkDetail="detail" @edit="edit" @deleteHandel="deleteHandel" />
        <!-- 已提交 -->
        <frameEstablishTable v-if="searchForm.framePlanStatus==='01'" :table-data="tableData" :loading="loading" @orderData="onOrderData" @checkDetail="detail" @handleFlow="handleFlow" />
        <!-- 已完成 -->
        <accomplishTable v-if="searchForm.framePlanStatus==='02'" :table-data="tableData" :loading="loading" @orderData="onOrderData" @checkDetail="detail" @handleFlow="handleFlow" />
      </template>
    </table-crud>
    <!-- 查看附件 -->
    <checkFIleCompDialog :dialog-file-data="dialogFileData" />
    <!--流程追踪查看弹框-->
    <flow-detail-dialog ref="tracingFlow" />
  </div>
</template>

<script>
/* api接口*/
import {
  deletePurchasePlanFramePack, // 删除
  getPurchasePlanFramePackList // 列表数据
} from '@/api/procurement/purchasplan'

/* 弹框*/
import checkFIleCompDialog from '@/views/procurement/procurementPlan/components/checkFIleComp-dialog.vue'// 查看附件
/* 表格*/
// 待提交
import framePurchaseTable from './framePurchaseTable.vue'
// 已提交
import frameEstablishTable from './frameEstablishTable.vue'
// 已完成
import accomplishTable from './accomplishTable.vue'

/* 公共参数方法*/
import { procurementPlanDictMixins } from '@/views/procurement/procurementPlan/mixins/procurementPlanDictMixins' // 字典信息
import { filterDictText } from '@/assets/js/utils' // 字典
/* 公共组件*/
import flowDetailDialog from '@views/work/process/flowDetail-dialog' //  流程追踪组件

export default {
  name: 'PurPlanFrameList',
  components: {
    flowDetailDialog, // 查看附件
    checkFIleCompDialog, // 流程追踪
    framePurchaseTable, // 待提交
    frameEstablishTable, // 已提交
    accomplishTable // 已完成
  },
  mixins: [procurementPlanDictMixins],
  data() {
    return {
      value: [], // 时间选择器搜索
      loading: true,
      /* -----------数据字典start-------------*/
      tenderMethodList: [], // 采购方式
      tenderTypeList: [], // 公开/邀请
      supplierAttributeList: [], // 供应商属性
      supplierCategoryList: [], // 供应商分类
      dictionaryType: ['tenderMethod', 'tenderType', 'supplierAttribute', 'supplierCategory'],
      /* -----------数据字典end-------------*/
      searchForm: {
        dataStatus: '', // 采购计划状态
        purchasePlanNo: '', // 框架计划编号
        tenderNo: '', // 采购单编号
        tenderMethod: '', // 采购方式
        tenderType: '', // 公开/邀请
        bizAuditStatus: '', // 审核状态
        supplierAttribute: '', // 供应商属性
        supplierCategory: '', // 供应商分类
        framePlanStatus: '00' // tabs状态
      },
      dialogFileData: {
        checkFileVisible: false, // 查看附件弹框状态
        bizId: ''
      },
      tabList: [
        {
          name: '待提交',
          index: '00'
        },
        {
          name: '已提交',
          index: '01'
        },
        {
          name: '已完成',
          index: '02'
        }
      ],
      tableData: [] // 表格数据
    }
  },
  created() {
    // 字典请求初始化
    this.getGroupType()
  },
  methods: {
    filterDictText,
    // 数据字典查询
    getGroupType() {
      this.$store.dispatch('getGroupType', this.dictionaryType).then((data) => {
        // 遍历key存储相应的数据
        for (const key in data.bidTypeData) {
          /* 是否有数据*/
          if (data.bidTypeData[key]) {
            this[key] = data.bidTypeData[key]
          }
        }
      })
    },
    // 进入新增录入采购计划页面
    // detailIder: 框架计划编制/采购计划编制状态码 '00'新增 '01' 编辑
    implementPurchase() {
      this.$router.push({ name: 'addFrameAdd', params: {
        detailIder: '01'
      }})
    },
    // 获取数据
    loadData(params, callback, tabData) {
      if (tabData) {
        params.framePlanStatus = tabData.index
        this.searchForm.framePlanStatus = tabData.index
      }
      // params.planType = '01' // 计划类型，00-采购计划;01-框架计划;
      getPurchasePlanFramePackList(params)
        .then(response => {
          this.searchForm.column = ''
          this.searchForm.orderSort = ''
          this.loading = false
          this.tableData = response.data.records
          callback(response.data.total)
        })
        .catch(() => {
          this.searchForm.column = ''
          this.searchForm.orderSort = ''
          this.loading = false
        })
    },
    // 查看附件
    onCheckFile(res, flg) {
      this.dialogFileData.checkFileVisible = flg
      this.dialogFileData.bizId = res.planDetailId
    },
    // 查看
    detail(row) {
      this.$router.push({
        name: 'purPlanFrameDetail',
        params: { tenderId: row.bizAuditId, isShowBack: true } // isShowBack 是否显示返回
      })
    },
    // 编辑
    edit(row) {
      this.$router.push({
        name: 'addFrameAdd',
        params: { detailIder: '01', tenderId: row.bizAuditId, operation: '01' } // detailIder 01编辑标识
      })
    },
    // 删除
    deleteHandel(row) {
      this.$confirm('确定删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      })
        .then(() => {
          this.loading = true
          const params = {
            tenderId: row.tenderId
          }
          deletePurchasePlanFramePack(params).then((res) => {
            this.$message({ type: 'success', message: res.header.msg })
            // 查询数据
            this.$refs.tableCrud.onSearchChange()
          })
          // 框架计划编制列表删除
          // this.removeProject(row.tenderId)
        })
        .catch(() => {})
    },
    /*
    * 框架计划编制列表删除方法
    * @params tenderId 项目id
    */
    // async removeProject(tenderId) {
    //   this.loading = true
    //   const params = {
    //     tenderId: tenderId
    //   }
    //   const res = await deletePurchasePlanFramePack(params)
    //   this.$message({ type: 'success', message: res.header.msg })
    //   // 查询数据
    //   this.$refs.tableCrud.onSearchChange()
    // },
    //  流程追踪
    handleFlow(row) {
      this.$refs.tracingFlow.openDialogInitData(row.bizId)
    },
    // 排序
    onOrderData(res) {
      this.searchForm.column = res.column
      this.searchForm.orderSort = res.orderSort
      this.$refs.tableCrud.onSearchChange()
    }
  }
}
</script>

<style lang="less" scoped></style>
