<template>
  <div class="app-container">
    <div v-show="!isShowDetail && !isShowForm && !isShowExamine && !isShowReturn">
      <!-- 筛选条件 -->
      <div class="screen-container">
        <Collapse :screen-form="screenForm">
          <template #right_btn>
            <el-button size="mini" @click="resetScreenForm">清空</el-button>
            <el-button size="mini" type="primary" @click="submitScreenForm">搜索</el-button>
          </template>
          <template #left_btn>
            <el-checkbox-group
              v-model="screenForm.status"
              @change="
                currentPage = 1
                getList()
              "
              size="mini"
            >
              <el-checkbox-button v-for="(item, index) in statusList" :key="index" :label="item.value">{{
                item.label
              }}</el-checkbox-button>
            </el-checkbox-group>
          </template>
          <template #search>
            <el-form ref="screenForm" :model="screenForm" label-width="100px" size="mini" label-position="left">
              <el-row :gutter="20">
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="工程订单号" prop="orderNum">
                    <el-input v-model="screenForm.orderNum" placeholder="请输入工程订单号" />
                  </el-form-item>
                </el-col>
                <!--            <el-col :xs="24" :sm="12" :lg="6">-->
                <!--              <el-form-item label="工程编码" prop="enginNum">-->
                <!--                <el-input-->
                <!--                  v-model="screenForm.enginNum"-->
                <!--                  placeholder="请输入工程编码"-->
                <!--                />-->
                <!--              </el-form-item>-->
                <!--            </el-col>-->
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="工程登录编号" prop="loginNum">
                    <el-input v-model="screenForm.loginNum" placeholder="请输入工程登录编号" />
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="行业类别" prop="refTradeCategory">
                    <el-input v-model="screenForm.refTradeCategory" placeholder="请输入项目名称" />
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="制单日期" prop="date">
                    <el-date-picker
                      v-model="screenForm.date"
                      type="datetimerange"
                      :default-time="['00:00:00', '23:59:59']"
                      range-separator="至"
                      style="width: 100%"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期"
                    />
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="销售类型" prop="saleType">
                    <el-select v-model="screenForm.saleType" placeholder="选择销售类型" style="width: 100%" clearable>
                      <el-option v-for="item in salesTypeList" :key="item.id" :label="item.saleName" :value="item.id" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="制单人" prop="createMan">
                    <el-input v-model="screenForm.createMan" placeholder="请输入制单人" />
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="审核人" prop="examineMan">
                    <el-input v-model="screenForm.examineMan" placeholder="请输入审核人" />
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="表头业务员" prop="salesMan">
                    <el-select
                      v-model="screenForm.salesMan"
                      placeholder="选择表头业务员"
                      clearable
                      filterable
                      style="width: 100%"
                    >
                      <el-option
                        v-for="item in salesmanList"
                        :key="item.adminUserId"
                        :label="item.nickName"
                        :value="item.adminUserId"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="使用单位" prop="refUseUnit">
                    <el-input v-model="screenForm.refUseUnit" placeholder="请输入使用单位" />
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="产品编码" prop="materialOldNumber">
                    <el-input v-model="screenForm.materialOldNumber" placeholder="请输入产品编码" />
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="规格型号" prop="specification">
                    <el-input v-model="screenForm.specification" placeholder="请输入规格型号" />
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="经销商" prop="customerKeyword">
                    <el-input v-model="screenForm.customerKeyword" placeholder="请输入经销商" />
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="区域" prop="refRegionWork">
                    <el-input v-model="screenForm.refRegionWork" placeholder="请输入区域" />
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="备注" prop="remark">
                    <el-input v-model="screenForm.remark" placeholder="备注" />
                  </el-form-item>
                </el-col>
                <el-col v-if="!isCustomer" :xs="24" :sm="12" :lg="6">
                  <el-form-item label="格力内部备注" prop="geLiInerNote">
                    <el-input v-model="screenForm.geLiInerNote" placeholder="格力内部备注" />
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="跨区厂编号" prop="refFactoryNo">
                    <el-input v-model="screenForm.refFactoryNo" placeholder="跨区厂编号" />
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="购买单位" prop="refBuyUnitName">
                    <el-input v-model="screenForm.refBuyUnitName" placeholder="购买单位" />
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="保证函" prop="refPromiseProvide">
                    <el-select
                      v-model="screenForm.refPromiseProvide"
                      placeholder="保证函"
                      filterable
                      style="width: 100%"
                    >
                      <el-option label="全部" value="" />
                      <el-option label="未保证" value="未保证" />
                      <el-option label="已保证" value="已保证" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="是否直调" prop="isDirectTransfer">
                    <el-select v-model="screenForm.isDirectTransfer" placeholder="选择是否直" style="width: 100%">
                      <el-option :value="null" label="默认" />
                      <el-option v-for="item in transfer" :key="item.value" :label="item.label" :value="item.value" />
                    </el-select>
                  </el-form-item>
                </el-col>

                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="订单日期" prop="orderTime">
                    <el-date-picker
                      v-model="screenForm.orderTime"
                      type="datetimerange"
                      :default-time="['00:00:00', '23:59:59']"
                      range-separator="至"
                      style="width: 100%"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期"
                    />
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="钱包" prop="customerWalletId">
                    <el-select
                      v-model="screenForm.customerWalletId"
                      placeholder="选择钱包"
                      clearable
                      filterable
                      style="width: 100%"
                    >
                      <el-option v-for="item in NoRebateWalletList" :key="item.id" :label="item.name" :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="销售类型" prop="saleTypeId">
                    <el-select
                      v-model="screenForm.saleTypeId"
                      placeholder="选择销售类型"
                      clearable
                      filterable
                      style="width: 100%"
                    >
                      <el-option v-for="item in typeList" :key="item.id" :label="item.saleName" :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </template>
        </Collapse>
      </div>
      <ul class="ulStyle">
        <li class="title">
          金额：<span class="num">{{ (Number(numSum.amountC) || 0) | numToFixed }}</span>
        </li>
        <li class="title">
          数量：<span class="num">{{ Number(numSum.totalC) || 0 | numToFixed }}</span>
        </li>
      </ul>
      <div class="mymain-container">
        <div class="btn-group clearfix">
          <div class="fl">
            <el-button
              v-if="$checkBtnRole('add', $route.meta.roles)"
              size="mini"
              type="primary"
              icon="el-icon-plus"
              @click="toForm()"
              >新增</el-button
            >
            <el-button
              v-if="$checkBtnRole('del', $route.meta.roles)"
              size="mini"
              type="danger"
              icon="el-icon-minus"
              :disabled="multipleSelection.length < 1"
              @click="batchDelete()"
              >批量删除</el-button
            >
          </div>
          <div class="fr">
            <ExportButton :ex-url="'engin-order/export'" :ex-params="exParams" />
          </div>
        </div>
        <div class="table">
          <el-table
            v-loading="listLoading"
            :data="dataList"
            element-loading-text="Loading"
            border
            fit
            highlight-current-row
            stripe
            show-summary
            :summary-method="$getSummaries"
            @selection-change="handleSelectionChange"
          >
            <el-table-column align="center" type="selection" width="55" />
            <el-table-column align="left" label="审核状态" prop="examineStatus" min-width="100" show-overflow-tooltip>
              <template slot-scope="scope">
                {{ scope.row.examineStatus | statusFilter }}
              </template>
            </el-table-column>
            <el-table-column align="left" label="工程订单号" prop="enginOrderNo" min-width="140" show-overflow-tooltip>
              <template slot-scope="scope">
                <CopyButton :copy-text="scope.row.enginOrderNo" />
                <span>{{ scope.row.enginOrderNo }}</span>
              </template>
            </el-table-column>
            <el-table-column align="left" label="订单日期" prop="orderDate" min-width="160" show-overflow-tooltip>
              <template slot-scope="scope">
                <div>
                  <span>{{ scope.row.orderDate }}</span>
                  <el-button
                    v-if="$checkBtnRole('date', $route.meta.roles) && !isCustomer && scope.row.examineStatus !== 'SAVE'"
                    type="text"
                    icon="el-icon-edit"
                    style="padding: 0; margin-left: 4px"
                    @click="editDate(scope.row)"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column align="left" label="审核人" prop="confirmName" min-width="100" show-overflow-tooltip />
            <el-table-column align="left" label="经销商名称" prop="customerName" min-width="250" show-overflow-tooltip>
              <template slot-scope="scope">
                <CopyButton :copy-text="scope.row.customerName" />
                <span>{{ scope.row.customerName }}</span>
              </template>
            </el-table-column>
            <el-table-column
              align="left"
              label="工程登录编号"
              prop="refEnginRecordNo"
              min-width="160"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <CopyButton :copy-text="scope.row.refEnginRecordNo" />
                <span>{{ scope.row.refEnginRecordNo }}</span>
              </template>
            </el-table-column>
            <el-table-column align="left" label="使用单位" prop="refUseUnit" min-width="160" show-overflow-tooltip />
            <el-table-column
              align="left"
              label="购买单位"
              prop="refBuyUnitName"
              min-width="160"
              show-overflow-tooltip
            />
            <el-table-column
              align="left"
              label="产品编号"
              prop="materialOldNumber"
              min-width="140"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <CopyButton :copy-text="scope.row.materialOldNumber" />
                <span>{{ scope.row.materialOldNumber }}</span>
              </template>
            </el-table-column>
            <el-table-column align="left" label="产品名称" prop="materialName" min-width="160" show-overflow-tooltip>
              <template slot-scope="scope">
                <CopyButton :copy-text="scope.row.materialName" />
                <span>{{ scope.row.materialName }}</span>
              </template>
            </el-table-column>
            <el-table-column align="left" label="规格型号" prop="specification" min-width="350" show-overflow-tooltip>
              <template slot-scope="scope">
                <CopyButton :copy-text="scope.row.specification" />
                <span>{{ scope.row.specification }}</span>
              </template>
            </el-table-column>
            <el-table-column align="right" label="总数量" prop="qty" min-width="100" sortable show-overflow-tooltip />
            <el-table-column align="right" label="单价" prop="price" min-width="100" sortable show-overflow-tooltip>
              <template slot-scope="scope">
                {{ scope.row.price | numToFixed }}
              </template>
            </el-table-column>
            <el-table-column
              align="right"
              label="订单金额"
              prop="totalAmount"
              min-width="110"
              sortable
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                {{ scope.row.totalAmount | numToFixed }}
              </template>
            </el-table-column>
            <el-table-column
              align="right"
              label="发货数量"
              prop="retiredQty"
              min-width="110"
              sortable
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                {{ scope.row.applySendQty }}
              </template> </el-table-column
            ><el-table-column
              align="right"
              label="退货数量"
              prop="refundProductQty"
              min-width="110"
              sortable
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                {{ scope.row.refundProductQty }}
              </template>
            </el-table-column>
            <el-table-column
              align="left"
              label="是否直调"
              prop="isDirectTransfer"
              min-width="100"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                {{ scope.row.isDirectTransfer ? '是' : '否' }}
              </template>
            </el-table-column>
            <el-table-column
              align="right"
              label="出库数量"
              prop="hasSendQty"
              min-width="110"
              sortable
              show-overflow-tooltip
            />
            <el-table-column
              align="left"
              label="项目类型"
              prop="refProjectCategory"
              min-width="160"
              show-overflow-tooltip
            />
            <el-table-column
              align="left"
              label="行业类别"
              prop="refTradeCategory"
              min-width="160"
              show-overflow-tooltip
            />
            <el-table-column align="left" label="备注" prop="remark" min-width="160" show-overflow-tooltip />
            <el-table-column
              v-if="!isCustomer"
              align="left"
              label="格力内部备注"
              prop="geLiInerNote"
              min-width="160"
              show-overflow-tooltip
            />
            <el-table-column align="left" label="制单日期" prop="createTime" min-width="160" show-overflow-tooltip />
            <el-table-column align="left" label="制单人" prop="createName" min-width="100" show-overflow-tooltip />
            <el-table-column
              align="left"
              label="保证函"
              prop="refPromiseProvide"
              min-width="100"
              show-overflow-tooltip
            />
            <el-table-column
              align="left"
              label="跨区厂编号"
              prop="refFactoryNo"
              min-width="160"
              show-overflow-tooltip
            />
            <el-table-column align="left" label="区域" prop="refRegionWork" min-width="160" show-overflow-tooltip />
            <el-table-column align="left" label="销售类型" prop="saleTypeName" min-width="120" show-overflow-tooltip />
            <el-table-column align="left" label="物料编码" prop="materialNumber" min-width="120" show-overflow-tooltip>
              <template slot-scope="scope">
                <CopyButton :copy-text="scope.row.materialNumber" />
                <span>{{ scope.row.materialNumber }}</span>
              </template>
            </el-table-column>
            <el-table-column
              align="right"
              label="实付金额"
              prop="payAmount"
              min-width="110"
              sortable
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                {{ scope.row.payAmount | numToFixed }}
              </template>
            </el-table-column>
            <el-table-column
              align="left"
              label="经销商编码"
              prop="customerNumber"
              min-width="100"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <CopyButton :copy-text="scope.row.customerNumber" />
                <span>{{ scope.row.customerNumber }}</span>
              </template>
            </el-table-column>
            <el-table-column
              align="right"
              label="直调数量"
              prop="directTransferQty"
              min-width="110"
              sortable
              show-overflow-tooltip
            />
            <el-table-column
              align="left"
              label="返利钱包"
              prop="customerWalletName2"
              min-width="100"
              show-overflow-tooltip
            />
            <el-table-column
              align="right"
              label="使用返利金额"
              prop="rebateAmount"
              min-width="120"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <div v-if="scope.row.examineStatus === 'OK'">
                  {{ scope.row.payRebateAmount | numToFixed }}
                </div>
                <div v-else>{{ scope.row.rebateAmount | numToFixed }}</div>
              </template>
            </el-table-column>
            <el-table-column
              align="right"
              label="格力折扣"
              prop="discAmount"
              min-width="110"
              sortable
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                {{ scope.row.discAmount | numToFixed }}
              </template>
            </el-table-column>
            <el-table-column align="left" label="备注" prop="remark" min-width="160" show-overflow-tooltip />
            <el-table-column align="left" label="表头业务员" prop="serviceName" min-width="100" show-overflow-tooltip />
            <el-table-column
              align="left"
              label="表体业务员"
              prop="itemServiceName"
              min-width="100"
              show-overflow-tooltip
            />
            <el-table-column align="left" label="审核日期" prop="confirmTime" min-width="160" show-overflow-tooltip />
            <el-table-column align="left" label="订单类型" prop="enginOrderType" min-width="100" show-overflow-tooltip>
              <template slot-scope="scope">
                {{ scope.row.enginOrderType | typeFilter }}
              </template>
            </el-table-column>
            <el-table-column align="left" label="单位" prop="unit" min-width="100" show-overflow-tooltip />
            <el-table-column align="center" label="操作" width="220" fixed="right">
              <template slot-scope="scope">
                <el-popconfirm
                  v-if="scope.row.examineStatus === 'SAVE'"
                  style="margin-right: 10px"
                  title="确定申请吗？"
                  @onConfirm="handleSubmit(scope.row.parentId, scope.row)"
                >
                  <el-button slot="reference" type="text">申请</el-button>
                </el-popconfirm>
                <el-popconfirm
                  v-if="scope.row.examineStatus === 'WAIT'"
                  style="margin-right: 10px"
                  title="确定撤回吗？"
                  @onConfirm="handleWithdraw(scope.row.parentId, scope.row)"
                >
                  <el-button slot="reference" type="text">撤回</el-button>
                </el-popconfirm>
                <el-popconfirm
                  v-if="$checkBtnRole('examine', $route.meta.roles) && scope.row.examineStatus === 'OK'"
                  style="margin-right: 10px"
                  title="确定弃审吗？"
                  @onConfirm="handleAbandon(scope.row.parentId, scope.row)"
                >
                  <el-button slot="reference" type="text">弃审</el-button>
                </el-popconfirm>
                <el-button
                  v-if="
                    $checkBtnRole('edit', $route.meta.roles) &&
                    (scope.row.examineStatus === 'SAVE' || scope.row.examineStatus === 'FAIL')
                  "
                  type="text"
                  @click="toForm(scope.row)"
                >
                  编辑
                </el-button>
                <el-button
                  v-if="$checkBtnRole('examine', $route.meta.roles) && scope.row.examineStatus === 'WAIT'"
                  type="text"
                  @click="toExamine(scope.row)"
                >
                  审批
                </el-button>
                <el-button
                  v-if="$checkBtnRole('examine', $route.meta.roles) && scope.row.examineStatus !== 'FAIL'"
                  type="text"
                  @click="toReturn(scope.row)"
                >
                  退订
                </el-button>
                <el-button type="text" @click="toDetail(scope.row)"> 详情 </el-button>
                <el-popconfirm
                  v-if="$checkBtnRole('del', $route.meta.roles) && scope.row.examineStatus !== 'OK'"
                  style="margin-left: 10px"
                  title="确定删除吗？"
                  @onConfirm="handleDelete(scope.row.parentId, scope.row)"
                >
                  <el-button slot="reference" type="text" style="color: #f56c6c">删除</el-button>
                </el-popconfirm>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div class="pagination clearfix">
        <div class="fr">
          <el-pagination
            :current-page="currentPage"
            :page-sizes="[10, 20, 30, 50, 500]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="listTotal"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>

    <EditDateDialog :is-show.sync="isShowEditDateDialog" :date-form.sync="dateForm" />

    <HomeDetail v-if="isShowDetail" :list-item="queryItem" @backListFormDetail="backList" />
    <HomeForm v-if="isShowForm" :list-item="queryItem" @backListFormDetail="backList" />
    <HomeExamine v-if="isShowExamine" :list-item="queryItem" @backListFormDetail="backList" />
    <HomeReturn v-if="isShowReturn" :list-item="queryItem" @backListFormDetail="backList" />
  </div>
</template>

<script>
import {
  getOrderList,
  applyHome,
  withdrawHome,
  deleteHome,
  editDateHome,
  abandonHome,
  getEnginCountList
} from '@/api/supply/engin'
import { getSalesmanList, getTypeList } from '@/api/common'
import HomeDetail from '@/views/supply/engin/components/home_detail'
import HomeForm from '@/views/supply/engin/components/home_form'
import HomeExamine from '@/views/supply/engin/components/home_examine'
import HomeReturn from '@/views/supply/engin/components/home_return'
import EditDateDialog from '@/components/Common/edit-date-dialog'
import { getNoRebateWalletList } from '@/api/policy_list'

let that
export default {
  components: {
    HomeDetail,
    HomeForm,
    HomeExamine,
    HomeReturn,
    EditDateDialog
  },
  filters: {
    statusFilter(val) {
      const obj = that.statusList.find(o => o.value === val)
      return obj ? obj.label : ''
    },
    typeFilter(val) {
      const MAP = {
        TRADE: '商用',
        HOME: '家用'
      }
      return MAP[val]
    }
  },
  data() {
    return {
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页数量
      listTotal: 0, // 列表总数
      dataList: null, // 列表数据
      listLoading: false, // 列表加载loading
      screenForm: {
        // 筛选表单数据
        status: [],
        orderNum: '',
        enginNum: '',
        loginNum: '',
        refTradeCategory: '',
        date: [],
        saleType: '',
        createMan: '',
        examineMan: '',
        salesMan: '',
        refUseUnit: '',
        materialOldNumber: '',
        specification: '',
        customerKeyword: '',
        refRegionWork: '',
        remark: '',
        geLiInerNote: '',
        refFactoryNo: '',
        refBuyUnitName: '',
        refPromiseProvide: '',
        isDirectTransfer: null,
        orderTime: [],
        saleTypeId: '',
        customerWalletId: ''
      },
      statusList: [
        { label: '已保存', value: 'SAVE' },
        { label: '待审核', value: 'WAIT' },
        { label: '审核通过', value: 'OK' }
        //  // { label: '审核驳回', value: 'FAIL' },,
        // { label: '已关闭', value: 'CLOSE' },
      ],
      salesmanList: [],
      transfer: [
        { label: '是', value: true },
        { label: '否', value: false }
      ],
      multipleSelection: [],

      queryItem: {},
      isShowDetail: false,
      isShowForm: false,
      isShowExamine: false,
      isShowReturn: false,

      editId: null,
      isShowEditDateDialog: false,
      dateForm: {
        date: ''
      },
      isCollapse: true,
      salesTypeList: [],
      NoRebateWalletList: [],
      typeList: [],
      numSum: {
        totalC: 0,
        amountC: 0
      }
    }
  },

  computed: {
    exParams() {
      const ids = this.multipleSelection.map(item => {
        return item.enginOrderNo
      })
      return {
        examineStatus: this.screenForm.status.join(','),
        enginOrderNo: ids && ids.length ? ids.join(',') : this.screenForm.orderNum,
        refProjectNo: this.screenForm.enginNum,
        refEnginRecordNo: this.screenForm.loginNum,
        refTradeCategory: this.screenForm.refTradeCategory,
        startCreateTime: this.screenForm.date ? this.screenForm.date[0] : '',
        endCreateTime: this.screenForm.date ? this.screenForm.date[1] : '',
        startOrderTime: this.screenForm.orderTime ? this.screenForm.orderTime[0] : '',
        endOrderTime: this.screenForm.orderTime ? this.screenForm.orderTime[1] : '',
        saleTypeId: this.screenForm.saleType,
        createName: this.screenForm.createMan,
        confirmName: this.screenForm.examineMan,
        serviceId: this.screenForm.salesMan,
        refUseUnit: this.screenForm.refUseUnit,
        materialOldNumber: this.screenForm.materialOldNumber,
        specification: this.screenForm.specification,
        customerKeyword: this.screenForm.customerKeyword,
        refRegionWork: this.screenForm.refRegionWork,
        remark: this.screenForm.remark,
        geLiInerNote: this.screenForm.geLiInerNote,
        refFactoryNo: this.screenForm.refFactoryNo,
        refBuyUnitName: this.screenForm.refBuyUnitName,
        refPromiseProvide: this.screenForm.refPromiseProvide,
        isDirectTransfer: this.screenForm.isDirectTransfer,

        enginOrderType: 'HOME' // TRADE=商用 HOME=家用
      }
    },
    isCustomer() {
      return this.$store.getters.customerId && this.$store.getters.customerNumber
    }
  },

  beforeCreate() {
    that = this
  },

  created() {
    this.getSalesTypeList()
    this.getSalesmanList()
    this.getList()
  },

  methods: {
    // 获取业务员列表
    getSalesmanList() {
      getSalesmanList({
        pageNum: 1,
        pageSize: -1,
        isCustomer: 0,
        status: true
      }).then(res => {
        this.salesmanList = res.data.records
      })
      getNoRebateWalletList({
        walletName: ''
      }).then(res => {
        console.log(res)
        this.NoRebateWalletList = res.data
        console.log(this.NoRebateWalletList)
      })
      getTypeList({ pageNum: 1, pageSize: -1 }).then(res => {
        this.typeList = res.data.records
        console.log(this.typeList)
      })
    },

    // 获取销售类型列表
    getSalesTypeList() {
      getTypeList({
        pageNum: 1,
        pageSize: -1
      }).then(res => {
        this.salesTypeList = res.data.records
      })
    },

    // 查询列表
    getList() {
      this.listLoading = true
      const params = {
        pageNum: this.currentPage,
        pageSize: this.pageSize,
        examineStatus: this.screenForm.status.join(','),
        enginOrderNo: this.screenForm.orderNum,
        refProjectNo: this.screenForm.enginNum,
        refEnginRecordNo: this.screenForm.loginNum,
        refTradeCategory: this.screenForm.refTradeCategory,
        startCreateTime: this.screenForm.date ? this.screenForm.date[0] : '',
        endCreateTime: this.screenForm.date ? this.screenForm.date[1] : '',
        startOrderTime: this.screenForm.orderTime ? this.screenForm.orderTime[0] : '',
        endOrderTime: this.screenForm.orderTime ? this.screenForm.orderTime[1] : '',
        createName: this.screenForm.createMan,
        confirmName: this.screenForm.examineMan,
        serviceId: this.screenForm.salesMan,
        refUseUnit: this.screenForm.refUseUnit,
        materialOldNumber: this.screenForm.materialOldNumber,
        specification: this.screenForm.specification,
        customerKeyword: this.screenForm.customerKeyword,
        refRegionWork: this.screenForm.refRegionWork,
        remark: this.screenForm.remark,
        geLiInerNote: this.screenForm.geLiInerNote,
        saleTypeId: this.screenForm.saleTypeId,
        customerWalletId: this.screenForm.customerWalletId,
        refFactoryNo: this.screenForm.refFactoryNo,
        refBuyUnitName: this.screenForm.refBuyUnitName,
        isDirectTransfer: this.screenForm.isDirectTransfer,

        refPromiseProvide: this.screenForm.refPromiseProvide,
        enginOrderType: 'HOME' // TRADE=商用 HOME=家用
      }

      getOrderList(params).then(res => {
        res.data.records.forEach(item => {
          item.sums1 = ['qty', 'directTransferQty', 'hasSendQty']
          item.sums2 = ['price', 'totalAmount', 'payAmount', 'discAmount']
        })
        this.dataList = res.data.records
        this.listTotal = res.data.total
        this.listLoading = false
      })

      getEnginCountList({
        examineStatus: this.screenForm.status.join(','),
        enginOrderNo: this.screenForm.orderNum,
        refProjectNo: this.screenForm.enginNum,
        refEnginRecordNo: this.screenForm.loginNum,
        refTradeCategory: this.screenForm.refTradeCategory,
        startCreateTime: this.screenForm.date ? this.screenForm.date[0] : '',
        endCreateTime: this.screenForm.date ? this.screenForm.date[1] : '',
        startOrderTime: this.screenForm.orderTime ? this.screenForm.orderTime[0] : '',
        endOrderTime: this.screenForm.orderTime ? this.screenForm.orderTime[1] : '',
        createName: this.screenForm.createMan,
        confirmName: this.screenForm.examineMan,
        serviceId: this.screenForm.salesMan,
        refUseUnit: this.screenForm.refUseUnit,
        materialOldNumber: this.screenForm.materialOldNumber,
        specification: this.screenForm.specification,
        customerKeyword: this.screenForm.customerKeyword,
        refRegionWork: this.screenForm.refRegionWork,
        remark: this.screenForm.remark,
        geLiInerNote: this.screenForm.geLiInerNote,
        saleTypeId: this.screenForm.saleTypeId,
        customerWalletId: this.screenForm.customerWalletId,
        refFactoryNo: this.screenForm.refFactoryNo,
        refBuyUnitName: this.screenForm.refBuyUnitName,
        isDirectTransfer: this.screenForm.isDirectTransfer,

        refPromiseProvide: this.screenForm.refPromiseProvide,
        enginOrderType: 'HOME' // TRADE=商用 HOME=家用
      }).then(res => {
        if (res.data) {
          this.numSum = res.data
        }
      })
    },

    // 提交筛选表单
    submitScreenForm() {
      this.currentPage = 1
      this.getList()
    },

    // 重置筛选表单
    resetScreenForm() {
      this.$refs.screenForm.resetFields()
      this.currentPage = 1
      this.getList()
    },

    // 更改每页数量
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.getList()
    },

    // 更改当前页
    handleCurrentChange(val) {
      this.currentPage = val
      this.getList()
    },

    // 进入表单
    toForm(item) {
      this.queryItem = item
      this.isShowForm = true
    },

    // 进入审批
    toExamine(item) {
      this.queryItem = item
      this.isShowExamine = true
    },

    // 进入详情
    toDetail(item) {
      this.queryItem = item
      this.isShowDetail = true
    },

    // 进入退订
    toReturn(item) {
      if (item.refundableQty <= 0) {
        return this.$errorMsg('可退数量为0')
      }
      this.queryItem = item
      this.isShowReturn = true
    },

    backList() {
      this.queryItem = {}
      this.isShowDetail = false
      this.isShowForm = false
      this.isShowExamine = false
      this.isShowReturn = false
    },

    // 申请
    handleSubmit(id, row) {
      this.$confirm('发货时将暂扣工程押金，请确保钱包余额充足', '温馨提示').then(() => {
        applyHome({ id, refEnginRecordNo: row.refEnginRecordNo }).then(res => {
          this.$successMsg()
          this.getList()
        })
      })
    },

    // 撤回
    handleWithdraw(id, row) {
      withdrawHome({ id, refEnginRecordNo: row.refEnginRecordNo }).then(res => {
        this.$successMsg()
        this.getList()
      })
    },

    // 弃审
    handleAbandon(id, row) {
      abandonHome({ id, refEnginRecordNo: row.refEnginRecordNo }).then(res => {
        this.$successMsg()
        this.getList()
      })
    },

    // 删除
    handleDelete(id, row) {
      deleteHome({ ids: id }).then(res => {
        this.$successMsg()
        this.getList()
      })
    },

    // 批量删除
    batchDelete() {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          const ids = this.multipleSelection.map(item => {
            return item.parentId
          })
          deleteHome({ ids: ids.join(',') }).then(res => {
            this.$successMsg()
            this.getList()
          })
        })
        .catch(() => {})
    },

    handleSelectionChange(val) {
      this.multipleSelection = val
    },

    // 打开 修改订单日期
    editDate(item) {
      this.editId = item.parentId
      this.dateForm.date = item.orderDate.slice(0, 10)
      this.isShowEditDateDialog = true
    },

    // 提交 修改订单日期
    submitDateForm() {
      editDateHome({
        enginOrderId: this.editId,
        orderDate: this.dateForm.date + ' 00:00:00',
        refEnginRecordNo: this.screenForm.loginNum
      }).then(res => {
        this.isShowEditDateDialog = false
        this.getList()
        this.$successMsg('修改成功')
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.ulStyle {
  list-style: none;
  margin: 0;
  padding: 10px 0;
  background-color: #ffffff;
  z-index: 1;
}
.title {
  display: inline-block;
  font-weight: 700;
  margin-right: 20px;
}
.num {
  padding-left: 6px;
  font-weight: 400;
}
</style>
