<template>
  <!--全部订单-->
  <basic-container>
    <div class="avue-crud">
      <el-row v-if="!search">
        <!-- 查询模块 -->
        <el-form :inline="true" :model="query" class="el-fr">
          <div class="el-form-left">
            <el-form-item label="订单自编号:">
              <el-input v-model="query.orderCodeNum" placeholder="请输入订单自编号"></el-input>
            </el-form-item>
            <el-form-item label="运单:">
              <el-input v-model="query.waybillNum" placeholder="请输入运单编号" />
            </el-form-item>
            <el-form-item label="入库时间:" class="el-times">
              <!--            <el-input v-model="query.stockupArea" placeholder="请输入备货区"></el-input>-->
              <el-date-picker
                v-model="stockupDate"
                type="datetimerange"
                unlink-panels
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                :shortcuts="shortcuts"
                :default-time="defaultTime2"
              />
            </el-form-item>
            <!--          <el-form-item label="货物名称:">-->
            <!--            <el-input v-model="query.descriptionGoods" placeholder="请输入货物名称"></el-input>-->
            <!--          </el-form-item>-->
            <!--          <el-form-item label="仓库:">-->
            <!--            <el-input v-model="query.warehouse" placeholder="请输入仓库"></el-input>-->
            <!--          </el-form-item>-->
            <!--          <el-form-item label="是否齐套:">-->
            <!--            <el-input v-model="query.completeSet" placeholder="请输入是否齐套"></el-input>-->
            <!--          </el-form-item>-->
            <!--          <el-form-item label="品牌:">-->
            <!--            <el-input v-model="query.brand" placeholder="请输入品牌"></el-input>-->
            <!--          </el-form-item>-->
            <!--          <el-form-item label="服务类型:">-->
            <!--            <el-input v-model="query.typeService" placeholder="请输入服务类型"></el-input>-->
            <!--          </el-form-item>-->
            <!--          <el-form-item label="类型;1 预约单  2库存单:">-->
            <!--            <el-input v-model="query.genre" placeholder="请输入类型;1 预约单  2库存单"></el-input>-->
            <!--          </el-form-item>-->
            <!--          <el-form-item label="状态;1 配送 2 待配送:">-->
            <!--            <el-input v-model="query.state" placeholder="请输入状态;1 配送 2 待配送"></el-input>-->
            <!--          </el-form-item>-->
          </div>
          <!-- 查询按钮 -->

          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="searchChange">搜 索</el-button>
            <el-button icon="el-icon-delete" @click="searchReset()">清 空</el-button>
          </el-form-item>
        </el-form>
      </el-row>
      <el-row>
        <!-- <div class="avue-crud__header">
          &lt;!&ndash; 头部左侧按钮模块 &ndash;&gt;
          <div class="avue-crud__left">
            <el-button type="primary" icon="el-icon-plus" @click="handleTrade"  v-if="handler && taker || handler && trade"> 商配</el-button>
            <el-button type="danger" icon="el-icon-delete" @click="handleMunicipal" v-if="handler && taker || handler && trade">市配</el-button>
            <el-button type="primary" icon="el-icon-plus" @click="handlePickUpStore" v-if="permission.stockArticle_add && handler && !trade || permission.stockArticle_add && !taker" >自提</el-button>
            <el-button type="danger" icon="el-icon-delete" @click="handleEntire" >全部</el-button>
            <el-button type="primary" icon="el-icon-plus" @click="handleInform('2')" v-if = "!handler && !taker">未通知</el-button>
            <el-button type="danger" icon="el-icon-delete" @click="handleInform('1')" v-if = "!handler && !taker">已通知</el-button>
          </div>
          &lt;!&ndash; 头部右侧按钮模块 &ndash;&gt;
&lt;!&ndash;          <div class="avue-crud__right">&ndash;&gt;
&lt;!&ndash;            <el-button icon="el-icon-refresh" @click="searchChange" circle></el-button>&ndash;&gt;
&lt;!&ndash;            <el-button icon="el-icon-search" @click="searchHide" circle></el-button>&ndash;&gt;
&lt;!&ndash;          </div>&ndash;&gt;
        </div>-->
        <div class="avue-crud__header">
          <!-- 头部左侧按钮模块 -->
          <div class="avue-crud__left">
            <el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-if="handler"
              >创建异常</el-button
            >
            <!--            <el-button type="danger" icon="el-icon-delete" @click="handleMoke" v-if = "handler">转预约单</el-button>-->
            <!--            <el-button type="primary" icon="el-icon-plus" @click="handleStockList" v-if = "handler">批量加配转库存品</el-button>-->
            <el-button
              type="danger"
              icon="el-icon-delete"
              @click="handleCallDelivery('3')"
              v-if="handler"
              >修改客户信息</el-button
            >
            <el-button
              type="danger"
              icon="el-icon-delete"
              @click="handleCallDelivery('2')"
              v-if="handler"
              >修改服务类型</el-button
            >
            <el-button type="danger" icon="el-icon-plus" @click="handleExport" plain>导 出</el-button>
          </div>
          <!--   <div class="avue-crud__left">
            <el-button type="primary" icon="el-icon-plus" @click="handlebill"  v-if = "!handler">创建提货单</el-button>
            <el-button type="danger" icon="el-icon-delete" @click="handleCallDelivery('1')"  v-if = "!handler">再次通知</el-button>
            <el-button type="primary" icon="el-icon-plus" @click="handleCallDelivery('1')"  v-if = "!handler">通知提货</el-button>
          </div>-->
          <!-- 头部右侧按钮模块 -->
          <div class="avue-crud__right">
            <el-button icon="el-icon-refresh" @click="searchChange" circle></el-button>
            <el-button icon="Operation" @click="showdrawer(true)" circle></el-button>
            <el-button icon="el-icon-search" @click="searchHide" circle></el-button>
          </div>
        </div>
      </el-row>
      <el-row>
        <!-- 列表模块 -->
        <tablecmt
          :columnList="columnList"
          :tableData="data"
          :loading="loading"
          @inputTxt="inputsc"
          @timeCheck="timesc"
          @btnCheck="btnsc"
          @selectCheck="selectsc"
          @selection="selectionChange"
        >
          <template #default="slotProps">
            <el-text type="primary" text icon="el-icon-view" @click="handleView(slotProps.scope)"
              >查看</el-text
            >
            <el-text
              type="primary"
              text
              icon="el-icon-edit"
              @click="handleCallDeliveryOwn(slotProps.scope)"
              >修改客户信息</el-text
            >
          </template>
        </tablecmt>
      </el-row>
      <el-row>
        <div class="avue-crud__pagination flex-c-sb" style="width: 100%">
          <div style="font-size: 14px">勾选数量: {{ selectionList.length }}</div>
          <!-- 分页模块 -->
          <el-pagination
            align="right"
            background
            @size-change="sizeChange"
            @current-change="currentChange"
            :current-page="page.currentPage"
            :page-sizes="[30, 50, 80, 120]"
            :page-size="page.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page.total"
          >
          </el-pagination>
        </div>
      </el-row>
      <el-dialog v-model="dialogFormVisible" title="通知提货">
        <el-form :model="formCall">
          <el-form-item label="顾客姓名" :label-width="formLabelWidth">
            <el-input v-model="formCall.customerName" autocomplete="off" />
          </el-form-item>
          <el-form-item label="顾客电话" :label-width="formLabelWidth">
            <el-input v-model="formCall.customerTelephone" autocomplete="off" />
          </el-form-item>
          <el-form-item label="运单" :label-width="formLabelWidth">
            <el-input v-model="formCall.waybill" autocomplete="off" />
          </el-form-item>
          <el-form-item label="跟进记录" :label-width="formLabelWidth">
            <el-input
              v-model="formCall.followUpRecord"
              :rows="2"
              type="textarea"
              placeholder="请填写内容"
            />
          </el-form-item>
          <el-form-item label="历史跟进" :label-width="formLabelWidth"> </el-form-item>
        </el-form>
        <template #footer>
          <span class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取消</el-button>
            <!--        <el-button type="primary" @click="dialogFormVisible = false"> 确定 </el-button>-->
            <el-button type="primary" @click="callFordelivery('1')"> 确定 </el-button>
          </span>
        </template>
      </el-dialog>
      <el-dialog v-model="dialogFormService" title="修改服务类型">
        <el-form :model="formService">
          <el-form-item label="服务类型" :label-width="formLabelWidth">
            <!--            <el-input v-model="formService.typeService" autocomplete="off" />-->
            <el-select v-model="formService.typeService" clearable placeholder="请选择服务类型">
              <el-option
                v-for="item in distributionType"
                :key="item.dictKey"
                :label="item.dictValue"
                :value="item.dictKey"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="费用" :label-width="formLabelWidth">
            <el-input v-model="formService.cost" autocomplete="off" />
          </el-form-item>
          <el-form-item label="原因" :label-width="formLabelWidth">
            <el-input
              v-model="formService.cause"
              :rows="2"
              type="textarea"
              placeholder="请填写原因"
            />
          </el-form-item>
        </el-form>
        <template #footer>
          <span class="dialog-footer">
            <el-button @click="dialogFormService = false">取消</el-button>
            <!--        <el-button type="primary" @click="dialogFormVisible = false"> 确定 </el-button>-->
            <el-button type="primary" @click="callFordelivery('2')"> 确定 </el-button>
          </span>
        </template>
      </el-dialog>
      <el-dialog v-model="dialogFormCustomer" title="修改客户信息">
        <el-form :model="formCustomer">
          <el-form-item label="姓名" :label-width="formLabelWidth">
            <el-input v-model="formCustomer.name" autocomplete="off" />
          </el-form-item>
          <el-form-item label="电话" :label-width="formLabelWidth">
            <el-input v-model="formCustomer.phone" autocomplete="off" />
          </el-form-item>
          <el-form-item label="地址" :label-width="formLabelWidth">
            <el-input
              v-model="formCustomer.address"
              :rows="2"
              type="textarea"
              placeholder="请填写地址"
            />
          </el-form-item>
        </el-form>
        <template #footer>
          <span class="dialog-footer">
            <el-button @click="dialogFormCustomer = false">取消</el-button>
            <!--        <el-button type="primary" @click="dialogFormVisible = false"> 确定 </el-button>-->
            <el-button type="primary" @click="callFordelivery('3')"> 确定 </el-button>
          </span>
        </template>
      </el-dialog>
      <!-- 表单模块 -->
      <el-dialog
        :title="title"
        v-model="box"
        width="50%"
        :before-close="beforeClose"
        append-to-body
      >
        <el-form :disabled="view" ref="form" :model="form" label-width="80px">
          <!-- 表单字段 -->
          <el-form-item label="服务号" prop="serviceNumber">
            <el-input v-model="form.serviceNumber" placeholder="请输入服务号" />
          </el-form-item>
          <el-form-item label="订单自编号" prop="orderCode">
            <el-input v-model="form.orderCode" placeholder="请输入订单自编号" />
          </el-form-item>
          <el-form-item label="商场名称" prop="mallName">
            <el-input v-model="form.mallName" placeholder="请输入商场名称" />
          </el-form-item>
          <el-form-item label="货物名称" prop="descriptionGoods">
            <el-input v-model="form.descriptionGoods" placeholder="请输入货物名称" />
          </el-form-item>
          <el-form-item label="仓库" prop="warehouse">
            <el-input v-model="form.warehouse" placeholder="请输入仓库" />
          </el-form-item>
          <el-form-item label="入库时间" prop="warehouseEntryTime">
            <!--            <el-input v-model="form.warehouseEntryTime" placeholder="请输入入库时间"/>-->
            <el-date-picker
              v-model="form.warehouseEntryTime"
              type="datetime"
              placeholder="请输入入库时间"
              format="YYYY-MM-DD hh:mm:ss"
              value-format="YYYY-MM-DD hh:mm:ss"
            />
          </el-form-item>
          <el-form-item label="在库时长" prop="storeTime">
            <el-input v-model="form.storeTime" placeholder="请输入在库时长" />
          </el-form-item>
          <el-form-item label="订单总件数" prop="totalNumber">
            <el-input v-model="form.totalNumber" placeholder="请输入订单总件数" />
          </el-form-item>
          <el-form-item label="在库件数" prop="handQuantity">
            <el-input v-model="form.handQuantity" placeholder="请输入在库件数" />
          </el-form-item>
          <el-form-item label="是否齐套" prop="completeSet">
            <el-select v-model="form.completeSet" clearable placeholder="请选择是否齐套">
              <!--              <el-option-->
              <!--                v-for="item in completeSetData"-->
              <!--                :key="item.dictKey"-->
              <!--                :label="item.dictValue"-->
              <!--                :value="item.dictKey">-->
              <!--              </el-option>-->
              <el-option label="是" value="2">是</el-option>
              <el-option label="否" value="1">否</el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="品牌" prop="brand">
            <el-input v-model="form.brand" placeholder="请输入品牌" />
          </el-form-item>
          <el-form-item label="服务类型" prop="typeService">
            <el-select v-model="form.typeService" clearable placeholder="请选择服务类型">
              <!--              <el-option-->
              <!--                v-for="item in typeServiceData"-->
              <!--                :key="item.dictKey"-->
              <!--                :label="item.dictValue"-->
              <!--                :value="item.dictKey">-->
              <!--              </el-option>-->
              <el-option label="干" value="1">干</el-option>
              <el-option label="仓" value="2">仓</el-option>
              <el-option label="配" value="3">配</el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="顾客名字" prop="customerName">
            <el-input v-model="form.customerName" placeholder="请输入顾客名字" />
          </el-form-item>
          <el-form-item label="顾客电话" prop="customerTelephone">
            <el-input v-model="form.customerTelephone" placeholder="请输入顾客电话" />
          </el-form-item>
          <el-form-item label="顾客地址" prop="customerAddress">
            <el-input v-model="form.customerAddress" placeholder="请输入顾客地址" />
          </el-form-item>
          <el-form-item label="类型;1 预约单  2库存单" prop="genre">
            <el-select v-model="form.genre" clearable placeholder="请选择类型;1 预约单  2库存单">
              <!--              <el-option-->
              <!--                v-for="item in genreData"-->
              <!--                :key="item.dictKey"-->
              <!--                :label="item.dictValue"-->
              <!--                :value="item.dictKey">-->
              <!--              </el-option>-->
              <el-option label="库存单" value="2">库存单</el-option>
              <el-option label="预约单" value="1">预约单</el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="状态;1 配送 2 待配送" prop="state">
            <el-select v-model="form.state" clearable placeholder="请选择状态;1 配送 2 待配送">
              <!--              <el-option-->
              <!--                v-for="item in stateData"-->
              <!--                :key="item.dictKey"-->
              <!--                :label="item.dictValue"-->
              <!--                :value="item.dictKey">-->
              <!--              </el-option>-->
              <el-option label="待配送" value="2">待配送</el-option>
              <el-option label="配送" value="1">配送</el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <!-- 表单按钮 -->
        <template #footer>
          <span v-if="!view" class="dialog-footer">
            <el-button type="primary" icon="el-icon-circle-check" @click="handleSubmit"
              >提 交</el-button
            >
            <el-button icon="el-icon-circle-close" @click="box = false">取 消</el-button>
          </span>
        </template>
      </el-dialog>
    </div>
  </basic-container>
  <edittablehead
    @setcolum="setnewcolum"
    @closce="showdrawer"
    :drawerShow="drawerShow"
    :columnList="columnList"
  ></edittablehead>
</template>

<script>
import {
  getList,
  getDetail,
  add,
  update,
  remove,
  addStock, stockArticExport
} from '@/api/distribution/distributionStockArticle';
import { getListOwn } from '@/api/distribution/distributionParcelList';
import { addCallDelivery } from '@/api/distribution/distrilbutionCallDelivery';
import { addClient } from '@/api/distribution/distributionClientMessage';
import { addService } from '@/api/distribution/distributionServiceLog';
import option from '@/option/distribution/distributionStockArticle';
import { mapGetters } from 'vuex';
import { getDictionaryBiz } from '@/api/system/dict';
import dayjs from 'dayjs';
import { downloadXls } from '@/utils/util';

export default {
  data() {
    return {
      columnList: [
        {
          prop: '',
          label: '序号',
          type: 0,
          values: '',
          width: 55,
          checkarr: [],
          fixed: true,
        },
        {
          prop: 'serviceNumber',
          label: '服务号',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: 'waybillNumber',
          label: '运单号',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: 'orderCode',
          label: '订单自编号',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'mallName',
          label: '商场名称',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'descriptionGoods',
          label: '货物名称',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'warehouse',
          label: '所在仓库',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'warehouseEntryTime',
          label: '入库时间',
          type: 4,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'warehouseEntryTimeEnd',
          label: '最新入库时间',
          type: 4,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'storeTime',
          label: '在库时间',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'totalNumber',
          label: '订单总件数',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'consigneeUnit',
          label: '收货单位',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'consigneePerson',
          label: '收货人',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'handQuantity',
          label: '在库件数',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'availableQuantity',
          label: '可用数量',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'notReceived',
          label: '未入库数量',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'sortingQuantity',
          label: '分拣数量',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'deliveryQuantity',
          label: '配送数量',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'transferQuantity',
          label: '中转数量',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'signinQuantity',
          label: '签收数量',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'groundingStatusName',
          label: '上架状态',
          type: 3,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'allocation',
          label: '货区-货位-货架',
          type: 1,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'resource',
          label: '订单来源',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'trays',
          label: '所在托盘',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'freezeStatusName',
          label: '冻结状态',
          type: 3,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'orderStatusName',
          label: '订单状态',
          type: 3,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'reservationStatusName',
          label: '预约状态',
          type: 3,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'stockupStatusName',
          label: '备货状态',
          type: 3,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'orderReceiveStatusName',
          label: '入库状态',
          type: 3,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'completeSetName',
          label: '是否齐套',
          type: 3,
          values: '',
          width: '130',
          checkarr: [
            {
              value: '2',
              label: '是',
            },
            {
              value: '1',
              label: '否',
            },
          ],
          fixed: false,
          sortable: true,
        },
        // {
        //   prop: 'brand',
        //   label: '品牌',
        //   type: 2,
        //   values: '',
        //   width: '150',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        // {
        //   prop: 'typeServerName',
        //   label: '服务类型',
        //   type: 1,
        //   values: '',
        //   width: '150',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        {
          prop: 'customerName',
          label: '顾客名字',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'customerTelephone',
          label: '顾客电话',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'customerAddress',
          label: '顾客地址',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'fee',
          label: '增值服务',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'createUserName',
          label: '创建人',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'createTime',
          label: '创建时间',
          type: 4,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        // {
        //   prop: 'inventoryDate',
        //   label: '最新盘点时间',
        //   type: 1,
        //   values: '',
        //   width: '150',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // }, {
        //   prop: 'inventoryPerson',
        //   label: '盘点人',
        //   type: 1,
        //   values: '',
        //   width: '150',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        {
          prop: '',
          label: '操作',
          type: 6,
          values: '',
          width: '200',
          checkarr: [],
          fixed: 'right',
          hide: true,
        },
        // 更多列的配置...
      ],
      columnListedit: [],
      drawerShow: false,
      height: 0,
      // 弹框标题
      title: '',
      // 是否展示弹框
      box: false,
      // 是否显示查询
      search: true,
      // 加载中
      loading: true,
      // 是否为查看模式
      view: false,
      // 查询信息
      query: {},
      // 分页信息
      page: {
        currentPage: 1,
        pageSize: 30,
        total: 40,
      },
      // 表单数据
      form: {},
      formCall: {}, // 通知
      formService: {}, // 服务
      formCustomer: {}, // 客户
      // 选择行
      selectionList: [],
      // 表单配置
      option: option,
      // 表单列表
      data: [],
      distributionType: [],
      dialogTableVisible: false,
      dialogFormVisible: false,
      dialogFormCustomer: false, //多选客户弹窗
      dialogFormCustomerOwn: false, //单独的客户标识
      dialogFormService: false,
      formLabelWidth: '120px',
      handler: true, //首次
      trade: false, // 商
      municipal: true, // 市
      taker: true, // 自提
      stockupDate: [],
      defaultTime2: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)], // '12:00:00', '08:00:00'
      shortcuts: [
        {
          text: '最近一周',
          value: () => {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            return [start, end];
          },
        },
        {
          text: '最近一个月',
          value: () => {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            return [start, end];
          },
        },
        {
          text: '最近三个月',
          value: () => {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            return [start, end];
          },
        },
      ],
    };
  },
  mounted() {
    this.init();
    this.onLoad(this.page);
    /**
     * 初始化获取本地缓存的编辑隐藏的列表
     *  固定搭配，不能更改
     */
    // let checkList=[]
    // this.columnList.map(item => {
    //     item.head = false;
    // });
    let checkListnewarr = this.$functions.getStorage(window.location.pathname + 'checkList');
    let flexListnewarr = this.$functions.getStorage(window.location.pathname + 'flexList');
    let sortlistnewarr = this.$functions.getStorage(window.location.pathname + 'sortlist');
    if (checkListnewarr) {
      this.columnList.map(item => {
        item.head = false;
      });
      checkListnewarr.map(ite => {
        this.columnList.map(item => {
          if (ite == item.label) {
            item.head = true;
          }
        });
      });
    } else {
      let arr = [];
      this.columnList.map(item => {
        if (item.head) {
          arr.push(item.label);
        }
      });
      this.$functions.setStorage(window.location.pathname + 'checkList', arr);
    }
    if (flexListnewarr) {
      this.columnList.map(item => {
        item.fixed = false;
      });
      flexListnewarr.map(ite => {
        this.columnList.map(item => {
          if (ite == item.label) {
            if (item.type == 6) {
              item.fixed = 'right';
            } else {
              item.fixed = true;
            }
          }
        });
      });
    } else {
      let arr = [];
      this.columnList.map(item => {
        if (item.fixed) {
          arr.push(item.label);
        }
      });
      this.$functions.setStorage(window.location.pathname + 'flexList', arr);
    }
    if (sortlistnewarr) {
      this.columnList.map(item => {
        item.sortable = false;
      });
      sortlistnewarr.map(ite => {
        this.columnList.map(item => {
          if (ite == item.label) {
            item.sortable = true;
          }
        });
      });
    } else {
      let arr = [];
      this.columnList.map(item => {
        if (item.sortable) {
          arr.push(item.label);
        }
      });
      this.$functions.setStorage(window.location.pathname + 'sortlist', arr);
    }
  },
  computed: {
    ...mapGetters(['permission']),
  
    permissionList() {
      return {
        addBtn: this.validData(this.permission.basicdataBrandCategory_add, false),
        viewBtn: this.validData(this.permission.basicdataBrandCategory_view, false),
        delBtn: this.validData(this.permission.basicdataBrandCategory_delete, false),
        editBtn: this.validData(this.permission.basicdataBrandCategory_edit, false),
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(',');
    },

  },
  methods: {
    //导出
    handleExport() {
      let row = {  };
      if(!!this.ids){
        row.ids = this.ids;
      }
      row.typeService ="1";
      stockArticExport(row).then( res =>{
        console.log(res.data);
        downloadXls(res.data, '商配订单数据.xlsx');
      });

    },

    showdrawer(value) {
      this.drawerShow = value;
    },
    /**
     * 弹窗的勾选回调，用于更改头部数组
     * 固定搭配，只需要更换   columnList
     */
    setnewcolum(newarr, headarr, type) {
      // console.log(newarr,'+++++++++++')
      if (type == 1) {
        this.columnList = newarr;
        this.$functions.setStorage(window.location.pathname + 'checkList', headarr);
      } else if (type == 2) {
        this.columnList = newarr;
        this.$functions.setStorage(window.location.pathname + 'flexList', headarr);
      } else if (type == 3) {
        this.columnList = newarr;
        this.$functions.setStorage(window.location.pathname + 'sortlist', headarr);
      }
    },
    selectionsc(value) {
      console.log(value);
    },
    delectsolt(scope) {
      const { row } = scope;
      console.log(row);
    },
    editsolt(scope) {
      const { row } = scope;
      console.log(row);
    },
    btnsc(index, row) {
      console.log(index, row);
    },
    /**
     * 处理字段和名称不一致的问题
     * @param {} index
     * @param {*} row
     */
    selectsc(index, row) {
      if (row.prop === 'freezeStatusName') {
        this.query['freezeStatus'] = index;
      } else if (row.prop === 'completeSetName') {
        this.query['completeSet'] = index;
      } else if (row.prop === 'reservationStatusName') {
        this.query['reservationStatus'] = index;
      } else if (row.prop === 'groundingStatusName') {
        this.query['groundingStatus'] = index;
      } else if (row.prop === 'stockupStatusName') {
        this.query['stockupStatus'] = index;
      } else if (row.prop === 'orderStatusName') {
        this.query['orderStatus'] = index;
      } else if (row.prop === 'typeServerName') {
        this.query['typeService'] = index;
      } else if (row.prop === 'orderReceiveStatusName') {
        this.query['orderReceiveStatus'] = index;
      } else {
        this.query[row.prop] = index;
      }
      this.onLoad(this.page);
    },
    timesc(index, row) {
      console.log(index, row);
      if (!!index) {
        index = dayjs(index).format('YYYY-MM-DD');
      }
      this.query[row.prop] = index;
      if (!index) {
        delete this.query[row.prop];
      }
      this.onLoad(this.page);
    },
    inputsc(index, row) {
      console.log(index, row);
      // console.log(index, row.prop);
      this.query[row.prop] = index;
      this.onLoad(this.page);
    },
    handleMoke() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      let st = false;
      this.selectionList.some(i => {
        if (i.reservationStatus === '30') {
          st = true;
          this.$message.warning(i.orderCode + ' - 已预约，请勿重复预约！！！');
        }
        if (i.typeService === 3) {
          st = true;
          this.$message.warning(i.orderCode + ' - 为自提单，无法预约！！！');
        }
      });
      if (st) {
        return;
      }
      // 判断orderId是否全都相等
      const notEqualFlag = this.selectionList.some(
        item =>
          this.selectionList.filter(
            ele =>
              ele.customerName !== item.customerName &&
              ele.customerTelephone !== item.customerTelephone &&
              ele.customerAddress !== item.customerAddress
          ).length >= 1
      );
      console.log('notEqualFlag=====', notEqualFlag);
      // 返回true,说明有不同
      // 返回false,说明全都相等
      if (!notEqualFlag) {
        this.$router.push({
          path: '/distribution/reservation/reservationFrom',
          query: {
            id: this.ids,
          },
        });
      } else {
        this.$message.warning('请选择相同收货信息的订单！！！');
      }
    },
    async handleStockList() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.getSock();

      /*else if (this.selectionList.length > 1){
        this.getSock();
      }else if (this.selectionList.length < 2){
        //判断有没有包件
        let params ={
          stockArticleId : this.selectionList[0].id
        }

      let a =  await  getListOwn(this.page.currentPage,this.page.pageSize,params);
        // console.log("aaaaaaa===",a.data.data);
        if(a.data.data.records.length > 0){
          this.$router.push({
            path: '/distribution/inventory/distributionStockArticleFrom',
            query: {
              id : this.ids,
              name : "转库存单"
            }
          });
        }else{
          this.getSock();
        }
      }*/
    },
    getSock() {
      this.$confirm('确定将选择的订单转为库存品吗？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          return addStock(this.ids);
        })
        .then(() => {
          this.selectionClear();
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
        });
    },
    //确定通知提货按钮
    callFordelivery(inde) {
      switch (inde) {
        case '1':
          console.log(this.formCall);
          this.formCall.waybillNumber = this.ids;
          addCallDelivery(this.formCall).then(() => {
            this.$message({
              type: 'success',
              message: '操作成功!',
            });
            this.dialogFormVisible = false;
            this.formCall = {};
            this.onLoad(this.page);
          });
          break;
        case '2':
          this.formService.stockArticleId = this.ids;
          console.log('服务类型', this.formService);
          addService(this.formService).then(() => {
            this.$message({
              type: 'success',
              message: '操作成功!',
            });
            this.dialogFormService = false;
            this.formService = {};
            this.onLoad(this.page);
          });
          break;
        case '3':
          console.log('客户信息！！！', this.formCustomer);
          if (!this.dialogFormCustomerOwn) {
            this.formCustomer.stockArticleId = this.ids;
          }
          addClient(this.formCustomer).then(() => {
            this.$message({
              type: 'success',
              message: '操作成功!',
            });
            this.dialogFormCustomer = false;
            this.dialogFormCustomerOwn = false;
            this.formCustomer = {};
            this.onLoad(this.page);
          });
          break;
      }
    },
    //提货跳转
    handlebill(row) {
      console.log('>>>>', this.ids);
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.$router.push({
        path: '/distribution/inventory/distrilbutionBillLading',
        query: {
          id: this.ids,
        },
      });
    },
    //修改客户信息
    handleCallDeliveryOwn(row) {
      console.log('row', row);
      this.formCustomer.name = row.row.customerName;
      this.formCustomer.phone = row.row.customerTelephone;
      this.formCustomer.address = row.row.customerAddress;
      this.formCustomer.stockArticleId = row.row.id;
      this.dialogFormCustomer = true;
      this.dialogFormCustomerOwn = true;
    },
    //通知提货
    handleCallDelivery(ind) {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      let a = this.selectionList.find(i => i.reservationStatus == '30');
      if (!!a) {
        this.$message.warning('有已预约的数据，不能修改！！！');
        return;
      }
      switch (ind) {
        case '1':
          let ids = [];
          this.selectionList.forEach(ele => {
            ids.push(ele.orderCode);
          });
          this.formCall.waybill = ids;
          this.dialogFormVisible = true;
          break;
        case '2':
          this.dialogFormService = true;
          break;
        case '3':
          this.dialogFormCustomer = true;
          break;
      }
    },
    init() {
      this.height = this.setPx(document.body.clientHeight - 340);
      getDictionaryBiz('distribution_type').then(res => {
        this.distributionType = res.data.data;
        /*   this.$functions.checkcColumnList("typeServerName", this.columnList).checkarr=res.data.data.map(item=>{
            item.value=item.dictKey
            item.label=item.dictValue
            return item
          });*/

        // this.columnList[26].checkarr =res.data.data.map(item=>{
        //   item.value=item.dictKey
        //   item.label=item.dictValue
        //   return item
        // });
      });
      getDictionaryBiz('order_status').then(res => {
        this.deliveryOrderStatus = res.data.data;
        this.$functions.checkcColumnList('orderStatusName', this.columnList).checkarr =
          res.data.data.map(item => {
            item.value = item.dictKey;
            item.label = item.dictValue;
            return item;
          });
      });
      getDictionaryBiz('basic_grounding').then(res => {
        this.$functions.checkcColumnList('groundingStatusName', this.columnList).checkarr =
          res.data.data.map(item => {
            item.value = item.dictKey;
            item.label = item.dictValue;
            return item;
          });
      });
      getDictionaryBiz('freeze_status').then(res => {
        this.$functions.checkcColumnList('freezeStatusName', this.columnList).checkarr =
          res.data.data.map(item => {
            item.value = item.dictKey;
            item.label = item.dictValue;
            return item;
          });
      });
      getDictionaryBiz('stockup_status').then(res => {
        this.$functions.checkcColumnList('stockupStatusName', this.columnList).checkarr =
          res.data.data.map(item => {
            item.value = item.dictKey;
            item.label = item.dictValue;
            return item;
          });
      });
      getDictionaryBiz('order_reservation_status').then(res => {
        this.$functions.checkcColumnList('reservationStatusName', this.columnList).checkarr =
          res.data.data.map(item => {
            item.value = item.dictKey;
            item.label = item.dictValue;
            return item;
          });
      });

      getDictionaryBiz('order_receive_status').then(res => {
        this.$functions.checkcColumnList('orderReceiveStatusName', this.columnList).checkarr =
          res.data.data.map(item => {
            item.value = item.dictKey;
            item.label = item.dictValue;
            return item;
          });
      });
    },
    searchHide() {
      this.search = !this.search;
    },
    searchChange() {
      this.onLoad(this.page);
    },
    searchReset() {
      this.query = {};
      this.stockupDate = [];
      this.page.currentPage = 1;
      this.onLoad(this.page);
    },
    handleSubmit() {
      if (!this.form.id) {
        add(this.form).then(() => {
          this.box = false;
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
        });
      } else {
        update(this.form).then(() => {
          this.box = false;
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
        });
      }
    },

    //全部
    handleEntire() {
      this.handler = true;
      this.taker = true;
      this.trade = false;
    },
    //商配
    handleTrade() {
      // this.handler = true;
      this.trade = true;
    },
    //商配
    handleMunicipal() {
      // this.handler = true;
      // this.taker = true;
    },
    //自提
    handlePickUpStore() {
      this.loading = true;
      // console.log("this.query",this.query);
      let params = {};
      this.query.typeService = '1';
      getList(this.page.currentPage, this.page.pageSize, Object.assign(params, this.query)).then(
        res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
          this.handler = false;
          this.taker = false;
        }
      );
    }, //自提的通知
    handleInform(index) {
      this.loading = true;
      // console.log("this.query",this.query);
      let params = {};
      this.query.typeService = '1';
      switch (index) {
        case '1':
          this.query.notification = index;
          break;
        case '2':
          this.query.notification = index;
          break;
      }
      this.query.typeService = '1';
      getList(this.page.currentPage, this.page.pageSize, Object.assign(params, this.query)).then(
        res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
          this.handler = false;
          this.taker = false;
        }
      );
    },
    handleAdd() {
      return this.$message({
        type: 'error',
        message: '功能还在开发中',
      });
    },
    handleEdit(row) {
      this.title = '编辑';
      this.box = true;
      getDetail(row.row.id).then(res => {
        this.form = res.data.data;
      });
    },
    handleView(row) {
      // this.title = '查看'
      // this.view = true;
      // this.box = true;
      // getDetail(row.id).then(res => {
      //   this.form = res.data.data;
      // });
      // console.log("查看===",row.row);
      this.$router.push({
        path: '/distribution/inventory/distributionStockArticleDetails',
        query: {
          id: row.row.id,
          name: '详情 - ' + row.row.orderCode,
        },
      });
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          return remove(this.ids);
        })
        .then(() => {
          this.selectionClear();
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
        });
    },
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
        });
    },
    beforeClose(done) {
      done();
      this.form = {};
      this.view = false;
    },
    selectionChange(list) {
      // console.log("添加阿斯顿发生",list);
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      // this.$refs.table.clearSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.onLoad(this.page);
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.onLoad(this.page);
    },
    getTime(dat) {
      let date = new Date(dat);
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? '0' + m : m;
      var d = date.getDate();
      d = d < 10 ? '0' + d : d;
      var h = date.getHours();
      h = h < 10 ? '0' + h : h;
      var minute = date.getMinutes();
      minute = minute < 10 ? '0' + minute : minute;
      var s = date.getSeconds();
      s = s < 10 ? '0' + s : s;
      return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + s;
    },
    onLoad(page, params = {}) {



      this.loading = true;
      if (this.stockupDate.length > 0) {
        let startDate = this.stockupDate[0];
        let entDate = this.stockupDate[1];
        params.startDate = this.getTime(startDate.toString());
        params.entDate = this.getTime(entDate.toString());
      }
      this.query.genre = 1;
      this.query.typeService = 1;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.data = this.data.map(i => {
          // const freezeStatusMap = {
          //   0: "未冻结",
          //   1: "已冻结",
          //   default: "无"
          // };
          const nuMap = {
            '-1': '0',
          };
          // const groundingStatusMap = {
          //   0: "未上架",
          //   1: "部分上架",
          //   2: "已上架",
          //   3: "已下架",
          //   default: "无"
          // };
          // i.freezeStatusName = freezeStatusMap[i.freezeStatus] || freezeStatusMap.default;
          // i.groundingStatusName = groundingStatusMap[i.groundingStatus] || groundingStatusMap.default;
          i.handQuantity = nuMap[i.handQuantity] || i.handQuantity;
          i.sortingQuantity = nuMap[i.sortingQuantity] || i.sortingQuantity;
          i.deliveryQuantity = nuMap[i.deliveryQuantity] || i.deliveryQuantity;
          i.signinQuantity = nuMap[i.signinQuantity] || i.signinQuantity;
          i.transferQuantity = nuMap[i.transferQuantity] || i.transferQuantity;
          i.availableQuantity = nuMap[i.availableQuantity] || i.availableQuantity;
          i.notReceived = parseInt(i.totalNumber) - parseInt(i.handQuantity);
          return i;
        });
        this.loading = false;
        this.selectionClear();
      });
    },
  },
};
</script>
<style scoped lang="scss">
.el-button--text {
  margin-right: 15px;
}
.el-select {
  width: 300px;
}
.el-input {
  width: 300px;
}
.dialog-footer button:first-child {
  margin-right: 10px;
}
.el-fr {
  width: 100%;
  display: flex;
  justify-content: space-between;
  .asterisk-left:last-child {
    margin-right: 0;
  }
}
.el-input {
  margin-left: 8px;
}

:deep(.el-form-item__content) {
  margin-left: 8px;
}
.el-times {
  width: auto;
  :deep(.el-tooltip__trigger) {
    height: 30px !important;
  }
}
:deep(.el-form-item__label) {
  padding: 0;
}
</style>
