
<!--
  @description: 部门经理-订单审核列表
  @author: wxy
  @routerPath:/procurement/procurementOrderAuditList
  @date：2020-07-08 10:26:00
-->
<template>
  <div>
    <table-crud
      ref="tableCrud"
      :menu="true"
      :search-form="searchForm"
      :tabs="orderAuditStatus"
      search-label-width="100px"
      @on-load="loadData"
    >
      <!--标题-->
      <template v-slot:header>
        <span>订单审核</span>
      </template>
      <!--查询条件-->
      <template v-slot:search="search">
        <!--采购单编号-->
        <el-form-item ref="orderCode" label="订单编号" class="el-form-item--two" prop="orderCode">
          <el-input
            v-model.trim="searchForm.orderCode"
            placeholder="订单编号"
            style="width:20vw"
            @keyup.enter.native="search.onSearch"
          />
        </el-form-item>
        <!--采购单名称-->
        <el-form-item ref="orderName" label="订单名称" class="el-form-item--two" prop="orderName">
          <el-input
            v-model.trim="searchForm.orderName"
            placeholder="订单名称"
            style="width:20vw"
            @keyup.enter.native="search.onSearch"
          />
        </el-form-item>
        <!--提交人-->
        <el-form-item
          ref="createRealName"
          label="提交人"
          class="el-form-item--two"
          prop="createRealName"
        >
          <el-input
            v-model.trim="searchForm.createRealName"
            placeholder="提交人"
            style="width:20vw"
            @keyup.enter.native="search.onSearch"
          />
        </el-form-item>
        <!--提交时间-->
        <el-form-item ref="date" label="提交时间  " prop="date">
          <el-date-picker
            v-model="searchForm.submitTime_begin"
            type="datetime"
            placeholder="选择日期时间"
            style="width:15vw"
          />~
          <el-date-picker
            v-model="searchForm.submitTime_end"
            type="datetime"
            placeholder="选择日期时间"
            style="width:15vw"
          />
        </el-form-item>
      </template>
      <template v-slot:menuLeft>
        <!-- <div v-if="activeName === '02'" style="padding-bottom:10px"> -->
        <!--        <el-button type="primary" @click="patchAuditIs">-->
        <!--          批量审核-->
        <!--        </el-button>-->
        <!-- </div> -->
      </template>
      <!--查询结果-->
      <!-- <div>
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane
            v-for="(item,index) in orderAuditStatus"
            :key="index"
            :label="item.typename"
            :name="item.index"
          />
        </el-tabs>
      </div> -->
      <template v-slot:GXTable>
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
          @selection-change="patchAudit"
        >
          <!-- <el-table-column v-if="searchForm.orderStatus === '02'" type="selection" width="50" align="center" /> -->
          <el-table-column type="index" label="序号" align="center" width="55" />
          <el-table-column
            prop="orderCode"
            label="订单编号"
            header-align="center"
            align="center"
            min-width="140"
          />
          <el-table-column
            prop="orderName"
            label="订单名称"
            header-align="center"
            align="left"
            min-width="230"
          />
          <el-table-column
            prop="winningDepartName"
            label="供应商名称"
            min-width="200"
            header-align="center"
          />
          <el-table-column
            label="采购单位"
            min-width="180"
            header-align="center"
            align="left"
          >
            <template slot-scope="scope">
              <span>
                {{ scope.row.purchaseDepartName }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            prop="purchaseDepartExecuteName"
            label="采购执行单位"
            min-width="150"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="tenderMethod"
            label="采购方式"
            width="90"
            header-align="center"
            align="center"
          >
            <template slot-scope="scope">
              <span>{{ filterDictText(tendermethodList,scope.row.tenderMethod) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="orderTotalMoney"
            label="订单总额(元)"
            min-width="110"
            header-align="center"
            align="right"
          >
            <template slot-scope="scope">
              <span>{{ moneyFormat(scope.row.orderTotalMoney.toFixed(2)) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="createRealName"
            label="提交人"
            min-width="110"
            header-align="center"
            align="center"
          />
          <el-table-column label="提交日期" align="center" width="150" header-align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.submitTime">{{ $Moment(scope.row.submitTime).format(momentDateTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="orderStatus"
            label="订单状态"
            min-width="100"
            header-align="center"
            align="center"
            fixed="right"
          >
            <template slot-scope="scope">
              <span> {{ filterDictText(procurementOrderOrderStatus, scope.row.orderStatus) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="120" fixed="right">
            <template slot-scope="scope">
              <!-- 订单状态  02  待审核  -->
              <el-link
                v-if="scope.row.orderStatus==='02'"
                type="primary"
                @click.stop="edit(scope.row)"
              >
                [审核]
              </el-link>
              <el-link v-else type="primary" @click.stop="edit(scope.row)">
                [查看]
              </el-link>
              <!-- <el-link
                type="primary"
                @click="openOrderLog(scope.row.id)"
              >[日志]</el-link> -->
            </template>
          </el-table-column>
        </el-table>
      </template>
    </table-crud>
    <!-- 审核弹框 -->
    <auditDialog :dialog-data="dialogData" :order-ids="orderIds" @initData="loadData" />
    <!-- 订单日志 -->
    <orderLog ref="orderLog" />
  </div>
</template>

<script>
/* api接口*/
import { listProcurementOrderAuditPages } from '@/api/procurement/procurementContract'
/* 公共参数方法*/
import { commonMxin } from '@/mixins/commonMxin'
import { orderManagementGroupMixin } from '../mixins/orderManagementGroupMixins'
import { filterDictText } from '@/assets/js/utils'
import { moneyFormat } from '@assets/js/utils'// 常用方法
/* 分页组件*/
import auditDialog from '../procurementOrderAudit/procurementOrder-dialog' // 审核弹框
import orderLog from '../components/procurementOrderLog-dialog.vue' // 订单日志
export default {
  name: 'OrderManagementList',
  components: {
    auditDialog, // 审核弹框
    orderLog // 订单日志组件
  },
  mixins: [commonMxin, orderManagementGroupMixin],
  data() {
    return {
      moneyFormat: moneyFormat, // 金额添加千分位
      // 订单审核状态
      orderAuditStatus: [
        { index: '02', name: '待审核' },
        { index: '03', name: '审核驳回' },
        { index: '04', name: '审核通过' },
        { index: '3', name: '全部' }
      ],
      loading: true,
      searchForm: {
        orderStatus: '02', // 订单状态
        orderCode: '', // 订单编号
        orderName: '', // 订单名称
        createRealName: '', // 提交人
        submitTime_begin: '', // 提交开始时间
        submitTime_end: '' // 提交结束时间
      },
      // activeName: '02',
      tableData: [], // 订单信息列表
      multipleSelection: [], // 批量审核 选中记录存放数组
      dialogData: {
        // 批量审核-弹框
        dialog: false
      },
      purchaseDepartName: '', // 采购单位
      orderIds: '' // 多个报名id以,隔开拼接的字符串
    }
  },
  created() {
    // 查询数据字典
    this.getProcurementOderInfo()
    // // 获取数据
    // this.loadData()
  },
  methods: {
    filterDictText, // 引入字典值替换文本通用方法
    // 查询条件
    // getQueryParams() {
    //   const param = Object.assign({}, this.searchForm)
    //   param.pageNo = this.paginationData.pageNo
    //   param.pageSize = this.paginationData.pageSize
    //   return filterObj(param)
    // },
    // 获取数据
    loadData(params, callback, tabData) {
      if (tabData) {
        params.orderStatus = tabData.index
        this.searchForm.orderStatus = tabData.index
      }
      listProcurementOrderAuditPages(params)
        .then(response => {
          this.loading = false
          this.tableData = response.data.records
          callback(response.data.total)
        })
        .catch(() => {
          this.loading = false
        })
    },
    // 搜索
    // onSearch() {
    //   this.paginationData.page = 1
    //   this.paginationData.pageSize = 10
    //   this.searchForm.orderStatus = this.activeName
    //   this.loadData()
    // },
    // // 重置
    // resetForm(formName) {
    //   this.searchForm.submitTime_begin = ''
    //   this.searchForm.submitTime_end = ''
    //   this.paginationData.page = 1
    //   this.paginationData.pageSize = 10
    //   this.searchForm.orderStatus = this.activeName
    //   this.$refs[formName].resetFields()
    //   this.loadData()
    // },
    // 批量审核选择
    patchAudit(val) {
      this.multipleSelection = val
    },
    // 批量审核弹框
    patchAuditIs() {
      if (!this.multipleSelection.length) {
        this.$message({
          type: 'warning',
          message: '请选择需要审核的数据'
        })
      } else {
        const arr = []
        this.dialogData.dialog = true
        this.multipleSelection.forEach(val => {
          arr.push(val.id)
        })
        if (arr.length > 1) {
          this.orderIds = arr.join(',')
        } else {
          this.orderIds = arr[0]
        }
      }
    },
    // 审核
    edit(row) {
      this.$router.push({
        name: 'procurementOrderAuditAdd',
        params: {
          orderId: row.id, // 订单id
          orderStatus: row.orderStatus // 状态
        }
      })
    },
    // // 切换订单审核状态
    // handleClick() {
    //   // 初始化订单状态
    //   this.searchForm.orderStatus = this.activeName
    //   // 获取数据
    //   this.loadData()
    // },
    // 打开订单日志
    openOrderLog(id) {
      this.$refs.orderLog.openDialogInitData(id)
    }
  }
}
</script>

<style lang="less" scoped>
/deep/.el-table {
  .el-table__fixed {
    height: auto !important; // 此处的important表示优先于element.style
  }
}
/deep/.el-table__body-wrapper::-webkit-scrollbar {
  height: 12px;
}
</style>

