<!--商家端-在线订单-index-->
<template>
  <div class="order-base-container">
    <vab-query-form>
      <vab-query-form-left-panel :span="4">
        <el-button
          v-if="3 != rid"
          icon="el-icon-plus"
          type="primary"
          @click="handleAdd"
        >
          {{ __('代客下单') }}
        </el-button>
        <el-button icon="el-icon-check" type="primary" @click="pickUp">
          {{ __('核销') }}
        </el-button>
        <el-button v-show="selectRows.length > 0" icon="el-icon-check" type="primary" @click="exportCsv">
          {{ __('导出') }}
        </el-button>
        <el-button
          v-show="selectRows.length > 0"
          icon="el-icon-check"
          type="primary"
          @click="review"
        >
          {{ __('订单审核') }}
        </el-button>
        <el-button
          v-show="selectRows.length > 0"
          icon="el-icon-check"
          type="primary"
          @click="reviewFinance"
        >
          {{ __('财务审核') }}
        </el-button>
        <el-button
          v-show="selectRows.length > 0"
          icon="el-icon-check"
          type="primary"
          @click="reviewPicking()"
        >
          {{ __('出库确认') }}
        </el-button>
        <el-button
          v-show="selectRows.length > 0"
          icon="el-icon-check"
          type="primary"
          @click="reviewShipping()"
        >
          {{ __('发货确认') }}
        </el-button>
      </vab-query-form-left-panel>
      <vab-query-form-right-panel :span="20">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-select
              v-if="false"
              v-model="queryForm.order_state_id"
              clearable
              filterable
              :placeholder="__('全部状态')"
              style="width: 140px"
            >
              <el-option
                v-for="item in optionsId"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
            <!--查询订单状态组-->
            <el-radio-group v-model="queryForm.order_state_id" @change="queryData">
              <el-radio-button v-for="item in optionsId" :key="item.value" :label="item.value" >{{item.label}}</el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item v-if="false">
            <el-select
              v-model="queryForm.kind_id"
              clearable
              :placeholder="__('订单类型')"
              style="width: 100px"
            >
              <el-option
                v-for="item in optionsKindId"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item v-if="false">
            <el-select
              v-model="queryForm.order_buyer_evaluation_status"
              clearable
              :placeholder="__('是否评论')"
              style="width: 100px"
            >
              <el-option
                v-for="item in optionsStatus"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-select
              v-model="queryForm.buyer_user_id"
              clearable
              filterable
              :loading="loading"
              :placeholder="__('用户名称')"
              remote
              :remote-method="remoteFindUserList"
              reserve-keyword
              style="width: 100px"
            >
              <el-option
                v-for="item in dataList"
                :key="item.user_id"
                :label="item.user_account"
                :value="item.user_id"
              />
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-input
              v-model.trim="queryForm.order_id"
              clearable
              :placeholder="__('订单编号')"
              style="width: 100px"
            />
          </el-form-item>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.order_title"
              clearable
              :placeholder="__('订单标题')"
              style="width: 100px"
            />
          </el-form-item>
          <el-form-item>
            <div class="block">
              <ms-date-range-picker
                v-model="order_time_range"
                @update:modelValue="order_time_range = $event"
              />
              <el-date-picker
                v-if="false"
                v-model="queryForm.order_date"
                :placeholder="__('选择日期')"
                style="width: 150px"
                type="date"
                value-format="yyyy-MM-dd"
              />
            </div>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="queryData">
              {{ __('查询') }}
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table
      ref="table"
      v-loading="listLoading"
      border
      :data="list"
      :height="tableConfig.height"
      @selection-change="setSelectRows"
    >
      <el-table-column align="center" show-overflow-tooltip type="selection" />
      <el-table-column align="center" class="opt-opt" fixed="left" :label="t('操作')" width="160">
        <template #default="{ row }">
          <el-button v-if="true || stateCode.ORDER_STATE_WAIT_PAY==row.order_state_id" v-permissions="{ permission: ['/manage/trade/orderBase/edit'] }" size="mini" type="text" @click="handleEdit(row)">{{ t('详情') }}</el-button>
          <el-button v-if="stateCode.ORDER_STATE_WAIT_PAY==row.order_state_id" v-permissions="{ permission: ['/manage/trade/orderBase/remove'] }" size="small"  type="text" @click.stop="handleCancel(row.order_id)">{{ t('取消') }}</el-button>

          <el-button v-if="stateCode.ORDER_STATE_WAIT_PAY==row.order_state_id" v-permissions="{ permission: ['/manage/trade/orderBase/finance'] }" size="mini" type="text" @click="handlePaid(row)">{{ t('付款') }}</el-button>

          <el-button v-if="ifReview && stateCode.ORDER_STATE_WAIT_REVIEW==row.order_state_id" v-permissions="{ permission: ['/manage/trade/orderBase/review'] }" size="mini" type="text" @click="handleReview(row.order_id)">{{ t('订单审核') }}</el-button>
          <el-button v-if="ifFinanceReview && stateCode.ORDER_STATE_WAIT_FINANCE_REVIEW==row.order_state_id" v-permissions="{ permission: ['/manage/trade/orderBase/finance'] }" size="mini" type="text" @click="handleFinanceReview(row.order_id)">{{ t('财务审核') }}</el-button>

          <el-button v-if="ifPickingReview && stateCode.ORDER_STATE_PICKING==row.order_state_id" v-permissions="{ permission: ['/manage/trade/orderBase/picking'] }" size="mini" type="text" @click="pickingOut(row.order_id)">{{ t('出库') }}</el-button>
          <el-button v-if="!ifPickingReview && stateCode.ORDER_STATE_PICKING==row.order_state_id" v-permissions="{ permission: ['/manage/trade/orderBase/shipping'] }" size="mini" type="text" @click="handleShipping(row)">{{ t('发货') }}</el-button>

          <el-button v-if="stateCode.ORDER_STATE_WAIT_SHIPPING==row.order_state_id" v-permissions="{ permission: ['/manage/trade/orderBase/shipping'] }" size="mini" type="text" @click="handleShipping(row)">{{ t('发货') }}</el-button>

          <el-button v-if="stateCode.ORDER_STATE_SHIPPED==row.order_state_id" v-permissions="{ permission: ['/manage/trade/orderBase/receive'] }" size="mini" type="text" @click="handleReceive(row.order_id)">{{ t('签收') }}</el-button>
          <el-button v-if="stateCode.ORDER_STATE_SHIPPED==row.order_state_id" v-permissions="{ permission: ['/manage/trade/orderBase/shipping'] }" size="mini" type="text" @click="handleTraceInfo(row)">{{ t('配送') }}</el-button>

          <el-button v-permissions="{ permission: ['/manage/trade/orderBase/list'] }" size="mini"  type="text"  @click.stop="handleLogInfo(row)">{{ t('记录') }}</el-button>
          <el-popover v-if="false" placement="left-end" trigger="click" width="150">
            <template #reference>
              <el-button size="mini"  type="text" style="margin: 5px 10px;">
                <vab-icon class="rightIcon" icon="more-fill"/>
              </el-button>
            </template>
            <div class="oper-btn">
              <el-button v-permissions="{ permission: ['/manage/trade/orderBase/list'] }" size="mini"  type="text"  @click.stop="handleEdit(row)">{{ t('订单详情') }}</el-button>
              <el-button v-permissions="{ permission: ['/manage/trade/orderBase/list'] }" size="mini"  type="text"  @click.stop="handleLogInfo(row)">{{ t('操作记录') }}</el-button>
              <el-button v-if="false && stateCode.ORDER_STATE_WAIT_PAY==row.order_state_id || stateCode.ORDER_STATE_WAIT_REVIEW==row.order_state_id || stateCode.ORDER_STATE_PICKING==row.order_state_id || stateCode.ORDER_STATE_WAIT_SHIPPING==row.order_state_id" v-permissions="{ permission: ['/manage/trade/orderBase/remove'] }" size="small"  type="text" @click.stop="handleCancel(row.order_id)">{{ t('取消订单') }}</el-button>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        fixed="left"
        :label="__('订单编号')"
        show-overflow-tooltip
        width="150"
      >
        <template #default="{ row }">
          <span v-if="row.return_flag">
            <el-link style="color: red" @click="handleEdit(row)">
              {{ row.order_id }}
            </el-link>
          </span>
          <span v-if="!row.return_flag">
            <el-link type="primary" @click="handleEdit(row)">
              {{ row.order_id }}
            </el-link>
          </span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="__('退货退款')"
        show-overflow-tooltip
        width="80px"
      >
        <template #default="{ row }">
          <span v-if="row.return_flag" style="color: orangered">
            <el-button v-if="row.return_flag" type="text" @click="goToPath('/order/productOrder', { order_id: row.order_id })">
              {{ __('退货信息') }}
            </el-button>
          </span>
          <span v-if="!row.return_flag">
            {{ __('否') }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        fixed="left"
        :formatter="formatStateId"
        :label="__('订单状态')"
        prop="order_state_id"
        show-overflow-tooltip
        width="100"
      >
        <template #default="{ row }">
          <el-button v-if="row.order_state_id === 2010" plain size="mini">{{ formatStateId(row) }}</el-button>
          <el-button v-else-if="row.order_state_id === 2011" plain size="mini">{{  formatStateId(row) }}</el-button>
          <el-button v-else-if="row.order_state_id === 2013" plain size="mini">{{  formatStateId(row) }}</el-button>
          <el-button v-else-if="row.order_state_id === 2020" plain size="mini" type="warning">{{  formatStateId(row) }}</el-button>
          <el-button v-else-if="row.order_state_id === 2030" plain size="mini" type="danger">{{  formatStateId(row) }}</el-button>
          <el-button v-else-if="row.order_state_id === 2040" plain size="mini" type="info">{{  formatStateId(row) }}</el-button>
          <el-button v-else-if="row.order_state_id === 2060" plain size="mini" type="success">{{  formatStateId(row) }}</el-button>
          <el-button v-else-if="row.order_state_id === 2070" plain size="mini" type="plain">{{  formatStateId(row) }}</el-button>
          <el-button v-else>
            {{ __('未知') }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column
        align="left"
        :label="__('应付金额')"
        show-overflow-tooltip
      >
        <template #default="{ row }">
          {{ row.currency_symbol_left }}{{ row.order_payment_amount }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="__('付款方式')"
        show-overflow-tooltip
      >
        <template #default="{ row }">
          <span v-if="row.payment_type_id === 1301" style="color: red">{{ __('货到付款') }}</span>
          <span v-if="row.payment_type_id === 1302">{{ __('在线支付') }}</span>
          <span v-if="row.payment_type_id === 1303">{{ __('白条支付') }}</span>
          <span v-if="row.payment_type_id === 1304">{{ __('现金支付') }}</span>
          <span v-if="row.payment_type_id === 1305" style="color: red">
            {{ __('线下支付') }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :formatter="formatTime"
        :label="__('下单时间')"
        prop="order_time"
        show-overflow-tooltip
        width="150"
      />

      <el-table-column
        v-if="configs.config.supplier_market_enable && 1 == configs.store_type"
        align="center"
        :label="__('转单状态')"
        prop="has_supplier_trans"
        show-overflow-tooltip
        width="140"
      >
        <template #default="{ row }">
          <span v-if="row.has_supplier_trans == 0">
            <span v-if="row.order_state_id == 2060 || row.order_state_id == 2070">
              {{ __('无') }}
            </span>
            <el-button
              v-else
              type="primary"
              size="mini"
              plain
              @click="doSupplierTrans(row.order_id)"
            >
              {{ __('转单') }}
            </el-button>
          </span>
          <span v-else-if="row.has_supplier_trans == 3"></span>
          <span v-else>
            {{ row.has_supplier_trans }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="__('配送方式')"
        show-overflow-tooltip
      >
        <template #default="{ row }">
          <span v-if="row.delivery_type_id === 5">{{ __('自提') }}</span>
          <span v-else-if="row.delivery_type_id === 10">{{ __('配送') }}</span>
          <span v-else>
            {{ __('配送') }}
          </span>
        </template>
      </el-table-column>

      <el-table-column
        align="center"
        :label="__('配送时间')"
        show-overflow-tooltip
        width="170"
      >
        <template #default="{ row }">
          <span v-if="row.delivery_time_name != '正常配送'" style="color: red">
            {{ row.delivery_time_name }}
          </span>
          <span v-if="row.delivery_time_name == '正常配送'">
            {{ row.delivery_time_name }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="__('配送地址')"
        prop="mo_receive_area"
        show-overflow-tooltip
        width="250"
      />

      <el-table-column
        align="center"
        :label="__('活动类型')"
        prop="activity_type_name"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('客户名称')"
        prop="buyer_user_name"
        show-overflow-tooltip
        width="100px"
      />
      <el-table-column
        align="center"
        :formatter="formatReview"
        :label="__('订单审核')"
        prop="order_is_review"
        show-overflow-tooltip
      />

      <el-table-column
        align="center"
        :label="__('积分')"
        prop="order_resource_ext1"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="false"
        align="center"
        :label="__('报关状态')"
        prop="order_cb_sync"
        show-overflow-tooltip
      />

      <el-table-column
        align="center"
        :formatter="formatReview"
        :label="__('财务状态')"
        prop="order_finance_review"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :formatter="formatOut"
        :label="__('出库状态')"
        prop="order_is_out"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :formatter="foematShipped"
        :label="__('发货状态')"
        prop="order_is_shipped"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :formatter="formatDealTime"
        :label="__('状态时间')"
        prop="order_deal_time"
        show-overflow-tooltip
        width="160"
      />
      <el-table-column
        align="center"
        :formatter="formatPaid"
        :label="__('付款状态')"
        prop="order_is_paid"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :formatter="formatReceived"
        :label="__('收货状态')"
        prop="order_is_received"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('买家留言')"
        prop="order_message"
        show-overflow-tooltip
      />
      <!--<el-table-column-->
      <!--align="center"-->
      <!--:formatter="formatPrint"-->
      <!--:label="__('打印状态')"-->
      <!--prop="order_express_print"-->
      <!--show-overflow-tooltip-->
      <!--/>-->
    </el-table>

    <el-pagination
      background
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <item ref="item" @fetch-data="fetchData" />
    <add ref="add" @fetch-data="fetchData" />
    <PickUp ref="pickUp" @fetch-data="fetchData" />
    <Return ref="Return" />
    <payment-edit ref="paymentEditRef" @fetch-data="fetchData" />
    <order-state-log-drawer ref="orderStateLogDrawerRef" @fetch-data="fetchData" />
    <express-edit ref="expressRef" :shipping="true" @fetch-data="fetchData" />
  </div>
</template>

<script>
  import { translateTitle as __ } from '@/utils/i18n'
  import { renderTime, timestampToTime } from '@/utils/date'
  import {
    getBaseList,
    cancel,
    picking,
    receive,
    review,
    reviewFinance,
    reviewPicking,
    reviewShipping,
    exportFile,
    transferToSupplier,
  } from '@/api/order/base'
  import { getList } from '@/api/user/base'
  import Item from './components/OnlineOrderItem'
  import add from './components/OrderBaseEdit'
  import Return from './components/OrderReturnList'
  import PickUp from './components/PickUpWriteOff'
  import PaymentEdit from './components/PaymentEdit'
  import OrderStateLogDrawer from './components/OrderStateLogDrawer'
  import ExpressEdit from './components/ExpressEdit'
  import { mapGetters } from 'vuex'
  import MsDateRangePicker from '@/components/MsDateRangePicker'
  import {stateCode} from '@/config'

  export default {
    name: 'OrderBase',
    components: { Item, add, Return, PickUp,PaymentEdit, MsDateRangePicker, OrderStateLogDrawer, ExpressEdit },
    data() {
      return {
        stateCode:stateCode,
        tableConfig: {
          height: window.innerHeight - 220 - 90,
        },
        list: [],
        dataList: [],
        optionsStatus: [
          {
            value: 0,
            label: this.__('未评价'),
          },
          {
            value: 1,
            label: this.__('已评价'),
          },
        ],
        optionsKindId: [
          {
            value: 1201,
            label: this.__('实物订单'),
          },
          {
            value: 1202,
            label: this.__('服务订单'),
          },
          {
            value: 1203,
            label: this.__('电子卡券'),
          },
          {
            value: 1204,
            label: this.__('外卖订单'),
          },
          {
            value: 1205,
            label: this.__('课程订单'),
          },
        ],
        // optionsId: [
        //   {
        //     value: 2011,
        //     label: this.__('待订单审核'),
        //   },
        //   {
        //     value: 2013,
        //     label: this.__('待财务审核'),
        //   },
        //   {
        //     value: 2020,
        //     label: this.__('待配货/待出库审核'),
        //   },
        //   {
        //     value: 2030,
        //     label: this.__('待发货'),
        //   },
        //   {
        //     value: 2040,
        //     label: this.__('已发货/待签收确认'),
        //   },
        //   {
        //     value: 2060,
        //     label: this.__('已完成/已签收'),
        //   },
        //   {
        //     value: 2070,
        //     label: this.__('已取消/已作废'),
        //   },
        // ],
        optionsId: [
          {
            value: null,
            label: this.__('全部'),
          },
          {
            value: 2010,
            label: this.__('待付款'),
          },
          /*
          {
            value: 2011,
            label: this.__('待审核'),
          },
          {
            value: 2013,
            label: this.__('待财务'),
          },
          {
            value: 2020,
            label: this.__('待配货'),
          },
           */
          {
            value: 2030,
            label: this.__('待发货'),
          },
          {
            value: 2040,
            label: this.__('待签收'),
          },
          /*
          {
            value: 2050,
            label: this.__('已签收'),
          },
           */
          {
            value: 2060,
            label: this.__('完成'),
          },
          {
            value: 2070,
            label: this.__('关闭'),
          },
        ],
        value: '',
        listLoading: true,
        loading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        queryForm: {
          stime: null,
          etime: null,
          kind_id:null,
          order_state_id:null,

          pageNum: 1,
          pageSize: 20,
        },
        order_time_range:["", ""],
      }
    },
    computed: {
      ...mapGetters({
        configs: 'routes/configs',
      }),
      ...mapGetters({
        rid: 'user/rid',
      }),
      ifReview() {
        for (const k in this.optionsId) {
          const item = this.optionsId[k]
          if (item.value == stateCode.ORDER_STATE_WAIT_REVIEW) {
            return true
          }
        }
        return false
      },
      ifFinanceReview() {
        for (const k in this.optionsId) {
          const item = this.optionsId[k]
          if (item.value == stateCode.ORDER_STATE_WAIT_FINANCE_REVIEW) {
            return true
          }
        }
        return false
      },
      ifPickingReview() {
        return false;

        for (const k in this.optionsId) {
          const item = this.optionsId[k]
          if (item.value == stateCode.ORDER_STATE_PICKING) {
            return true
          }
        }
        return false
      }
    },
    created() {
      let query = this.$route.query
      if (query.order_state_id) {
        this.queryForm.order_state_id = Number(query.order_state_id)
      }

      this.fetchData()
    },
    methods: {
      goToPath(path, query) {
        this.$router.push({ path: path, query: query }) 
      },
      formatDealTime(row) {
        return timestampToTime(row.order_deal_time)
      },
      formatTime(row) {
        return renderTime(row.order_time)
      },
      // 查询用户列表 
      async remoteFindUserList(user_nickname) {
        if (user_nickname !== '') {
          this.loading = true;
          setTimeout(() => {
            this.loading = false
            getList({ user_nickname: user_nickname }).then((res) => {
              this.dataList = res.data.items
            })
          }, 200)
        } else {
          this.dataList = []
        }
      },
      handleAdd() {
        this.$refs['add'].showEdit()
      },
      pickUp() {
        this.$refs['pickUp'].showEdit()
      },
      handleReturnTable(row) {
        this.$refs['Return'].showTable(row)
      },
      handleEdit(row) {
        this.$refs['item'].showEdit(row)
      },
      formatPaid(row) {
        return row.order_is_paid === 3010
          ? this.__('未付款')
          : row.order_is_paid === 3011
          ? this.__('付款待审核')
          : row.order_is_paid === 3012
          ? this.__('部分付款')
          : this.__('已付款')
      },
      formatReceived(row) {
        return row.order_is_received === 0
          ? this.__('未收货')
          : this.__('已收货')
      },
      formatPrint(row) {
        return row.order_express_print === 0
          ? this.__('未打印')
          : this.__('已打印')
      },
      formatFlag(row) {
        return row.return_flag ? this.__('是') : this.__('否')
      },
      formatReview(row) {
        return row.order_is_review === 0 ? this.__('未审核') : this.__('已审核')
      },
      foematShipped(row) {
        return row.order_is_shipped === 3030
          ? this.__('未发货')
          : row.order_is_shipped === 3032
          ? this.__('已发货')
          : this.__('部分发货')
      },
      formatOut(row) {
        return row.order_is_out === 3020
          ? this.__('未出库')
          : row.order_is_out === 3021
          ? this.__('部分出库通过')
          : this.__('已出库')
      },
      formatStateId(row) {
        return row.order_state_id === 2011
          ? this.__('待审核')
          : row.order_state_id === 2013
          ? this.__('待财务审核')
          : row.order_state_id === 2020
          ? this.__('待配货')
          : row.order_state_id === 2030
          ? this.__('待发货')
          : row.order_state_id === 2040
          ? this.__('待签收')
          : row.order_state_id === 2060
          ? this.__('已完成')
          : row.order_state_id === 2010
          ? this.__('待付款')
          : this.__('已关闭')
      },
      setSelectRows(val) {
        this.selectRows = val
      },
      __,
      t:__,
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
      queryData() {
        this.queryForm.pageNum = 1
        this.fetchData()
      },

      async handleCancel (order_id) {
        this.$prompt(this.t('取消订单原因'), {
          confirmButtonText: this.t('确定'),
          cancelButtonText: this.t('取消'),
        })
          .then(async ({ value }) => {
            const {msg, status} = await cancel({
              order_id: order_id,
              order_cancel_reason: value
            })

            if (200 == status) {
              this.$baseMessage(msg, 'success')
            } else {
              this.$baseMessage(msg, 'error')
            }

            this.fetchData()
          })
          .catch(() => {})
      },

      handlePaid (row) {
        //state.itemRef.showEdit(row)
        const obj = {
          order_id: row.order_id,
          deposit_total_fee: row.order_payment_amount,
        }

        this.$refs['paymentEditRef'].showEdit(obj)
      },

      async handleReview (order_id){
        this.$baseConfirm(this.t('你确定要审核订单吗?'), null, async () => {
          const {msg, status} = await review({order_id})
          if (200 == status) {
            this.$baseMessage(msg, 'success')
          } else {
            this.$baseMessage(msg, 'error')
          }
          await this.fetchData()
        })
      },

      async handleFinanceReview (order_id) {
        this.$baseConfirm(this.t('你确定要财务审核订单吗?'), null, async () => {
          const {msg, status} = await finance({order_id})
          if (200 == status) {
            this.$baseMessage(msg, 'success')
          } else {
            this.$baseMessage(msg, 'error')
          }
          await this.fetchData()
        })
      },

      async pickingOut (row) {
        const id = row
        const obj = {
          order_ids: id,
          order_is_out: 1,

          //
          order_id: id,
          bill_type_id: 2700,
          warehouse_id: 0,
          stock_transport_type_id: 2751,
          picking_flag: true,
        }
        this.handlePicking(obj)
      },
      async handlePicking (params) {
        this.$baseConfirm(this.t('你确定要出库吗?'), null, async () => {
          const {msg, status} = await reviewPicking(params)
          if (200 == status) {
            this.$baseMessage(msg, 'success')
          } else {
            this.$baseMessage(msg, 'error')
          }
          await this.fetchData()
        })
      },


      handleShipping (row) {
        //调出UI
        this.$refs['expressRef'].showEdit(row)

        /*
        this.$baseConfirm(this.t('你确定要发货吗?'), null, async () => {
          const {msg, status} = await shipping({order_id})
          if (200 == status) {
            this.$baseMessage(msg, 'success')
          } else {
            this.$baseMessage(msg, 'error')
          }
          await this.fetchData()
        })
         */
      },

       handleReceive (order_id) {
        this.$baseConfirm(this.t('你确定要将订单更改为收货状态吗?'), null, async () => {
          const { msg, status } = await receive({order_id})
          if (200 == status) {
            this.$baseMessage(msg, 'success')
          } else {
            this.$baseMessage(msg, 'error')
          }
          await this.fetchData()
        })
      },

      handleLogInfo (row) {
        this.$refs['orderStateLogDrawerRef'].showEdit(row)
      },

      handleTraceInfo (row) {
        this.$refs['item'].showEdit(row, 2)
      },


      async doSupplierTrans(order_id) {
        this.$baseConfirm(this.__('请确认是否转单？'), null, async () => {
          const { msg, status } = await transferToSupplier({
            order_id: order_id,
          })

          if (200 == status) {
            this.$baseMessage(msg, 'success')
          } else {
            this.$baseMessage(msg, 'error')
          }

          await this.fetchData()
        })
      },
      //订单审核
      async review() {
        let order_id = this.selectRows.map((item) => item.order_id)
        const { msg, status } = await review({
          order_ids: order_id.toString(),
          order_is_review: 1,
        })
        if (200 == status) {
          this.$baseMessage(msg, 'success')
        } else {
          this.$baseMessage(msg, 'error')
        }
        this.fetchData()
      },
      //财务审核
      async reviewFinance() {
        let order_id = this.selectRows.map((item) => item.order_id)
        const { msg, status } = await reviewFinance({
          order_ids: order_id.toString(),
          order_finance_review: 1,
        })
        if (200 == status) {
          this.$baseMessage(msg, 'success')
        } else {
          this.$baseMessage(msg, 'error')
        }
        this.fetchData()
      },
      //发货确认
      async reviewShipping() {
        let order_id = this.selectRows.map((item) => item.order_id)
        const { msg, status } = await reviewShipping({
          order_ids: order_id.toString(),
          order_state_id: 2030,
        })
        if (200 == status) {
          this.$baseMessage(msg, 'success')
        } else {
          this.$baseMessage(msg, 'error')
        }
        this.fetchData()
      },
      // 出库确认
      async reviewPicking() {
        let order_id = this.selectRows.map((item) => item.order_id)
        const { msg, status } = await reviewPicking({
          order_ids: order_id.toString(),
          order_is_out: 1,
        })
        if (200 == status) {
          this.$baseMessage(msg, 'success')
        } else {
          this.$baseMessage(msg, 'error')
        }
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true

        if (this.order_time_range.length > 0) {
          if (this.order_time_range[0]) {
            this.queryForm.stime = this.order_time_range[0].getTime();
          }
          if (this.order_time_range[1]) {
            this.queryForm.etime = this.order_time_range[1].getTime();
          }
        } else {
          this.queryForm.stime = null
          this.queryForm.etime = null
        }

        const { data } = await getBaseList(this.queryForm)
        this.list = data.items
        this.total = data.records
        this.listLoading = false
      },
      exportCsv() {
        const rows = this.$refs.table.selection
        if (!rows || rows.length <= 0) {
          this.$baseMessage('没有选中的数据！', 'error')
          return
        }
        let order_ids = rows.map((item) => item.order_id)
        exportFile({ order_ids: order_ids.toString() }).then((data) => {
          const blob = new Blob([data])
          const downloadElement = document.createElement('a')
          const href = window.URL.createObjectURL(blob) //创建下载的链接
          downloadElement.href = href
          downloadElement.download = decodeURIComponent('订单数据.csv') //下载后文件名
          document.body.appendChild(downloadElement)
          downloadElement.click() //点击下载
          document.body.removeChild(downloadElement) //下载完成移除元素
          window.URL.revokeObjectURL(href) //释放掉blob对象
        })
      },
    },
  }
</script>
<style lang="scss" scoped>

.el-popper {
  width: 100px;

  .oper-btn{
    display: inline-grid;
    width: 100%;

    .el-button{
      margin: 5px auto;
    }
  }
}

</style>
