<template>
  <!--全部订单-->
  <basic-container>
    <div class="avue-crud">
      <el-row v-if="!search" style="padding: 6px 18px">
        <!-- 查询模块 -->
        <!-- <el-form :inline="true" :model="query">
          <el-form-item label="订单自编号:">
            <el-input v-model="query.orderCode" placeholder="请输入订单自编号" ></el-input>
          </el-form-item> -->
        <!-- 查询按钮 -->
        <!-- <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">
          <!-- 头部左侧按钮模块 -->
          <div class="avue-crud__left">
            <el-button type="danger" icon="el-icon-bottom" @click="handleExportInfo" plain
              >导出
            </el-button>
          </div>
          <div class="avue-crud__left"></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-button type="primary" text icon="el-icon-view" @click="handleView(slotProps.scope)">查看</el-button>-->
          <!--            <el-button type="primary" text icon="el-icon-edit" @click="handleCallDeliveryOwn(slotProps.scope)">修改客户信息</el-button>-->
          <!--          </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>
    </div>
  </basic-container>
  <edittablehead
    @setcolum="setnewcolum"
    @closce="showdrawer"
    :drawerShow="drawerShow"
    :columnList="columnList"
  ></edittablehead>
</template>

<script>
import {
  getList,
  getDetail,
  add,
  update,
  remove,
  addStock,
} from '@/api/distribution/distributionStockArticle';
import { getListOwn } from '@/api/distribution/distributionParcelList';
import { addCallDelivery } from '@/api/distribution/distrilbutionCallDelivery';
import { addClient,$_distributionStockArticle } 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 { getUser } from '@/api/system/user';
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: '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: [
            // {
            //   value: '0',
            //   label: '未上架',
            // },
            // {
            //   value: '1',
            //   label: '部分上架',
            // }, {
            //   value: '2',
            //   label: '已上架',
            // },
            // {
            //   value: '3',
            //   label: '已下架',
            // },
          ],
          fixed: false,
          sortable: true,
        },
        // {
        //   prop: 'allocation',
        //   label: '货区-货位-货架',
        //   type: 1,
        //   values: '',
        //   width: '130',
        //   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: [
        //     // {
        //     //   value: '1',
        //     //   label: '已冻结',
        //     // },
        //     // {
        //     //   value: '0',
        //     //   label: '未冻结',
        //     // },
        //   ],
        //   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: '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: '130',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        {
          prop: 'typeServerName',
          label: '服务类型',
          type: 3,
          values: '',
          width: '130',
          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: 'driverName',
          label: '配送司机',
          type: 1,
          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: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },

        // {
        //   prop: '',
        //   label: '操作',
        //   type: 6,
        //   values: '',
        //   width: '230',
        //   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: [],
      deliveryOrderStatus: [],
      dialogTableVisible: false,
      dialogFormVisible: false,
      dialogFormCustomer: false, //多选客户弹窗
      dialogFormCustomerOwn: false, //单独的客户标识
      dialogFormService: false,
      formLabelWidth: '120px',
      handler: true, //首次
      trade: false, // 商
      municipal: true, // 市
      taker: true, // 自提
    };
  },
  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: {
    // 导出表格
    handleExportInfo() {
      let row = {};
      if (!!this.ids) {
        row.ids = this.ids;
      } else {
        row.ids = '';
      }
      $_distributionStockArticle(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);
    },
    selectsc(index, row) {
      console.log(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 {
        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.forEach(i => {
        console.log('yuyuyuuyu', i);
        if (i.reservationStatusName === '已预约') {
          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;
      } else {
        let st = false;
        let lost = false;
        for (const i of this.selectionList) {
          console.log('yuyuyuuyu', i);
          if (i.reservationStatusName == '已预约') {
            st = true;
            this.$message.warning(i.orderCode + ' - 已预约，无法转为库存品！！！');
          }
          if (i.typeService == 3) {
            st = true;
            this.$message.warning(i.orderCode + ' - 为自提单，无法转为库存品！！！');
          }
          if (i.freezeStatus == '30') {
            st = true;
            this.$message.warning(i.orderCode + ' - 为冻结单，无法转为库存品！！！');
          }
          if (!st) {
            //查询库存数据
            // console.log("cxcxcxc",i);
            let aa = await getListOwn(this.page.currentPage, this.page.pageSize, {
              stockArticleId: i.id,
            }).then();
            // console.log("包件物料不存在！！",aa.data.data.records);
            aa.data.data.records.forEach(l => {
              console.log(l.materialId, l.materialName, l.materialCode, l.materialUnit);
              if (!l.materialId || l.materialId == '-1') {
                lost = true;
              }
            });
          }
        }
        if (st) {
          return;
        }
        if (lost) {
          this.$message.warning(
            '订单信息不完整，请完善包件信息！如没有请维护物料信息，在选择！！！'
          );
        } else {
          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;
      }
      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);
      let that = this;
      getDictionaryBiz('distribution_type').then(res => {
        that.distributionType = res.data.data;
        this.$functions.checkcColumnList('typeServerName', that.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 => {
        that.deliveryOrderStatus = res.data.data;
        this.$functions.checkcColumnList('orderStatusName', that.columnList).checkarr =
          res.data.data.map(item => {
            item.value = item.dictKey;
            item.label = item.dictValue;
            return item;
          });
        // this.columnList[24].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', that.columnList).checkarr =
          res.data.data.map(item => {
            item.value = item.dictKey;
            item.label = item.dictValue;
            return item;
          });
        // this.columnList[19].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', that.columnList).checkarr =
          res.data.data.map(item => {
            item.value = item.dictKey;
            item.label = item.dictValue;
            return item;
          });
        // this.columnList[19].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', that.columnList).checkarr =
          res.data.data.map(item => {
            item.value = item.dictKey;
            item.label = item.dictValue;
            return item;
          });
        // this.columnList[36].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', that.columnList).checkarr =
          res.data.data.map(item => {
            item.value = item.dictKey;
            item.label = item.dictValue;
            return item;
          });
        // this.columnList[35].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.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() {
      this.title = '新增';
      this.form = {};
      this.box = true;
    },
    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);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      (this.query.orderStatus = 80),
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          console.log('>>>>>>>', data.records);
          this.page.total = data.total;
          this.data = data.records;
          this.data = this.data.map(i => {
            // console.log("iiiii",i.createUser);
            // 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;
            // console.log("i.totalNumber",i.totalNumber,"i.handQuantitys",i.handQuantity);
            i.notReceived = parseInt(i.totalNumber) - parseInt(i.handQuantity);
            return i;
          });
          this.loading = false;
          this.selectionClear();
        });
    },
  },
};
</script>
<style scoped>
.el-button--text {
  margin-right: 15px;
}
.el-select {
  width: 300px;
}
.el-input {
  width: 300px;
}
.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>
