<template>
  <div class="">
    <div v-if="isEdit == 1">
      <div>
        <div class="diy-table-1">
          <el-row>
            <el-col :span="8" class="item">
              <div class="label">销售政策编号</div>
              <div class="value">{{ detail.code }}</div>
            </el-col>
            <el-col :span="8" class="item">
              <div class="label">销售政策类型</div>
              <div class="value">
                {{ detail.type == 'PROVISION' ? '配提' : '限量' }}
              </div>
            </el-col>
            <el-col :span="8" class="item">
              <div class="label">状态</div>
              <div class="value">
                {{ detail.status == 1 ? '已生效' : '未生效' }}
              </div>
            </el-col>
            <el-col :span="24" class="item">
              <div class="label">销售政策名称</div>
              <div class="value">
                <el-input v-model="detail.title" disabled placeholder="请输入销售政策名称" />
              </div>
            </el-col>

            <el-col :span="24" class="item">
              <div class="label">表头备注</div>
              <div class="value">
                {{ detail.remark }}
              </div>
            </el-col>
            <el-col v-if="(detail.examineStatus = 'SAVE' && detail.examineTime != null)" :span="24" class="item">
              <div class="label">驳回原因</div>
              <div class="value">
                {{ detail.examineRemark }}
              </div>
            </el-col>
            <el-col :span="8" class="item">
              <div class="label">制单人</div>
              <div class="value">{{ detail.createBy }}</div>
            </el-col>
            <el-col :span="8" class="item">
              <div class="label">制单日期</div>
              <div class="value">
                {{ detail.createTime }}
              </div>
            </el-col>
            <el-col :span="8" class="item">
              <div class="label">生效日期</div>
              <div class="value">
                {{ detail.startTime }}
              </div>
            </el-col>
            <el-col :span="24" class="item">
              <div class="label">失效日期</div>
              <div class="value">
                {{ detail.endTime }}
              </div>
            </el-col>
            <template v-if="detail.type === 'LIMIT'">
              <el-col :span="12" class="item">
                <div class="label">商家最少起提数量</div>
                <div class="value">
                  {{ detail.minBuyNum }}
                </div>
              </el-col>
              <el-col :span="12" class="item">
                <div class="label">商家最大提货组数</div>
                <div class="value">
                  {{ detail.maxBuyNum }}
                </div>
              </el-col>
            </template>
          </el-row>

          <el-row v-if="detail.imgSrc && isShow !== 5" class="img-box">
            <el-col :span="24" class="item">
              <div class="label" style="height: 150px">政策封面图</div>
              <div class="value" style="height: 150px">
                <template v-for="item in detail.imgSrc">
                  <el-image
                    v-if="checkFileType(item) == 'image'"
                    ref="img"
                    :src="$imageUrl + item"
                    style="width: 120px; height: 120px; margin-right: 20px"
                    fit="cover"
                    :preview-src-list="[$imageUrl + item]"
                    class="elImageClose"
                  />
                  <img v-if="checkFileType(item) == 'word'" class="file" src="@/assets/common/word.png">
                  <img v-if="checkFileType(item) == 'excel'" class="file" src="@/assets/common/excel.png">
                  <img v-if="checkFileType(item) == 'ppt'" class="file" src="@/assets/common/ppt.png">

                  <img
                    v-if="checkFileType(item) == 'pdf'"
                    class="file"
                    style="cursor: pointer"
                    src="@/assets/common/pdf.png"
                    @click="openPdf(item)"
                  >

                  <img v-if="checkFileType(item) == 'file'" class="file aaa" src="@/assets/common/zip.jpeg">
                </template>
                <!-- <el-image
                  v-for="item in detail.imgSrc"
                  style="height: 120px; widht: 120px;margin-left: 20px"
                  :src="$imageUrl + item"
                  fit="fill"
                  :preview-src-list="srcList"
                /> -->
              </div>
            </el-col>
          </el-row>
          <el-row v-if="isShow == 5">
            <el-col :span="24" class="item">
              <div class="label" style="height: 150px">政策封面图</div>
              <div class="value" style="height: 150px">
                <image-upload :file-list="fileList" :multiple="false" />
              </div>
            </el-col>
          </el-row>
          <el-row v-if="this.isShow == 4">
            <el-col :span="8" class="item">
              <div class="label">审核人</div>
              <div class="value">{{ detail.examineBy }}</div>
            </el-col>
            <el-col :span="16" class="item">
              <div class="label">审核日期</div>
              <div class="value">{{ detail.examineTime }}</div>
            </el-col>
            <el-col :span="12" class="item">
              <div class="label">返利使用金额需满额使用</div>
              <div class="value">
                <el-checkbox v-model="detail.isFullRebate" disabled>{{
                  detail.isFullRebate ? '是' : '否'
                }}</el-checkbox>
              </div>
            </el-col>
            <el-col :span="12" class="item">
              <div class="label">商用空调政策</div>
              <div class="value">
                <el-checkbox v-model="detail.commercialType" disabled>{{
                  detail.commercialType ? '是' : '否'
                }}</el-checkbox>
              </div>
            </el-col>

            <!--            <el-col :span="8" class="item">-->
            <!--              <div class="label">关闭人</div>-->
            <!--              <div class="value"></div>-->
            <!--            </el-col>-->
            <!--            <el-col :span="24" class="item">-->
            <!--              <div class="label">关闭日期</div>-->
            <!--              <div class="value"></div>-->
            <!--            </el-col>-->
          </el-row>
        </div>
        <div class="mymain-container">
          <el-row>
            <el-divider />
            <el-row type="flex">
              <el-col :span="12">
                <h4 style="display: inline-block; margin-right: 20px">货品信息</h4>
                <ExportButton
                  v-if="isShow === 4"
                  style="display: inline-block"
                  :ex-url="'policy/material/export'"
                  ex-text="导出货品"
                  :ex-params="{ policyId: detail.code }"
                />

                <el-upload
                  v-if="isShow == 5"
                  class="import-btn"
                  :action="baseURL + 'student/import'"
                  :http-request="handleImport"
                  :file-list="importFileList"
                  :show-file-list="false"
                >
                  <el-button size="mini">导入货品价格表</el-button>
                </el-upload>
              </el-col>
              <el-col :span="12" class="tr" />
            </el-row>
            <el-divider />
            <el-row :gutter="20">
              <el-col :span="12" :offset="0"> <el-input v-model="specification" placeholder="请输入规格型号" size="mini" clearable />
              </el-col>
              <el-col :span="12" :offset="0">
                <el-button
                  style="margin-left: 20px"
                  type="primary"
                  size="mini"
                  @click=" dcurrentPage =1; handletwoList() "
                >查询</el-button>
                <el-button size="mini" @click="specification=''; handletwoList()">重置</el-button>
              </el-col>
            </el-row>
          </el-row>
          <div class="table">
            <el-table
              v-loading="listLoading"
              :data="dataList"
              element-loading-text="Loading"
              border
              max-height="700"
              fit
              highlight-current-row
              stripe
            >
              <el-table-column fixed type="index" label="序号" width="50" align="left" />
              <el-table-column
                prop="materialNumber"
                label="物料编码"
                min-width="160"
                show-overflow-tooltip
                align="left"
              >
                <template slot-scope="scope">
                  <CopyButton :copy-text="scope.row.materialNumber" />
                  <span>{{ scope.row.materialNumber }}</span>
                </template>
              </el-table-column>
              <el-table-column prop="materialName" label="产品名称" min-width="160" show-overflow-tooltip align="left">
                <template slot-scope="scope">
                  <CopyButton :copy-text="scope.row.materialName" />
                  <span>{{ scope.row.materialName }}</span>
                </template>
              </el-table-column>
              <el-table-column prop="specification" label="规格型号" min-width="300" show-overflow-tooltip align="left">
                <template slot-scope="scope">
                  <CopyButton :copy-text="scope.row.specification" />
                  <span>{{ scope.row.specification }}</span>
                </template>
              </el-table-column>
              <el-table-column
                prop="saleTypeCode"
                label="销售类型编码"
                min-width="160"
                show-overflow-tooltip
                align="left"
              />
              <el-table-column
                prop="saleTypeName"
                label="销售类型"
                min-width="160"
                show-overflow-tooltip
                align="left"
              />
              <el-table-column prop="discAmount" label="格力折扣" align="right" />
              <el-table-column prop="price" label="单价" align="right" />
              <el-table-column prop="orgPrice" label="原供价" align="right" min-width="150">
                <template slot-scope="scope">
                  {{ scope.row.orgPrice }}
                </template>
              </el-table-column>
              <el-table-column prop="priceType" label="价格类型" align="left" min-width="150">
                <template slot-scope="scope">
                  {{ scope.row.priceType }}
                </template>
              </el-table-column>
              <el-table-column label="返利钱包" align="left" min-width="200" show-overflow-tooltip>
                <template slot-scope="scope">
                  <template v-for="item in scope.row.walletRelaList">
                    <el-tag v-if="item.type === 'REBATE'" style="margin: 5px" type="success" size="mini">{{
                      item.walletName
                    }}</el-tag>
                  </template>
                </template>
              </el-table-column>
              <el-table-column label="现金钱包" align="left" min-width="200" show-overflow-tooltip>
                <template slot-scope="scope">
                  <template v-for="item in scope.row.walletRelaList">
                    <el-tag v-if="item.type === 'COMMONLY'" style="margin: 5px" type="success" size="mini">{{
                      item.walletName
                    }}</el-tag>
                  </template>
                </template>
              </el-table-column>
              <el-table-column prop="status" label="状态" align="left" show-overflow-tooltip min-width="150">
                <template slot-scope="scope">
                  {{ scope.row.status ? '启用' : '作废' }}
                </template>
              </el-table-column>
            </el-table>
          </div>
          <!-- 分页 -->
          <div style="margin: 20px 0">
            <el-pagination
              :current-page="dcurrentPage"
              :page-sizes="[10, 20, 30, 50]"
              :page-size="10"
              layout="total, sizes, prev, pager, next, jumper"
              :total="dlistTotal"
              @size-change="handleSizeChange2"
              @current-change="handleCurrentChange2"
            />
          </div>
          <!-- 不管是新增还是编辑还是详情，如果类型选的是配提才显示这个条件信息，否则隐藏 -->
          <template v-if="detail.type == 'PROVISION'">
            <el-row>
              <el-divider />
              <el-row type="flex">
                <el-col :span="12">
                  <h4 style="display: inline-block; margin-right: 20px">条件信息</h4>
                </el-col>
              </el-row>
              <el-divider />
            </el-row>
            <div class="table">
              <el-table :data="conditionList" element-loading-text="Loading" border fit highlight-current-row stripe>
                <el-table-column fixed type="index" label="序号" width="50" align="left" />
                <el-table-column prop="name" label="限定条件" align="left">
                  <template slot-scope="scope">
                    {{ scope.row.name }}
                  </template>
                </el-table-column>
                <el-table-column label="操作" align="left" width="150">
                  <template slot-scope="scope">
                    <template v-if="isShow == 5">
                      <el-button type="text" size="mini" @click="getCommonApi(scope.row)">编辑</el-button>
                      <el-popconfirm
                        confirm-button-text="好的"
                        cancel-button-text="不用了"
                        icon="el-icon-info"
                        icon-color="red"
                        title="内容确定删除吗？"
                        @confirm="handleCondition(scope.row.id, scope.$index)"
                      >
                        <el-button slot="reference" type="text" class="textColor el-popover-left">删除</el-button>
                      </el-popconfirm>
                    </template>
                    <el-button v-else type="text" size="mini" @click="getCommonApi(scope.row)">查看条件</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </template>

          <el-row>
            <el-divider />

            <el-row type="flex">
              <el-col :span="12">
                <h4 style="display: inline-block; margin-right: 20px">经销商使用范围</h4>

                <template v-if="detail.flag == 0">
                  <ExportButton
                    v-if="isShow === 4"
                    style="display: inline-block"
                    :ex-url="'policy/customer/export'"
                    ex-text="导出经销商"
                    :ex-params="{ policyId: detail.code }"
                  />
                </template>
              </el-col>
            </el-row>
            <el-divider />
            <el-radio-group v-model="detail.flag">
              <el-radio label="0" :disabled="detail.flag != 0">指定经销商</el-radio>
              <el-radio label="1" :disabled="detail.flag != 1">广州经销商</el-radio>
              <el-radio label="2" :disabled="detail.flag != 2">佛山经销商</el-radio>
            </el-radio-group>
          </el-row>
          <div class="table">
            <template v-if="isShow != 5">
              <template v-if="detail.flag == 0">
                <el-table
                  v-loading="listLoading"
                  :data="custoList"
                  element-loading-text="Loading"
                  border
                  fit
                  highlight-current-row
                  stripe
                >
                  <el-table-column fixed type="index" label="序号" width="50" align="left" />
                  <el-table-column prop="customerNumber" label="经销商编码" align="left">
                    <template slot-scope="scope">
                      <CopyButton :copy-text="scope.row.customerNumber" />
                      <span>{{ scope.row.customerNumber }}</span>
                    </template></el-table-column>
                  <el-table-column prop="customerName" label="经销商名称" align="left">
                    <template slot-scope="scope">
                      <CopyButton :copy-text="scope.row.customerName" />
                      <span>{{ scope.row.customerName }}</span>
                    </template>
                  </el-table-column>
                </el-table>

                <!-- 分页 -->
                <div style="margin: 20px 0">
                  <el-pagination
                    :current-page="currentPages"
                    :page-sizes="[10, 20, 30, 50]"
                    :page-size="10"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="clistTotals"
                    @size-change="handleSizeChanges"
                    @current-change="handleCurrentChanges"
                  />
                </div>
              </template>
            </template>
            <template v-else>
              <el-row :gutter="20">
                <el-col :span="10" :offset="0">
                  <h5>未选经销商</h5>
                  <el-divider direction="horizontal" content-position="left" />

                  <el-table
                    ref="multipleTable"
                    :data="dataL"
                    element-loading-text="Loading"
                    border
                    height="480px"
                    fit
                    highlight-current-row
                    @select-all="handleSelectionAllChange"
                    @selection-change="handleSelectionChange"
                  >
                    <el-table-column type="selection" width="55" :selectable="selectable" align="left" />
                    <el-table-column prop="number" label="经销商编码" align="left">
                      <template slot-scope="scope">
                        <CopyButton :copy-text="scope.row.number" />
                        <span>{{ scope.row.number }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="name" label="经销商名称" align="left">
                      <template slot-scope="scope">
                        <CopyButton :copy-text="scope.row.name" />
                        <span>{{ scope.row.name }}</span>
                      </template>
                    </el-table-column>
                  </el-table>
                  <!-- 分页 -->
                  <div style="margin: 20px 0">
                    <el-pagination
                      :current-page="currentPages"
                      :page-sizes="[10, 20, 30, 50]"
                      :page-size="10"
                      layout="total, sizes, prev, pager, next, jumper"
                      :total="clistTotal"
                      @size-change="handleSizeChanges"
                      @current-change="handleCurrentChanges"
                    />
                  </div>
                </el-col>
                <el-col :span="4" class="middle_box" :offset="0">
                  <el-col>
                    <el-button size="mini" :disabled="type == 2" @click="handleAllAdd">全部添加</el-button></el-col>
                  <el-col> <el-button size="mini" :disabled="type == 2" @click="handleAdd">增加</el-button></el-col>
                  <el-col> <el-button size="mini" :disabled="type == 1" @click="handleDelete">删除</el-button></el-col>
                  <el-col>
                    <el-button size="mini" :disabled="type == 1" @click="handleAllDelete">全部删除</el-button></el-col>
                </el-col>
                <el-col :span="10" :offset="0">
                  <h5>已选经销商</h5>
                  <el-divider direction="horizontal" content-position="left" />

                  <el-table
                    v-loading="listLoading"
                    :data="custoList"
                    element-loading-text="Loading"
                    border
                    height="480px"
                    fit
                    highlight-current-row
                    stripe
                    @select-all="handleSelectionAllChange2"
                    @selection-change="handleSelectionChange2"
                  >
                    <el-table-column type="selection" width="55" align="left" />
                    <el-table-column prop="customerNumber" label="经销商编码" align="left">
                      <template slot-scope="scope">
                        <CopyButton :copy-text="scope.row.customerNumber" />
                        <span>{{ scope.row.customerNumber }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="customerName" label="经销商名称" align="left">
                      <template slot-scope="scope">
                        <CopyButton :copy-text="scope.row.customerName" />
                        <span>{{ scope.row.customerName }}</span>
                      </template>
                    </el-table-column>
                  </el-table>
                  <!-- 分页 -->
                  <!-- <div style="margin: 20px 0">
                  <el-pagination
                    @size-change="handleSizeChanges"
                    @current-change="handleCurrentChanges"
                    :current-page="currentPages"
                    :page-sizes="[10, 20, 30, 50]"
                    :page-size="10"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="clistTotals"
                  >
                  </el-pagination>
                </div> -->
                </el-col>
              </el-row>
            </template>

            <template>
              <div style="dispaly: flex">
                <h4 style="display: inline-block; margin-right: 20px">经销商上限</h4>
                <ExportButton
                  style="display: inline-block; margin-right: 20px"
                  :ex-url="'policy/limit/export'"
                  :ex-params="exParams"
                />
                <!-- <el-button
                  v-if="detail.type !== 'PROVISION'"
                  type="primary"
                  size="mini"
                  @click="()=>{
                    visible = true
                    handelBatchData()
                  }"
                >批量修改</el-button> -->
                <template>
                  <el-button
                    type="primary"
                    size="mini"
                    @click="
                      () => {
                        visible = true
                        handelBatchData()
                      }
                    "
                  >批量修改上限</el-button>
                </template>
                <el-button
                  v-if="detail.flag == 0"
                  type="primary"
                  size="mini"
                  @click="
                    operationType = null
                    linitVisible = true
                    linitType = 'add'
                    recordSelected = []
                  "
                >添加</el-button>
                <el-divider />
              </div>
              <div>
                <div class="table">
                  <el-table
                    v-loading="clistLoading"
                    :data="list"
                    element-loading-text="Loading"
                    border
                    fit
                    highlight-current-row
                    stripe
                    @selection-change="hanldeSelectionChange"
                  >
                    <el-table-column type="index" width="50" />
                    <el-table-column
                      prop="customerNumber"
                      label="经销商编号
"
                      align="left"
                      min-width="300"
                    >
                      <template slot-scope="scope">
                        <CopyButton :copy-text="scope.row.customerNumber" />
                        <span>{{ scope.row.customerNumber }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="customerName" label="经销商名称" align="left" min-width="300">
                      <template slot-scope="scope">
                        <CopyButton :copy-text="scope.row.customerName" />
                        <span>{{ scope.row.customerName }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="materialName" label="物料名称" align="left" min-width="200">
                      <template slot-scope="scope">
                        {{ scope.row.materialName }}
                      </template>
                    </el-table-column>
                    <el-table-column prop="materialNumber" label="物料编号" align="left" min-width="200">
                      <template slot-scope="scope">
                        {{ scope.row.materialNumber }}
                      </template>
                    </el-table-column>
                    <el-table-column prop="specification" label="规格型号" align="left" min-width="200">
                      <template slot-scope="scope">
                        {{ scope.row.specification }}
                      </template>
                    </el-table-column>

                    <el-table-column prop="orderNums" label="已下订单台数" align="left" min-width="200">
                      <template slot-scope="scope">
                        {{ scope.row.orderNums }}
                      </template>
                    </el-table-column>
                    <el-table-column prop="examineOrderNums" label="已审订单台数" align="left" min-width="200">
                      <template slot-scope="scope">
                        {{ scope.row.examineOrderNums }}
                      </template>
                    </el-table-column>
                    <el-table-column prop="limitQty" label="购买量上限" align="left" min-width="200">
                      <template slot-scope="scope">
                        {{ scope.row.limitQty }}
                      </template>
                    </el-table-column>
                    <el-table-column fixed="right" label="操作" width="120">
                      <template slot-scope="scope">
                        <el-button
                          type="text"
                          size="mini"
                          @click="
                            ;(operationType = null),
                              (linitVisible = true),
                              (linitType = 'edit'),
                              (recordSelected = [scope.row])
                          "
                        >编辑</el-button>
                        <el-popconfirm
                          style="margin-left: 10px"
                          title="是否确定需要克隆该项内容?"
                          @confirm="handleDelLinit(scope.row.id)"
                        >
                          <el-button slot="reference" type="text" size="mini">删除</el-button>
                        </el-popconfirm>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
                <!-- 分页 -->
                <div style="margin: 20px 0">
                  <el-pagination
                    :current-page="policyList.currentPages"
                    :page-sizes="[10, 20, 30, 50]"
                    :page-size="10"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="cTotal"
                    @size-change="handleSizeChanges4"
                    @current-change="handleCurrentChanges4"
                  />
                </div>
              </div>
            </template>

            <div>
              <div>
                <h4 style="display: inline-block; margin-right: 20px">经销商提货上限</h4>
                <el-divider />
              </div>
              <div style="margin: 20px 0">
                <!-- <el-upload
                  class="import-btn cus-btn"
                  :action="baseURL + 'policy/limit/group/import'"
                  :http-request="handleImportPolicyLimitGroupPolicy"
                  :file-list="importFileList"
                  :show-file-list="false"
                >
                  <el-button type="primary" size="mini">导入经销商配提套数</el-button>
                </el-upload> -->
                <ExportButton
                  style="display: inline-block; margin-right: 10px"
                  :ex-url="'policy/limit/group/export'"
                  ex-text="导出经销商配提套数"
                  :ex-params="{ policyId: detail.code }"
                />
                <template v-if="detail.type !== 'LIMIT'">
                  <el-button
                    type="primary"
                    size="mini"
                    @click="
                      () => {
                        limitGroupvisible = true
                        handelLimitGroupData()
                      }
                    "
                  >批量修改配提套数上限</el-button>
                </template>
                <template v-else>
                  <el-button
                    type="primary"
                    size="mini"
                    @click="
                      () => {
                        buyNumvisible = true
                        handelLimitGroupData()
                      }
                    "
                  >批量修改上限</el-button>
                </template>
                <el-button
                  v-if="detail.flag == 0"
                  type="primary"
                  size="mini"
                  @click="
                    operationType = 'group'
                    linitVisible = true
                    linitType = 'add'
                    recordSelected = []
                  "
                >添加</el-button>
                <!-- <el-button type="primary" size="mini" @click="hanleDownloadFilesPolicyLimitGroupPolicy"
                  >下载模板</el-button
                > -->
              </div>
              <!-- <el-row style="margin: 20px 0">
                <el-col :span="12">
                  <el-input v-model="policyKeyWord" placeholder="查找经销商" size="mini" />
                </el-col>
                <el-col :span="10" style="margin-left: 20px">
                  <el-button size="mini" @click="getPolicyLimitGroupList">确定</el-button>
                  <el-button size="mini" @click="onPolicyReset">重置</el-button>
                </el-col>
              </el-row> -->
              <div>
                <div class="table">
                  <el-table
                    v-loading="policyLoading"
                    :data="policyLimitGroupList"
                    element-loading-text="Loading"
                    border
                    fit
                    highlight-current-row
                    stripe
                  >
                    <el-table-column type="index" width="50" />
                    <el-table-column
                      prop="customerNumber"
                      label="经销商编号
"
                      align="left"
                      width="300"
                    >
                      <template slot-scope="scope">
                        <CopyButton :copy-text="scope.row.customerNumber" />
                        <span>{{ scope.row.customerNumber }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="customerName" label="经销商名称" align="left" min-width="300">
                      <template slot-scope="scope">
                        <CopyButton :copy-text="scope.row.customerName" />
                        <span>{{ scope.row.customerName }}</span>
                      </template>
                    </el-table-column>
                    <template v-if="detail.type == 'LIMIT'">
                      <el-table-column prop="minBuyNum" label="最小提货数量" align="left" min-width="200">
                        <template slot-scope="scope">
                          {{ scope.row.minBuyNum }}
                        </template>
                      </el-table-column>
                      <el-table-column prop="maxBuyNum" label="最大提货组数" align="left" min-width="200">
                        <template slot-scope="scope">
                          {{ scope.row.maxBuyNum }}
                        </template>
                      </el-table-column>
                    </template>
                    <template v-else>
                      <el-table-column prop="groupLimitNum" label="配提上限组数" align="left" min-width="200">
                        <template slot-scope="scope">
                          {{ scope.row.groupLimitNum }}
                        </template>
                      </el-table-column>
                    </template>
                    <el-table-column prop="orderNums" label="已下订单数" align="left" min-width="200">
                      <template slot-scope="scope">
                        {{ scope.row.orderNums }}
                      </template>
                    </el-table-column>
                    <el-table-column prop="examineOrderNums" label="已审订单数" align="left" min-width="200">
                      <template slot-scope="scope">
                        {{ scope.row.examineOrderNums }}
                      </template>
                    </el-table-column>
                    <el-table-column fixed="right" label="操作" width="120">
                      <template slot-scope="scope">
                        <el-button
                          type="text"
                          size="mini"
                          @click="
                            ;(operationType = 'group'),
                              (linitVisible = true),
                              (linitType = 'edit'),
                              (recordSelected = [scope.row])
                          "
                        >编辑</el-button>
                        <el-popconfirm
                          style="margin-left: 10px"
                          title="是否确定需要克隆该项内容?"
                          @confirm="handleDelLimitGroup(scope.row.id)"
                        >
                          <el-button slot="reference" type="text" size="mini">删除</el-button>
                        </el-popconfirm>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
                <!-- 分页 -->
                <div style="margin: 20px 0">
                  <el-pagination
                    :current-page="policyCurrentPages"
                    :page-sizes="[10, 20, 30, 50]"
                    :page-size="10"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="policyListTotal"
                    @size-change="handlePolicySizeChanges"
                    @current-change="handlePolicyCurrentChanges"
                  />
                </div>
              </div>
            </div>
          </div>

          <div v-if="isShow == 8 && detail.examineStatus == 'WAIT'" class="descriptions diy-table-1">
            <el-row>
              <el-col :span="6">审核人</el-col>
              <el-col :span="6">{{ $store.getters.name }}</el-col>
              <el-col :span="6">审核结果</el-col>
              <el-col :span="6">
                <template>
                  <el-radio-group v-model="examineStatus">
                    <el-radio :label="'OK'">通过</el-radio>
                    <el-radio :label="'FAIL'">驳回</el-radio>
                  </el-radio-group>
                </template>
              </el-col>
            </el-row>
            <el-row class="item">
              <el-col :span="4">审批说明</el-col>
              <el-col :span="20" class="col value" style="padding-left: 10px">
                <el-input v-model="remark" size="mini" placeholder="请输入内容" />
              </el-col>
            </el-row>
            <el-row>
              <el-button type="primary" size="mini" @click="handleSubmit">审核通过</el-button>
            </el-row>
          </div>
        </div>
        <div>
          <el-button v-if="isShow == 5" type="primary" size="default" @click="handleSave">保存</el-button>
        </div>
      </div>
      <operation-records v-if="detail && detail.code" ref="operation" :policy-id="detail.code" />
      <el-dialog
        title="批量修改"
        :visible.sync="visible"
        width="50%"
        :append-to-body="true"
        :close-on-click-modal="false"
        @close="handleDialogVisible"
      >
        <el-row :gutter="20">
          <el-col :span="24" style="display: flex; align-items: center; margin-bottom: 20px">
            <el-col :span="4" :offset="0"> 购买量上限 </el-col>
            <el-col :span="8" :offset="0"> <el-input v-model.number="limitQty" type="number" size="mini" /></el-col>
          </el-col>
          <el-col :span="24" :offset="0" style="margin-bottom: 20px">
            <div style="display: flex">
              <el-input v-model="limitQtyKeyWord" placeholder="输入关键字搜索" size="mini" />
              <el-button
                style="margin-left: 20px"
                type="primary"
                size="mini"
                @click="handelBatchData('search')"
              >查询</el-button>
              <el-button size="mini" @click="onReset">重置</el-button>
            </div>
          </el-col>
        </el-row>

        <zj-table
          :table-attributes="tableAttributes"
          :table-events="tableEvents"
          :is-drop="true"
          :columns="columns"
          :table-data="tableData"
        />
        <div style="margin: 20px 0">
          <el-pagination
            :current-page="batchCurrentPages"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="batchTotal"
            @size-change="handleBatchSizeChanges"
            @current-change="handleBatchCurrentChanges"
          />
        </div>
        <span slot="footer">
          <el-button @click="handleDialogVisible">取消</el-button>
          <el-button type="primary" @click="onSubmit($event, 'limit')">确定</el-button>
        </span>
      </el-dialog>
      <el-dialog
        title="批量修改"
        :visible.sync="limitGroupvisible"
        width="50%"
        :append-to-body="true"
        :close-on-click-modal="false"
        @close="handleLimitDialogVisible"
      >
        <el-row :gutter="20">
          <el-col :span="24" style="display: flex; align-items: center; margin-bottom: 20px">
            <el-col :span="4" :offset="0"> 配提套数上限 </el-col>
            <el-col :span="8" :offset="0">
              <el-input
                v-model.number="limitGroupNum"
                type="number"
                size="mini"
              /></el-col>
          </el-col>
          <el-col :span="24" :offset="0" style="margin-bottom: 20px">
            <div style="display: flex">
              <el-input v-model="limitGroupKeyWord" placeholder="输入关键字搜索" size="mini" />
              <el-button
                style="margin-left: 20px"
                type="primary"
                size="mini"
                @click="handelLimitGroupData('search')"
              >查询</el-button>
              <el-button size="mini" @click="onLimitReset">重置</el-button>
            </div>
          </el-col>
        </el-row>

        <zj-table
          :table-attributes="tableAttributes"
          :table-events="tableEvents"
          :is-drop="true"
          :columns="limitColumns"
          :table-data="limitTableData"
        />
        <div style="margin: 20px 0">
          <el-pagination
            :current-page="limitCurrentPages"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="limitTotal"
            @size-change="handleLimitSizeChanges"
            @current-change="handleLimitCurrentChanges"
          />
        </div>
        <span slot="footer">
          <el-button @click="handleLimitDialogVisible">取消</el-button>
          <el-button type="primary" @click="onLimitSubmit($event, 'limit')">确定</el-button>
        </span>
      </el-dialog>
      <el-dialog
        title="批量修改"
        :visible.sync="buyNumvisible"
        width="50%"
        :append-to-body="true"
        :close-on-click-modal="false"
        @close="handleLimitDialogVisible"
      >
        <el-row :gutter="20">
          <el-col :span="24" style="display: flex; align-items: center; margin-bottom: 20px">
            <el-col :span="4" :offset="0"> 最小提货数量 </el-col>
            <el-col :span="8" :offset="0"> <el-input v-model.number="minBuyNum" type="number" size="mini" /></el-col>
            <el-col :span="4" :offset="0"> 最大提货组数 </el-col>
            <el-col :span="8" :offset="0"> <el-input v-model.number="maxBuyNum" type="number" size="mini" /></el-col>
          </el-col>
          <el-col :span="24" :offset="0" style="margin-bottom: 20px">
            <div style="display: flex">
              <el-input v-model="limitGroupKeyWord" placeholder="输入关键字搜索" size="mini" />
              <el-button
                style="margin-left: 20px"
                type="primary"
                size="mini"
                @click="handelLimitGroupData('search')"
              >查询</el-button>
              <el-button size="mini" @click="onLimitReset">重置</el-button>
            </div>
          </el-col>
        </el-row>
        <zj-table
          :table-attributes="tableAttributes"
          :table-events="tableEvents"
          :is-drop="true"
          :columns="limitColumns"
          :table-data="limitTableData"
        />
        <div style="margin: 20px 0">
          <el-pagination
            :current-page="limitCurrentPages"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="limitTotal"
            @size-change="handleLimitSizeChanges"
            @current-change="handleLimitCurrentChanges"
          />
        </div>
        <span slot="footer">
          <el-button @click="handleLimitDialogVisible">取消</el-button>
          <el-button type="primary" @click="onLimitSubmit">确定</el-button>
        </span>
      </el-dialog>
    </div>
    <add-condition
      v-else
      :id="cid"
      :is-edit="isEdit"
      :is-show="isShow"
      @close="handleConditionClose"
      @back="handleBack"
    />
    <LinitVisible
      v-if="linitVisible"
      :policy-id="id || detail.code"
      :linit-visible="linitVisible"
      :data-list="recordSelected"
      :linit-type="linitType"
      :detail-type="detail.type"
      :operation-type="operationType"
      @cancel="linitVisible = false"
      @sbumit="handleLinitSave"
    />
  </div>
</template>

<script>
import {
  deleteCondition,
  deleteMaterialPolicy,
  getConditionList,
  getCrList,
  getCustomerList,
  getMaterialList,
  getPolicyDetail,
  toExamine,
  updatePolicy,
  getPolicyList,
  updateLimitBatchupdate,
  getPolicyLimitGroupList,
  updateLimitGrouppdate,
  delLimit,
  saveLimit,
  delLimitGroup,
  saveLimitGroup
} from '@/api/policy_list'
import { downloadFiles, handleImport } from '@/utils/util'
import AddCondition from './AddCondition'
import ImageUpload from '@/components/Common/image-upload.vue'
import OperationRecords from './OperationRecords.vue'
import LinitVisible from './LinitVisible.vue'

import Minxin from '@/mixin'

export default {
  name: 'Examine',
  components: {
    AddCondition,
    ImageUpload,
    OperationRecords,
    LinitVisible
  },
  mixins: [Minxin],
  props: ['id', 'isShow'],
  data() {
    return {
      baseURL: '',
      dcurrentPage: 1,
      dpageSize: 10,
      dlistTotal: 0,
      currentPages: 1, // 当前页码
      pageSizes: 10, // 每页数量
      clistTotal: 0,
      input: '',
      remark: '',
      fileList: [],
      listLoading: false,
      imageUrl: '',
      dataList: [],
      examineStatus: 'OK',
      options: {},
      value: '',
      detail: {},
      srcList: [],
      screenForm: {
        code: '',
        createBy: '',
        endCreateTime: '',
        endTime1: '',
        endTime2: '',
        examineBy: '',
        remark: '',
        startCreateTime: '',
        startTime1: '',
        startTime2: '',
        status: '',
        title: '',
        type: ''
      },
      conditionList: [],
      custoList: [],
      isEdit: 1,
      cid: '',
      cpolicyId: '',
      dataL: [],
      clistTotals: 0,
      type: 1,
      importFileList: [],
      leftData: [],
      rightData: [],
      typeOptions: [
        {
          value: 'PROVISION',
          label: '配提'
        },
        {
          value: 'LIMIT',
          label: '限量'
        }
      ],
      detailFang: false,
      policyList: {
        pageNum: 1,
        pageSize: 10,
        policyId: '',
        keyword: '',
        currentPages: 1
      },
      list: [],
      cTotal: 1,
      clistLoading: false,
      visible: false,
      maxBuyNumVisible: false,
      tableData: [],
      tableAttributes: {
        selectColumn: true
      },
      tableEvents: {
        'selection-change': this.selectionChange
      },
      limitQty: null,
      maxBuyNum: null,
      limitQtyKeyWord: '',
      maxBuyNumKeyWord: '',
      selectedData: [],
      batchCurrentPages: 1,
      batchPageSizes: 10,
      batchTotal: 0,
      policyLimitGroupList: [],
      policyLoading: false,
      policyCurrentPages: 1,
      policyPageSize: 10,
      policyListTotal: 0,
      policyKeyWord: '',
      limitGroupvisible: false,
      limitGroupNum: null,
      limitGroupKeyWord: '',
      limitCurrentPages: 1,
      limitTotal: 0,
      limitPageSizes: 10,
      limitTableData: [],
      buyNumvisible: false,
      minBuyNum: null,
      linitVisible: false,
      linitType: null,
      recordSelected: [],
      operationType: null,
      specification: ''
    }
  },
  computed: {
    exParams() {
      return {
        policyId: this.detail.code
      }
    },
    columns() {
      return [
        {
          columnAttributes: {
            label: '经销商编码',
            prop: 'customerNumber'
          }
        },
        {
          columnAttributes: {
            label: '经销商名称',
            prop: 'customerName'
          }
        },
        {
          columnAttributes: {
            label: '物料名称',
            prop: 'materialName'
          }
        },
        {
          columnAttributes: {
            label: '物料编号',
            prop: 'materialNumber'
          }
        }
      ]
    },
    limitColumns() {
      return [
        {
          columnAttributes: {
            label: '经销商编码',
            prop: 'customerNumber'
          }
        },
        {
          columnAttributes: {
            label: '经销商名称',
            prop: 'customerName'
          }
        }
      ]
    }
  },
  created() {},
  methods: {
    handleConditionClose() {
      this.isEdit = 1
    },
    funTitle() {
      const title = '详情页'
      return title
    },
    handleBack() {
      this.isEdit = 1
    },
    getList() {
      this.listLoading = true
      getPolicyDetail({ policyId: this.id }).then(res => {
        this.detail = res.data
        this.detail.flag = this.detail.flag + ''
        this.detail.imgSrc = this.detail.imgSrc.split(',')
        this.detail.imgSrc.forEach(k => {
          this.srcList.push(this.$imageUrl + k)
        })
        // this.srcList = [this.$imageUrl + this.detail.imgSrc]
        if (this.isShow == 5 && this.detail.imgSrc) {
          this.fileList = [
            {
              hover: '',
              url: this.detail.imgSrc
            }
          ]
        }
        this.handletwoList()
        // 获取条件政策
        this.getConditionList()
        this.getCond()
        this.getPolicyList()
        this.getPolicyLimitGroupList()
      })
    },
    getPolicyList() {
      this.clistLoading = true
      getPolicyList({
        pageNum: this.policyList.currentPages,
        pageSize: this.policyList.pageSize,
        policyId: this.id,
        keyword: this.policyList.keyword
      }).then(res => {
        this.list = res.data.records
        this.cTotal = res.data.total
        this.clistLoading = false
      })
    },
    // 检查文件类型
    checkFileType(url) {
      if (!url) return ''
      const fileSuffix = url.substring(url.lastIndexOf('.') + 1)

      if (['jpg', 'jpeg', 'png'].includes(fileSuffix)) {
        return 'image'
      } else if (['doc', 'docx', 'dot', 'wps', 'wpt'].includes(fileSuffix)) {
        return 'word'
      } else if (['xls', 'xlsx', 'xlt', 'et', 'ett'].includes(fileSuffix)) {
        return 'excel'
      } else if (['ppt', 'pptx', 'dps', 'dpt', 'pot', 'pps'].includes(fileSuffix)) {
        return 'ppt'
      } else if (['pdf'].includes(fileSuffix)) {
        return 'pdf'
      } else if (['zip', 'rar', 'gz', 'apk'].includes(fileSuffix)) {
        return 'file'
      } else {
        return ''
      }
    },
    openPdf(pdfUrl) {
      window.open(this.$imageUrl + pdfUrl)
    },
    getCrList() {
      const customerParams = {
        pageNum: this.currentPage,
        pageSize: this.pageSize,
        keyword: this.region == 1 || this.region == '' ? '' : this.keyword,
        region: this.region == 1 ? this.keyword : ''
      }
      // 获取经销商列表
      getCrList(customerParams).then(res => {
        for (let j = 0; j < this.custoList.length; j++) {
          for (let i = 0; i < res.data.records.length; i++) {
            if (res.data.records[i].id == this.custoList[j].customerId) {
              res.data.records[i].disabled = true
            }
          }
        }
        this.dataL = res.data.records
        for (let k = 0; k < this.dataL.length; k++) {
          (this.dataL[k].customerId = this.dataL[k].id),
          (this.dataL[k].customerName = this.dataL[k].name),
          (this.dataL[k].customerNumber = this.dataL[k].number)
        }

        console.log(this.dataL, '获取经销商列表')
        this.clistTotal = res.data.total
      })
    },
    // 更改每页数量
    handleSizeChanges(val) {
      this.pageSizes = val
      this.currentPages = 1
      this.getCond()
    },
    // 更改当前页
    handleCurrentChanges(val) {
      this.currentPages = val
      this.getCond()
    },
    // 更改每页数量
    handleSizeChange2(val) {
      this.dpageSize = val
      this.dcurrentPage = 1
      this.handletwoList()
    },
    // 更改当前页
    handleCurrentChange2(val) {
      this.dcurrentPage = val
      this.handletwoList()
    },
    getCommonApi(row) {
      this.isEdit = 2
      this.cid = row.id
      this.cpolicyId = row.policyId
    },
    getCond() {
      this.listLoading = true
      const custoParams = {
        pageNum: this.currentPages,
        pageSize: this.pageSizes,
        policyId: this.detail.code
      }
      getCustomerList(custoParams).then(res => {
        this.custoList = res.data.records
        this.clistTotals = res.data.total
        this.listLoading = false
        this.getCrList()
      })
    },
    handleSubmit() {
      toExamine({
        examineStatus: this.examineStatus,
        policyId: this.id,
        examineRemark: this.remark
      }).then(res => {
        this.$successMsg('已提交审核')
        this.isShow = 1
        this.$emit('close')
      })
    },
    // 获取货品信息
    handletwoList() {
      // this.searchForm.type
      const paramss = {
        pageNum: this.dcurrentPage,
        pageSize: this.dpageSize,
        policyId: this.detail.code,
        saleTypeCode: '',
        specification: this.specification
      }
      getMaterialList(paramss)
        .then(result => {
          this.dataList = result.data.records
          this.dlistTotal = result.data.total
          this.listLoading = false
        })
        .catch(err => {
          console.error(err)
        })
    },
    // 更改每页数量
    handleSizeChanges4(val) {
      this.$set(this.policyList, 'pageSize', val)
      this.$set(this.policyList, 'currentPages', 1)
      this.getPolicyList()
    },
    // 更改当前页
    handleCurrentChanges4(val) {
      this.$set(this.policyList, 'currentPages', val)

      this.getPolicyList()
    },
    // 导入
    async handleImport(param) {
      this.importLoading = true
      const file = param.file
      console.log(file, 123)
      const formData = new FormData()
      formData.append('file', file)
      formData.append('policyId', this.detail.code)
      // formData.append("mainId", this.detail.mainId);
      const result = await handleImport('/policy/material/import', formData)
      this.importLoading = false
      this.importFileList = []
      if (result.code == 200) {
        this.$alert(result.message, '导入成功', {
          confirmButtonText: '确定'
        })

        this.handletwoList()
      } else {
        this.$alert(result.message, '导入失败', {
          confirmButtonText: '确定'
        })
      }
    },
    handleCondition(id, index) {
      deleteCondition({ id }).then(res => {
        // this.conditionList.splice(index, 1);
        // Object.assign(
        //   this.$children[9].$data,
        //   this.$children[9].$options.data()
        // );
        this.getConditionList()
        this.$successMsg('删除成功')
      })
    },
    getConditionList() {
      const condParams = {
        policyId: this.detail.code
      }
      getConditionList(condParams).then(res => {
        this.conditionList = res.data
      })
    },
    // 删除
    hanleDelete(id) {
      const params = { policyMaterialId: id }
      deleteMaterialPolicy(params).then(res => {
        this.$successMsg('删除成功')
        this.handletwoList()
      })
    },
    /**
     * 根据条件禁用行复选框
     * 函数返回值为false则禁用选择(反之亦然)
     * @param {Object} row - 行数据
     * @param {String} index - 索引值
     * @return Boolean
     */
    selectable: function(row, index) {
      // row.disabled == undefined 才能被选中
      if (row.disabled == undefined || row.disabled == false) {
        return true
      } else {
        return false
      }
      // 函数必须有返回值且是布尔值
      // 页面刷新后该函数会执行 N 次进行判断(N 为表格行数)
      // 如果没有返回值则默认返回false(全部无法选中)
    },
    handleSelectionAllChange(e) {
      this.leftData = e
      this.type = 1
    },
    handleSelectionChange(e) {
      this.leftData = e
      this.type = 1
    },
    handleSelectionAllChange2(e) {
      this.rightData = e
      this.type = 2
    },
    handleSelectionChange2(e) {
      this.rightData = e
      this.type = 2
    },
    handleLeft(e) {
      this.type = 1
    },
    handleRight(e) {
      this.type = 2
    },
    handleAllAdd() {
      if (this.type == 1 && this.leftData.length) {
        for (let i = 0; i < this.dataL.length; i++) {
          for (let j = 0; j < this.leftData.length; j++) {
            if (this.dataL[i].id == this.leftData[j].id) {
              this.dataL[i].disabled = true
            }
          }
        }
        this.custoList = [...this.custoList, ...this.leftData]
        this.$refs.multipleTable.clearSelection()
      } else {
        this.$errorMsg('请选择要添加的经销商')
      }
    },
    handleAllDelete() {
      if (this.type == 2 && this.rightData.length) {
        for (let i = 0; i < this.dataL.length; i++) {
          for (let j = 0; j < this.rightData.length; j++) {
            if (this.dataL[i].id == this.rightData[j].customerId) {
              this.$set(this.dataL[i], 'disabled', false)
            }
          }
        }
        const arr = this.resArr(this.custoList, this.rightData)
        this.custoList = arr
      } else {
        this.$errorMsg('请选择要删除的经销商')
      }
    },
    handleAdd() {
      if (this.type == 1 && this.leftData.length) {
        for (let i = 0; i < this.dataL.length; i++) {
          for (let j = 0; j < this.leftData.length; j++) {
            if (this.dataL[i].id == this.leftData[j].id) {
              this.dataL[i].disabled = true
            }
          }
        }
        this.custoList = [...this.custoList, ...this.leftData]
        this.leftData = []
        this.$refs.multipleTable.clearSelection()
      } else {
        this.$errorMsg('请选择要添加的经销商')
      }
    },
    handleDelete() {
      if (this.type == 2 && this.rightData.length) {
        for (let i = 0; i < this.dataL.length; i++) {
          for (let j = 0; j < this.rightData.length; j++) {
            if (this.dataL[i].id == this.rightData[j].customerId) {
              this.$set(this.dataL[i], 'disabled', false)
            }
          }
        }
        const arr = this.resArr(this.custoList, this.rightData)
        this.custoList = arr
      } else {
        this.$errorMsg('请选择要删除的经销商')
      }
    },
    // 去掉相同数据
    resArr(arr1, arr2) {
      return arr1.filter(v => arr2.every(val => val.id != v.id))
    },
    async handleSave() {
      if (this.custoList.length) {
        var arr = []
        this.custoList.forEach(el => {
          arr.push({
            customerId: el.customerId,
            customerName: el.customerName,
            customerNumber: el.customerNumber,
            lastOrderTime: '',
            limitTakeNum: 0,
            policyId: this.detail.code,
            policyTitle: '',
            remark: ''
          })
        })

        const params = {
          ...this.detail,
          policyCustomers: arr,
          imgSrc: this.fileList.length ? this.fileList[0].url : ''
        }
        await updatePolicy(params)
        await this.getCond()
        this.$successMsg('编辑成功')
        this.fileList = []
        this.isShow = 1
      }
    },
    selectionChange(data) {
      this.selectedData = data
    },
    handelBatchData(search) {
      if (search) {
        this.batchCurrentPages = 1
      }
      getPolicyList({
        pageNum: this.batchCurrentPages,
        pageSize: this.batchPageSizes,
        policyId: this.id,
        keyword: this.limitQtyKeyWord
      }).then(res => {
        this.tableData = res.data.records
        this.batchTotal = res.data.total
      })
    },
    handleDialogVisible() {
      this.visible = false
      this.buyNumvisible = false
      this.maxBuyNumVisible = false
      this.batchCurrentPages = 1
      this.batchPageSizes = 10
      this.limitQty = null
      this.maxBuyNum = null
      this.minBuyNum = null
      this.limitQtyKeyWord = ''
      this.maxBuyNumKeyWord = ''
    },
    onSubmit(e, type) {
      console.log(type)
      if (!this.selectedData.length) {
        this.$errorMsg('不能为空,请选择')
        return
      }
      let params = {}

      const customerIds = this.selectedData
        .map(k => {
          return k.customerId
        })
        .join(',')
      const ids = this.selectedData
        .map(k => {
          return k.id
        })
        .join(',')
      if (this.limitQty <= 0) {
        this.$errorMsg('购买量上限不能小于0或不能为空')
        return
      }
      params = {
        customerIds,
        ids,
        limitQty: this.limitQty
      }
      updateLimitBatchupdate(params).then(res => {
        this.handleDialogVisible()
        this.getPolicyList()
        this.getPolicyLimitGroupList()
        this.$refs.operation.getCommonLogList()
        this.$successMsg('批量修改成功')
      })
    },
    handleBatchSizeChanges(val) {
      this.batchCurrentPages = 1
      this.batchPageSizes = val
      this.handelBatchData()
    },
    onReset() {
      this.limitQtyKeyWord = ''
      this.maxBuyNumKeyWord = ''
      this.handelBatchData()
    },
    handleBatchCurrentChanges(val) {
      this.batchCurrentPages = val
      this.handelBatchData()
    },
    getPolicyLimitGroupList() {
      this.policyLoading = true
      getPolicyLimitGroupList({
        pageNum: this.policyCurrentPages,
        pageSize: this.policyPageSize,
        policyId: this.id,
        keyword: this.policyKeyWord
      }).then(res => {
        this.policyLimitGroupList = res.data.records
        this.policyListTotal = res.data.total
        this.policyLoading = false
      })
    },
    handlePolicySizeChanges(val) {
      this.policyCurrentPages = 1
      this.policyPageSize = val
      this.getPolicyLimitGroupList()
    },
    onPolicyReset() {
      this.policyCurrentPages = 1
      this.policyPageSize = 10
      this.policyKeyWord = ''
      this.getPolicyLimitGroupList()
    },
    handlePolicyCurrentChanges(val) {
      this.policyCurrentPages = val
      this.getPolicyLimitGroupList()
    },
    hanleDownloadFilesPolicyLimitGroupPolicy() {
      downloadFiles('policy/limit/group/download')
    },
    async handleImportPolicyLimitGroupPolicy(param) {
      this.importLoading = true
      const file = param.file
      const formData = new FormData()
      formData.append('file', file)
      formData.append('policyId', this.id)
      // formData.append('type', this.detail.type)

      // formData.append("mainId", this.searchForm.mainId);
      const result = await handleImport('policy/limit/group/import', formData)
      this.importLoading = false
      this.importFileList = []
      if (result.code === 200) {
        await this.$alert(result.message, '导入成功', {
          confirmButtonText: '确定'
        })
        // this.policyLimitGroupList = result.data
        this.getPolicyLimitGroupList()
      } else {
        await this.$alert(result.message, '导入失败', {
          confirmButtonText: '确定'
        })
      }
    },
    handelLimitGroupData(search) {
      if (search) {
        this.limitCurrentPages = 1
      }
      this.limitGroupvisible = true
      getPolicyLimitGroupList({
        pageNum: this.limitCurrentPages,
        pageSize: this.limitPageSizes,
        policyId: this.id,
        keyword: this.limitGroupKeyWord
      }).then(res => {
        this.limitTableData = res.data.records
        this.limitTotal = res.data.total
      })
    },
    onLimitSubmit(e, type) {
      if (!this.selectedData.length) {
        this.$errorMsg('不能为空,请选择')
        return
      }

      const ids = this.selectedData
        .map(k => {
          return k.id
        })
        .join(',')
      let params = {}
      if (type) {
        if (this.limitGroupNum <= 0) {
          this.$errorMsg('配提套数上限不能小于0或不能为空')
          return
        }
        params = {
          ids,
          limitGroupNum: this.limitGroupNum
        }
      } else {
        params = {
          ids,
          minBuyNum: this.minBuyNum,
          maxBuyNum: this.maxBuyNum
        }
      }

      updateLimitGrouppdate(params).then(res => {
        this.handleLimitDialogVisible()
        this.$successMsg('批量修改成功')
        this.getPolicyLimitGroupList()
        this.getPolicyList()
        this.$refs.operation.getCommonLogList()
      })
    },
    handleLimitSizeChanges(val) {
      this.limitCurrentPages = 1
      this.limitPageSizes = val
      this.handelLimitGroupData()
    },
    handleLimitCurrentChanges(val) {
      this.limitCurrentPages = val
      this.handelLimitGroupData()
    },
    onLimitReset() {
      this.limitGroupKeyWord = ''
      this.handelLimitGroupData()
    },
    handleLimitDialogVisible() {
      this.buyNumvisible = false
      this.limitGroupvisible = false
      this.limitGroupNum = null
      this.limitGroupKeyWord = ''
      this.limitCurrentPages = 1
      this.limitTotal = 0
      this.limitPageSizes = 10
      this.maxBuyNum = null
      this.minBuyNum = null
      this.limitQtyKeyWord = ''
      this.maxBuyNumKeyWord = ''
    },
    hanldeSelectionChange(data) {
      this.recordSelected = JSON.parse(JSON.stringify(data))
    },
    handleDelLinit(id) {
      delLimit({ id }).then(res => {
        this.$successMsg('删除成功')
        this.getPolicyList()
      })
    },
    handleDelLimitGroup(id) {
      delLimitGroup({ id }).then(res => {
        this.$successMsg('删除成功')
        this.getPolicyLimitGroupList()
      })
    },
    handleLinitSave({ dataList, type, operationType }) {
      if (!operationType) {
        saveLimit(dataList[0]).then(res => {
          this.$successMsg(type === 'add' ? '新增成功' : '修改成功')
          this.getPolicyList()
          this.linitVisible = false
        })
      } else {
        saveLimitGroup(dataList[0]).then(res => {
          this.$successMsg(type === 'add' ? '新增成功' : '修改成功')
          this.getPolicyLimitGroupList()
          this.linitVisible = false
        })
      }
      this.linitType = 'add'
      this.operationType = null
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .elImageClose .el-image-viewer__wrapper span[class='el-image-viewer__btn el-image-viewer__close'] {
  top: 100px;
}

.file {
  margin-right: 20px;
}
.el-col {
  overflow: hidden;
}
.value {
  ::v-deep .el-input__prefix {
    display: none;
  }
}
.descriptions {
  // border: #EBEEF5;
  border: 1px solid #ebeef5;
  border-bottom: none;
  .el-row {
    height: 40px;
    line-height: 40px;
  }
  .el-col:nth-child(odd) {
    background-color: #ebeef5;
  }
  .el-col {
    padding: 0 15px;
    height: 100%;
    border-bottom: 1px solid #ebeef5;
  }
}
.el-divider--horizontal {
  margin: 20px 0;
}
.col {
  height: 100px;
}

.import-btn {
  margin-right: 10px;
  display: inline-block;
}
::v-deep .el-input__icon .el-icon-time {
  display: none;
}
.middle_box {
  margin-top: 80px;
  text-align: center;
  height: 430px;
  display: flex;
  flex-direction: column;
  align-content: center;
  justify-content: space-between;
  align-items: center;
}
.img-box {
  height: 150px;
  display: flex;
  align-items: center;
}
</style>
