<template>
  <div>
    <div class="customer-head">
      <div class="customer-back">
        <el-button
          type="danger"
          style="border: none; background: none; color: red"
          icon="el-icon-arrow-left"
          @click="backToList(0)"
          >返回列表
        </el-button>
      </div>
      <div class="add-customer-btn">
        <el-button
          class="el-button&#45;&#45;small-yh"
          :disabled="isEditButton"
          style="margin-left: 6px"
          type="primary"
          size="small"
          v-if="editButton"
          @click="confirmEditing"
          >编 辑
        </el-button>
        <el-button
          class="el-button--small-yh"
          v-else
          style="margin-left: 6px"
          type="primary"
          size="small"
          :disabled="editDis"
          @click="editCustomer"
          >保 存
        </el-button>
        <el-button
          class="el-button--small-yh"
          style="margin-left: 6px"
          type="success"
          size="small"
          :disabled="editButton"
          @click="orderConfirmation"
          v-if="form.status == '待确认'"
        >
          订单确认
        </el-button>
        <el-button
          class="el-button--small-yh"
          style="margin-left: 6px"
          type="danger"
          size="small"
          :disabled="editButton"
          v-if="form.status == '待发货'"
          @click="revokeOrderConfirmation"
        >
          撤销订单确认
        </el-button>
        <el-button
          v-if="form.id"
          class="el-button--small-yh"
          style="margin-left: 6px"
          type="info"
          size="small"
          :disabled="form.status != '已发货' || form.returnsNumber == form.goodsTotalNum || editButton"
          @click="getReturns"
        >
          销售退货
        </el-button>

        <el-dropdown style="padding: 0 6px; line-height: 0">
          <el-button v-show="form.id" type="danger" :loading="buttonLoading" :disabled="form.id" size="small">
            售 后<i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="applySettlement('申请')" :disabled="isApplySettlement"
              >申请退款
            </el-dropdown-item>
            <!--                        <el-dropdown-item @click.native="confirmRefundBtn('确认')" :disabled="isConfirmRefundBtn">确认退款
                        </el-dropdown-item>-->
            <el-dropdown-item @click.native="revocationRequest('撤销')" :disabled="isRevocationRequest"
              >撤销请核
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
    <div style="margin-top: 50px">
      <trade-card title="基础信息">
        <avue-form :option="optionForm" v-model="form" ref="form">
          <tempalte slot="customerName" slot-scope="{ row }">
            <search-query
              :datalist="customerData"
              :selectValue="form.customerName"
              :clearable="true"
              :buttonIf="false"
              :filterable="true"
              :remote="true"
              :disabled="editDis || form.orderItemsList.length"
              placeholder="请选择店铺名称"
              :forParameter="{ key: 'id', label: 'cname', value: 'cname' }"
              @corpFocus="KHgetListfun"
              @remoteMethod="KHgetListfun"
              @corpChange="KHcorpChange"
              @corpClear="KHClear"
            >
            </search-query>
          </tempalte>
          <template slot-scope="{ row, index }" slot="contacts">
            <el-select
              v-model="form.contacts"
              placeholder="请选择"
              size="small"
              style="width: 60%"
              clearable
              filterable
              allow-create
              default-first-option
              @change="contactsChange($event)"
              :disabled="editDis"
            >
              <el-option v-for="item in contactsOption" :key="item.id" :label="item.contacts" :value="item.contacts" />
            </el-select>
          </template>
          <tempalte slot="salerName">
            <dic-select
              v-model="form.salerName"
              placeholder="业务员"
              key="id"
              label="name"
              url="/blade-user/salerList"
              :filterable="true"
              @selectChange="dicChange('salerName', $event)"
              :disabled="editDis"
            >
            </dic-select>
          </tempalte>
        </avue-form>
      </trade-card>
      <trade-card title="明细信息">
        <el-tabs v-model="activeName" type="card">
          <el-tab-pane label="销售明细" name="sale_detail">
            <avue-crud
              :option="optionContacts"
              v-model="formContacts"
              ref="formContacts"
              :data="form.orderItemsList"
              :key="key"
              @row-save="rowSave"
              @row-update="rowUpdate"
              @row-close="rowClose"
              :before-close="beforeClose"
              @selection-change="selectionContacts"
            >
              <template slot-scope="{ scope, row }" slot="menuLeft">
                <el-button type="primary" icon="el-icon-plus" size="small" :disabled="editDis" @click="rowAdd(row, 1)"
                  >添加商品</el-button
                >
                <el-button
                  type="success"
                  size="small"
                  :disabled="editDis"
                  icon="el-icon-bottom"
                  @click="excelDialogfun('名称')"
                  >按名称导入
                </el-button>
                <el-button
                  type="success"
                  size="small"
                  :disabled="editDis"
                  icon="el-icon-bottom"
                  @click="excelDialogfun('code')"
                  >按Code导入
                </el-button>
                <el-button type="primary" icon="el-icon-printer" size="small" @click="handlePrint">打印</el-button>
                <el-button type="danger" plain size="small" @click="batchDelete" :disabled="editDis"
                  >一键删除</el-button
                >
                <el-button type="primary" plain size="small" @click="quickCopy">快捷复制</el-button>
                <el-popover width="600" trigger="click">
                  <avue-crud :data="inventoryData" :option="inventoryOption"></avue-crud>
                  <el-button
                    type="primary"
                    plain
                    size="small"
                    slot="reference"
                    @click="viewInventory"
                    :disabled="selectionMultilist.length != 1"
                    >查看库存</el-button
                  >
                </el-popover>
                <el-button type="primary" icon="el-icon-plus" size="small" :disabled="editDis" @click="rowAdd(row, 2)"
                  >无库存商品</el-button
                >
                <el-popover width="600" trigger="click">
                  <avue-crud :data="inventoryData2" :option="inventoryOption2">
                    <template slot-scope="{ row }" slot="menu">
                      <el-button
                        type="text"
                        icon="el-icon-getDetail"
                        size="small"
                        :disabled="row.storageId != form.storageId"
                        @click.stop="synchronous(row)"
                        >更新库存
                      </el-button>
                    </template>
                  </avue-crud>
                  <el-button
                    type="primary"
                    plain
                    size="small"
                    slot="reference"
                    @click="viewInventory2"
                    :disabled="selectionMultilist.length != 1 || isAddBtn"
                    >同步库存</el-button
                  >
                </el-popover>
              </template>
              <template slot="goodsId" slot-scope="{ row }">
                {{ row.goodsName }}
              </template>
              <tempalte slot-scope="{ row, index }" slot="reservoirArea">
                <dic-select
                  v-if="row.$cellEdit"
                  v-model="row.reservoirArea"
                  placeholder="库区"
                  label="cname"
                  :key="form.storageId"
                  @selectChange="rowDicChange('reservoirArea', $event, row)"
                  :url="'/gubersail-admin/warehouse/list?current=1&size=5&storageId=' + form.storageId"
                  :filterable="true"
                  :remote="true"
                  dataName="cname"
                  res="records"
                >
                </dic-select>
                <span v-else>{{ row.reservoirArea }}</span>
              </tempalte>
              <template slot="goodsNum" slot-scope="{ row }">
                <el-input-number
                  v-if="row.$cellEdit"
                  size="small"
                  v-model="row.goodsNum"
                  :precision="numberDecimal"
                  :controls="false"
                  @change="goodsNumblurfun(row)"
                  :max="Number(row.inventory)"
                  style="width: 100%"
                ></el-input-number>
                <span v-else>{{ row.goodsNum }}</span>
              </template>
              <template slot="price" slot-scope="{ row }">
                <el-input v-if="row.$cellEdit" size="small" v-model="row.price" style="width: 100%"></el-input>
                <span v-else>{{ row.price }}</span>
              </template>
              <template slot="dot" slot-scope="{ row }">
                <el-select
                  v-if="row.$cellEdit"
                  v-model="row.dot"
                  filterable
                  default-first-option
                  @focus="picihaolistfun(row.goodsId)"
                  @change="dotchangefun($event, row)"
                  size="small"
                >
                  <el-option
                    v-for="(item, index) in picihaolist"
                    :key="index"
                    :label="item.dot"
                    :value="item.dot"
                  ></el-option>
                </el-select>
                <span v-else>{{ row.dot }}</span>
              </template>
              <template slot="subTotalMoney" slot-scope="{ row }">{{ row.goodsNum * row.price }}</template>

              <template slot="remarks" slot-scope="{ row }">
                <el-input v-if="!mingxibaocun" size="small" v-model="row.remarks" style="width: 100%"></el-input>
                <span v-else>{{ row.remarks }}</span>
              </template>
              <template slot-scope="{ type, size, row, index, disabled }" slot="menu">
                <el-button size="small" type="text" icon="el-icon-edit" :disabled="editDis" @click="rowEdit(row)">{{
                  row.$cellEdit ? "保存" : "编辑"
                }}</el-button>
                <el-button
                  icon="el-icon-delete"
                  :size="size"
                  :disabled="editDis"
                  :type="type"
                  @click="rowDelBox(row, index, 'orderItemsList')"
                  >删除
                </el-button>
              </template>
            </avue-crud>
            <el-dialog
              title="导入明细"
              append-to-body
              :visible.sync="excelBox"
              v-if="excelBox"
              width="555px"
              :close-on-click-modal="false"
              v-dialog-drag
            >
              <avue-form
                :option="excelOption"
                v-model="excelForm"
                table-loading="excelLoading"
                :upload-before="uploadBefore"
                :upload-after="uploadAfter"
              >
                <template slot="excelTemplate">
                  <el-button type="primary" @click="derivation">
                    点击下载<i class="el-icon-download el-icon--right"></i>
                  </el-button>
                </template>
              </avue-form>
              <p style="text-align: center; color: #dc0505">温馨提示 第一次导入时请先下载模板</p>
            </el-dialog>
          </el-tab-pane>
          <el-tab-pane label="支付明细" name="payment_details">
            <avue-crud
              :option="optionPaymentDetails"
              v-model="formContacts"
              ref="payment_details"
              :data="dataList"
              @row-save="rowSave"
              @row-update="rowUpdate"
              @resetColumn="
                resetColumnTwo('payment_details', 'optionPaymentDetails', 'optionPaymentDetailsBack', 269.2)
              "
              @saveColumn="saveColumnTwo('payment_details', 'optionPaymentDetails', 'optionPaymentDetailsBack', 269.2)"
            >
              <!-- <template slot-scope="{type,size,row,index,disabled}" slot="menu">
                                <el-button :size="size" :disabled="disabled" :type="type"
                                    :icon="row.$cellEdit ? 'el-icon-plus' : 'el-icon-edit'"
                                    @click="$refs.formContacts.rowCell(row, index)">{{ row.$cellEdit ? '确认' : '修改' }}
                                </el-button>
                                <el-button icon="el-icon-delete" :size="size" :disabled="disabled" :type="type"
                                    @click="rowDelBox(row, index, 'paymentRecordsList')">删除
                                </el-button>
                            </template> -->
            </avue-crud>
          </el-tab-pane>
          <el-tab-pane label="出库记录" name="outbound_records">
            <avue-crud
              :option="optionOutboundRecords"
              v-model="formContacts"
              ref="outbound_records"
              :data="form.outboundRecordsList"
              @row-save="rowSave"
              @row-update="rowUpdate"
              @resetColumn="
                resetColumnTwo('outbound_records', 'optionOutboundRecords', 'optionOutboundRecordsBack', 269.3)
              "
              @saveColumn="
                saveColumnTwo('outbound_records', 'optionOutboundRecords', 'optionOutboundRecordsBack', 269.3)
              "
            >
              <!-- <template slot-scope="{type,size,row,index,disabled}" slot="menu">
                                <el-button :size="size" :disabled="disabled" :type="type"
                                    :icon="row.$cellEdit ? 'el-icon-plus' : 'el-icon-edit'"
                                    @click="$refs.formContacts.rowCell(row, index)">{{ row.$cellEdit ? '确认' : '修改' }}
                                </el-button>
                                <el-button icon="el-icon-delete" :size="size" :disabled="disabled" :type="type"
                                    @click="rowDelBox(row, index)">删除
                                </el-button>
                            </template> -->
            </avue-crud>
          </el-tab-pane>
        </el-tabs>
      </trade-card>
      <report-dialog
        :switchDialog="switchDialog"
        :reportName="reportName"
        :reportId="form.id"
        @onClose="onClose()"
      ></report-dialog>
      <el-dialog
        append-to-body
        title="审批"
        class="el-dialogDeep"
        :visible.sync="checkDialog"
        width="50%"
        :close-on-click-modal="false"
        :destroy-on-close="true"
        :close-on-press-escape="false"
        v-dialog-drag
      >
        <check
          :checkData="checkData"
          :checkDetail="true"
          :idList="[]"
          @operationType="operationType"
          @choceCheckFun="choceCheckFun"
        >
        </check>
      </el-dialog>
      <el-dialog
        append-to-body
        title="审批进度"
        class="el-dialogDeep"
        :visible.sync="checkScheduleDialog"
        width="40%"
        :close-on-click-modal="false"
        :destroy-on-close="true"
        :close-on-press-escape="false"
        v-dialog-drag
      >
        <check-schedule :checkId="checkId" :batchNo="batchNo" @choceScheduleFun="choceScheduleFun"></check-schedule>
      </el-dialog>
    </div>

    <el-dialog
      title="选择商品"
      append-to-body
      class="el-dialogDeep"
      :visible.sync="dialogVisible"
      width="80%"
      :close-on-click-modal="false"
      :destroy-on-close="true"
      :close-on-press-escape="false"
      @close="closeGoods"
    >
      <el-row :style="{ height: rowHeight }">
        <el-col :span="5">
          <div>
            <el-scrollbar>
              <basic-container>
                <avue-tree
                  style="height: 60vh; overflow-y: auto"
                  :option="treeOption"
                  :data="treeDataGoods"
                  @node-click="nodeClick"
                />
              </basic-container>
            </el-scrollbar>
          </div>
        </el-col>
        <el-col :span="19">
          <basic-container>
            <avue-crud
              :option="optionTwo"
              :table-loading="loading"
              :data="goodsListShow"
              ref="crud"
              :search.sync="SelectSearch"
              @getDetail-change="refreshChange"
              @selection-change="selectionChange"
              @search-change="goodsSearch"
              :page.sync="page"
              @on-load="onLoadfun"
              @resetColumn="resetCrud"
              @saveColumn="saveCrud"
            >
              <template slot="menuLeft">
                <el-tabs v-model="activeNameTabs" @tab-click="tabHandle">
                  <el-tab-pane label="查询结果" name="searchList" />
                  <el-tab-pane label="已选定数据" name="importStaging" />
                </el-tabs>
              </template>
              <template slot="goodsNum" slot-scope="{ row }">
                <el-input-number
                  v-model="row.goodsNum"
                  size="small"
                  :controls="false"
                  :precision="numberDecimal"
                  @input="amountChange($event, row)"
                  style="width: 100%"
                />
              </template>
              <template slot="dot" slot-scope="{ row }">
                <!--使用allow-create属性即可通过在输入框中输入文字来创建新的条目。注意此时filterable必须为真。-->
                <!--本例还使用了default-first-option属性， 在该属性打开的情况下，按下回车就可以选中当前选项列表中的第一个选项，-->
                <!--无需使用鼠标或键盘方向键进行定位。-->
                <!--allow-create filterable default-first-option-->
                <el-select
                  v-model="row.dot"
                  filterable
                  default-first-option
                  size="small"
                  @focus="picihaolistfun(row.id)"
                  @change="dotchangefun($event, row)"
                >
                  <el-option
                    v-for="(item, index) in picihaolist"
                    :key="index"
                    :label="item.dot"
                    :value="item.dot"
                  ></el-option>
                </el-select>
                <!--<span v-else>{{ row.dot }}</span>-->
              </template>
              <template slot="price" slot-scope="{ row }">
                <el-input-number v-model="row.price" size="small" :controls="false" style="width: 100%" />
              </template>
              <template slot-scope="scope" slot="menu">
                <el-button
                  type="text"
                  icon="el-icon-edit"
                  size="small"
                  @click.stop="importStagList(scope.row, scope.index)"
                  v-if="activeNameTabs == 'searchList'"
                  :disabled="goodsListSave.findIndex((item) => item.id == scope.row.id) !== -1"
                  >选择
                </el-button>
                <el-button
                  type="text"
                  icon="el-icon-delete"
                  size="small"
                  @click.stop="removeStagList(scope.row, scope.index)"
                  v-else
                  >移除
                </el-button>
              </template>
              <template slot="inventory" slot-scope="scope">
                <span style="color: #489fef">
                  {{ Number(scope.row.inventory) }}
                </span>
              </template>
            </avue-crud>
          </basic-container>
        </el-col>
      </el-row>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" :loading="saveLoading">取 消</el-button>
        <el-button type="primary" @click="importGoods" v-if="commodityData !== true" :loading="saveLoading"
          >导入</el-button
        >
        <!--<el-button type="primary" @click="importChoice" v-if="commodityData === true" :loading="saveLoading"-->
        <!--           :disabled="tableData.length !== 1">导入</el-button>-->
      </span>
    </el-dialog>
  </div>
</template>

<script>
// @ts-nocheck
import { getDetails as getCustom } from "@/api/basicData/customerInformation";
import { getDetails as getDetailsGods } from "@/api/basicData/commodityInformation";
import {
  getDetails,
  submit,
  generateShipTask,
  tradingBox,
  delOrderItem,
  checkOrder,
  confirmRefund,
  revokeCheckOrder,
  goodsListXs,
  revokeGenerateShipTask,
  goodsPageXs,
  getGoodAllList,
  generateReturns,
  whetherExistenceFinancing,
  checkOrderRW,
  revokeCheckOrderRW,
  getParamservice,
  orderConfirmation,
  revokeOrderConfirmation,
} from "@/api/salesManagement/saleOrder.js";
import { dotList, goodsDetail } from "@/api/purchasingManagement/warehouseEntryOrder.js";
import { dateFormat } from "@/util/date";
import { number } from "echarts";
import { getCorpTypes } from "@/api/basicData/commodityInformation";
import { getWorkDicts } from "@/api/system/dictbiz";
import { getList as KHgetList } from "@/api/basicData/customerInformation";
import { getToken } from "@/util/auth";
import { isProcurement } from "@/api/basicData/configuration.js";
import { getList as inventoryList } from "@/api/salesManagement/inventory";
import SearchQuery from "@/components/iosbasic-data/searchquery.vue";
import dicSelect from "@/components/dicSelect/main.vue";
export default {
  name: "detailsPage",
  data() {
    return {
      editDis: true,
      inventoryData2: [],
      numberDecimal: 0,
      goodsType: 1,
      inventoryOption: {
        header: false,
        menu: false,
        column: [
          {
            label: "商品名称",
            prop: "cname",
            overHidden: true,
          },
          {
            label: "仓库",
            prop: "storageName",
            overHidden: true,
          },
          {
            label: "库存数量",
            prop: "balanceQuantity",
            overHidden: true,
          },
          {
            label: "批次号",
            prop: "dot",
            overHidden: true,
          },
        ],
      },
      inventoryOption2: {
        header: false,
        menu: true,
        menuWidth: 90,
        editBtn: false,
        delBtn: false,
        column: [
          {
            label: "商品名称",
            prop: "cname",
            overHidden: true,
          },
          {
            label: "仓库",
            prop: "storageName",
            overHidden: true,
          },
          {
            label: "库存数量",
            prop: "balanceQuantity",
            overHidden: true,
          },
          {
            label: "批次号",
            prop: "dot",
            overHidden: true,
          },
        ],
      },
      inventoryData: [],
      excelBox: false,
      reportName: "", // 打印传的名字
      SelectSearch: {}, // 添加商品检索
      // 编辑还是保存
      mingxibaocun: true,
      // 批次号请求到的数据
      picihaolist: [],
      // 添加商品弹窗
      dialogVisible: false,
      // 弹窗高度
      rowHeight: "",
      // 左侧选择搜索
      treeDataGoods: [],
      treeDeptId: "",
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
        pageSizes: [10, 50, 100, 300, 500],
      },
      pageList: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      // 左侧选择
      treeOption: {
        addBtn: false,
        menu: false,
        size: "small",
        props: {
          labelText: "标题",
          label: "title",
          value: "id",
        },
      },
      templateUrl: "", // 模板url
      // 表格需要的配置
      optionTwo: {
        align: "center",
        height: "400",
        calcHeight: 80,
        stripe: true,
        tip: false,
        addBtn: false,
        searchShow: true,
        searchShowBtn: false,
        menu: true,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        menuWidth: 80,
        searchSpan: 8,
        searchMenuSpan: 8,
        searchMenuPosition: "right",
        border: true,
        index: true,
        selection: true,
        dialogClickModal: false,
        searchIcon: true,
        searchIndex: 2,
        column: [
          {
            label: "商品名称",
            prop: "cname",
            search: true,
            width: 100,
            overHidden: true,
          },
          {
            label: "商品编号",
            prop: "code",
            search: true,
            width: 100,
            overHidden: true,
          },
          {
            label: "数量",
            prop: "goodsNum",
            overHidden: true,
            width: 120,
          },
          {
            label: "单价",
            prop: "price",
            overHidden: true,
            width: 120,
            rules: [
              {
                required: true,
                message: " ",
                trigger: "blur",
              },
            ],
          },
          {
            label: "批次号",
            prop: "dot",
            width: "150",
            type: "select",
            disabled: true,
            allowCreate: true,
            filterable: true,
            dicData: [],
            props: {
              label: "dot",
              value: "dot",
            },
            dicUrl: "/api/gubersail-admin/tireStockDesc/dotList",
            overHidden: true,
          },
          {
            label: "是否批次号",
            prop: "whether",
            width: 100,
            type: "select",
            search: true,
            dicData: [
              {
                label: "否",
                value: "0",
              },
              {
                label: "是",
                value: "1",
              },
            ],
          },

          {
            label: "库存",
            prop: "inventory",
            addDisabled: false,
            multiple: true,
            overHidden: true,
          },
          {
            label: "规格型号",
            prop: "specificationAndModel",
            width: "120",
            slot: true,
            overHidden: true,
            search: true,
          },
          {
            label: "公司",
            prop: "salesCompanyName",
            slot: true,
            width: "120",
            overHidden: true,
          },
          {
            label: "商品分类",
            prop: "goodsTypeName",
            slot: true,
            overHidden: true,
          },
          {
            label: "品牌",
            prop: "brandName",
            slot: true,
            overHidden: true,
          },
          {
            label: "花纹",
            prop: "brandItem",
            width: "120",
            slot: true,
            overHidden: true,
            search: true,
          },
          {
            label: "是否静音棉",
            prop: "originalFactory",
            type: "select",
            search: true,
            hide: false,
            showColumn: true,
            width: 120,
            dicData: [
              {
                label: "否",
                value: "0",
              },
              {
                label: "是",
                value: "1",
              },
            ],
          },
          {
            label: "是否防爆",
            prop: "explosionProof",
            type: "select",
            search: true,
            hide: false,
            showColumn: true,
            width: 120,
            dicData: [
              {
                label: "否",
                value: 0,
              },
              {
                label: "是",
                value: 1,
              },
            ],
          },
          {
            label: "是否自修补",
            prop: "selfRecovery",
            type: "select",
            search: true,
            hide: false,
            showColumn: true,
            width: 120,
            dicData: [
              {
                label: "否",
                value: "0",
              },
              {
                label: "是",
                value: "1",
              },
            ],
          },
          {
            label: "共享公司",
            prop: "sharedCompany",
            slot: true,
            width: "120",
            overHidden: true,
          },
        ],
      },
      loading: false,
      // 商品列表数据合计
      goodsListShow: [],
      // 商品列表暂存
      goodsListSave: [],
      saveLoading: false,
      commodityData: false,
      surplusRouteQuantityOption: [],
      tableData: [],
      // tabs切换
      activeNameTabs: "searchList",
      data: [],

      courierCompaniesList: [],

      inventory: 0,
      isStatus: 1,
      goodsIdoptions: [],
      dataList: [],
      dicUrlWithCustomId: "",
      sharedCompanyId: 0,
      isAddBtn: true, // 添加商品的是否禁用
      isSaveBtn: false, // 大保存的是否禁用
      viewDisabled: false, // 大审批的是否禁用
      isAdd: false, // 表格按钮的是否点击
      editButton: true, // 大编辑大隐藏显示
      isEditButton: false, // 大编辑是否禁用
      goods: [],
      isDisabled: false, // 表格删除的是否禁用
      isDisabledTask: false, // 撤销任务和生成任务的是否禁用
      contactsOption: [],
      isContacts: false, // 表单的联系人是否禁用
      checkData: {},
      buttonText: "生成任务", // 生成任务和撤销任务文本
      buttonColor: "success", // 初始颜色为success  生成任务和撤销任务颜色状态
      checkScheduleDialog: false, // 审批进度的弹窗开启关闭
      isApplySettlement: true, // 申请退款的是否禁用
      isConfirmRefundBtn: true, // 确认退款的是否禁用
      isExamineBtn: true, // 审批是否禁用
      isRevocationRequest: true, // 撤销审核是否禁用
      checkDialog: false, // 审核弹窗的开启关闭
      checkId: "",
      batchNo: "",
      switchDialog: false, // 打印弹窗的开启和关闭
      activeName: "sale_detail",
      disabled: false, // 表格按钮的禁用
      key: 0,
      form: {
        orderItemsList: [],
        paymentRecordsList: [],
        outboundRecordsList: [],
        freight: 5,
      },
      excelOption: {
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "模板下载",
            prop: "excelTemplate",
            formslot: true,
            span: 24,
          },
          {
            label: "导入明细",
            prop: "excelFile",
            type: "upload",
            drag: true,
            loadText: "上传中，请稍等",
            accept: ".xls,.xlsx",
            span: 24,
            propsHttp: {
              res: "data",
            },
            tip: "请上传 .xls,.xlsx 标准格式文件",
            action: "/api/gubersail-admin/ship/import-item",
          },
        ],
      },
      customerData: [], // 店铺名称数据
      optionForm: {
        menuBtn: false,
        span: 8,
        disabled: false,
        column: [
          {
            label: "店铺名称",
            prop: "customerName",
            disabled: false,
            formslot: true,
            rules: [
              {
                required: true,
                message: " ",
                trigger: "blur",
              },
            ],
          },
          {
            label: "业务员",
            disabled: false,
            prop: "salerName",
            rules: [
              {
                required: true,
                message: " ",
                trigger: "blur",
              },
            ],
          },
          // {
          //   label: "仓库",
          //   prop: "storageId",
          //   type: "select",
          //   disabled: false,
          //   placeholder: "仓库为空即为异地销售",
          //   props: {
          //     label: "cname",
          //     value: "id",
          //   },
          //   dicUrl: "/api/gubersail-admin/storageDesc/listAll",
          //   // rules: [{
          //   //     required: true,
          //   //     message: " ",
          //   //     trigger: "blur"
          //   // }]
          // },
          {
            label: "联系人",
            type: "select",
            prop: "contacts",
            disabled: false,
            allowCreate: true,
            filterable: true,
            dicData: [],
            props: {
              label: "address",
              value: "id",
            },
            dicUrl: "/api/gubersail-admin/corpsAddr/corpIdByAddr?pid={{key}}",
          },
          {
            label: "电话",
            disabled: false,

            prop: "phone",
          },
          {
            label: "收货地址",
            prop: "recAddress",
            type: "select",
            allowCreate: true,
            filterable: true,
            disabled: false,
            props: {
              label: "address",
              value: "address",
            },
            dicUrl: "/api/gubersail-admin/corpsAddr/corpIdByAddr?pid={{key}}",
          },
          {
            label: "业务日期",
            prop: "businesDate",
            searchProp: "businesDateList",
            disabled: false,
            type: "datetime",
            value: dateFormat(new Date(), "yyyy-MM-dd"),
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            rules: [
              {
                required: true,
                message: "",
                trigger: "blur",
              },
            ],
          },
          {
            label: "收款方式",
            prop: "receivableType",
            type: "select",
            disabled: false,
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=receivableType",
            props: {
              label: "dictValue",
              value: "dictValue",
            },
            value: "网络支付",
          },
          {
            label: "业务来源",
            prop: "businessSource",
            disabled: true,
          },
          {
            label: "配送方式",
            type: "select",
            prop: "shipType",
            disabled: false,
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=deliveryMethod",
            props: {
              label: "dictValue",
              value: "dictValue",
            },
            value: "物流",
          },
          {
            label: "货运公司",
            type: "select",
            prop: "logisticsCorpName",
            allowCreate: true,
            filterable: true,
            disabled: false,
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=tyre_express_company",
            props: {
              label: "dictValue",
              value: "dictValue",
            },
          },
          {
            label: "货运单号",
            disabled: false,
            prop: "expressNo",
          },
          {
            label: "成本",
            prop: "cost",
            display: false,
            disabled: true,
          },
          {
            label: "毛利",
            prop: "grossProfit",
            display: false,
            disabled: true,
          },
          {
            label: "销售金额",
            prop: "salesAmount",
            disabled: true,
          },
          {
            label: "运费",
            prop: "freight",
            disabled: true,
          },
          {
            label: "总金额",
            prop: "totalMoney",
            disabled: true,
          },
          {
            label: "余额抵扣",
            prop: "paymentRecoveredBalance",
            overHidden: true,
            disabled: true,
          },
          {
            label: "已收金额",
            prop: "paymentAmountTl",
            disabled: true,
          },
          {
            label: "单据编号",
            prop: "ordNo",
            disabled: true,
          },
          {
            label: "来源单号",
            prop: "srcOrdNo",
            disabled: true,
          },
          {
            label: "退货数量",
            prop: "returnsNumber",
            disabled: true,
          },
          {
            label: "退货金额",
            prop: "returnsAmount",
            disabled: true,
          },
          {
            label: "出库日期",
            prop: "deliveryBusinesDate",
            disabled: true,
            type: "datetime",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
          },
          {
            label: "备注",
            prop: "remarks",
            type: "textarea",
            disabled: false,
            span: 16,
            minRows: 1,
          },
        ],
      },
      formContacts: {},
      optionContacts: {
        disabled: false,
        goodsId: "",
        border: true,
        align: "center",
        index: true,
        addBtnText: "添加商品",
        updateBtnText: "保存",
        refreshBtn: false,
        dialogDrag: true,
        addBtn: false,
        span: 8,
        height: 500,
        // addRowBtn: false,
        editBtn: false,
        delBtn: false,
        menuWidth: 140,
        dialogTop: 25,
        dialogWidth: "80%",
        summaryText: "合计",
        showSummary: true,
        selection: true,
        sumColumnList: [
          {
            name: "goodsNum",
            type: "sum",
          },
          {
            name: "sendNum",
            type: "sum",
          },
          {
            name: "profit",
            type: "sum",
          },
          {
            name: "subTotalMoney",
            type: "sum",
          },
          {
            name: "thisAmount",
            type: "sum",
          },
          {
            name: "costprie",
            type: "sum",
          },
          {
            name: "grossProfit",
            type: "sum",
          },
          {
            name: "returnsNumber",
            type: "sum",
          },
          {
            name: "returnsAmount",
            type: "sum",
          },
        ],
        column: [
          {
            label: "商品名称",
            prop: "goodsId",
            width: 250,
            disabled: false,
            remote: true,
            overHidden: true,
            hide: true,
            type: "select",
            dicData: [],
            props: {
              label: "goodsName",
              value: "goodsId",
            },
            // dicUrl: '/api/gubersail-admin/goodsDesc/goodsListAll?cname={{key}}'
            dicUrl: `/api/gubersail-admin/goodsDesc/goodsListXs?cname={{key}}&customId=&enableOrNot=1&stock=${this.goodsId}`,
            // dicUrl: "/api/gubersail-admin/goodsDesc/goodsListXs?cname={{key}}"
          },
          {
            label: "商品名称",
            prop: "goodsName",
            width: 250,
            disabled: false,
            remote: true,
            overHidden: true,
          },
          {
            label: "发货仓库",
            prop: "storageName",
            width: 120,
            overHidden: true,
          },
          {
            label: "库区",
            prop: "reservoirArea",
            width: 120,
            overHidden: true,
          },
          {
            label: "库存",
            prop: "inventory",
            width: 250,
            disabled: false,
            remote: true,
            overHidden: true,
          },
          {
            label: "数量",
            prop: "goodsNum",
            overHidden: true,
            // cell: true,
            width: 100,
            rules: [
              {
                required: true,
                message: " ",
                trigger: "blur",
              },
              // {
              //   validator: (rule, value, callback) => {
              //     console.log(this.formContacts.inventory);
              //     if (value < 0) {
              //       callback(new Error("数量不能小于0"));
              //     } else if (Number(value) > Number(this.formContacts.inventory)) {
              //       callback(new Error("数量不能大于库存"));
              //     } else {
              //       callback();
              //     }
              //   },
              //   trigger: "blur",
              // },
            ],
          },
          {
            label: "价格",
            prop: "price",
            overHidden: true,
            width: 100,
            cell: true,
            rules: [
              {
                required: true,
                message: " ",
                trigger: "blur",
              },
              {
                validator: (rule, value, callback) => {
                  if (value < 0) {
                    callback(new Error("价格不能小于0"));
                  } else {
                    callback();
                  }
                },
                trigger: "blur",
              },
            ],
          },
          {
            label: "库存",
            prop: "inventory",
            overHidden: true,
            hide: true,
            width: 100,
          },
          {
            label: "批次号",
            prop: "dot",
            cell: true,
            type: "select",
            width: 120,
            allowCreate: true,
            filterable: true,
            dicData: [],
            props: {
              label: "dot",
              value: "dot",
            },
            dicUrl: "/api/gubersail-admin/tireStockDesc/dotList",
            overHidden: true,
          },
          // {
          //     label: '单号',
          //     prop: 'poNo',
          //     overHidden: true,
          //     disabled: false,
          //     width: 100
          // },
          {
            label: "商品编码",
            prop: "goodsNo",
            overHidden: true,
            disabled: false,
            width: 100,
          },
          {
            label: "品牌",
            prop: "brandName",
            disabled: false,
            width: 100,
            overHidden: true,
          },
          {
            label: "规格型号",
            prop: "propertyName",
            overHidden: true,
            disabled: false,
            width: 100,
          },
          {
            label: "花纹",
            prop: "pattern",
            overHidden: true,
            disabled: false,
            width: 100,
          },
          {
            label: "商品描述",
            prop: "goodsDescription",
            disabled: false,
            overHidden: true,
            width: 100,
          },
          {
            label: "单位",
            prop: "units",
            type: "select",
            disabled: false,
            props: {
              label: "dictValue",
              value: "dictValue",
            },
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=unit",
            overHidden: true,
            width: 100,
          },

          {
            label: "发货数量",
            prop: "sendNum",
            overHidden: true,
            width: 100,
            disabled: true,
            editDisplay: false,
            addDisplay: false,
          },
          // {
          //     label: '利润',
          //     prop: 'profit',
          //     overHidden: true,
          //     width: 100
          // },
          {
            label: "小计",
            prop: "subTotalMoney",
            overHidden: true,
            width: 100,
            disabled: true,
            editDisplay: false,
            addDisplay: false,
          },
          // {
          //     label: '返利',
          //     prop: 'thisAmount',
          //     overHidden: true,
          //     width: 100
          // },
          {
            label: "成本",
            prop: "costprie",
            overHidden: true,
            width: 100,
            disabled: true,
            editDisplay: false,
            addDisplay: false,
          },
          {
            label: "毛利",
            prop: "grossProfit",
            overHidden: true,
            width: 100,
            disabled: true,
            editDisplay: false,
            addDisplay: false,
          },
          {
            label: "返利后单价",
            prop: "rebatePrice",
            overHidden: true,
            width: 100,
            disabled: true,
            editDisplay: false,
            addDisplay: false,
            hide: false,
            showColumn: true,
          },
          {
            label: "返利后成本价",
            prop: "rebateCostprie",
            overHidden: true,
            width: 100,
            disabled: true,
            editDisplay: false,
            addDisplay: false,
            hide: false,
            showColumn: true,
          },
          {
            label: "返利后利润",
            prop: "rebateProfit",
            overHidden: true,
            width: 100,
            disabled: true,
            editDisplay: false,
            addDisplay: false,
            hide: false,
            showColumn: true,
          },
          {
            label: "退货数量",
            prop: "returnsNumber",
            overHidden: true,
            width: 100,
            disabled: true,
          },
          {
            label: "退货金额",
            prop: "returnsAmount",
            overHidden: true,
            width: 100,
            disabled: true,
          },
          {
            label: "备注",
            prop: "remarks",
            overHidden: true,
            width: 100,
            disabled: false,
          },
        ],
      },
      selectionMultilist: [], // 多选数据
      optionPaymentDetails: {
        align: "center",
        index: true,
        addBtnText: "录入明细",
        menu: false,
        refreshBtn: false,
        dialogDrag: true,
        addBtn: false,
        span: 8,
        height: 600,
        addRowBtn: false,
        editBtn: false,
        delBtn: false,
        menuWidth: 140,
        dialogTop: 25,
        dialogWidth: "80%",
        column: [
          {
            label: "支付编号",
            prop: "serialNumber",
          },
          {
            label: "金额",
            prop: "amount",
          },
          {
            label: "类型",
            prop: "type",
          },
          {
            label: "支付时间",
            prop: "createTime",
          },
        ],
      },
      optionOutboundRecords: {
        align: "center",
        index: true,
        menu: false,
        addBtnText: "录入明细",
        refreshBtn: false,
        dialogDrag: true,
        addBtn: false,
        span: 8,
        height: 600,
        addRowBtn: false,
        editBtn: false,
        delBtn: false,
        // menuWidth: 140,
        dialogTop: 25,
        dialogWidth: "80%",
        column: [
          {
            label: "出库单号",
            prop: "billno",
          },
          //     {
          //     label: '来源单号',
          //     prop: 'ordNo'
          // },
          {
            label: "数量",
            prop: "goodsTotalNum",
          },
          {
            label: "实际数量",
            prop: "sendTotalNum",
          },
          {
            label: "业务类型",
            prop: "bizTypeName",
          },
          {
            label: "状态",
            prop: "statusName",
          },
          {
            label: "业务时间",
            prop: "createTime",
          },
        ],
      },
    };
  },
  components: { SearchQuery, dicSelect },
  props: {
    onLoad: Object,
    detailData: Object,
  },
  async created() {
    console.log(this.detailData.id);
    console.log(JSON.parse(localStorage.getItem("saber-tenantId")).content, 959);
    if (JSON.parse(localStorage.getItem("saber-tenantId")).content == "069164") {
      this.reportName = "轮胎商城-玉玲珑销售单";
    } else {
      this.reportName = "轮胎商城-销售订单";
    }
    getWorkDicts("tyre_express_company").then((res) => {
      this.courierCompaniesList = res.data.data;
    });

    this.findObject(this.optionContacts.column, "goodsId").change = ({ value, column }) => {
      if (this.formContacts.goodsId !== value) {
        goodsDetail({
          id: value,
          customId: this.dicUrlWithCustomId,
          stock: this.form.storageId ? this.form.storageId : "",
        }).then((res) => {
          this.goods = res.data.data;
          this.formContacts.goodsNo = res.data.data.code;
          this.formContacts.brandId = res.data.data.brandId;
          this.formContacts.inventory = res.data.data.inventory;
          this.formContacts.propertyName = res.data.data.specificationAndModel;
          this.formContacts.pattern = res.data.data.brandItem;
          this.formContacts.goodsDescription = res.data.data.goodsDescription;
          this.formContacts.units = res.data.data.unit;
          this.formContacts.price = res.data.data.price;
          this.formContacts.sharedCompanyId = res.data.data.sharedCompanyId;
          console.log(res.data.data.sharedCompanyId);
          console.log(res.data.data.sharedCompanyName);
          this.form.sharedCompanyId = res.data.data.sharedCompanyId;
          this.form.sharedCompanyName = res.data.data.sharedCompanyName;
          this.sharedCompanyId = res.data.data.sharedCompanyId;
          console.log(res.data.data.sharedCompanyId);
          console.log(this.form.orderItemsList);
          for (let i = 0; i < this.form.orderItemsList.length; i++) {
            console.log(Number(this.form.orderItemsList[i].sharedCompanyId));
            if (Number(this.form.orderItemsList[i].sharedCompanyId) != Number(res.data.data.sharedCompanyId)) {
              this.isStatus = 0;
            }
          }
          if (res.data.data.whether == 0) {
            this.findObject(this.optionContacts.column, "dot").disabled = true;
          } else {
            this.findObject(this.optionContacts.column, "dot").disabled = false;
            dotList({
              storageId: this.form.storageId,
              goodsId: this.formContacts.goodsId,
            }).then((res) => {
              this.findObject(this.optionContacts.column, "dot").dicData = res.data.data;
            });
          }
          // this.formContacts.goodsId = res.data.data.cname
          // this.formContacts.goodsName = res.data.data.id
        });
      }
    };
    isProcurement({ param: "whether.model" }).then((res) => {
      if (res.data.data == 1) {
        this.findObject(this.optionContacts.column, "pattern").label = "规格型号1";
        this.findObject(this.optionTwo.column, "brandItem").label = "规格型号1";
        this.findObject(this.optionTwo.column, "originalFactory").search = false;
        this.findObject(this.optionTwo.column, "explosionProof").search = false;
        this.findObject(this.optionTwo.column, "selfRecovery").search = false;
        this.findObject(this.optionTwo.column, "explosionProof").hide = true;
        this.findObject(this.optionTwo.column, "originalFactory").hide = true;
        this.findObject(this.optionTwo.column, "selfRecovery").hide = true;
        this.findObject(this.optionContacts.column, "rebatePrice").hide = true;
        this.findObject(this.optionContacts.column, "rebateCostprie").hide = true;
        this.findObject(this.optionContacts.column, "rebateProfit").hide = true;
        this.findObject(this.optionTwo.column, "explosionProof").showColumn = false;
        this.findObject(this.optionTwo.column, "originalFactory").showColumn = false;
        this.findObject(this.optionTwo.column, "selfRecovery").showColumn = false;
        this.findObject(this.optionContacts.column, "rebatePrice").showColumn = true;
        this.findObject(this.optionContacts.column, "rebateCostprie").showColumn = true;
        this.findObject(this.optionContacts.column, "rebateProfit").showColumn = true;
      }
    });
    this.findObject(this.optionContacts.column, "goodsId").change = ({ value, column }) => {
      if (this.formContacts.goodsId !== value) {
        goodsDetail({
          id: value,
          customId: this.dicUrlWithCustomId,
          stock: this.form.storageId ? this.form.storageId : "",
        }).then((res) => {
          this.goods = res.data.data;
          this.formContacts.goodsNo = res.data.data.code;
          this.formContacts.brandId = res.data.data.brandId;
          this.formContacts.inventory = res.data.data.inventory;
          // this.formContacts.brandId = res.data.data.brandName
          // this.formContacts.brandName = res.data.data.brandId
          this.formContacts.propertyName = res.data.data.specificationAndModel;
          this.formContacts.pattern = res.data.data.brandItem;
          this.formContacts.goodsDescription = res.data.data.goodsDescription;
          this.formContacts.dotListunits = res.data.data.unit;
          this.sharedCompanyId = res.data.data.sharedCompanyId;
          this.formContacts.sharedCompanyId = res.data.data.sharedCompanyId;
          //
          this.form.sharedCompanyId = res.data.data.sharedCompanyId;
          this.form.sharedCompanyName = res.data.data.sharedCompanyName;
          for (let i = 0; i < this.form.orderItemsList.length; i++) {
            if (this.form.orderItemsList[i].sharedCompanyId != res.data.data.sharedCompanyId) {
              this.isStatus = 0;
            }
          }
          if (res.data.data.whether == 0) {
            this.findObject(this.optionContacts.column, "dot").disabled = true;
          } else {
            this.findObject(this.optionContacts.column, "dot").disabled = false;
            dotList({
              storageId: this.form.storageId,
              goodsId: this.formContacts.goodsId,
            }).then((res) => {
              this.findObject(this.optionContacts.column, "dot").dicData = res.data.data;
            });
          }
          // this.formContacts.goodsId = res.data.data.cname
          // this.formContacts.goodsName = res.data.data.id
        });
      }
    };

    this.key++;
    if (this.onLoad.id && this.detailData.id) {
      this.isContacts = true;
      this.isDisabled = true;
      //添加删除按钮禁用
      this.isAdd = true;
      this.getDetail(this.onLoad.id, true);
    } else if (this.onLoad.id) {
      console.log(2);
      this.getDetail(this.onLoad.id, true);
    }
    if (!this.form.id) {
      console.log(3);
      this.isSaveBtn = true;
      this.isDisabledTask = true;
      this.viewDisabled = true;
    }
    if (!this.detailData.id) {
      this.editDis = false;
      this.editButton = false;
      this.isAddBtn = false;
      this.isDisabledTask = false;
      this.isSaveBtn = false;
      this.viewDisabled = false;
      this.form.businessSource = "内部销售";
      isProcurement({ param: "freight" }).then((res) => {
        // res.data.data === '1'
        this.form.freight = res.data.data;
      });
    }
    if (this.detailData.check) {
      this.isExamineBtn = false;
      // this.batchNo = this.detailData.check.batchNo
    }

    //成本、毛利对业务员隐藏
    this.optionForm.column.forEach((its) => {
      if (JSON.parse(localStorage.getItem("saber-userInfo")).content.role_name.split(",").includes("业务员")) {
        if (its.prop == "cost" || its.prop == "grossProfit") {
          this.$set(its, "display", false);
        }
      } else {
        if (its.prop == "cost" || its.prop == "grossProfit") {
          this.$set(its, "display", true);
        }
      }
    });
    // 明细信息成本、毛利对业务员隐藏
    this.optionContacts.column.forEach((its) => {
      if (JSON.parse(localStorage.getItem("saber-userInfo")).content.role_name.split(",").includes("业务员")) {
        if (its.prop == "costprie" || its.prop == "grossProfit") {
          this.$set(its, "hide", true);
        }
      } else {
        if (its.prop == "costprie" || its.prop == "grossProfit") {
          this.$set(its, "hide", false);
        }
      }
    });

    // if (this.detailData.id) {
    //     this.getDetailsfun()
    // }
    isProcurement({ param: "number.decimal" }).then((res) => {
      this.numberDecimal = res.data.data ? Number(res.data.data) : 0;
    });
  },

  watch: {
    dicUrlWithCustomId() {
      console.log(this.form);
      // this.findObject(this.optionContacts.column, "goodsId").dicUrl = `/api/gubersail-admin/goodsDesc/goodsListXs?cname={{key}}&customId=${this.dicUrlWithCustomId}&enableOrNot=0`
      goodsListXs(this.dicUrlWithCustomId, this.form.storageId ? this.form.storageId : "").then((res) => {
        this.findObject(this.optionContacts.column, "goodsId").dicData = res.data.data;
      });
    },
    "form.storageId"(newStorageId, oldStorageId) {
      goodsListXs(this.dicUrlWithCustomId, this.form.storageId ? this.form.storageId : "").then((res) => {
        console.log(res.data.data, "2");

        this.findObject(this.optionContacts.column, "goodsId").dicData = res.data.data;
      });
    },
    // 'form.orderItemsList.length'(newformContacts, oldformContacts) {
    //     console.log(this.formContacts);
    //     console.log(this.form.orderItemsList);
    //     // for (let i = 0; i < this.form.orderItemsList.length - 1; i++) {
    //     //     const currentItem = this.form.orderItemsList[i];
    //     //     const nextItem = this.form.orderItemsList[i + 1];

    //     //     if (currentItem.sharedCompanyId !== nextItem.sharedCompanyId) {
    //     //         console.log('不能添加');
    //     //     }
    //     // }
    //     if (this.form.orderItemsList.length) {
    //         this.findObject(this.optionForm.column, 'storageId').disabled = true
    //     } else {
    //         this.findObject(this.optionForm.column, 'storageId').disabled = false
    //     }
    // },
    "form.sharedCompanyId"(newSharedCompanyId, oldSharedCompanyId) {
      console.log(newSharedCompanyId, oldSharedCompanyId);
      if (newSharedCompanyId != oldSharedCompanyId) {
        console.log("不能添加");
      }
      console.log(this.sharedCompanyId);
    },
    $route(to, from) {
      if (this.onLoad.id && this.detailData.id) {
        this.$set(this.optionForm, "disabled", true);
        this.$set(this.optionContacts, "disabled", true);
        this.isContacts = true;
        this.isDisabled = true;
        this.isAdd = true;
        this.getDetail(this.onLoad.id, true);
      } else if (this.onLoad.id) {
        this.getDetail(this.onLoad.id, true);
      }

      if (this.detailData.status == 1) {
        this.isExamineBtn = false;
      }
    },
  },
  methods: {
    rowDicChange(name, row, el) {
      if (name == "reservoirArea") {
        if (row) {
          el.reservoirAreaId = row.id;
        } else {
          el.reservoirArea = null;
          el.reservoirAreaId = null;
        }
      }
    },
    viewInventory() {
      this.inventoryData = [];
      inventoryList({ cname: this.selectionMultilist[0].goodsName }).then((res) => [
        (this.inventoryData = res.data.data.records),
      ]);
    },
    viewInventory2() {
      inventoryList({ cname: this.selectionMultilist[0].goodsName }).then((res) => [
        (this.inventoryData2 = res.data.data.records),
        // res.data.data.records.forEach(item => {
        //     if (item.storageId == this.form.storageId && item.dot == this.selectionMultilist[0].dot) {
        //         if (Number(item.balanceQuantity) == Number(this.selectionMultilist[0].inventory)) {
        //             this.$message.success("库存一致，不需要同步");
        //         }
        //         if (Number(item.balanceQuantity) != Number(this.selectionMultilist[0].inventory)) {
        //             this.$confirm('是否更新库存', '提示', {
        //                 confirmButtonText: '确定',
        //                 cancelButtonText: '取消',
        //                 type: 'warning'
        //             }).then(() => {
        //                 this.form.orderItemsList.forEach(e => {
        //                     if (e.goodsName == this.selectionMultilist[0].goodsName) {
        //                         e.inventory = item.balanceQuantity
        //                     }
        //                 })
        //                 //   this.editCustomer()
        //             })
        //         }
        //     }
        // })
      ]);
    },
    synchronous(row) {
      this.form.orderItemsList.forEach((e) => {
        if (e.goodsName == this.selectionMultilist[0].goodsName) {
          e.inventory = row.balanceQuantity;
          e.dot = row.dot;
        }
      });
    },
    uploadAfter(res, done, loading, column) {
      if (Array.isArray(res)) {
        if (res instanceof Array) {
          this.form.orderItemsList = this.form.orderItemsList.concat(res);
          res.forEach((item) => {
            dotList({
              storageId: this.form.storageId,
              goodsId: res.goodsId,
            }).then((e) => {
              this.findObject(this.optionContacts.column, "dot").dicData = e.data.data;
            });
          });
        }
      } else {
        this.$message.error(res);
      }

      this.excelBox = false;
      loading = false;
      done(res);
    },
    derivation() {
      window.open(`${this.templateUrl}?${this.website.tokenHeader}=${getToken()}&stockId=${this.form.storageId}`);
    },
    uploadBefore(file, done, loading) {
      done();
      loading = true;
    },
    // 销售明细 导入按钮
    excelDialogfun(name) {
      if (!this.form.customerId) {
        this.$message.error("请选择店铺名称");
        return;
      }
      if (name == "名称") {
        this.findObject(this.excelOption.column, "excelFile").action = "/api/gubersail-admin/order/import-item-name";
        this.templateUrl = "/api/gubersail-admin/order/export-item-name";
      } else if (name == "code") {
        this.findObject(this.excelOption.column, "excelFile").action = "/api/gubersail-admin/order/import-item-code";
        this.templateUrl = "/api/gubersail-admin/order/export-item-code";
      }
      this.excelBox = true;
    },
    //生成退货单
    getReturns() {
      this.$confirm("您确定要退货吗?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$router.push({
          path: "/salesService/returns/index",
          query: {
            bsType: "TKXS",
            id: this.form.id,
          },
        });
      });
    },
    // 店铺名称监听
    KHcorpChange(value) {
      for (let item of this.customerData) {
        if (item.cname == value) {
          this.$set(this.form, "customerId", item.id);
          this.$set(this.form, "customerName", item.cname);
          getCustom({ id: item.id }).then((res) => {
            if (res.data.data) {
              this.dicUrlWithCustomId = res.data.data.id ? res.data.data.id : "";
              this.form.storageId = res.data.data.deliveryWarehouseId;
              this.form.storageName = res.data.data.deliveryWarehouseName;

              this.form.contacts = res.data.data.corpsAttnList[0].cname;
              this.form.phone = res.data.data.corpsAttnList[0].tel;
              this.contactsOption = res.data.data.corpsAddrList;
              this.form.recAddress =res.data.data.corpsAddrList[0].detailedAddress;
              this.form.salerId = res.data.data.salesmanId ? res.data.data.salesmanId : "";
              this.form.salerName = res.data.data.salesmanName ? res.data.data.salesmanName : "";
            }
            if (!res.data.data.deliveryWarehouseId) {
              return this.$message.error("请维护店铺名称的发货仓库");
            }
          });
        }
      }
    },
    KHClear() {
      this.form.customerId = "";
      this.form.customerName = "";
      this.dicUrlWithCustomId = "";
      this.form.storageId = "";
      this.form.contacts = "";
      this.form.phone = "";
      this.contactsOption = "";
      this.form.recAddress = "";
      this.form.salerId = "";
      this.form.salerName = "";
      this.KHgetListfun();
    },
    // 获取店铺名称数据
    KHgetListfun(cname) {
      KHgetList({
        current: 1,
        size: 10,
        corpType: "KH",
        enableOrNot: 1,
        cname: cname ? cname : null,
      }).then((res) => {
        this.customerData = res.data.data.records;
      });
    },
    // 获取详细明细信息
    getDetailsfun() {
      getDetails({
        id: this.detailData.id,
      }).then((res) => {
        this.form = res.data.data;
        this.form.orderItemsList = res.data.data.orderItemsList;

        console.log(this.isEditButton, "bianj");
        console.log(this.isDisabledTask, "chexiao");
        console.log(this.buttonColor, "123");
        // if (this.form.status == '待发货') {
        //
        // }
      });
    },
    // 获取左侧筛选
    getAllWorkDicts() {
      getCorpTypes({ whetherIntegral: "0" }).then((res) => {
        this.treeDataGoods = res.data.data;
      });
    },
    //导入页左商品类型查询
    nodeClick(data) {
      this.treeDeptId = data.id;
      this.page.currentPage = 1;
      this.onLoadfun(this.page, { ...this.SelectSearch, goodsTypeId: this.treeDeptId });
    },
    closeGoods() {
      this.treeDataGoods = [];
      this.treeDeptId = "";
      this.activeNameTabs = "searchList";
      this.goodsType = 1;
    },
    //刷新触发
    refreshChange() {
      this.page.currentPage = 1;
      this.onLoadfun(this.page);
    },
    //选中触发
    selectionChange(list) {
      this.tableData = list;
    },
    // 点击搜索触发
    goodsSearch(params, done) {
      this.page.currentPage = 1;
      params = {
        ...params,
        artsVision: this.form.belongToCorpId,
      };
      // params.specificationAndModel = params.cname
      // delete params.cname
      this.onLoadfun(this.page, params);
      done();
    },
    dicChange(name, row) {
      if (name == "salerName") {
        if (row) {
          this.form.salerId = row.id;
          this.form.salerName = row.name;
        } else {
          this.form.salerId = null;
          this.form.salerName = null;
        }
      }
    },
    // 标签页切换
    tabHandle(data) {
      if (data.name == "searchList") {
        this.goodsListShow = this.data;
        this.page.total = this.pageList.total;
      } else if (data.name == "importStaging") {
        this.goodsListShow = this.goodsListSave;
        this.page.total = 0;
      }
    },
    // 商品信息价格计算
    amountChange(value, row) {
      if (value > 0) {
        this.$refs.crud.toggleRowSelection(row, true);
      } else {
        this.$refs.crud.toggleRowSelection(row, false);
      }
      // 价格
      // if (!row.price) {
      //     row.price = 0;
      // }
    },
    importStagList(row, index, type) {
      this.goodsListSave.push(row);
    },
    removeStagList(row, index, type) {
      this.goodsListSave.splice(row.$index, 1);
    },
    //确认导入触发
    async importGoods() {
      this.surplusRouteQuantityOption.push({ storageQuantity: "0" });
      if (this.goodsListSave.length > 0) {
        this.goodsListSaveHandle();
      } else {
        if (this.tableData.length > 0) {
          this.tableDataHandle();
        }
      }
    },

    // 导入按钮事件
    tableDataHandle() {
      // 循环获取库存数量
      for (let item of this.tableData) {
        let page = {};
        if (this.form.storageId) {
          page.storageId = this.form.storageId;
        }
        page.goodsId = item.goodsId;
        let obj = {
          goodsId: item.id,
          price: item.price,
          goodsName: item.cname,
          goodsNum: item.goodsNum,
          brandName: item.brandName,
          storageId: this.form.storageId,
          storageName: this.form.storageName,
          brandId: item.brandId,
          goodsNo: item.code,
          propertyName: item.specificationAndModel,
          inventory: item.inventory,
          pattern: item.brandItem,
          goodsDescription: item.goodsDescription,
          dot: item.dot,
          // poNo: item.poNo,
          whether: item.whether,
          units: item.unit,
          // 小计
          subTotalMoney: Number(item.goodsNum * item.price) ? Number(item.goodsNum * item.price).toFixed(2) : 0,
          // 备注
          remarks: item.remarks,
          // 批次号的状态
          dotedittype: false,
          // 价格数量
          goodsNumtype: false,
          // 价格
          pricetype: false,
          // sendNum: 0,
          $cellEdit: true,
        };
        if (item.goodsFilesList && item.goodsFilesList.length) {
          for (let ite of item.goodsFilesList) {
            if (ite.version == "0") {
              obj.url = ite.url;
            }
          }
        }
        this.form.orderItemsList.push(obj);
      }
      this.dialogVisible = false;
    },
    // 导入
    goodsListSaveHandle() {
      this.tableData = this.goodsListSave;
      this.tableDataHandle();
    },
    // 获取添加商品弹窗里的数据
    goodsPageXsfun() {
      goodsPageXs({
        customId: this.form.customerId,
        stock: this.form.storageId,
        enableOrNot: 1,
        whetherIntegral: "0",
      }).then((res) => {
        const data = res.data.data;
        this.goodsListShow = data.records;
      });
    },
    //导入商品弹窗列表查询
    onLoadfun(page, params = { artsVision: this.form.belongToCorpId }) {
      this.goodsListShow = [];
      this.loading = true;
      if (this.goodsType == 1) {
        goodsPageXs({
          current: page.currentPage,
          size: page.pageSize,
          customId: this.form.customerId,
          stock: this.form.storageId,
          enableOrNot: 1,
          goodsTypeId: this.treeDeptId,
          ...Object.assign(params, this.SelectSearch),
          whetherIntegral: "0",
        }).then((res) => {
          const data = res.data.data;
          this.page.total = data.total;
          this.pageList.total = data.total;
          this.data = data.records;
          this.goodsListShow = data.records;

          for (let item of this.goodsListShow) {
            item.goodsNum = item.goodsNum ? item.goodsNum : 0;
          }
          this.loading = false;
        });
      }
      if (this.goodsType == 2) {
        getGoodAllList({
          current: page.currentPage,
          size: page.pageSize,
          customId: this.form.customerId,
          stock: this.form.storageId,
          enableOrNot: 1,
          goodsTypeId: this.treeDeptId,
          ...Object.assign(params, this.SelectSearch),
          whetherIntegral: "0",
        }).then((res) => {
          res.data.data.records.forEach((item) => {
            item.goodsNum = item.goodsNum ? item.goodsNum : 0;
            item.inventory = item.inventory ? item.inventory : 0;
          });
          const data = res.data.data;
          this.page.total = data.total;
          this.pageList.total = data.total;
          this.data = data.records;
          this.goodsListShow = data.records;
          this.loading = false;
        });
      }
    },
    // 采购明细行编辑
    rowEdit(row) {
      // 获取是否管理批次号
      if (row.$cellEdit == true) {
        this.$set(row, "$cellEdit", false);
      } else {
        getDetailsGods({ id: row.goodsId }).then((res) => {
          row.whether = res.data.data.whether;
          this.picihaolistfun(row.id);
          this.$set(row, "$cellEdit", true);
          this.goodsPageXsfun();
        });
      }
    },
    // 批次号获取数据
    picihaolistfun(goodsId) {
      dotList({
        storageId: this.form.storageId,
        goodsId: goodsId,
      }).then((res) => {
        this.picihaolist = res.data.data;
      });
    },
    // 批次号切换库存
    dotchangefun(value, row) {
      for (let item of this.picihaolist) {
        if (item.dot == value) {
          this.$set(row, "inventory", item.balanceQuantity);
          this.$set(row, "rebatePrice", item.rebatePrice);
        }
      }
    },
    // 数量失焦触发
    goodsNumblurfun(row) {
      if (Number(row.goodsNum) > Number(row.inventory)) {
        this.$message.warning("不能大于库存数量");
        return;
      }
    },
    editBtn(row, index) {
      this.confirmEditing();
      this.$refs.formContacts.rowEdit(row, index);
      dotList({
        storageId: this.form.storageId,
        goodsId: this.formContacts.goodsId,
      }).then((res) => {
        this.findObject(this.optionContacts.column, "dot").dicData = res.data.data;
      });
      goodsListXs(this.dicUrlWithCustomId, this.form.storageId ? this.form.storageId : "").then((res) => {
        this.findObject(this.optionContacts.column, "goodsId").dicData = res.data.data;
      });
    },
    //表头编辑
    confirmEditing() {
      this.editButton = false;
      if (this.form.status == "待确认") {
        this.editDis = false;
      }
    },

    revokeTask() {
      this.$confirm("是否撤销出库任务审批?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        revokeCheckOrderRW(this.form).then((res) => {
          this.buttonText = "生成任务";
          // 将按钮颜色还原为success
          this.buttonColor = "success";
          this.$message.success("撤销出库成功");
          this.getDetail(res.data.data.id);
          this.isApplySettlement = false;
          this.isContacts = true;
          this.isDisabled = true;
          this.isDisabledTask = false;
          this.$set(this.optionForm, "disabled", false); // form 表单的禁用放开
          this.$set(this.optionContacts, "disabled", false); // table 表格的禁用放开
          // this.editButton = true // 把编辑按钮显示出来
          //添加删除按钮禁用
          this.isAdd = true;
        });
      });
    },
    //联系人change
    contactsChange(e) {
      // 假设this.contactsOption是你的数组对象
      let matchedContact = this.contactsOption.find((item) => item.contacts == e);
      // 判断是否找到匹配的对象
      this.$set(this.form, "phone", matchedContact.tel);
      this.$set(this.form, "recAddress", matchedContact.belongtoarea + matchedContact.detailedAddress);
    },
    //修改提交触发
    editCustomer() {
      this.$refs["form"].validate((valid, done) => {
        done();
        if (valid) {
          if (this.form.orderItemsList.length == 0) {
            this.$message.warning("请添加商品");
            return;
          }
          for (let i in this.form.orderItemsList) {
            this.form.orderItemsList[i].subTotalMoney = Number(
              this.form.orderItemsList[i].goodsNum * this.form.orderItemsList[i].price
            )
              ? Number(this.form.orderItemsList[i].goodsNum * this.form.orderItemsList[i].price).toFixed(2)
              : 0;
            if (this.form.orderItemsList[i].goodsNum <= 0) {
              return this.$message.warning(`销售明细序号${Number(i) + 1}的数量不能为零`);
            }
            if (!this.form.orderItemsList[i].sendNum) {
              this.form.orderItemsList[i].sendNum = 0;
            }
          }
          const loading = this.$loading({
            lock: true,
            text: "加载中",
            spinner: "el-icon-loading",
            background: "rgba(255,255,255,0.7)",
          });
          for (let courierCompanies of this.courierCompaniesList) {
            if (courierCompanies.dictValue === this.form.logisticsCorpName) {
              this.form.logisticsCorpId = courierCompanies.dictKey;
              break;
            }
          }
          // this.form.storageName = this.form.$storageId ? this.form.$storageId : "";
          this.form.billType = this.form.billType ? this.form.billType : 0;
          submit({
            bsType: "XS",
            ...this.form,
          })
            .then((res) => {
              this.$message.success("保存成功");
              this.getDetail(res.data.data.id);
            })
            .finally(() => {
              loading.close();
            });
        } else {
          return false;
        }
      });
    },
    orderConfirmation() {
      let obj = {
        bsType: "XS",
        ...this.form,
      };
      const loading = this.$loading({
        lock: true,
        text: "加载中",
        spinner: "el-icon-loading",
        background: "rgba(255,255,255,0.7)",
      });
      orderConfirmation(obj)
        .then((res) => {
          this.$message.success("操作成功");
          this.getDetail(this.form.id);
        })
        .finally(() => {
          loading.close();
        });
    },
    revokeOrderConfirmation() {
      let obj = {
        bsType: "XS",
        ...this.form,
      };
      const loading = this.$loading({
        lock: true,
        text: "加载中",
        spinner: "el-icon-loading",
        background: "rgba(255,255,255,0.7)",
      });
      revokeOrderConfirmation(obj)
        .then((res) => {
          this.$message.success("操作成功");
          this.editDis = false;
          this.getDetail(this.form.id, "撤销确认订单");
        })
        .finally(() => {
          loading.close();
        });
    },
    //关闭弹窗表单
    beforeClose(done, type) {
      console.log(type);
      // if(row == "add"){
      //     this.form.sharedCompanyId = this.form.sharedCompanyId?this.form.sharedCompanyId:''
      //     this.form.sharedCompanyName = this.form.sharedCompanyName?this.form.sharedCompanyName:''
      // }
      console.log("this.form.sharedCompanyId", this.form.sharedCompanyId);
      console.log("this.form.sharedCompanyName", this.form.sharedCompanyName);
      done();
    },
    getDetail(id, type) {
      const loading = this.$loading({
        lock: true,
        text: "加载中",
        spinner: "el-icon-loading",
        background: "rgba(255,255,255,0.7)",
      });
      getDetails({ id: id })
        .then((res) => {
          this.form = res.data.data;
          this.dataList = res.data.data.paymentRecordsList ? res.data.data.paymentRecordsList : [];
          if (
            this.form.status == "待发货" ||
            this.form.status == "已发货" ||
            this.form.status == "已收货" ||
            this.form.status == "已退款" ||
            this.form.status == "申请退货" ||
            this.form.status == "已取消"
          ) {
            this.editDis = true;
          }
          //成本、毛利对业务员隐藏
          this.optionForm.column.forEach((its) => {
            if (JSON.parse(localStorage.getItem("saber-userInfo")).content.role_name.split(",").includes("业务员")) {
              if (its.prop == "cost" || its.prop == "grossProfit") {
                this.$set(its, "display", false);
              }
            } else {
              if (its.prop == "cost" || its.prop == "grossProfit") {
                this.$set(its, "display", true);
              }
            }
          });
          // 明细信息成本、毛利对业务员隐藏
          this.optionContacts.column.forEach((its) => {
            if (JSON.parse(localStorage.getItem("saber-userInfo")).content.role_name.split(",").includes("业务员")) {
              if (its.prop == "costprie" || its.prop == "grossProfit") {
                this.$set(its, "hide", true);
              }
            } else {
              if (its.prop == "costprie" || its.prop == "grossProfit") {
                this.$set(its, "hide", false);
              }
            }
          });

          this.form.orderItemsList.forEach((items) => {
            if (!items.subTotalMoney) {
              items.subTotalMoney = Number(items.goodsNum * items.price)
                ? Number(items.goodsNum * items.price).toFixed(2)
                : 0;
              items.grossProfit = items.subTotalMoney - items.costprie;
            }
          });
          loading.close();
        })
        .catch(() => {
          loading.close();
        });
    },
    //请核关闭
    choceScheduleFun() {
      this.checkScheduleDialog = false;
    },
    //关闭审核
    choceCheckFun() {
      this.isExamineBtn = !this.isExamineBtn;
      this.checkDialog = false;
    },
    //申请退款
    applySettlement(type) {
      this.$confirm("您确定申请退款吗?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$refs["form"].validate((valid, done) => {
          done();
          if (valid) {
            const data = {
              id: this.form.id,
              url: "/salesManagement/saleOrder/index",
              pageStatus: "this.$store.getters.ltxsStatus",
              pageLabel: "销售订单",
            };
            const loading = this.$loading({
              lock: true,
              text: "加载中",
              spinner: "el-icon-loading",
              background: "rgba(255,255,255,0.7)",
            });
            checkOrder({ ...data })
              .then((res) => {
                this.getDetail(res.data.data.id);
                this.$message.success("申请退款成功");
                this.isApplySettlement = !this.isApplySettlement;
                loading.close();
              })
              .catch(() => {
                loading.close();
              });
          }
        });
      });
    },
    //确认退款
    confirmRefundBtn() {
      this.$confirm("您确定退款吗?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        const loading = this.$loading({
          lock: true,
          text: "加载中",
          spinner: "el-icon-loading",
          background: "rgba(255,255,255,0.7)",
        });
        // this.form.orderItemsList.forEach((items) => {

        //     let brandName = items.brandId
        //     items.brandId = items.brandName
        //     items.brandName = brandName

        //     let goodsName = items.goodsId
        //     items.goodsId = items.goodsName
        //     items.goodsName = goodsName

        // })
        confirmRefund({ ...this.form })
          .then((res) => {
            loading.close();
            this.$message.success("确定退款成功");
          })
          .catch(() => {
            loading.close();
          });
      });
    },
    //审批
    examineBtn() {
      this.checkData = this.$route.query.check;
      this.checkDialog = true;
    },
    //撤销请核
    revocationRequest() {
      this.$confirm("您确定撤回此次申请吗？", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        const loading = this.$loading({
          lock: true,
          text: "加载中",
          spinner: "el-icon-loading",
          background: "rgba(255,255,255,0.7)",
        });
        // this.form.orderItemsList.forEach((items) => {
        //     if (!items.subTotalMoney) {
        //         items.subTotalMoney = items.goodsNum * items.price
        //         items.grossProfit = items.subTotalMoney - items.costprie
        //     }
        //     let brandName = items.brandId
        //     items.brandId = items.brandName
        //     items.brandName = brandName

        //     let goodsName = items.goodsId
        //     items.goodsId = items.goodsName
        //     items.goodsName = goodsName

        // })
        revokeCheckOrder({ ...this.form }).then((res) => {
          this.isRevocationRequest = !this.isRevocationRequest;
          this.getDetail(res.data.data.id);
          this.$message.success("撤回成功");
          loading.close();
        });
      });
    },
    rowDelBox(row, index, type) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        if (row.id) {
          delOrderItem({ ids: row.id }).then((res) => {
            this.form.orderItemsList.splice(index, 1);
            this.$message.success("操作成功!");
          });
        } else {
          this.form[type].splice(index, 1);
          this.$message.success("操作成功!");
        }
      });
    },
    // 明细信息多选
    selectionContacts(list) {
      this.selectionMultilist = list;
    },
    // 快捷复制
    quickCopy() {
      let temp = document.createElement("textarea");
      let txt = `${this.form.customerName} ${this.form.businesDate}`;
      for (let item of this.form.orderItemsList) {
        txt += `\n${item.goodsName} ${item.goodsNum}`;
      }
      document.body.appendChild(temp);
      temp.value = txt;
      temp.select();
      document.execCommand("copy");
      document.body.removeChild(temp);
    },
    // 一键删除
    batchDelete() {
      if (this.selectionMultilist.length == 0) {
        return this.$message.warning("请选择要删除的数据");
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let multiList = this.selectionMultilist;
        let arr = this.form.orderItemsList;
        // 获取有id 的数据
        const itemsWithId = multiList.filter((item) => item.hasOwnProperty("id"));
        let arrIds = itemsWithId.map((item) => item.id); // 获取id 数据
        // 把选中的删除掉
        multiList.forEach((item) => {
          for (let index in arr) {
            if (JSON.stringify(item) == JSON.stringify(arr[index])) {
              arr.splice(Number(index), 1);
            }
          }
        });
        // 有id 的处理
        if (itemsWithId.length != 0) {
          delOrderItem({ ids: arrIds.join(",") }).then((res) => {
            this.$message.success("操作成功!");
          });
        }
      });
    },
    rowSave(form, done, loading) {
      if (this.isStatus) {
        done(form);
      } else {
        this.$message.error("请选择相同公司的商品");
      }
      console.log(form);
      // this.form.sharedCompanyId = res.data.data.sharedCompanyId
      // this.form.sharedCompanyName = res.data.data.sharedCompanyName
    },
    rowUpdate(form, index, done, loading) {
      done(form);
    },
    // 新增商品
    rowAdd(row, type) {
      if (!this.form.customerId) {
        return this.$message.error("请选择店铺名称");
      }
      if (!this.form.storageId) {
        return this.$message.error("请维护店铺名称的发货仓库");
      }
      this.findObject(
        this.optionContacts.column,
        "goodsId"
      ).dicUrl = `/api/gubersail-admin/goodsDesc/goodsListXs?cname={{key}}&customId=${this.dicUrlWithCustomId}&enableOrNot=1&stock=${this.form.storageId}`;
      this.goodsType = type;
      this.getAllWorkDicts();

      this.goodsListSave = [];
      setTimeout((res) => {
        this.refreshChange();
        this.dialogVisible = true;
      }, 300);
      // this.$refs.formContacts.rowAdd()
    },
    //打印
    handlePrint() {
      this.switchDialog = !this.switchDialog;
    },
    onClose(val) {
      this.switchDialog = val;
    },
    backToList(type) {
      this.$emit("backToList", type);
    },

    // 弹框的重置
    resetCrud() {
      this.$message.success("重置成功");
    },
    // 弹窗的保存
    saveCrud() {
      this.$message.success("保存成功");
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-form-item {
  margin-bottom: 8px !important;
}
</style>
