<!--
  @description:招标计划分配-部门级-未分配
  @Modifier: 肖文龙
  @routerPath:
  @date: 2020-6-2
-->
<template>
  <div>
    <p class="mb10">
      <el-button v-if="configData.configType" type="primary" plain @click="batchAllot()">
        批量分配
      </el-button>
      <span style="color: red;margin-left: 10px">当前分配规则为{{ configData.configText }}分配</span>
    </p>
    <section>
      <el-table
        ref="smallTable"
        v-loading="loading"
        :data="tableData"
        @selection-change="selectionChange"
      >
        <el-table-column
          type="selection"
          width="55"
          align="center"
        />
        <el-table-column
          type="index"
          label="序号"
          align="center"
          width="60"
        />
        <el-table-column
          prop="schemeNo"
          align="center"
          label="招标汇总/计划号"
          width="160"
        />
        <el-table-column

          header-align="center"
          prop="schemeName"
          label="招标汇总/计划名称"
          min-width="300"
        />
        <el-table-column

          header-align="center"
          prop="schemeDeptname"
          label="招标人"
          min-width="230"
        />
        <el-table-column
          header-align="center"
          prop="schemeBudget"
          label="概算金额（元）"
          min-width="140"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="purchaseClassName"
          label="采购品类"
          min-width="300"
        />
        <el-table-column
          prop="purchasLevel"
          label="采购级别"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in purchaseSchemeLevelList"
              v-if="scope.row.purchasLevel === item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="bidEvaluationMethod"
          label="评标办法"
          min-width="150px"
          align="center"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in purchasesSchemeProEvalMethodList"
              v-if="scope.row.bidEvaluationMethod === item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="biddingSchemeType"
          label="采购类别"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in purchaseSchemeProjectTypeList"
              v-if="scope.row.biddingSchemeType === item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="purchasType"
          label="采购类型"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in purchaseSchemeTypeList"
              v-if="scope.row.purchasType === item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="150" fixed="right">
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click="view(scope.row.id)"
            >
              [查看]
            </el-link>
            <el-link
              v-if="configData.configType"
              type="primary"
              @click="allot(scope.row)"
            >
              [分配]
            </el-link>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </section>
    <!-- 招标人/代理机构-选择弹框 -->
    <projectManagerDialog
      :dialog-data="dialogData"
      role-codes="11"
      @projectManagerInfo="projectManagerInfo"
    />
  </div>
</template>

<script>
/* api */
import { getPretenderingPurchasesSchemeDepartmentPlanAdminPages, departmentManualAssignScheme, departmentAutoAssignScheme } from '@/api/purchasePlan/pretcloudPurchasescheme'
/* 组件*/
import pagination from '@comp/common/pagination/pagination' // 分页组件
/* 常用公共方法*/
import { filterObj } from '@/assets/js/utils'
/* 混入公共方法*/
import { ListMixin } from '@/mixins/ListMixin'
import { tenderPlan } from '../../../mixins/tenderPlan'
import { tenderPlanAllotMixin } from '../../../mixins/tenderPlanAllotMixin'
/* 组件 */
import projectManagerDialog from '@/views/common/user/projectManager-dialog'// 代理机构-选择弹框
export default {
  name: 'TenderPlanAllotComp',
  components: {
    pagination,
    projectManagerDialog
  },
  mixins: [ListMixin, tenderPlan, tenderPlanAllotMixin],
  props: {
    // 搜索参数
    searchForm: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      dialogData: {
        departId: this.$store.getters.info.departid, // 部门id
        dialog: false, // 展示状态
        title: '项目经理', // 标题
        departRoleName: '10', // 10采购人 11代理机构(项目经理)
        materialId: [] // Id去重列表
      },
      loading: false,
      ids: [], // 选中的招标计划id-分配
      tableData: [] // 获取获取招标计划已分配列表
    }
  },
  created() {
    this.initDataType('departmentCurrentAssignedType', this.$store.getters.info.departid)// 查询当前节点分配状态-mixins
    // 招标计划-字典信息
    this.initPurchaseSchemeWebTypeGroup()
  },
  methods: {
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()
    },
    // 公司级计划管理员分页获取获取招标计划列表
    loadData() {
      const params = this.getQueryParams(this.searchForm)// 查询条件
      getPretenderingPurchasesSchemeDepartmentPlanAdminPages(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 查询条件
    getQueryParams(searchForm) {
      const param = Object.assign({}, searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      param.assignedDepartmentId = this.$store.getters.info.currentDepart.id//  公司级计划管理员分配至部门id(必填，当前登录人组织机构id)
      param.deptAssignedStatus = '00'// 部门级分配状态，00未分配，01已分配(必填)
      delete param.createUserDate
      return filterObj(param)
    },
    // 系统自动审核招标计划信息
    assignScheme() {
      departmentAutoAssignScheme().then(res => {
        this.$message({
          type: 'success',
          message: res.header.msg
        })
        this.onSearch()// 查询招标计划分配列表
      })
    },
    // 分配招标计划复选框事件
    selectionChange(val) {
      this.ids = []// 初始化
      const data = [...val]
      data.forEach(item => {
        this.ids.push(item.id)// 添加要分配的招标计划id
      })
    },
    // 选择要分配的项目经理
    projectManagerInfo(data) {
      const dataAjax = {
        ids: [...this.ids], // 选中的招标计划id-分配
        projectManagerId: data.id, // 项目经理id(只有在公司级和部门级手动分配时必填，系统级分配时不填)
        projectManagerName: data.name, // 项目经理名称(只有在公司级和部门级手动分配时必填，系统级分配时不填)
        projectManagerPhone: data.phone// 项目经理电话(只有在公司级和部门级手动分配时必填，系统级分配时不填)
      }
      departmentManualAssignScheme(dataAjax).then(res => {
        this.$message({
          type: 'success',
          message: res.header.msg
        })
        this.ids = []// 初始化
        this.dialogData.dialog = false// 关闭弹框
        this.loadData()
      })
    },
    // 批量分配
    batchAllot() {
      if (this.ids.length > 0) {
        this.dialogData.dialog = true// 打开弹框
      } else {
        this.$message({
          message: '请选择招标计划',
          type: 'warning'
        })
      }
    },
    // 分配
    allot(row) {
      this.ids = [row.id]
      this.dialogData.dialog = true// 打开弹框
    },
    // 查看
    view(id) {
      this.$router.push({
        name: 'TenderPlanSectionClassAllotDetail',
        params: { id }
      })
    }
  }
}
</script>

<style scoped>

</style>
