<!--
  @description: 代理-订单-订单列表
  @author: 苏志刚/wxy
  @routerPath:/procurement/procurementOrderAgentList
  @date： 2020-7-30 23:04: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" inline>
            <!--订单编号-->
            <el-form-item ref="orderCode" label="订单编号" prop="orderCode">
              <el-input
                v-model.trim="searchForm.orderCode"
                placeholder="订单编号"
                style="width:215px"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!--订单名称-->
            <el-form-item ref="orderName" label="订单名称" prop="orderName">
              <el-input
                v-model.trim="searchForm.orderName"
                placeholder="订单名称"
                style="width:215px"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!--供应商名称-->
            <el-form-item ref="winningDepartName" label="供应商名称" prop="winningDepartName">
              <el-input
                v-model.trim="searchForm.winningDepartName"
                placeholder="供应商名称"
                style="width:215px; margin-left:10px"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!--采购单位-->
            <el-form-item ref="purchaseDepartName" label="采购单位" prop="purchaseDepartName">
              <el-input
                v-model.trim="searchForm.purchaseDepartName"
                placeholder="采购单位"
                style="width:215px;margin-left:12px"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!--采购方式-->
            <el-form-item ref="tenderMethod" label="采购方式" prop="tenderMethod">
              <el-select v-model="searchForm.tenderMethod" placeholder="请选择">
                <el-option
                  v-for="item in tendermethodList"
                  :key="item.typename"
                  :label="item.typename"
                  :value="item.typecode"
                  style="width:215px"
                />
              </el-select>
            </el-form-item>
            <!-- 代理单位 -->
            <el-form-item
              ref="purchaseDepartExecuteName"
              label="采购执行单位"
              prop="purchaseDepartExecuteName"
            >
              <el-input
                v-model.trim="searchForm.purchaseDepartExecuteName"
                placeholder="采购执行单位"
                style="width:215px"
              />
            </el-form-item>
            <!--订单状态-->
            <el-form-item ref="orderStatus" label="订单状态" prop="orderStatus">
              <el-select v-model="searchForm.orderStatus" placeholder="请选择" style="width:215px">
                <el-option
                  v-for="item in procurementOrderOrderStatus"
                  :key="item.typename"
                  :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: 75px" />
            </el-form-item>~
            <el-form-item prop="max">
              <el-input v-model="searchForm.orderTotalMoney_end" type="number" style="width: 75px" />
            </el-form-item>
            <!--创建日期-->
            <el-form-item ref="date" label="创建日期  " prop="date">
              <el-date-picker
                v-model="searchForm.createTime_begin"
                type="datetime"
                placeholder="选择日期时间"
                style="width:215px"
              />~
              <el-date-picker
                v-model="searchForm.createTime_end"
                type="datetime"
                placeholder="选择日期时间"
                style="width:215px"
              />
            </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>
      <el-tabs v-model="activeName" @tab-click="handleTabClick">
        <el-tab-pane v-for="(item, index) in procurementOrderOrderStatus" :key="index" :code="item.typecode" :label="item.typename" :name="item.typecode" />
      </el-tabs>
      <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">
              <el-tooltip :content="scope.row.orderName" placement="top">
                <span>{{ scope.row.orderName }}</span>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column
            prop="winningDepartName"
            label="供应商名称"
            min-width="180"
            header-align="center"
            align="left"
          />
          <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="orderStatus"
            label="订单状态"
            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" min-width="160" fixed="right">
            <template slot-scope="scope">
              <!-- 代理角色下 是否显示编辑权限 isShow 01 项目经理自采 isShow 00 项目经理委托 自采的可以编辑作废 委托的仅显示查看  -->
              <span v-if="scope.row.isShow==='01'">
                <!-- 订单状态 已保存 01  审核不通过 03  -->
                <el-link
                  v-if="scope.row.orderStatus==='01'||scope.row.orderStatus==='03'"
                  type="primary"
                  @click.stop="edit(scope.row)"
                >
                  [编辑]
                </el-link>
                <!-- 订单状态 已保存 01 审核不通过 03 待接单  04  -->
                <!--                <el-link-->
                <!--                  v-if="scope.row.orderStatus==='01'||scope.row.orderStatus==='03' || scope.row.orderStatus === '04'"-->
                <!--                  type="primary"-->
                <!--                  @click.stop="detail(scope.row, '00')"-->
                <!--                >-->
                <!--                  [作废]-->
                <!--                </el-link>-->
                <!-- 订单状态 01 暂存 02待审核 03审核驳回 04待接单 05已发布 06已释放 07已退回 08 已作废  09已提合同-->
                <el-link v-if="scope.row.orderStatus!=='01'&&scope.row.orderStatus!=='03'" type="primary" @click.stop="detail(scope.row, '01')">
                  [查看]
                </el-link>
              </span>
              <!-- 订单状态 01 暂存 02待审核 03审核驳回 04待接单 05已发布 06已释放 07已退回 08 已作废  09已提合同-->
              <span>
                <el-link v-if="scope.row.isShow==='00'" type="primary" @click.stop="detail(scope.row, '01')">
                  [查看]
                </el-link>
                <el-link
                  type="primary"
                  @click="openOrderLog(scope.row.id)"
                >
                  [日志]
                </el-link>
              </span>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="getOrderListData" />
      </section>
    </section>
    <!-- 订单日志 -->
    <orderLog ref="orderLog" />
  </div>
</template>

<script>
/* api接口*/
import { listAgentProcurementOrderPages } 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'
// 订单日志
import orderLog from '../components/procurementOrderLog-dialog.vue'

export default {
  name: 'OrderManagementList',
  components: {
    pagination, // 分页组件
    orderLog // 订单日志
  },
  mixins: [ListMixin, commonMxin, orderManagementGroupMixin],
  data() {
    return {
      moneyFormat: moneyFormat, // 金额添加千分位
      loading: true,
      searchForm: {
        orderTotalMoney_begin: '', // 订单总额开始
        orderTotalMoney_end: '', // 订单总额结束
        tenderMethod: '', // 采购方式
        orderStatus: '01', // 订单状态
        orderCode: '', // 订单编号
        orderName: '', // 订单名称
        winningDepartName: '', // 供应商名称
        purchaseDepartName: '', // 创建人
        createTime_begin: '', // 创建日期
        createTime_end: '', // 结束日期
        purchaseDepartExecuteName: '' // 代理单位
      },
      activeName: '01',
      tableData: [], // 订单信息列表
      purchaseDepartName: '' // 采购单位
    }
  },
  created() {
    // 查询数据字典
    this.getProcurementOderInfo()
  },
  mounted() {
    // 调用查看订单列表数据
    this.getOrderListData()
  },
  methods: {
    filterDictText, // 引入字典值替换文本通用方法
    procurementUnitOmit,
    // 获取数据
    getOrderListData() {
      const params = this.getQueryParams() // 查询条件
      listAgentProcurementOrderPages(params)
        .then(response => {
          this.tableData = response.data.records
          this.paginationData.total = response.data.total
          this.loading = false
        })
        .catch(() => {
          this.loading = false
        })
    },
    // tab切换
    handleTabClick(tab, event) {
      this.activeName = String(tab.$attrs.code)
      if (tab.label !== '全部') {
        this.searchForm.orderStatus = tab.$attrs.code
      } else {
        // 如果是全部 则传空
        this.searchForm.orderStatus = ''
      }
      // 让点击的获取一次
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.onSearch()
    },
    // 查询条件
    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.getOrderListData()
    },
    // 重置
    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.getOrderListData()
    },
    // 查看
    detail(row, linkStatus) {
      this.$router.push({
        name: 'procurementOrderNotarize',
        params: {
          linkStatus: linkStatus, // 操作状态
          status: '01', // 采购员
          orderId: row.id, // 订单id
          orderStatus: row.orderStatus // 状态
        }
      })
    },
    // 编辑
    edit(row) {
      this.$router.push({
        name: 'procurementOrderSubmit',
        params: {
          orderId: row.id, // 订单id
          status: '01', // 采购员
          orderStatus: row.orderStatus // 状态
        }
      })
    },
    // 打开订单日志
    openOrderLog(id) {
      this.$refs.orderLog.openDialogInitData(id)
    }
  }
}
</script>

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

