<!--
  @description:招标项目/采购项目-合同签订-项目信息列表弹窗
  @Modifier:zyy
  @routerPath:
  @date:2021/4/21-14:52
-->
<template>
  <el-dialog
    ref="dialog"
    v-dialogDrag
    :visible.sync="projectDialog"
    :close-on-click-modal="false"
    title="选择订单"
    width="1200px"
    append-to-body
    custom-class="el-dialog__body-p8 el-dialog_table"
    @close="close()"
  >
    <div class="clearfix">
      <el-form ref="searchForm" :model="searchForm" inline>
        <el-form-item label="订单编号" prop="orderCode">
          <el-input
            v-model.trim="searchForm.orderCode"
            placeholder="订单编号"
            style="width: 150px"
          />
        </el-form-item>
        <el-form-item label="采购单编号" prop="tenderNo">
          <el-input
            v-model.trim="searchForm.tenderNo"
            placeholder="采购单编号"
            style="width: 150px"
          />
        </el-form-item>
        <el-form-item label="采购单名称" prop="tenderName">
          <el-input
            v-model.trim="searchForm.tenderName"
            placeholder="采购单名称"
            style="width: 150px"
          />
        </el-form-item>
        <!-- <el-form-item
          label="框架采购"
          prop="contractSource"
        >
          <el-select v-model="searchForm.isFocus" placeholder="请选择" style="width: 120px">
            <el-option
              v-for="(item,index) in isFocusList"
              :key="index"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item> -->
        <el-form-item class="fr">
          <el-button
            type="primary"
            @click="search('searchForm')"
          >
            搜索
          </el-button>
          <el-button
            plain
            type="info"
            @click="resetForm('searchForm')"
          >
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-table
        ref="singleTable"
        v-loading="loading"
        :data="list"
        class="pointer"
        highlight-current-row
        size="mini"
        row-key="id"
        @select="currentChange"
      >
        <!--<el-table-column type="index" label="序号" align="center" width="80" />
        <el-table-column label="项目编码" prop="orgCode" align="center" width="200" />
        <el-table-column label="项目名称" prop="departName" />-->
        <el-table-column
          type="selection"
          :reserve-selection="true"
          width="55"
          align="center"
        />
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          prop="orderCode"
          align="center"
          label="订单编号"
          width="160"
        />
        <el-table-column
          prop="tenderNo"
          align="center"
          label="采购单编号"
          width="160"
        />
        <el-table-column
          header-align="center"
          prop="tenderName"
          :label="contractSource == '00' ? '采购单名称' : '项目名称'"
          min-width="230"
        />
        <el-table-column
          v-if="contractSource == '01'"
          header-align="center"
          label="标段（包）名称"
          prop="packName"
          align="left"
          min-width="200"
        />
        <el-table-column
          header-align="center"
          prop="supplyDepartName"
          label="中标人"
          min-width="220"
        />
        <el-table-column
          v-if="contractSource == '00'"
          prop="tenderMethod"
          label="采购方式"
          width="80"
          align="center"
        >
          <template slot-scope="scope">
            {{ filterDictText(tender_methodList, scope.row.tenderMethod) }}
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop="orderTotalTaxMoney"
          label="订单含税总额(元)"
          min-width="110"
          align="right"
        />
        <!--        <el-table-column
          header-align="center"
          prop="choiceType"
          label="是否被选中过"
          min-width="110"
          align="center"
        />-->
        <!--<el-table-column
          prop="contractSource"
          label="合同来源"
          width="80"
          align="center"
        >
          <template slot-scope="scope">
            {{ filterDictText(contractSourceList, scope.row.contractSource) }}
          </template>
        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="ensure">确 定</el-button>
      <el-button @click="projectDialog = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* 接口*/
import { listTenderProjectContractPages } from '@/api/bidding/biddingProject' // 招标合同签订获取关联项目列表
import { listProcurementProjectContractPages } from '@/api/procurement/procurementProject' // 招标合同签订获取关联项目列表
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 过滤空的key
import { filterDictText } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
// import { initGroupMixin } from '@/mixins/initGroupMixin'
import { procurementGroupMixins } from '@/views/procurement/mixins/procurementGrounpMixins'
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
export default {
  name: 'ProjectInfo',
  components: {
    pagination// 分页
  },
  mixins: [ListMixin, procurementGroupMixins],
  props: {
    contractSource: { // 合同来源00采购01招标
      type: String,
      default: ''
    }
  },
  data() {
    return {
      contractSourceList: [
        {
          typename: '招标',
          typecode: '01'
        },
        {
          typename: '采购',
          typecode: '00'
        }
      ],
      isFocusList: [
        {
          typename: '是',
          typecode: '01'
        },
        {
          typename: '否',
          typecode: '00'
        }
      ],
      loading: true,
      projectDialog: false, // 弹框打开状态
      // 搜索信息
      searchForm: {
        orderCode: '', // 订单编号
        tenderNo: '', // 采购单编号
        tenderName: '', // 项目名称
        isFocus: '00' // 是否是框架合同
      },
      list: [], // 列表数据
      currentData: []// 当前选择的信息
    }
  },
  created() {
    // 字典信息
    // this.initTypeGroup('bidType')// 招标方式
    this.initWebTypeGroup() // 采购方式
  },
  methods: {
    filterDictText, // 字典值替换文本通用方法
    // 当前选择的信息
    currentChange(val) {
      this.currentData = val
    },
    // 打开弹框
    openProjectInfoDialog() {
      this.searchForm.tenderNo = '' // 打开弹框清空
      this.searchForm.tenderName = '' // 打开弹框清空
      this.searchForm.isFocus = '00' // 是否是框架合同
      this.loadData()
      this.projectDialog = true // 打开弹框
    },
    // 加载数据
    loadData() {
      const params = this.getParams()// 查询条件
      if (this.contractSource === '01') {
        // 招标
        listTenderProjectContractPages(params).then(response => {
          this.loading = false
          this.list = response.data.records
          this.paginationData.total = response.data.total
        }).catch(() => {
          this.loading = false
        })
      } else {
        // 采购
        listProcurementProjectContractPages(params).then(response => {
          this.loading = false
          this.list = response.data.records
          this.paginationData.total = response.data.total
        }).catch(() => {
          this.loading = false
        })
      }
    },
    // 查询条件
    getParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      param.contractSource = this.contractSource
      return filterObj(param)// 过滤空的key
    },
    // 选择信息-确定
    ensure() {
      const newArr = this.currentData.map(item => item.supplyDepartId)
      const arrSet = new Set(newArr)
      if (this.currentData) {
        if (arrSet.size > 1) {
          this.$message({
            message: `选中的中标人不一致，请重新选择`,
            type: 'warning'
          })
        } else {
          this.$emit('dialogDataInfo', this.currentData)
          this.projectDialog = false
        }
      } else {
        this.$message({
          message: `请选择项目`,
          type: 'warning'
        })
      }
    },
    // 搜索重置
    resetForm(formName) {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.$refs[formName].resetFields()
      this.loadData()
    },
    // 搜索
    search() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()
    },
    // 清空复选框选中
    close() {
      this.$refs.singleTable.clearSelection()
    }
  }
}
</script>

<style scoped lang="less">

</style>
