<template>
  <div>
    <div style="display: flex; align-items: flex-end">
      <img
        src="@/assets/setting/user.png"
        alt
        style="width: 26px; height: 26px"
      >
      <span
        style="
          font-size: 18px;
          font-weight: bold;
          color: #333333;
          line-height: 26px;
          margin-left: 5px;
        "
      >{{ $t('待结款订单') }}</span>
    </div>
    <div style="display: flex; align-items: flex-end; margin-top: 5px">
      <div style="width: 75px; height: 4px; background: #396fff" />
      <div
        style="
          width: 75px;
          height: 1px;
          background: #fff;
          border: 1px solid #acacac;
        "
      />
    </div>
    <!-- 搜索工作栏 -->
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" size="small" :inline="true" style="margin-top: 20px;">
      <el-row :gutter="10">
        <el-col :span="8">
          <el-form-item :label="$t('运输方式')" prop="transportId">
            <dict-selector v-model="queryParams.transportId" style="width: 130px;" :type="DICT_TYPE.ECW_TRANSPORT_TYPE" formatter="number" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('单号')" prop="orderNo">
            <el-input v-model="queryParams.orderNo" style="width: 130px;" :placeholder="$t('请输入单号')" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('唛头')" prop="marks">
            <el-input v-model="queryParams.marks" style="width: 130px;" :placeholder="$t('请输入唛头')" clearable />
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item :label="$t('日期筛选')" prop="phone">
        <dict-selector v-model="dateFilterType" :type="DICT_TYPE.ECW_BEGINTIME_TYPE_ENDTIME" style="width: 150px; margin-right: 5px" />
        <el-date-picker v-model="dateFilter" type="daterange" range-separator="-" :start-placeholder="$t('开始日期')" :end-placeholder="$t('结束日期')" value-format="yyyy-MM-dd HH:mm:ss" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>

    <!-- 列表 -->
    <el-table
      :data="orderList"
      style="width: 100%"
    >
      <el-table-column
        type="index"
        width="50"
      />
      <el-table-column
        :label="$t('订单编号')"
        width="120"
      >
        <template slot-scope="scope">
          <router-link :to="{path: '/jiedao/jd-orderdetail',query: {orderId: scope.row.orderId}}" class="link-type">
            <span>{{ scope.row.orderNo }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column
        prop="transportId"
        :label="$t('运输方式')"
        width="150"
      >
        <template slot-scope="{row}">
          <dict-tag :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="row.transportId" />
        </template>
      </el-table-column>
      <el-table-column
        prop="marks"
        :label="$t('唛头')"
        width="120"
      />
      <el-table-column
        :label="$t('订单状态')"
      >
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.ORDER_STATUS" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column
        prop="beginCreateTime"
        :label="$t('下单时间')"
      />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="150px">
        <template slot-scope="scope">
          <el-button slot="reference" type="text">{{ $t('操作') }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.rows"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getControl } from '@/api/order'
import { parseTime } from '@/utils'
import RightToolbar from '@/components/RightToolbar'
import Pagination from '@/components/Pagination'
import DictTag from '@/components/DictTag'
import DictSelector from '@/components/DictSelector'
export default {
  components: {
    RightToolbar,
    Pagination,
    DictTag,
    DictSelector
  },
  data() {
    return {
      parseTime,
      orderList: [],
      // 显示搜索条件
      showSearch: true,
      dateFilterType: '', // 日期筛选类别
      dateFilter: [], // 筛选日期
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        page: 1,
        rows: 10,
        phone: null,
        name: null,
        company: null,
        pid: null
      }
    }
  },
  computed: {
    // expoerCityList() {
    //   return this.tradeCityList.filter(item => item.type == 2)
    // },
    // importCityList() {
    //   return this.tradeCityList.filter(item => item.type == 1)
    // },
    combinedQueryParams() {
      const timeParams = {}
      if (this.dateFilterType && this.dateFilter) {
        timeParams['begin' + this.dateFilterType] = this.dateFilter[0]
        timeParams['end' + this.dateFilterType] = this.dateFilter[1]
      }
      return Object.assign({}, this.queryParams, timeParams)
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      getControl(this.combinedQueryParams).then((r) => {
        this.orderList = r.data.list
        this.total = r.data.total
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    specialRendering(val) {
      if (val !== undefined) {
        const i = val.split(',')
        const special = this.getDictDatas(this.DICT_TYPE.ORDER_SPECIAL_NEEDS).filter(e => {
          return i.indexOf(e.value) > -1
        })
        return special
      }
    }
  }
}
</script>

<style scoped>
::v-deep .el-table__header .el-table__cell{
  background-color: #27417C;
  font-size: 13px;
  height: 48px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: #FFFFFF;
}
</style>
