<!--
  @description: 供应商-订单确认-订单确认列表
  @author:wxy
  @routerPath:/procurement/procurementOrderConfirmList
  @date： 2020-8-17 14:44:01
-->
<template>
  <div>
    <!--标题-->
    <div class="title title_border p0-16">
      <i class="el-icon-s-home" />订单管理
    </div>
    <section class="p0-16">
      <!--查询条件-->
      <div class="crud_menu_title clearfix">
        <span class="icon-line fl">查询条件</span>
        <span class="fr pointer" @click="handleToggleSearch">
          <el-link
            :underline="false"
            :class="toggleSearchStatus ? 'arrow-is-active' : ''"
            type="primary"
            class="toggleSearchStatus icon el-icon-arrow-down"
          />
          {{ toggleSearchStatus ? '收起高级查询' : '展开高级查询' }}
        </span>
      </div>
      <section :class="{ SearchContent_show: toggleSearchStatus }" class="clearfix SearchContent">
        <div class="SearchContent_leftInput fl">
          <el-form
            ref="searchForm"
            :model="searchForm"
            label-width="108px"
            label-position="left"
            inline
          >
            <!--订单编号-->
            <el-form-item ref="orderCode" label="订单编号" class="el-form-item--three" prop="orderCode">
              <el-input
                v-model.trim="searchForm.orderCode"
                placeholder="订单编号"
                style="width:15vw"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!--订单名称-->
            <el-form-item ref="orderName" label="订单名称" class="el-form-item--three" prop="orderName">
              <el-input
                v-model.trim="searchForm.orderName"
                placeholder="订单名称"
                style="width:15vw"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!--采购单位-->
            <el-form-item
              ref="purchaseDepartName"
              label="采购单位"
              class="el-form-item--three"
              prop="purchaseDepartName"
            >
              <el-input
                v-model.trim="searchForm.purchaseDepartName"
                placeholder="采购单位"
                style="width:15vw"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!--采购方式-->
            <el-form-item
              ref="tenderMethod"
              label="采购方式"
              class="el-form-item--three"
              prop="tenderMethod"
            >
              <el-select v-model="searchForm.tenderMethod" style="width:15vw" 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="purchaseDepartExecuteName"
              label="采购执行单位"
              prop="purchaseDepartExecuteName"
              class="el-form-item--three"
            >
              <el-input
                v-model.trim="searchForm.purchaseDepartExecuteName"
                placeholder="采购执行单位"
                style="width:15vw"
              />
            </el-form-item>
            <!--订单状态-->
            <el-form-item
              ref="orderStatus"
              label="订单状态"
              class="el-form-item--three"
              prop="orderStatus"
            >
              <el-select v-model="searchForm.orderStatus" placeholder="请选择" style="width:15vw">
                <el-option
                  v-for="item in procurementSupplierOrderStatus"
                  :key="item.typecode"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </el-form-item>
            <!-- 订单总额 -->
            <el-form-item prop="min" label="订单总额(元)">
              <el-input v-model="searchForm.orderTotalMoney_begin" type="number" style="width: 15vw" />
            </el-form-item>~
            <el-form-item prop="max">
              <el-input v-model="searchForm.orderTotalMoney_end" type="number" style="width: 15vw; margin-right:65px" />
            </el-form-item>
            <!--创建日期-->
            <el-form-item ref="date" label="接受时间" prop="date">
              <el-date-picker
                v-model="searchForm.createTime_begin"
                type="datetime"
                placeholder="选择日期时间"
                style="width:15vw;margin-right: 10px;"
              />~
              <el-date-picker
                v-model="searchForm.createTime_end"
                type="datetime"
                placeholder="选择日期时间"
                style="width:15vw"
              />
            </el-form-item>
          </el-form>
        </div>
        <div class="fr">
          <el-button type="primary" @click="onSearch">
            搜 索
          </el-button>
          <el-button plain type="info" @click="resetForm('searchForm')">
            重 置
          </el-button>
        </div>
      </section>
      <!--查询结果-->
      <div class="crud_menu_title">
        <span class="icon-line">查询结果</span>
      </div>
      <section>
        <el-table ref="smallTable" v-loading="loading" :data="tableData">
          <el-table-column type="index" label="序号" align="center" width="60" />
          <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"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.orderName }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="purchaseDepartName"
            label="采购单位"
            min-width="180"
            header-align="center"
            align="left"
          >
            <template slot-scope="scope">
              <span>
                {{ procurementUnitOmit(scope.row.purchaseDepartName) }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            prop="purchaseDepartExecuteName"
            label="采购执行单位"
            min-width="200"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="tenderMethod"
            label="采购方式"
            width="100"
            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 label="发布时间" align="center" width="150" header-align="center">
            <template slot-scope="scope">
              <span>{{ $Moment(scope.row.createTime).format(momentDateTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="ProcurementSupplierOrderStatus"
            label="订单状态"
            width="100"
            header-align="center"
            align="center"
            fixed="right"
          >
            <template slot-scope="scope">
              <span>{{ filterDictText(procurementSupplierOrderStatus, scope.row.orderStatus) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" min-width="200" fixed="right">
            <template slot-scope="scope">
              <!-- 订单状态 待接单 04 -->
              <el-link
                v-if="scope.row.orderStatus==='04'"
                type="primary"
                @click.stop="confirmOrder(scope.row)"
              >
                [确认接单]
              </el-link>
              <el-link type="primary" @click.stop="detail(scope.row, '01')">
                [查看]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
      </section>
    </section>
  </div>
</template>

<script>
/* api接口*/
import { listSupplierProcurementOrderPages, supplierReceivingOrders } from '@/api/procurement/procurementContract'
/* 公共参数方法*/
import { ListMixin } from '@/mixins/ListMixin'
import { commonMxin } from '@/mixins/commonMxin'
import { orderManagementGroupMixin } from '../mixins/orderManagementGroupMixins'
import { filterObj, filterDictText } from '@/assets/js/utils'
import { moneyFormat } from '@assets/js/utils'// 常用方法
import { procurementUnitOmit } from '@/assets/js/procurement' // 采购单位名称多出...显示

/* 分页组件*/
import pagination from '@comp/common/pagination/pagination'
export default {
  name: 'OrderManagementList',
  components: {
    pagination // 分页组件
  },
  mixins: [ListMixin, commonMxin, orderManagementGroupMixin],
  data() {
    return {
      moneyFormat: moneyFormat, // 金额添加千分位
      loading: true,
      searchForm: {
        orderTotalMoney_begin: '', // 订单总额开始
        orderTotalMoney_end: '', // 订单总额结束
        tenderMethod: '', // 采购方式
        orderStatus: '', // 订单状态
        orderCode: '', // 订单编号
        orderName: '', // 订单名称
        createTime_begin: '', // 创建日期
        createTime_end: '', // 结束日期
        purchaseDepartName: '', // 采购单位
        purchaseDepartExecuteName: '' // 代理单位
      },
      tableData: [], // 订单信息列表
      purchaseDepartName: '' // 采购单位
    }
  },
  created() {
    // 查询数据字典
    this.getProcurementOderInfo()
    this.loadData()
  },
  methods: {
    filterDictText, // 引入字典值替换文本通用方法
    procurementUnitOmit,
    // 获取数据
    loadData() {
      const params = this.getQueryParams() // 查询条件
      listSupplierProcurementOrderPages(params)
        .then(response => {
          this.tableData = response.data.records
          this.paginationData.total = response.data.total
          this.loading = false
        })
        .catch(() => {
          this.loading = false
        })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 搜索
    onSearch() {
      this.paginationData.page = 1
      this.paginationData.pageSize = 10
      this.loadData()
    },
    // 重置
    resetForm(formName) {
      this.searchForm.orderTotalMoney_begin = ''
      this.searchForm.orderTotalMoney_end = ''
      this.searchForm.createTime_begin = ''
      this.searchForm.createTime_end = ''
      this.paginationData.page = 1
      this.paginationData.pageSize = 10
      this.$refs[formName].resetFields()
      this.loadData()
    },
    // 查看
    detail(row, linkStatus) {
      this.$router.push({
        name: 'procurementOrderNotarize',
        params: {
          linkStatus: linkStatus, // 操作状态
          status: '02', // 供应商
          orderId: row.id, // 订单id
          orderStatus: row.orderStatus // 状态
        }
      })
    },
    // 确认订单
    confirmOrder(row) {
      this.$confirm('确认接受订单吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn'
      }).then(() => {
        supplierReceivingOrders(row.id).then(res => {
          this.$message({
            type: 'success',
            message: '操作成功' })
          this.loadData() // 重新获取数据
        }).catch(() => {})
      }).catch(() => {})
    }
  }
}
</script>

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

