<template>
  <div>
    <div class="sty">
      <el-page-header content="申请退押" @back="goBack" />
    </div>
    <el-divider />
    <h3>工程项目信息</h3>
    <el-divider />
    <div class="diy-table-1">
      <el-form ref="form" :model="details">
        <el-row :gutter="0">
          <el-col :xs="12" :sm="8" :lg="8" class="item">
            <div class="label">工程登录编号</div>
            <div class="value">{{ details.refEnginRecordNo }}</div>
          </el-col>
          <el-col :xs="12" :sm="8" :lg="8" class="item">
            <div class="label">项目类别</div>
            <div class="value">{{ details.refProjectCategory }}</div>
          </el-col>
          <el-col :xs="12" :sm="8" :lg="8" class="item">
            <div class="label">行业类别</div>
            <div class="value">{{ details.refTradeCategory }}</div>
          </el-col>
          <el-col :xs="12" :sm="8" :lg="8" class="item">
            <div class="label">区域</div>
            <div class="value">{{ details.refRegionWork }}</div>
          </el-col>
          <el-col :xs="12" :sm="8" :lg="8" class="item">
            <div class="label">工程编号</div>
            <div class="value">{{ details.refProjectNo }}</div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">经销商名称</div>
            <div class="value">{{ details.customerName }}</div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">经销商编码</div>
            <div class="value">{{ details.customerNumber }}</div>
          </el-col>

          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">工程登录类型</div>
            <div class="value">{{ details.refPromiseStatus }}</div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">联系人</div>
            <div class="value">{{ details.refLinkman }}</div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">固定电话</div>
            <div class="value">{{ details.refTel }}</div>
          </el-col>

          <el-col :xs="24" :sm="24" :lg="16" class="item">
            <div class="label">跨区厂编号</div>
            <div class="value">
              <!--              {{ details.refFactoryNo }}-->
              <el-form-item prop="refFactoryNo">
                <el-input v-model="details.refFactoryNo" placeholder="跨区厂编号" size="small" />
              </el-form-item>
            </div>
          </el-col>

          <el-col :xs="24" :sm="24" :lg="16" class="item">
            <div class="label">移动电话</div>
            <div class="value">{{ details.refPhone }}</div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">押金总额</div>
            <div class="value">{{ details.depositAmount }}</div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="24" class="item">
            <div class="label">工程差价总额</div>
            <div class="value">{{ details.depositDiffAmount }}</div>
          </el-col>
          <el-col v-if="!isCustomer" :xs="24" :sm="24" :lg="24" class="item">
            <div class="label">格力备注</div>
            <div class="value">
              <el-input v-model="details.geLiInerNote" placeholder="格力备注" />
            </div>
          </el-col>
          <el-col v-if="!isCustomer" :xs="24" :sm="24" :lg="24" class="item">
            <div class="label">格力内部资料备注</div>
            <div class="value">{{ details.geLiInnerDataNote }}</div>
          </el-col>
          <el-col v-if="!isCustomer" :xs="24" :sm="24" :lg="24" class="item">
            <div class="label">订单格力内部备注</div>
            <div class="value">{{ details.orderGeLiInnerNote }}</div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="24" class="item">
            <div class="label">使用单位</div>
            <div class="value">{{ details.refUseUnit }}</div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="24" class="item">
            <div class="label">安装地址</div>
            <div class="value">{{ details.refInstallAddress }}</div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="24" class="item">
            <div class="label">安装时间</div>
            <div class="value" style="padding: 0">
              <el-form-item prop="installDate">
                <el-date-picker
                  v-model="details.installDate"
                  type="datetime"
                  placeholder="安装时间"
                  default-time="00:00:00"
                  value-format="yyyy-MM-dd HH:mm:ss"
                />
              </el-form-item>
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">登录有效期</div>
            <div class="value">
              {{ details.refBillsExpireDate }}
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">实际使用单位</div>
            <div class="value">
              <el-input v-model="details.realUseUnit" :readonly="isCustomer" placeholder="实际使用单位" />
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">实际安装地址</div>
            <div class="value">
              <el-input v-model="details.realInstallAddress" :readonly="isCustomer" placeholder="实际安装地址" />

            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">项目编号</div>
            <div class="value">
              {{ details.refProjectNo }}
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">购买单位</div>
            <div class="value">
              <el-input v-model="details.refBuyUnitName" :readonly="isCustomer" placeholder="购买单位" />

            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">合同变更批复意见</div>
            <div class="value">
              {{ details.refContractIdea }}
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">合同变更批复结果</div>
            <div class="value">
              {{ details.refContractResult }}
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">资料延期批复意见</div>
            <div class="value">
              {{ details.refDataDelayResult }}
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">资料延期批复结果</div>
            <div class="value">
              {{ details.refInstallAddress }}
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">工程机转零售批复意见</div>
            <div class="value">
              {{ details.refToRetailIdea }}
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">工程机转零售批复结果</div>
            <div class="value">
              {{ details.refToRetailResult }}
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">其他附件审批意见</div>
            <div class="value">
              {{ details.refOtherAnnexIdea }}
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">其他附件批复结果</div>
            <div class="value">
              {{ details.refOtherAnnexResult }}
            </div>
          </el-col>
          <!-- <el-col :xs="24" :sm="24" :lg="8" class="item">
            <div class="label">寄厂日期</div>
            <div class="value" style="padding: 0">
              <el-form-item prop="sendFactoryDate">
                <el-date-picker
                  v-model="details.sendFactoryDate"
                  type="datetime"
                  placeholder="寄厂日期"
                  default-time="00:00:00"
                  value-format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker>
              </el-form-item>
            </div>
          </el-col> -->
        </el-row>
      </el-form>
    </div>
    <h3>货品信息</h3>
    <el-divider />
    <!-- 列表 -->
    <div class="mymain-container">
      <div class="table">
        <el-table
          v-loading="listLoading"
          :data="details.items"
          element-loading-text="Loading"
          border
          fit
          show-summary
          highlight-current-row
          stripe
          :summary-method="$getSummaries"
        >
          <el-table-column
            align="center"
            label="物料编码"
            prop="materialNumber"
            min-width="130"
            show-overflow-tooltip
          />
          <el-table-column
            align="center"
            label="产品编码"
            prop="materialOldNumber"
            min-width="130"
            show-overflow-tooltip
          />
          <el-table-column align="center" label="产品名称" prop="materialName" min-width="160" show-overflow-tooltip />
          <el-table-column align="center" label="规格型号" prop="specification" min-width="300" show-overflow-tooltip />
          <el-table-column
            align="left"
            label="实装规格型号"
            prop="depositSpecification"
            min-width="300"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.depositSpecification"
                :class="scope.row.realSpecification != scope.row.specification ? 'input' : scope.row.depositSpecification !=scope.row.realSpecification ? 'input2':'' "
                size="mini"
                readonly
                @click.native="getRealMaterData(scope.$index)"
              />
            </template>
          </el-table-column>
          <el-table-column
            align="left"
            label="实装物料编号"
            prop="depositMaterialNumber"
            min-width="150"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.depositMaterialNumber"
                :class="scope.row.realMaterialNumber != scope.row.materialNumber? 'input' : scope.row.depositMaterialNumber != scope.row.realMaterialNumber? 'input2':'' "
                size="mini"
                readonly
                @click.native="getRealMaterData(scope.$index)"
              />
            </template>
          </el-table-column>
          <el-table-column
            align="left"
            label="实装厂产品编码"
            prop="depositMaterialOldNumber"
            min-width="200"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.depositMaterialOldNumber"
                :class="scope.row.realMaterialOldNumber != scope.row.materialOldNumber? 'input' : scope.row.depositMaterialOldNumber != scope.row.realMaterialOldNumber? 'input2':'' "
                size="mini"
                readonly
                @click.native="getRealMaterData(scope.$index)"
              />
            </template>
          </el-table-column>
          <el-table-column align="center" label="单价" prop="price" min-width="160" show-overflow-tooltip />
          <el-table-column align="center" label="数量" prop="qty" min-width="160" show-overflow-tooltip />
          <el-table-column align="right" label="金额" prop="totalAmount" min-width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.totalAmount | numToFixed }}
            </template>
          </el-table-column>
          <el-table-column align="right" label="销售数量" prop="salesQty" min-width="160" show-overflow-tooltip />
          <el-table-column align="right" label="销售金额" prop="salesAmount" min-width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.salesAmount | numToFixed }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="押金数量" prop="hasSendQty" min-width="160" show-overflow-tooltip />
          <el-table-column
            align="center"
            label="发货数量"
            prop="orderHasSendQty"
            min-width="160"
            show-overflow-tooltip
          />
          <el-table-column align="right" label="合同数量" prop="contractQty" min-width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-input v-model.number="scope.row.contractQty" class="inpt" size="mini" clearable />
            </template>
          </el-table-column>
          <el-table-column align="right" label="合同单价" prop="contractPrice" min-width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-input v-model.number="scope.row.contractPrice" class="inpt" size="mini" clearable />
            </template>
          </el-table-column>
          <el-table-column align="right" label="合同金额" prop="contractAmount" min-width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              <div>
                {{ comTotal(scope.row.contractQty, scope.row.contractPrice) }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="right" label="押金金额" prop="depositAmount" min-width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.depositAmount | numToFixed }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="上交资料" prop="dataQty" min-width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-input
                v-model.number="scope.row.dataQty"
                class="inpt"
                size="mini"
                clearable
                @blur="setDataQty($event, scope.row)"
              />
            </template>
          </el-table-column>
          <el-table-column align="right" label="收差金额" prop="diffAmount" min-width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.diffAmount | numToFixed }}
            </template>
          </el-table-column>
          <el-table-column
            align="right"
            label="收差政策价格"
            prop="diffPolicyPrice"
            min-width="200"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              {{ scope.row.diffPolicyPrice | numToFixed }}
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <h3>押金货品信息</h3>
    <el-divider />
    <!-- 列表 -->
    <div class="mymain-container">
      <div class="table">
        <el-table
          v-loading="listLoading"
          :data="details.collectList"
          element-loading-text="Loading"
          border
          fit
          highlight-current-row
          stripe
          show-summary
          :summary-method="$getSummaries"
        >
          <el-table-column align="left" label="工程登录单号" prop="refEnginRecordNo" min-width="130" 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="specification" min-width="130" 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="left" label="基本单位编码" prop="unit" min-width="130" show-overflow-tooltip>
            <template slot-scope="scope">
              <CopyButton :copy-text="scope.row.unit" />
              <span>{{ scope.row.unit }}</span>
            </template>
          </el-table-column>
          <el-table-column align="left" label="现金钱包" prop="customerWalletName" min-width="130" show-overflow-tooltip>
            <template slot-scope="scope">
              <CopyButton :copy-text="scope.row.customerWalletName" />
              <span>{{ scope.row.customerWalletName }}</span>
            </template>
          </el-table-column>
          <el-table-column align="left" label="现金钱包编码" prop="customerWalletNumber" min-width="130" show-overflow-tooltip>
            <template slot-scope="scope">
              <CopyButton :copy-text="scope.row.customerWalletNumber" />
              <span>{{ scope.row.customerWalletNumber }}</span>
            </template>
          </el-table-column>
          <el-table-column align="left" label="金蝶物料类型名称" prop="k3CategoryName" min-width="130" show-overflow-tooltip>
            <template slot-scope="scope">
              <CopyButton :copy-text="scope.row.k3CategoryName" />
              <span>{{ scope.row.k3CategoryName }}</span>
            </template>
          </el-table-column>
          <el-table-column align="left" label="金蝶物料类型编码" prop="k3CategoryNumber" min-width="130" show-overflow-tooltip>
            <template slot-scope="scope">
              <CopyButton :copy-text="scope.row.k3CategoryNumber" />
              <span>{{ scope.row.k3CategoryNumber }}</span>
            </template>
          </el-table-column>
          <el-table-column align="left" label="金蝶物料名称" prop="materialName" min-width="130" 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="materialNumber" min-width="130" 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="left" label="金蝶物料旧编码" prop="materialOldNumber" min-width="130" 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="hasSendQty" min-width="130" show-overflow-tooltip />
          <el-table-column align="left" label="单价" prop="price" min-width="130" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.price | numToFixed }}
            </template>
          </el-table-column>
          <el-table-column align="left" label="已退押金金额" prop="refundDepositAmount" min-width="130" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.refundDepositAmount | numToFixed }}
            </template>
          </el-table-column>
          <el-table-column align="left" label="押金金额" prop="depositAmount" min-width="130" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.depositAmount | numToFixed }}
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <h3>上传资料</h3>
    <el-divider />
    <!-- 筛选条件 -->
    <div>
      <el-form ref="form" :model="details" label-width="100px" size="small" label-position="left">
        <el-row :gutter="20">
          <el-col :xs="24" :sm="12" :lg="24">
            <el-form-item label="工程验收资料" prop="">
              <imageUpload
                :file-list="fileList"
                :multiple="true"
                :start-restricting="true"
                :restrict-filename="restrictFilename"
              />
            </el-form-item>
          </el-col>
          <el-col v-if="details.dataList && details.dataList.length" :xs="24" :sm="12" :lg="24">
            <!-- 列表 -->
            <div class="mymain-container">
              <div class="table">
                <el-table
                  v-loading="listLoading"
                  :data="details.dataList"
                  element-loading-text="Loading"
                  border
                  fit
                  highlight-current-row
                  stripe
                >
                  <el-table-column
                    align="center"
                    label="资料描述"
                    prop="dataDescribe"
                    min-width="160"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    align="center"
                    label="原文件名"
                    prop="fileName"
                    min-width="160"
                    show-overflow-tooltip
                  />
                  <el-table-column align="center" label="缩略图" prop="fileUrl" min-width="160" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <el-image
                        v-if="checkFileType(scope.row.fileUrl) == 'image'"
                        ref="img"
                        :src="imageURL + scope.row.fileUrl"
                        style="width: 120px; height: 120px"
                        fit="cover"
                        :preview-src-list="[imageURL + scope.row.fileUrl]"
                      />
                      <img
                        v-if="checkFileType(scope.row.fileUrl) == 'word'"
                        class="file"
                        src="@/assets/common/word.png"
                      >
                      <img
                        v-if="checkFileType(scope.row.fileUrl) == 'excel'"
                        class="file"
                        src="@/assets/common/excel.png"
                      >
                      <img
                        v-if="checkFileType(scope.row.fileUrl) == 'ppt'"
                        class="file"
                        src="@/assets/common/ppt.png"
                      >

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

                      <img
                        v-if="checkFileType(scope.row.fileUrl) == 'file'"
                        class="file aaa"
                        src="@/assets/common/zip.jpeg"
                      >
                    </template>
                  </el-table-column>
                  <el-table-column
                    align="center"
                    label="下载文件名称"
                    prop="fileName"
                    min-width="160"
                    show-overflow-tooltip
                  >
                    <template slot-scope="scope">
                      {{ '资料_' + scope.row.fileName }}
                    </template>
                  </el-table-column>
                  <el-table-column align="center" label="操作" min-width="160" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <el-button
                        type="text"
                        class="textColor"
                        @click="downLoadFn(scope.row.fileUrl, scope.row.fileName)"
                      >下载</el-button>
                      <el-popconfirm
                        style="margin-left: 10px"
                        title="这是一段内容确定删除吗？"
                        @onConfirm="delFile(scope.$index)"
                      >
                        <el-button slot="reference" type="text">删除</el-button>
                      </el-popconfirm>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="申请人" prop="submitName">
              <el-input v-model="details.submitName" readonly placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="申请日期" prop="submitTime">
              <el-date-picker
                v-model="details.submitTime"
                readonly
                class="dateStyle"
                type="datetime"
                placeholder="选择日期"
                default-time="00:00:00"
                value-format="yyyy-MM-dd HH:mm:ss"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="18">
            <el-form-item label="申请退押" prop="applyNote">
              <el-input v-model="details.applyNote" type="textarea" placeholder="请输入" class="textareaStyle" />
            </el-form-item>
          </el-col>
          <el-col v-if="details.checkBy && details.checkDate" :xs="24" :sm="12" :lg="18">
            <el-form-item
              label="验收说明
"
              prop="checkNote"
            >
              <el-input
                v-model="details.checkNote"
                disabled
                type="textarea"
                placeholder="请输入验收说明
"
                class="textareaStyle"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="24">
            <el-form-item label="">
              <el-button type="primary" size="small" @click="handleSvse">保存</el-button>
              <el-button type="primary" size="small" @click="handleReset">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <el-dialog title="添加产品" append-to-body :visible.sync="isSetMaterial" width="80%">
      <el-form ref="goodsScreenForm" :model="goodsScreenForm" size="small" label-position="left">
        <el-row :gutter="20">
          <el-col :xs="12" :sm="6" :lg="6">
            <el-form-item prop="proNum">
              <el-input v-model="goodsScreenForm.proNum" placeholder="请输入物料编码" />
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="6" :lg="6">
            <el-form-item prop="proName">
              <el-input v-model="goodsScreenForm.proName" placeholder="请输入产品名称" />
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="6" :lg="6">
            <el-form-item prop="proModel">
              <el-input v-model="goodsScreenForm.proModel" placeholder="请输入产品型号" />
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="6" :lg="6">
            <el-form-item prop="price1" style="display: flex">
              <el-input v-model="goodsScreenForm.price1" placeholder="请输入价格" style="width: 46%" />
              <span> - </span>
              <el-input v-model="goodsScreenForm.price2" placeholder="请输入价格" style="width: 46%" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="24" class="tr">
            <el-form-item label="">
              <el-button size="small" @click="resetGoodsScreenForm">清空</el-button>
              <el-button size="small" type="primary" @click="submitGoodsScreenForm">搜索</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div>
        <el-table :data="leftGoodsList" element-loading-text="Loading" border fit stripe height="400">
          <el-table-column align="center" width="55">
            <template slot-scope="scope">
              <el-radio v-model="currentRadio" :label="scope.row.id">{{ '' }}</el-radio>
            </template>
          </el-table-column>
          <el-table-column align="center" label="销售类型" prop="saleName" min-width="100" show-overflow-tooltip />
          <el-table-column align="center" label="物料编码" prop="number" min-width="100" show-overflow-tooltip />
          <el-table-column
            align="center"
            label="产品编码"
            prop="materialOldNumber"
            min-width="100"
            show-overflow-tooltip
          />
          <el-table-column align="center" label="产品名称" prop="name" min-width="160" show-overflow-tooltip />
          <el-table-column align="center" label="产品型号" prop="specification" min-width="160" show-overflow-tooltip />
          <el-table-column align="center" label="产品价格" prop="batchPrice" min-width="80" show-overflow-tooltip />
        </el-table>
        <div class="pagination clearfix" style="margin-top: 10px">
          <div class="fr">
            <el-pagination
              :current-page="currentPage"
              :page-size="10"
              background
              layout="prev, pager, next"
              :total="listTotal"
              @current-change="handleTableCurrentChange"
            />
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button type="primary" @click="submitPushGoods">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { applyDeposit, geDetail, computeDiff } from '@/api/engin_deposit.js'
import {
  getRetailProductList
} from '@/api/supply/engin'
import imageUpload from '@/components/Common/image-upload.vue'
import { downloadFiles, downloadPdf } from '@/utils/util'

export default {
  components: {
    imageUpload
  },
  props: {
    depositManageId: {
      type: [String, Number],
      default: null
    },
    refEnginRecordNo: {
      type: [String, Number],
      default: null
    }
  },
  data() {
    return {
      isDis: true,
      listLoading: false,
      baseURL: '',
      fileList: [],
      details: {},
      restrictFilename: ['结算单', '合同', '明细表', '审核表', '收据', '发票', '照片', '相片'],
      goodsScreenForm: {
        proNum: '',
        proName: '',
        proModel: '',
        price1: '',
        price2: ''
      },
      isSetMaterial: false,
      currentRadio: '',
      currentId: '',
      leftGoodsList: [],
      listTotal: 0,
      currentPage: 1
    }
  },
  computed: {
    isCustomer() {
      return !!(this.$store.getters.customerId && this.$store.getters.customerNumber)
    },
    comTotal() {
      return (qty, price) => {
        return Number(qty) * Number(price)
      }
    }
  },
  watch: {
    'details.items': {
      handler(newValue, oldValue) {
        if (newValue && newValue.length) {
          newValue.forEach((item, index) => {
            item.contractAmount = Number(item.contractQty) * Number(item.contractPrice)
          })
        }
        this.details.items = newValue
      },
      immediate: true,
      deep: true
    }
  },
  created() {
    this.imageURL = this.$imageUrl
    this.geDetail()
  },
  methods: {
    geDetail() {
      geDetail({ id: this.depositManageId }).then(res => {
        const arr = []
        res.data.items.forEach(item => {
          if (Number(item.qty) > 0) {
            arr.push(item)
          }
          // item.number = (item.qty*100 - item.directTransferQty*100 - item.retiredQty*100) / 100;
          item.sums1 = ['orderHasSendQty', 'dataQty', 'qty', 'hasSendQty', 'contractQty']
          item.sums2 = [
            'totalAmount',
            'diffAmount',
            'price',
            'depositAmount',
            'contractPrice',
            'comTotal',
            'contractAmount'
          ]
        })
        res.data.collectList.forEach(item => {
          // item.number = (item.qty*100 - item.directTransferQty*100 - item.retiredQty*100) / 100;
          item.sums1 = ['orderHasSendQty', 'dataQty', 'hasSendQty']
          item.sums2 = ['price', 'refundDepositAmount', 'depositAmount']
        })
        res.data.items = arr
        res.data.realUseUnit = res.data.realUseUnit || res.data.refUseUnit
        res.data.realInstallAddress = res.data.realInstallAddress || res.data.refInstallAddress
        this.details = res.data
      })
    },

    // 计算收差金额
    setDataQty(e, row) {
      if (!row.dataQty) return
      row.saleTypeId = this.details.saleTypeId
      computeDiff(row).then(res => {
        row.diffAmount = res.data.diffAmount
        row.diffPolicyPrice = res.data.diffPolicyPrice
        // this.$successMsg('已计算收差金额')
      })
    },
    goBack() {
      this.$emit('setShowPage', 1)
    },
    handleSvse() {
      const arr = []
      if (!this.details.installDate) {
        this.$errorMsg('请选择安装时间')
        return
      }

      if (this.isCustomer) {
        for (let i = 0; i < this.details.items.length; i++) {
          this.details.items[i].contractAmount = this.details.items[i].contractQty * this.details.items[i].contractPrice
          if (this.details.items[i].contractAmount == null) {
            return this.$errorMsg('合同单价、合同数量不能为空')
          }
        }
      }

      this.fileList.forEach(el => {
        if (this.details.dataList.length) {
          this.details.dataList.forEach((i, e) => {
            console.log(i.fileName == el.name)
            if (el.name === i.fileName) {
              this.details.dataList.splice(e, 1)
            }
          })
        }

        arr.push({
          dataDescribe: el.name,
          enginOrderNo: this.details.refProjectNo,
          fileName: el.name,
          fileUrl: el.url
        })
      })
      applyDeposit({
        ...this.details,
        dataList: [...arr, ...this.details.dataList]
      }).then(res => {
        this.$successMsg('申请成功')
        this.$emit('updateList')
        this.$emit('setShowPage', 1)
        this.deduction = ''
      })
    },
    delFile(index) {
      this.details.dataList.splice(index, 1)
      this.$successMsg('删除成功')
    },
    handleReset() {
      this.$refs.form.resetFields()
    },
    // 批量下载
    async batchDownloadFn() {
      downloadFiles('deposit-manage/downZip', { parentId: this.depositManageId })
    },
    // 下载
    downLoadFn(v, fileName) {
      if (this.checkFileType(v) === 'pdf') {
        downloadPdf(this.$imageUrl + v, fileName)
        return
      }
      downloadFiles('common/file/getStream', { key: v, fileName: fileName })
      // getFileUrl({ key: v }).then((res) => {
      //   window.open(res.data)
      // })
    },
    openPdf(pdfUrl) {
      window.open(this.$imageUrl + pdfUrl)
    },
    // 检查文件类型
    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 ''
      }
    },
    getRealMaterData(id) {
      this.currentId = id
      this.isSetMaterial = true
      this.getGoodsList()
    },
    // 获取商品列表
    getGoodsList() {
      getRetailProductList({
        pageNum: this.currentPage,
        pageSize: 10,
        saleId: this.details.saleTypeId,
        billType: 'HOME',
        materialCode: this.goodsScreenForm.proNum,
        materialName: this.goodsScreenForm.proName,
        specification: this.goodsScreenForm.proModel,
        price1: this.goodsScreenForm.price1,
        price2: this.goodsScreenForm.price2,
        refEnginRecordNo: '',
        customerId: ''
      }).then(res => {
        this.leftGoodsList = res.data.records
        this.listTotal = res.data.total
      })
    },
    submitPushGoods() {
      //    realMaterialId
      // 实装金蝶物料id
      //        realMaterialName
      // 实装金蝶物料名称
      //        realMaterialNumber
      // 实装金蝶物料编码
      //        realMaterialOldNumber
      // 实装金蝶物料旧编码
      //        realSpecification
      // 实装规格型号
      const currentData = this.leftGoodsList.find(e => e.id === this.currentRadio)
      this.$set(this.details.items[this.currentId], 'depositMaterialId', currentData.materialId)
      this.$set(this.details.items[this.currentId], 'depositMaterialName', currentData.materialName)
      this.$set(this.details.items[this.currentId], 'depositMaterialNumber', currentData.materialNumber)
      this.$set(this.details.items[this.currentId], 'depositMaterialOldNumber', currentData.materialOldNumber)
      this.$set(this.details.items[this.currentId], 'depositSpecification', currentData.specification)
      this.isSetMaterial = false
    },
    // 关闭 弹窗
    closeDialog() {
      this.isSetMaterial = false
    },

    // 更改列表当前页
    handleTableCurrentChange(val) {
      this.currentPage = val
      this.getGoodsList()
    },
    // 重置筛选表单
    resetGoodsScreenForm() {
      this.$refs.goodsScreenForm.resetFields()
      this.currentRadio = ''
      this.currentPage = 1
      this.getGoodsList()
    },
    // 提交筛选表单
    submitGoodsScreenForm() {
      this.currentPage = 1
      this.getGoodsList()
    }

  }
}
</script>

<style lang="scss" scoped>

::v-deep .input .el-input__inner {
  color: blue !important;
}
::v-deep .input2  .el-input__inner {
  color: #f00 !important;
}
.aaa {
  height: 64px;
  width: 64px;
}
.gdzl {
  display: inline-block;
}
::v-deep .textareaStyle {
  .el-textarea__inner {
    resize: none;
    height: 100px;
  }
}
.dateStyle {
  width: 100%;
}
::v-deep .el-input__prefix {
  display: none;
  left: 65px !important;
  -webkit-transition: all 0.3s;
  transition: all 0.3s;
}
::v-deep .el-date-editor.el-input {
  width: 100%;
  box-sizing: border-box;
  padding-left: 10px;
}
.diy-table-1 {
  ::v-deep .el-form-item {
    margin: 0;
  }
  ::v-deep .el-input__suffix {
    right: -15px;
    -webkit-transition: all 0.3s;
    transition: all 0.3s;
  }
}
.value {
  overflow: hidden;
}
</style>
