<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('receiveorder.header') }}</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('receiveorder.transport')" prop="transportId">
            <dict-selector v-model="queryParams.transportId" style="width: 160px;" :type="DICT_TYPE.ECW_TRANSPORT_TYPE" formatter="number" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('controlorder.No')" prop="searchKey">
            <el-input v-model="queryParams.searchKey" style="width: 230px;" :placeholder="$t('controlorder.NoRules')" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('receiveorder.marks')" prop="marks">
            <el-input v-model="queryParams.marks" style="width: 130px;" :placeholder="$t('receiveorder.marksRules')" clearable />
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item :label="$t('receiveorder.date')" 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="datetimerange" range-separator="-" :start-placeholder="$t('receiveorder.start')" :end-placeholder="$t('receiveorder.end')" 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('common.search') }}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{ $t('common.reload') }}</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"
        align="center"
        header-align="center"
      />
      <el-table-column
        :label="$t('receiveorder.orderNo')"
        width="120"
        align="center"
        header-align="center"
      >
        <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="tidanNo"
        :label="$t('提单号')"
        width="100"
        align="center"
        header-align="center"
      />
      <el-table-column
        prop="transportId"
        :label="$t('receiveorder.transport')"
        width="150"
        align="center"
        header-align="center"
      >
        <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('receiveorder.marks')"
        width="120"
        align="center"
        header-align="center"
      />
      <el-table-column
        :label="$t('receiveorder.status')"
        prop="statusMsg"
        align="center"
        header-align="center"
      >
        <!-- <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.ORDER_STATUS" :value="scope.row.status" />
        </template> -->
      </el-table-column>
      <el-table-column
        prop="createTime"
        :label="$t('receiveorder.createTime')"
      />
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.rows"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getReceived } 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
      }
    }
  },
  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)
    },
    isChinese() {
      return this.$i18n.locale === 'zh_CN'
    }
  },
  watch: {
    isChinese() {
      this.getList()
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      getReceived(this.combinedQueryParams).then((r) => {
        this.orderList = r.data.list
        this.total = r.data.total
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        page: 1,
        rows: 10
      }
      this.handleQuery()
    }
  }
}
</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>
