<template>
  <div class="app-container">
    <div class="search-bx">
      <div class="search">
        <el-row :gutter="0">
          <el-input
            v-model="tableObj.getdataListParm.parammaps.contractCode"
            placeholder="合同编号"
            class="filter-item"
            style="width: 120px; padding-bottom: 10px"
          />

          <!-- <el-autocomplete v-model="tableObj.getdataListParm.parammaps.customerName" :fetch-suggestions="customer_search" placeholder="客户名称" style="width: 200px;margin-right:10px" @select="change_customer_select" @clear="clear_customer_select" @blur="customer_search_blur" clearable>
                <template slot-scope="{ item }">
                  <span class="name">{{ item.name }}</span>
                </template>
              </el-autocomplete> -->
          <el-input
            v-model="tableObj.getdataListParm.parammaps.customerName"
            placeholder="客户名称"
            style="width: 180px"
            class="filter-item"
            clearable
          />

          <el-select
            v-model="tableObj.getdataListParm.parammaps.groupId"
            placeholder="集团"
            class="filter-item"
            style="width: 120px"
            clearable
          >
            <el-option
              v-for="item in groupNameList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>

          <el-select
            v-model="tableObj.getdataListParm.parammaps.dealerId"
            placeholder="经销商"
            class="filter-item"
            style="width: 190px; padding-bottom: 10px"
            clearable
            filterable
          >
            <el-option
              v-for="(item, index) in dealNameList"
              :key="index"
              :label="item.dealerName"
              :value="item.dealerId"
            />
          </el-select>

          <el-date-picker
            v-model="tableObj.getdataListParm.parammaps.inputDatetime1"
            class="inputDatetime filter-item"
            type="daterange"
            range-separator="至"
            start-placeholder="合同开始日期"
            end-placeholder="合同开始日期"
            style="width: 250px"
          />

          <el-date-picker
            v-model="tableObj.getdataListParm.parammaps.inputDatetime2"
            class="inputDatetime filter-item"
            type="daterange"
            range-separator="至"
            start-placeholder="合同结束日期"
            end-placeholder="合同结束日期"
            style="width: 250px"
          />

          <el-select
            v-model="tableObj.getdataListParm.parammaps.contractStatus"
            placeholder="合同状态"
            class="filter-item"
            style="width: 120px"
            clearable
          >
            <el-option
              v-for="item in statusNameList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>

          <el-input
            v-model="tableObj.getdataListParm.parammaps.beginContractMoney"
            placeholder="合同金额"
            style="width: 80px"
          ></el-input>
          -
          <el-input
            v-model="tableObj.getdataListParm.parammaps.endContractMoney"
            placeholder="合同金额"
            style="width: 80px"
          ></el-input>

          <el-input
            v-model="tableObj.getdataListParm.parammaps.beginMoneyStep"
            placeholder="款项分期"
            style="width: 80px"
          ></el-input>
          -
          <el-input
            v-model="tableObj.getdataListParm.parammaps.endMoneyStep"
            placeholder="款项分期"
            style="width: 80px"
          ></el-input>

          <el-date-picker
            v-model="tableObj.getdataListParm.parammaps.inputDatetime3"
            class="inputDatetime filter-item"
            type="daterange"
            range-separator="至"
            start-placeholder="创建时间"
            end-placeholder="创建时间"
            style="width: 250px"
          />

          <el-select
            v-model="tableObj.getdataListParm.parammaps.createrId"
            placeholder="创建人"
            class="filter-item"
            style="width: 120px"
            clearable
            filterable
          >
            <el-option
              v-for="(item, index) in createrNameList"
              :key="index"
              :label="item.name"
              :value="item.id"
            />
          </el-select>

          <el-button class="successBorder" @click="form_search">查询</el-button>
          <el-button class="successBorder" @click="form_clear">重置</el-button>

          <el-button
            v-if="isContractapplyAdd"
            class="success"
            icon="el-icon-plus"
            @click="form_add"
            >新增</el-button
          >
          <!-- <el-button  class="success" icon="el-icon-upload2" @click="form_export">导出</el-button> -->
        </el-row>
      </div>

      <!-- <div class="operation">
          <el-row :gutter="0">
            <el-col :span="21">
              <el-button v-if="isRoleEdit" class="success" icon="el-icon-plus" @click="form_add">新增</el-button>
            </el-col>

          </el-row>

        </div> -->
    </div>

    <div class="table">
      <el-table
        :key="tableObj.tableKey"
        v-loading="tableObj.listLoading"
        element-loading-text="给我一点时间"
        :data="tableObj.list"
        border
        fit
        highlight-current-row
        style="width: 100%"
        :row-style="rowStyle"
        :cell-style="cellStyle"
        class="elTable table-fixed"
        :max-height="myHeight"
      >
        <el-table-column
          label="序号"
          align="center"
          type="index"
          width="50px"
          fixed="left"
        >
          <template slot-scope="scope">
            <span>{{
              scope.$index + (tableObj.pageNum - 1) * tableObj.pageSize + 1
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="合同编号"
          min-width="130px"
          align="center"
          fixed="left"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span
              style="color: #409eff; cursor: pointer"
              @click="form_see(scope.row)"
              >{{ scope.row.contractCode }}</span
            >
          </template>
        </el-table-column>
        <el-table-column
          label="合同状态"
          min-width="90px"
          align="center"
          fixed="left"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.contractStatus }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="客户名称"
          min-width="120px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.customerName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="经销商"
          min-width="120px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.dealerName }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="营业执照" min-width="110px" align="center" show-overflow-tooltip>

            <template slot-scope="scope">
              <img  style="width: 50px; height: 50px" :src="scope.row.imgUrlDetil" alt="">
            </template>

        </el-table-column> -->
        <el-table-column label="所属集团" min-width="90px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.groupName }}</span>
          </template>
        </el-table-column>

        <el-table-column
          label="合同金额(元)"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.contractMoney }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="款项分期"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.moneyStep }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="合同开始时间"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.contractBeginDate }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="合同结束时间"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.contractEndDate }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="创建时间"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.createrDate }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="备注"
          min-width="120px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.remark }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="备注" min-width="190px" align="center" >
          <template slot-scope="scope">
              <el-popover trigger="hover" placement="top"  width="300">
                <p>{{scope.row.remark}}</p>
	              <div slot="reference">
	                  <span class="ellipsis">{{scope.row.remark}}</span>
                </div>
              </el-popover>
          </template>
        </el-table-column> -->

        <el-table-column
          label="操作"
          align="center"
          :width="autoWidth"
          v-if="autoWidth !== 0"
          class-name="small-padding fixed-width"
          fixed="right"
        >
          <template slot-scope="{ row }">
            <el-button
              class="miniSuccess"
              @click="form_edit(row)"
              v-if="isContractapplyAdd && row.isModify == '1'"
              >编辑</el-button
            >
            <el-button
              class="miniDanger"
              @click="form_delete(row)"
              v-if="isContractapplyAdd && row.isDel == '1'"
              >删除</el-button
            >
            <el-button
              class="miniSuccess"
              @click="form_exam1(row)"
              v-if="isContractapplyAdd && row.isExamine == '1'"
              >提交审核</el-button
            >
            <el-button
              class="miniSuccess"
              @click="form_revoke(row)"
              v-if="isContractapplyAdd && row.isRevoke == '1'"
              >撤销</el-button
            >

            <el-button
              class="miniSuccess"
              @click="form_auto(row)"
              v-if="
                isContractapplyAdd &&
                row.isStockuped == '0' &&
                row.contractStatus == '审核通过'
              "
              >一键备货</el-button
            >

            <el-button
              class="miniSuccess"
              v-if="
                row.contractStatus == '一审中' ||
                row.contractStatus == '二审中' ||
                row.contractStatus == '三审中' ||
                row.contractStatus == '四审中' ||
                row.contractStatus == '五审中'
              "
              @click="form_quick(row)"
              >催进度</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <el-row :gutter="0">
        <el-col :span="6" :offset="12" style="color: #f00">
          列表合同总金额：{{ tableSumMoney }}
        </el-col>
      </el-row>

      <pagination
        v-show="tableObj.total >= 0"
        :total="tableObj.total"
        :page.sync="tableObj.getdataListParm.offset"
        :limit.sync="tableObj.getdataListParm.pagecount"
        @pagination="get_table_data"
      />
    </div>

    <!-- 新增/编辑 -->
    <el-dialog
      :title="textMap[create.dialogStatus]"
      :visible.sync="create.dialogFormVisible"
      :close-on-click-modal="false"
      width="95%"
      append-to-body
    >
      <div class="app-add">
        <el-form
          ref="temp"
          :rules="create.rules"
          :model="create.temp"
          label-position="right"
          label-width="150px"
          style="width: 90%; margin: 0 auto 50px"
        >
          <h3>基本信息</h3>
          <el-row>
            <el-col :span="8">
              <el-form-item label="创建人：" prop="createrName">
                <el-input
                  ref="createrName"
                  v-model="create.temp.createrName"
                  class="filter-item"
                  style="width: 100%"
                  disabled
                />
              </el-form-item>

              <el-form-item label="客户名称：" prop="customerId">
                <el-select
                  v-model="create.temp.customerId"
                  filterable
                  placeholder="客户名称"
                  class="filter-item"
                  style="width: 100%"
                  clearable
                  @change="change_customer"
                  :disabled="create.dialogStatus == 'update'"
                >
                  <el-option
                    v-for="item in create.customerNameList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>

              <el-form-item label="经销商：" prop="dealerId">
                <el-select
                  v-model="create.temp.dealerId"
                  placeholder="请选择经销商"
                  class="filter-item"
                  style="width: 100%"
                  clearable
                  :disabled="create.dialogStatus == 'see'"
                  @change="change_deal"
                >
                  <el-option
                    v-for="(item, index) in create.dealNameList"
                    :key="index"
                    :label="item.dealerName"
                    :value="item.dealerId"
                  />
                </el-select>
              </el-form-item>

              <el-form-item label="备注：" prop="remark">
                <el-input
                  ref="remark"
                  v-model="create.temp.remark"
                  type="textarea"
                  :autosize="{ minRows: 1.3, maxRows: 4 }"
                  placeholder="请输入备注，最多255个字"
                  maxlength="255"
                  class="filter-item"
                  style="width: 100%"
                  :disabled="create.dialogStatus == 'see'"
                />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="创建时间：" prop="createrDate">
                <el-input
                  ref="createrDate"
                  v-model="create.temp.createrDate"
                  class="filter-item"
                  style="width: 100%"
                  disabled
                />
              </el-form-item>

              <el-form-item label="所属集团：" prop="groupName">
                <el-input
                  ref="groupName"
                  v-model="create.temp.groupName"
                  class="filter-item"
                  style="width: 100%"
                  disabled
                />
              </el-form-item>
              <!-- <el-form-item label="所属集团：" prop="groupId">
                  <el-select v-model="create.temp.groupId" placeholder="所属集团" class="filter-item" style="width: 100%;" filterable  @change="change_group" clearable>
                      <el-option v-for="item in groupNameList" :key="item.id" :label="item.name" :value="item.id" />
                  </el-select>
              </el-form-item> -->

              <el-form-item label="合同开始时间：" prop="contractBeginDate">
                <el-date-picker
                  v-model="create.temp.contractBeginDate"
                  type="date"
                  placeholder="选择日期"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  style="width: 100%"
                  :clearable="false"
                  :disabled="create.dialogStatus == 'see'"
                />
              </el-form-item>
              <el-form-item label="合同结束时间：" prop="contractEndDate">
                <el-date-picker
                  v-model="create.temp.contractEndDate"
                  type="date"
                  placeholder="选择日期"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  style="width: 100%"
                  :clearable="false"
                  :disabled="create.dialogStatus == 'see'"
                />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="营业执照：" prop="businessLicense">
                <el-upload
                  id="uploadPic"
                  list-type="picture-card"
                  class="uploadPic"
                  :action="uploadImageUrl"
                  :limit="1"
                  :headers="headers"
                  :file-list="fileList"
                  :on-preview="handlePicPreview"
                  :auto-upload="true"
                  :on-change="
                    (file, fileList) => {
                      return handlePicChange(file, fileList);
                    }
                  "
                  :on-success="
                    (response, file, fileList) => {
                      return handlePicSuccess(response, file, fileList);
                    }
                  "
                  :on-remove="
                    (file, fileList) => {
                      return handlePicRemove(file, fileList);
                    }
                  "
                >
                  <i slot="default" class="el-icon-plus"></i>
                </el-upload>
                <el-dialog
                  :visible.sync="dialogVisible"
                  append-to-body
                  width="40%"
                >
                  <img width="80%" :src="dialogImageUrl" alt="" />
                </el-dialog>
              </el-form-item>
            </el-col>
          </el-row>

          <h3>款项信息</h3>
          <el-row>
            <el-col :span="8">
              <el-form-item label="款项分期：" prop="moneyStep">
                <el-select
                  v-model="create.temp.moneyStep"
                  placeholder="款项分期"
                  class="filter-item"
                  style="width: 100%"
                  filterable
                  @change="change_moneyStep"
                  clearable
                >
                  <el-option
                    v-for="item in moneyStepList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="合同金额（元）：" prop="contractMoney">
                <el-input
                  ref="contractMoney"
                  v-model="create.temp.contractMoney"
                  class="filter-item"
                  style="width: 100%"
                  @input="change_contract"
                  placeholder="请输入合同金额"
                  :disabled="create.dialogStatus == 'see'"
                />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="技术服务费：" prop="serviceCost">
                <el-input
                  ref="serviceCost"
                  v-model="create.temp.serviceCost"
                  class="filter-item"
                  style="width: 100%"
                  placeholder="请输入技术服务费"
                  :disabled="create.dialogStatus == 'see'"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-table
              :data="tableStagesList"
              border
              fit
              highlight-current-row
              style="width: 100%"
              :row-style="rowStyle"
              :cell-style="cellStyle"
              class="elTable table-fixed"
            >
              <el-table-column label="期数" min-width="110px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.stages }}期</span>
                </template>
              </el-table-column>

              <el-table-column
                label="应收金额占比"
                min-width="110px"
                align="center"
              >
                <template slot-scope="scope">
                  <span v-if="create.dialogStatus == 'see'"
                    >{{ scope.row.planCostRate }}%</span
                  >
                  <el-input
                    v-if="
                      create.dialogStatus == 'update' ||
                      create.dialogStatus == 'create'
                    "
                    @input="change_rate(scope.row)"
                    v-model="scope.row.planCostRate"
                    style="width: 95%; padding: 10px 0"
                  />
                </template>
              </el-table-column>
              <el-table-column
                label="应收金额（元）"
                min-width="110px"
                align="center"
              >
                <template slot-scope="scope">
                  <span v-if="create.dialogStatus == 'see'">{{
                    scope.row.planCost
                  }}</span>
                  <el-input
                    v-if="
                      create.dialogStatus == 'update' ||
                      create.dialogStatus == 'create'
                    "
                    v-model="scope.row.planCost"
                    style="width: 95%; padding: 10px 0"
                  />
                </template>
              </el-table-column>
              <el-table-column
                label="收款时间"
                min-width="110px"
                align="center"
              >
                <template slot-scope="scope">
                  <span v-if="create.dialogStatus == 'see'">{{
                    scope.row.collectionDate
                  }}</span>
                  <el-date-picker
                    v-if="
                      create.dialogStatus == 'update' ||
                      create.dialogStatus == 'create'
                    "
                    v-model="scope.row.collectionDate"
                    style="width: 95%; padding: 10px 0"
                    type="date"
                    placeholder="选择日期"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                  />
                </template>
              </el-table-column>
            </el-table>
          </el-row>

          <h3>货物信息</h3>
          <el-row>
            <el-row
              v-if="
                create.dialogStatus == 'create' ||
                create.dialogStatus == 'update'
              "
            >
              <el-form-item label="添加备货物品：" prop="visiterId">
                <el-select
                  ref="visiterId"
                  v-model="create.temp.visiterId"
                  filterable
                  placeholder="请选择备货物品"
                  class="filter-item"
                  style="width: 100%"
                  :disabled="create.dialogStatus == 'see'"
                  @change="change_receProduct"
                >
                  <el-option
                    v-for="item in receProductNameList"
                    :key="item.productsId"
                    :label="
                      '货品名称：' +
                      item.productsName +
                      ' 型号：' +
                      item.model +
                      ' 规格：' +
                      item.Specifications
                    "
                    :value="item.productsId"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-row>
            <el-row>
              <el-table
                :data="tableStockList"
                border
                fit
                highlight-current-row
                style="width: 100%"
                :row-style="rowStyle"
                :cell-style="cellStyle"
                class="elTable table-fixed"
              >
                <el-table-column
                  label="序号"
                  align="center"
                  type="index"
                  width="50px"
                >
                  <template slot-scope="scope">
                    <span>{{ scope.$index + 1 }}</span>
                  </template>
                </el-table-column>

                <el-table-column
                  label="货品名称"
                  min-width="110px"
                  align="center"
                >
                  <template slot-scope="scope">
                    <span>{{ scope.row.productsName }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="型号" min-width="110px" align="center">
                  <template slot-scope="scope">
                    <span>{{ scope.row.model }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="规格" min-width="110px" align="center">
                  <template slot-scope="scope">
                    <span>{{ scope.row.Specifications }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="数量" min-width="110px" align="center">
                  <template slot-scope="scope">
                    <span v-if="create.dialogStatus == 'see'">{{
                      scope.row.nums
                    }}</span>
                    <el-input
                      v-if="
                        create.dialogStatus == 'update' ||
                        create.dialogStatus == 'create'
                      "
                      v-model="scope.row.nums"
                      style="width: 95%; padding: 10px 0"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="单价(元)"
                  min-width="110px"
                  align="center"
                >
                  <template slot-scope="scope">
                    <span>{{ scope.row.price }}</span>
                  </template>
                </el-table-column>

                <el-table-column
                  label="成交价(元)"
                  min-width="110px"
                  align="center"
                >
                  <template slot-scope="scope">
                    <span v-if="create.dialogStatus == 'see'">{{
                      scope.row.closingPrice
                    }}</span>
                    <el-input
                      v-if="
                        create.dialogStatus == 'update' ||
                        create.dialogStatus == 'create'
                      "
                      v-model="scope.row.closingPrice"
                      style="width: 95%; padding: 10px 0"
                    />
                  </template>
                </el-table-column>

                <el-table-column
                  label="总价(元)"
                  min-width="110px"
                  align="center"
                >
                  <template slot-scope="scope">
                    <span>{{ scope.row.sumPrice }}</span>
                  </template>
                </el-table-column>

                <el-table-column label="备注" min-width="280px" align="center">
                  <template slot-scope="scope">
                    <span v-if="create.dialogStatus == 'see'">{{
                      scope.row.remark
                    }}</span>
                    <el-input
                      v-if="
                        create.dialogStatus == 'update' ||
                        create.dialogStatus == 'create'
                      "
                      v-model="scope.row.remark"
                      type="textarea"
                      :autosize="{ minRows: 1.3, maxRows: 4 }"
                      style="width: 95%; padding: 10px 0"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  v-if="
                    create.dialogStatus == 'update' ||
                    create.dialogStatus == 'create'
                  "
                  label="操作"
                  align="center"
                  width="110"
                  class-name="small-padding fixed-width"
                  fixed="right"
                >
                  <template slot-scope="{ row }">
                    <el-button
                      v-if="
                        create.dialogStatus == 'update' ||
                        create.dialogStatus == 'create'
                      "
                      class="miniDanger"
                      @click="form_delete2(row)"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </el-row>

            <el-row type="flex" justify="end">
              <el-col style="color: #ff4949" :span="6" :offset="18"
                >列表货物总价：{{ stockSumPrice }}</el-col
              >
            </el-row>
            <el-divider></el-divider>
          </el-row>

          <h3>合同附件</h3>
          <el-row>
            <el-form-item label="合同附件" prop="">
              <el-upload
                class="avatar-uploader"
                :headers="headers3"
                :auto-upload="true"
                :show-file-list="true"
                :limit="1"
                :action="uploadFileUrl3"
                :on-exceed="handleExceed3"
                :on-success="handlefileSuccess3"
                :file-list="uploadfileList3"
              >
                <el-button size="small" type="primary">点击上传</el-button>
              </el-upload>

              <el-button
                class="miniSuccess"
                v-if="create.temp.applyFileId"
                @click="form_look3()"
                >在线预览</el-button
              >
            </el-form-item>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button
            v-if="
              create.dialogStatus === 'create' ||
              create.temp.contractStatus == '草稿' ||
              create.temp.isExamine == '1'
            "
            class="success"
            :disabled="isokDisable"
            @click="
              create.dialogStatus === 'create'
                ? add_dialog_save(1)
                : form_exam2(create.temp)
            "
            >提交审核</el-button
          >
          <el-button
            v-if="create.dialogStatus === 'create'"
            class="success"
            :disabled="isokDisable"
            @click="add_dialog_save(2)"
            >保存草稿</el-button
          >

          <el-button
            class="cancelClose"
            @click="
              create.dialogFormVisible = false;
              get_table_data();
            "
            >关闭</el-button
          >

          <el-button
            v-if="create.dialogStatus === 'update'"
            class="success"
            :disabled="isokDisable"
            @click="form_edit_save()"
            >保存</el-button
          >
        </div>
      </div>
    </el-dialog>

    <!-- 查看/反馈 -->
    <el-dialog
      title="合同详情"
      :visible.sync="createSee.dialogFormVisible"
      :close-on-click-modal="false"
      width="95%"
      :before-close="dialog_close_see"
    >
      <div class="app-add">
        <el-tabs v-model="activeName" type="card">
          <el-tab-pane label="合同信息" name="first">
            <ContractMoreDetail :conmore-data="conmoreData" />
          </el-tab-pane>
          <el-tab-pane label="合同履历" name="second">
            <ContractCustomerDetail :concustomer-data="concustomerData" />
          </el-tab-pane>
        </el-tabs>
        <div slot="footer" class="dialog-footer">
          <el-button
            class="cancelClose"
            v-if="
              createSeeTemp.contractStatus == '一审中' ||
              createSeeTemp.contractStatus == '二审中' ||
              createSeeTemp.contractStatus == '三审中' ||
              createSeeTemp.contractStatus == '四审中' ||
              createSeeTemp.contractStatus == '五审中'
            "
            @click="form_quick(createSeeTemp)"
            >催进度</el-button
          >

          <el-button class="cancelClose" @click="dialog_close_see()"
            >关闭</el-button
          >
        </div>
      </div>
    </el-dialog>

    <!-- PDF预览 -->
    <el-dialog
      title="在线预览"
      :visible.sync="dialogVisible4"
      width="96%"
      append-to-body
      center
    >
      <!-- <pdf v-for="item in numPages" :key="item" :src="pdfSrc" :page="item" ref="pdf"></pdf> -->
      <!-- <iframe :src="pdfSrc" frameborder="0" style="width: 100%; height: 600px"></iframe> -->

      <iframe
        :src="pdfSrc"
        ref="myIframe"
        frameborder="0"
        width="100%"
        height="1200px"
      >
      </iframe>
    </el-dialog>

    <!-- 撤销 -->
    <el-dialog
      title="确认是否撤销"
      :visible.sync="revoke.dialogFormVisible"
      :close-on-click-modal="false"
      width="60%"
    >
      <div class="app-add">
        <el-form
          ref="revoketemp"
          :rules="revoke.rules"
          :model="revoke.temp"
          label-position="right"
          label-width="150px"
          style="width: 80%; margin: 0 auto 50px"
        >
          <el-form-item label="撤销原因：" prop="revokeReason">
            <el-input
              ref="revokeReason"
              v-model="revoke.temp.revokeReason"
              type="textarea"
              :autosize="{ minRows: 4, maxRows: 8 }"
              :rows="8"
              placeholder="请输入备注，最多200个字"
              maxlength="200"
              class="filter-item"
              style="width: 100%"
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button
            class="cancelClose"
            @click="
              revoke.dialogFormVisible = false;
              get_table_data();
            "
            >关闭</el-button
          >
          <el-button class="success" @click="form_revoke_save()"
            >确认</el-button
          >
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  GetDataByName,
  PostDataByName,
  failproccess,
  ExecDataByConfig,
  GetDataByNames,
  checkButtons,
  calculativeWidth,
  wxpush,
} from "@/api/common";
import Cookies from "js-cookie";
import { parseTime, json2excel } from "@/utils/index.js";
// import littleTable from './components/littleTable'
import { getToken } from "@/utils/auth";
import Pagination from "@/components/Pagination";
import { MessageBox } from "element-ui";

import ContractMoreDetail from "@/componentView/ContractMoreDetail.vue";
import ContractCustomerDetail from "@/componentView/ContractCustomerDetail.vue";
import { constants } from "zlib";

export default {
  name: "ContractApply",
  components: { Pagination, ContractCustomerDetail, ContractMoreDetail },
  data() {
    return {
      myHeight: document.documentElement.clientHeight - 85 - 220,
      employeid: Cookies.get("employeid"),
      disabled: false,

      dialogImageUrl: "",
      dialogVisible: false,
      dialogImageUrl2: "",
      dialogVisible2: false,

      //图片请求地址
      uploadImageUrl: process.env.VUE_APP_BASE_API + "authdata/uploaderimage",
      //图片请求头
      headers: {
        optname: "insertcustompic",
        id: 1,
        token: getToken(), // 从cookie里获取token，并赋值token
      },
      //图片路径
      fileList: [],

      headers3: {
        optname: "insertcustompic",
        id: 1,
        token: getToken(), // 从cookie里获取token，并赋值token
      },

      //图片文件请求地址
      uploadFileUrl3: process.env.VUE_APP_BASE_API + "uploadfileCRM",
      uploadfileList3: [],

      fileList2: [],

      isRoleEdit: [],
      isContractapplyAdd: [],

      activeName: "first",

      //客户资料详情组件
      conmoreData: { id: "" },
      concustomerData: { id: "" },

      customerNameList: [], // 客户名称
      groupNameList: [], // 集团
      //经销商 - 下拉框
      dealNameList: [
        // {id: 253, name: "无"},
        // {id: 207, name: "星连星牧业"},
        // {id: 208, name: "海高牧业"},
        // {id: 254, name: "完达山"}
      ],

      // 下拉框 - 创建人
      createrNameList: [],

      // 下拉框 - 合同状态
      statusNameList: [
        { name: "草稿", id: "草稿" },
        { name: "一审中", id: "一审中" },
        { name: "二审中", id: "二审中" },
        { name: "三审中", id: "三审中" },
        { name: "审核通过", id: "审核通过" },
        { name: "已撤销", id: "已撤销" },
        { name: "被驳回", id: "被驳回" },
      ],

      // 下拉框 -款项分期
      moneyStepList: [
        { name: "1", id: "1" },
        { name: "2", id: "2" },
        { name: "3", id: "3" },
        { name: "4", id: "4" },
        { name: "5", id: "5" },
        { name: "6", id: "6" },
        { name: "7", id: "7" },
        { name: "8", id: "8" },
        { name: "9", id: "9" },
        { name: "10", id: "10" },
      ],

      dialogVisible4: false,
      pdfSrc: "",
      numPages: null,

      //表格 - 列表 - 查询
      tableObj: {
        getdataListParm: {
          name: "getContractApplication",
          page: 1,
          offset: 1,
          pagecount: parseInt(Cookies.get("pagecount")),
          returntype: "Map",
          parammaps: {
            roleId: Cookies.get("g_roleId"),
            userId: Cookies.get("g_userId"),
            contractCode: "",
            customerName: "",
            customerId: "",
            groupId: "",
            contractStatus: "",
            createrId: "",
            beginContractMoney: "",
            endContractMoney: "",
            beginMoneyStep: "",
            endMoneyStep: "",
            dealerId: "",

            inputDatetime1: "",
            inputDatetime2: "",
            inputDatetime3: "",

            beginContractBeginDate: "",
            endContractBeginDate: "",
            beginContractEndDate: "",
            endContractEndDate: "",
            beginCreaterDate: "",
            endCreaterDate: "",
          },
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {},
      },

      tableSumMoney: 1000,

      download: {
        getdataListParm: {
          name: "getContractApplication",
          page: 1,
          offset: 1,
          pagecount: 0,
          returntype: "Map",
          parammaps: {
            roleId: Cookies.get("g_roleId"),
            userId: Cookies.get("g_userId"),
            contractCode: "",
            customerName: "",
            customerId: "",
            groupId: "",
            contractStatus: "",
            createrId: "",
            beginContractMoney: "",
            endContractMoney: "",
            beginMoneyStep: "",
            endMoneyStep: "",

            inputDatetime1: "",
            inputDatetime2: "",
            inputDatetime3: "",

            beginContractBeginDate: "",
            endContractBeginDate: "",
            beginContractEndDate: "",
            endContractEndDate: "",
            beginCreaterDate: "",
            endCreaterDate: "",
          },
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {},
      },

      // 新增/编辑
      create: {
        dialogFormVisible: false,
        dialogStatus: "",
        temp: {
          contractStatus: "",
          customerId: "",
          groupId: "",
          groupName: "",
          serviceCode: "",
          contractBeginDate: parseTime(new Date(), "{y}-{m}-{d}"),
          contractEndDate: parseTime(new Date(), "{y}-{m}-{d}"),
          createrId: Cookies.get("employeid"),
          createrName: Cookies.get("employename"),
          moneyStep: "1",
          contractMoney: "",
          businessLicense: -1,
          picname1: "",
          applyFileId: "",
          applyFileName: "",
          dealerId: "",
          dealerId: "",
          serviceCost: "0",
        },

        rules: {
          // groupId: [{ required: true, message: '必填', trigger: 'blur' }],
          customerId: [{ required: true, message: "必填", trigger: "blur" }],
          contractEndDate: [
            { required: true, message: "必填", trigger: "blur" },
          ],
          contractBeginDate: [
            { required: true, message: "必填", trigger: "blur" },
          ],
          moneyStep: [{ required: true, message: "必填", trigger: "blur" }],
          contractMoney: [{ required: true, message: "必填", trigger: "blur" }],
          // serviceResult: [{ required: true, message: '必填', trigger: 'blur' }],
          // describe: [{ required: true, message: '必填', trigger: 'blur' }],
          // receiverName: [{ required: true, message: '必填', trigger: 'blur' }],
          // receiverTel: [{ required: true, message: '必填', trigger: 'blur' }],

          // businessLicense: [{ required: true, message: '必填', trigger: 'blur' }],
        },
        dealNameList: [],
        // 客户名称
        getdataListParmCust: {
          name: "getCustomerByGroupId",
          returntype: "Map",
          parammaps: { groupId: "" },
        },
        customerNameList: [],

        // 款项信息 - 表格
        getdataListParmStages: {
          name: "getContractCost",
          returntype: "Map",
          parammaps: { id: "" },
        },
        // 货物信息 - 表格
        getdataListParmStock: {
          name: "getContractGoodsByCid2",
          returntype: "Map",
          parammaps: { id: "" },
        },

        getdataListParmInvoice: {
          name: "getContractInvoice",
          returntype: "Map",
          parammaps: { id: "" },
        },
      },

      createSeeTemp: {},
      createSee: {
        dialogFormVisible: false,
      },

      //款项期数表格
      tableStagesList: [
        {
          stages: "1",
          planCostRate: "",
          planCost: "",
          collectionDate: parseTime(new Date(), "{y}-{m}-{d}"),
          customerId: "",
          createrId: "",
        },
      ],
      //下拉框 - 备货
      receProductNameList: [],
      //备货表格
      tableStockList: [],
      stockSumPrice: 0,

      textMap: {
        create: "新增",
        see: "查看",
        update: "编辑",
      },

      //备货ID集合
      stockupIdArr: [],
      //备货表格集合
      tableArrList: [],

      // 撤销
      revoke: {
        dialogFormVisible: false,
        dialogStatus: "",
        temp: { revokeReason: "", id: "" },
        rules: {
          revokeReason: [{ required: true, message: "必填", trigger: "blur" }],
        },
      },

      moneyShow: true,
      //获取反馈记录
      getFeedRecordParm: {
        name: "getServiceFeedbackById",
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: "Map",
        parammaps: { id: "" },
      },
      //保存反馈记录
      feedRecordTemp: {
        name: "insertServiceFeedback",
        page: 1,
        offset: 1,
        pagecount: 1000,
        returntype: "Map",
        parammaps: {
          serviceId: "",
          createrId: "",
          remark: "",
        },
      },
      //反馈记录
      feedRecordList: [
        // {id:1, num: 1, txt: '主板缺失零件，疫情关系，无法采购，延期1天',   director:'epans', date:"2022-12-01"},
        // {id:1, num: 1, txt: '主板缺失零件，疫情关系，无法采购，延期1天',   director:'epans', date:"2022-12-01"},
        // {id:1, num: 1, txt: '主板缺失零件，疫情关系，无法采购，延期1天',   director:'epans', date:"2022-12-01"},
      ],
      autoWidth: 130,
      requestParam: {},
      isokDisable: false,
      selectList: [],
      rowStyle: { maxHeight: 50 + "px", height: 45 + "px" },
      cellStyle: { padding: 0 + "px" },
    };
  },

  watch: {
    // contractMoney: {
    //   deep: true,
    //   handler: function (item) {
    //      //计算价格比例
    //       var contractMoney = this.create.temp.contractMoney
    //       var tableStagesList = this.tableStagesList
    //       for (let i = 0; i < tableStagesList.length; i++) {

    //         tableStagesList[i].planCost = (this.create.temp.contractMoney * 100) * ( tableStagesList[i].planCostRate * 100)  * 0.01 / 10000
    //       }
    //       this.tableStagesList = tableStagesList

    //   }
    // },

    tableStockList: {
      deep: true,
      handler: function (newValue, oldValue) {
        //计算每行总价

        for (let j = 0; j < newValue.length; j++) {
          if (newValue[j].nums && newValue[j].closingPrice) {
            this.tableStockList[j].sumPrice =
              parseInt(newValue[j].nums) * parseFloat(newValue[j].closingPrice);
          }
        }

        //计算大列表总价格
        var sum = 0;
        this.tableStockList.forEach(function (i) {
          sum = parseInt(i.nums) * parseFloat(i.closingPrice) + sum;
        });
        this.stockSumPrice = sum;
      },
    },
  },

  created() {
    this.get_table_data();
    this.get_select_list();
    this.get_auto_buttons();
  },

  methods: {
    form_look3() {
      console.log(11111111111111);
      var me = this;
      me.pdfSrc = "";
      var typeStr = me.create.temp.applyFileName;
      var url =
        process.env.VUE_APP_BASE_API +
        "viewfileCRM/" +
        this.create.temp.applyFileId;
      me.dialogVisible4 = true;
      me.pdfSrc = url;
    },
    handleExceed3(files, fileList) {
      this.$message.warning(
        `限制只能上传一个文件，请删除原文件后再上传新的原件`
      );
    },
    handlefileSuccess3(response, file, fileList) {
      console.log(response, file, fileList);
      this.create.temp.applyFileId = response.data.LastInsertId;
      this.create.temp.applyFileName = file.name;
      // this.$refs.temp.resetFields()

      console.log(file.name);
      console.log(response.data.LastInsertId);

      console.log("this.uploadfileList3", this.uploadfileList3);
    },

    //图片展示
    handlePicPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handlePicChange(file, fileList) {},
    //文件上传成功后的操作
    handlePicSuccess(response, file, fileList) {
      console.log("文件上传成功时的钩子response", response);
      console.log("文件上传成功时的钩子file", file);
      console.log("fileList", fileList);

      // //3张图片时，关闭新增的按钮
      if (fileList.length == 1) {
        document.getElementById("uploadPic").lastChild.style.display = "none";
      } else {
        document.getElementById("uploadPic").lastChild.style.display =
          "inline-block";
      }

      if (
        this.create.temp.businessLicense === undefined ||
        this.create.temp.businessLicense == -1
      ) {
        console.log("111");
        this.create.temp.businessLicense = response.execresult.LastInsertId;
      }
      console.log("this.picArr1", this.picArr1);

      console.log("this.create.temp", this.create.temp);
    },
    //图片文件删除
    handlePicRemove(file, fileList) {
      console.log(file, "文件列表移除文件时的钩子file---");
      console.log(fileList, "文件列表移除文件时的钩子fileList--");
      // this.$set(this.create.temp, "businessLicense", -1)
      // this.$set(this.create.temp, "scenePhoto2", -1)
      // this.$set(this.create.temp, "scenePhoto3", -1)
      //9张图片时，关闭新增的按钮
      if (fileList.length == 1) {
        document.getElementById("uploadPic").lastChild.style.display = "none";
      } else {
        document.getElementById("uploadPic").lastChild.style.display =
          "inline-block";
      }
      this.create.temp.businessLicense = -1;

      if (fileList.length == 1) {
        this.create.temp.businessLicense =
          fileList[0].response.execresult.LastInsertId;
      }
      console.log(this.create.temp);
    },

    change_rate(row) {
      if (this.create.temp.contractMoney && row.planCostRate) {
        row.planCost =
          (this.create.temp.contractMoney *
            100 *
            (row.planCostRate * 100) *
            0.01) /
          10000;
      }
    },

    change_contract() {
      //计算价格比例
      var contractMoney = this.create.temp.contractMoney;
      var tableStagesList = this.tableStagesList;
      for (let i = 0; i < tableStagesList.length; i++) {
        if (contractMoney && tableStagesList[i].planCostRate) {
          tableStagesList[i].planCost =
            (contractMoney *
              100 *
              (tableStagesList[i].planCostRate * 100) *
              0.01) /
            10000;
        }
      }
      this.tableStagesList = tableStagesList;
    },

    //获取按钮权限
    get_auto_buttons() {
      const Edit = "ContractApply";
      const isRoleEdit = checkButtons(
        JSON.parse(sessionStorage.getItem("buttons")),
        Edit
      );
      this.isRoleEdit = isRoleEdit;

      const ContractapplyAdd = "contract:contractapply:add";
      const isContractapplyAdd = checkButtons(
        this.$store.state.user.buttons,
        ContractapplyAdd
      );
      this.isContractapplyAdd = isContractapplyAdd;

      //操作的宽度
      // var widthCount = calculativeWidth(isContractapplyAdd,isContractapplyAdd,isContractapplyAdd)
      // this.autoWidth = widthCount
    },
    //获取所有下拉框的内容
    get_select_list() {
      var send_select_list = [
        { name: "getCustomerSelect", offset: 0, pagecount: 0, parammaps: {} },
        { name: "getDealerSelect", offset: 0, pagecount: 0, parammaps: {} },
        {
          name: "getDictListSelect",
          offset: 0,
          pagecount: 0,
          parammaps: { pid: "54" },
        },
        { name: "getUsersSelect", offset: 0, pagecount: 0, parammaps: {} },
        { name: "getProductsEnable", offset: 0, pagecount: 0, parammaps: {} },
      ];

      GetDataByNames(send_select_list).then((response) => {
        this.create.customerNameList = response.data.getCustomerSelect.list;
        console.log("客户名称下拉框", this.create.customerNameList);

        this.groupNameList = response.data.getDictListSelect.list;
        console.log("集团下拉框", this.groupNameList);

        this.dealNameList = response.data.getDealerSelect.list;
        console.log("经销商下拉框", this.dealNameList);

        this.createrNameList = response.data.getUsersSelect.list;
        console.log("创建人下拉框", this.createrNameList);

        response.data.getProductsEnable.list.map(function (i) {
          return (i.customerId = "");
        });
        response.data.getProductsEnable.list.map(function (i) {
          return (i.nums = "");
        });
        response.data.getProductsEnable.list.map(function (i) {
          return (i.remark = "");
        });
        this.receProductNameList = response.data.getProductsEnable.list;
        console.log("收件货品下拉框", this.receProductNameList);
      });

      // var send_data1 = {"name":"getCustomer","page":1,"offset":1,"pagecount":7,"returntype":"Map","parammaps":{ }}

      // GetDataByName(send_data1).then(response => {
      //   console.log('客户数据======>', response )
      //   if (response.data.list !== null) {

      //   } else {

      //   }
      // })
    },
    //加载表格
    get_table_data() {
      var me = this;
      this.tableObj.listLoading = true;
      console.log(
        "this.tableObj.getdataListParm======>",
        this.tableObj.getdataListParm
      );
      GetDataByName(this.tableObj.getdataListParm).then((response) => {
        console.log("table数据======>", response.data.list);
        if (response.data.list !== null) {
          for (let i = 0; i < response.data.list.length; i++) {
            var url =
              process.env.VUE_APP_BASE_API + response.data.list[i].picname1;
            this.$set(response.data.list[i], "imgUrlDetil", url);
          }

          this.tableObj.list = response.data.list;
          this.tableObj.pageNum = response.data.pageNum;
          this.tableObj.pageSize = response.data.pageSize;
          this.tableObj.total = response.data.total;

          //计算操作栏宽度
          var btnNum = 0;
          var arrList = response.data.list;
          arrList.forEach(function (row) {
            var itemBtnNum = 0;
            if (me.isContractapplyAdd && row.isModify == "1") {
              itemBtnNum = itemBtnNum + 1;
            }
            if (me.isContractapplyAdd && row.isDel == "1") {
              itemBtnNum = itemBtnNum + 1;
            }
            if (me.isContractapplyAdd && row.isExamine == "1") {
              itemBtnNum = itemBtnNum + 1;
            }
            if (me.isContractapplyAdd && row.isRevoke == "1") {
              itemBtnNum = itemBtnNum + 1;
            }

            console.log(itemBtnNum);
            if (itemBtnNum > btnNum) {
              btnNum = itemBtnNum;
            }
          });
          console.log("btnNum=============", btnNum);
          me.autoWidth = btnNum * 90 + 90;

          console.log("table数据======>", this.tableObj.list);
        } else {
          this.tableObj.list = [];
        }
        setTimeout(() => {
          this.tableObj.listLoading = false;
        }, 100);
      });

      var send_price = {
        name: "getContractOfPrice",
        parammaps: this.tableObj.getdataListParm.parammaps,
      };

      GetDataByName(send_price).then((response) => {
        console.log("table总价格数据======>", response);
        if (response.data.list !== null) {
          this.tableSumMoney = response.data.list[0].totlePrice;
        } else {
          this.tableSumMoney = "";
        }
      });
    },
    form_search() {
      console.log("点击了查询");

      if (
        this.tableObj.getdataListParm.parammaps.inputDatetime1 !== "" &&
        this.tableObj.getdataListParm.parammaps.inputDatetime1 !== null
      ) {
        this.tableObj.getdataListParm.parammaps.beginContractBeginDate =
          parseTime(
            this.tableObj.getdataListParm.parammaps.inputDatetime1[0],
            "{y}-{m}-{d}"
          );
        this.tableObj.getdataListParm.parammaps.endContractBeginDate =
          parseTime(
            this.tableObj.getdataListParm.parammaps.inputDatetime1[1],
            "{y}-{m}-{d}"
          );
      } else {
        this.tableObj.getdataListParm.parammaps.inputDatetime1 = "";
        this.tableObj.getdataListParm.parammaps.beginContractBeginDate = "";
        this.tableObj.getdataListParm.parammaps.endContractBeginDate = "";
      }

      if (
        this.tableObj.getdataListParm.parammaps.inputDatetime2 !== "" &&
        this.tableObj.getdataListParm.parammaps.inputDatetime2 !== null
      ) {
        this.tableObj.getdataListParm.parammaps.beginContractEndDate =
          parseTime(
            this.tableObj.getdataListParm.parammaps.inputDatetime2[0],
            "{y}-{m}-{d}"
          );
        this.tableObj.getdataListParm.parammaps.endContractEndDate = parseTime(
          this.tableObj.getdataListParm.parammaps.inputDatetime2[1],
          "{y}-{m}-{d}"
        );
      } else {
        this.tableObj.getdataListParm.parammaps.inputDatetime2 = "";
        this.tableObj.getdataListParm.parammaps.beginContractEndDate = "";
        this.tableObj.getdataListParm.parammaps.endContractEndDate = "";
      }

      if (
        this.tableObj.getdataListParm.parammaps.inputDatetime3 !== "" &&
        this.tableObj.getdataListParm.parammaps.inputDatetime3 !== null
      ) {
        this.tableObj.getdataListParm.parammaps.beginCreaterDate = parseTime(
          this.tableObj.getdataListParm.parammaps.inputDatetime3[0],
          "{y}-{m}-{d}"
        );
        this.tableObj.getdataListParm.parammaps.endCreaterDate = parseTime(
          this.tableObj.getdataListParm.parammaps.inputDatetime3[1],
          "{y}-{m}-{d}"
        );
      } else {
        this.tableObj.getdataListParm.parammaps.inputDatetime3 = "";
        this.tableObj.getdataListParm.parammaps.beginCreaterDate = "";
        this.tableObj.getdataListParm.parammaps.endCreaterDate = "";
      }

      this.tableObj.getdataListParm.offset = 1;
      this.get_table_data();
    },
    form_clear() {
      console.log("点击了重置");

      this.tableObj.getdataListParm.parammaps.customerName = "";
      this.tableObj.getdataListParm.parammaps.contractCode = "";
      this.tableObj.getdataListParm.parammaps.customerId = "";
      this.tableObj.getdataListParm.parammaps.groupId = "";
      this.tableObj.getdataListParm.parammaps.dealerId = "";
      this.tableObj.getdataListParm.parammaps.contractStatus = "";
      this.tableObj.getdataListParm.parammaps.createrId = "";
      this.tableObj.getdataListParm.parammaps.beginContractMoney = "";
      this.tableObj.getdataListParm.parammaps.endContractMoney = "";
      this.tableObj.getdataListParm.parammaps.beginMoneyStep = "";
      this.tableObj.getdataListParm.parammaps.endMoneyStep = "";

      this.tableObj.getdataListParm.parammaps.inputDatetime1 = "";
      this.tableObj.getdataListParm.parammaps.inputDatetime2 = "";
      this.tableObj.getdataListParm.parammaps.inputDatetime3 = "";

      this.tableObj.getdataListParm.parammaps.beginContractBeginDate = "";
      this.tableObj.getdataListParm.parammaps.endContractBeginDate = "";
      this.tableObj.getdataListParm.parammaps.beginContractEndDate = "";
      this.tableObj.getdataListParm.parammaps.endContractEndDate = "";
      this.tableObj.getdataListParm.parammaps.beginCreaterDate = "";
      this.tableObj.getdataListParm.parammaps.endCreaterDate = "";
      this.tableObj.getdataListParm.offset = 1;
      this.get_table_data();
    },

    // 新增
    form_reset() {
      (this.create.temp = {
        contractStatus: "",
        customerId: "",
        groupId: "",
        groupName: "",
        serviceCode: "",
        contractBeginDate: parseTime(new Date(), "{y}-{m}-{d}"),
        contractEndDate: parseTime(new Date(), "{y}-{m}-{d}"),
        createrId: Cookies.get("employeid"),
        createrName: Cookies.get("employename"),
        moneyStep: "1",
        contractMoney: "",
        businessLicense: -1,
        picname1: "",
        applyFileId: "",
        applyFileName: "",
        dealerId: "",
        dealerName: "",
      }),
        (this.fileList = []);

      this.tableStagesList = [
        {
          stages: "1",
          planCostRate: "",
          planCost: "",
          collectionDate: parseTime(new Date(), "{y}-{m}-{d}"),
          customerId: "",
          createrId: "",
        },
      ];
      this.tableStockList = [];

      this.uploadfileList3 = [];

      document.getElementById("uploadPic").lastChild.style.display =
        "inline-block";
    },

    //客户失去焦点
    customer_search_blur(item) {
      console.log("客户失去焦点");
      this.tableObj.getdataListParm.parammaps.customerId = "";
      this.tableObj.getdataListParm.parammaps.customerName = "";
      this.customerNameList = [];
    },

    dialog_close_see() {
      this.createSee.dialogFormVisible = false;
      this.conmoreData.id = "";

      this.get_table_data();
    },
    //模糊查询客户
    customer_search(queryString, cb) {
      console.log("模糊查询输入值", queryString);
      GetDataByName({
        name: "getCustomerNameFuzzy",
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: "Map",
        parammaps: { inputvalue: queryString },
      }).then((response) => {
        this.customerNameList = response.data.list;
        console.log("客户名称下拉框", response);
        cb(response.data.list);
      });
    },

    //模糊查询客户选择
    change_customer_select(item) {
      console.log("客户名称模糊查询选中值", item);
      this.tableObj.getdataListParm.parammaps.customerId = item.id;
      this.tableObj.getdataListParm.parammaps.customerName = item.name;

      this.$forceUpdate();
    },

    //清空客户选择
    clear_customer_select(item) {
      document.activeElement.blur();
      this.tableObj.getdataListParm.parammaps.customerId = "";
      this.tableObj.getdataListParm.parammaps.customerName = "";
    },

    //监听 - 集团
    change_group(item) {
      console.log(item);
      console.log(this.create.temp.groupId);
      this.create.temp.groupId = item;
      this.create.getdataListParmCust.parammaps.groupId = item;

      this.create.temp.customerName = "";
      this.create.temp.customerId = "";
      this.create.customerNameList = [];

      this.get_customer_list();
      this.$forceUpdate();
    },
    // 弹窗中的客户
    get_customer_list() {
      GetDataByName(this.create.getdataListParmCust).then((response) => {
        if (response.data.list !== null) {
          this.create.customerNameList = response.data.list;
          console.log("弹窗中的客户数据", response.data.list);
        } else {
          this.create.customerNameList = [];
        }
      });
    },
    change_deal(item) {
      console.log(item);
      this.create.temp.dealerId = item;
    },

    //监听 - 下拉中客户名称
    change_customer(item) {
      console.log(item);
      this.create.temp.customerId = item;
      this.get_groupName(item);

      this.get_dealNameList(item);
    },

    // 弹窗中的经销商
    get_dealNameList(item) {
      var me = this;
      var send_data = {
        name: "getDealerSelectByCustomerId",
        returntype: "Map",
        parammaps: { customerId: item },
      };

      GetDataByName(send_data).then((response) => {
        console.log(response);
        if (response.data.list !== null) {
          me.create.dealNameList = response.data.list;
        } else {
          me.create.dealNameList = [];
          me.create.temp.dealerId = "";
          me.create.temp.dealerName = "";
        }
      });
    },

    // 获取集团名称
    get_groupName(customerId) {
      var me = this;
      var send_data = {
        name: "getgroupNameById",
        returntype: "Map",
        parammaps: { id: customerId },
      };
      GetDataByName(send_data).then((response) => {
        console.log(response);
        if (response.data.list !== null) {
          me.create.temp.groupName = response.data.list[0].groupName;
          me.create.temp.groupId = response.data.list[0].groupId;
        } else {
          me.create.temp.groupName = "";
          me.create.temp.groupId = "";
        }
      });
    },

    // 款项信息表格
    getStagesTableList() {
      GetDataByName(this.create.getdataListParmStages).then((response) => {
        if (response.data.list !== null) {
          this.tableStagesList = response.data.list;
          console.log("款项信息表格数据", response.data.list);
        } else {
          this.tableStagesList = [];
        }
      });
    },

    // 备货信息表格
    getStockTableList() {
      GetDataByName(this.create.getdataListParmStock).then((response) => {
        if (response.data.list !== null) {
          this.tableStockList = response.data.list;
          console.log("备货信息表格数据", response.data.list);
        } else {
          this.tableStockList = [];
        }
      });
    },

    // 监听 - 下拉 - 款项分期
    change_moneyStep(item) {
      console.log(item);
      var me = this;

      var table_len = this.tableStagesList.length;

      console.log("table_len", table_len);

      if (item > table_len) {
        var num = parseInt(item) - parseInt(table_len);

        console.log("num", num);
        for (var i = 1; i < num + 1; i++) {
          console.log(i);
          me.tableStagesList.push({
            stages: i + parseInt(table_len),
            planCostRate: "",
            planCost: "",
            collectionDate: parseTime(new Date(), "{y}-{m}-{d}"),
            customerId: "",
            createrId: "",
          });
        }
      }

      if (item < table_len) {
        var arrTemp = me.tableStagesList.slice(0, item);

        me.tableStagesList = arrTemp;
      }
    },

    //小表格中的删除单号
    form_deleteCode(item, index) {
      console.log("小表格中的删除单号", item);
      this.tableArrList.splice(index, 1);
      this.stockupIdArr.splice(this.stockupIdArr.indexOf(item.stockupId), 1);
      console.log("stockupIdArr===>", this.stockupIdArr);
    },

    //下拉 - 备货品
    change_receProduct(item) {
      console.log("备货品ID ", item);
      var index = this.receProductNameList.findIndex(
        (obj) => obj.productsId == item
      );
      console.log("备货品index ", index);
      var ifHasId = this.tableStockList.findIndex(
        (obj) => obj.productsId == item
      );
      console.log("备货品是否存在列表 ", ifHasId);

      var addRow = Object.assign({}, this.receProductNameList[index]);

      console.log("备货单条====== ", addRow);

      addRow.nums = 1;
      addRow.remark = "";

      addRow.closingPrice = this.receProductNameList[index].price;
      addRow.sumPrice = parseInt(addRow.nums) * parseFloat(addRow.closingPrice);

      if (ifHasId == "-1") {
        this.tableStockList.unshift(addRow);
      }
    },

    //备货中的删除
    form_delete2(row, index) {
      console.log("备货中的删除", row);
      var index = this.tableStockList.findIndex((obj) => obj.id == row.id);
      this.tableStockList.splice(index, 1);
    },

    //新增
    form_add() {
      console.log("点击了新增");

      this.create.dialogStatus = "create";
      this.create.dialogFormVisible = true;
      this.form_reset();
    },
    //新增保存
    add_dialog_save(type) {
      console.log("点击了新增保存");
      this.isokDisable = true;
      setTimeout(() => {
        this.isokDisable = false;
      }, 1000);
      this.$refs["temp"].validate((valid) => {
        if (valid) {
          this.isokDisable = true;
          setTimeout(() => {
            this.isokDisable = false;
          }, 1000);

          //   serviceCost  技术服务费：
          //   合同金额  contractMoney
          // 列表货物总价： stockSumPrice

          var serviceCost = this.create.temp.serviceCost;
          var contractMoney = this.create.temp.contractMoney;
          var stockSumPrice = this.stockSumPrice;

          if (serviceCost == "" || serviceCost == null) {
            this.$message({
              type: "error",
              message: "技术服务费不能为空，没有请写0",
              duration: 2000,
            });
            return false;
          }

          if (
            parseFloat(contractMoney) !==
            parseFloat(serviceCost) + parseFloat(stockSumPrice)
          ) {
            console.log(parseFloat(contractMoney));
            console.log(parseFloat(serviceCost) + parseFloat(stockSumPrice));
            this.$message({
              type: "error",
              message: "合同金额填写错误！合同金额=技术服务费+货物总价",
              duration: 2000,
            });
            return false;
          }

          if (this.create.temp.businessLicense == "-1") {
            var isEmpty = false;
          } else {
            var isEmpty = false;
          }

          if (isEmpty) {
            this.$message({
              type: "error",
              message: "请添加照片！",
              duration: 2000,
            });
          } else {
            if (type == 1) {
              this.create.temp.contractStatus = "一审中";
            }
            if (type == 2) {
              this.create.temp.contractStatus = "草稿";
            }

            this.create.temp.createrId = Cookies.get("employeid");

            var createrId = Cookies.get("employeid");

            var customerId = this.create.temp.customerId;
            this.tableStockList.map(function (i) {
              return (i.customerId = customerId);
            });

            this.tableStockList.map(function (i) {
              return (i.createrId = createrId);
            });

            this.tableStagesList.map(function (i) {
              return (i.customerId = customerId);
            });
            this.tableStagesList.map(function (i) {
              return (i.createrId = createrId);
            });

            var send_data = {
              common: { returnmap: "0" },
              data: [
                {
                  name: "insertContract",
                  type: "e",
                  parammaps: this.create.temp,
                },
                {
                  name: "insertContractCost",
                  resultmaps: {
                    list: this.tableStagesList,
                  },
                  children: [
                    {
                      name: "insertContractCost",
                      type: "e",
                      parammaps: {
                        contractId: "@insertContract.LastInsertId",
                        customerId: "@insertContractCost.customerId",
                        stages: "@insertContractCost.stages",
                        planCost: "@insertContractCost.planCost",
                        planCostRate: "@insertContractCost.planCostRate",
                        collectionDate: "@insertContractCost.collectionDate",
                        createrId: "@insertContractCost.createrId",
                      },
                    },
                  ],
                },
                {
                  name: "insertApprovalOfYunYangNiu",
                  type: "e",
                  parammaps: {
                    objectId: "@insertContract.LastInsertId",
                    customerId: this.create.temp.customerId,
                  },
                },
                {
                  name: "insertContractGoods",
                  resultmaps: {
                    list: this.tableStockList,
                  },
                  children: [
                    {
                      name: "insertContractGoods",
                      type: "e",
                      parammaps: {
                        contractId: "@insertContract.LastInsertId",
                        productsId: "@insertStockupGoods.productsId",
                        nums: "@insertStockupGoods.nums",
                        remark: "@insertStockupGoods.remark",
                        customerId: "@insertStockupGoods.customerId",
                        closingPrice: "@insertStockupGoods.closingPrice",
                      },
                    },
                  ],
                },
                {
                  name: "updateCustomeStatusById",
                  parammaps: {
                    customerId: this.create.temp.customerId,
                  },
                },
              ],
            };

            console.log("新增保存发送参数", send_data);

            var isEmpty = this.tableStockList.find((i) => i.nums == "");
            console.log(isEmpty);

            var allSum = 0;
            var tableStagesList = this.tableStagesList;
            for (let i = 0; i < tableStagesList.length; i++) {
              allSum =
                allSum +
                (parseFloat(tableStagesList[i].planCostRate) * 100) / 100;
            }
            console.log("allSum", allSum);

            if (isEmpty) {
              this.$message({
                type: "error",
                message: "货品数量不可为空",
                duration: 2000,
              });
            } else if (allSum !== 100) {
              this.$message({
                type: "error",
                message: "期数应收金额占比总和必须为100",
                duration: 2000,
              });
            } else {
              if (type == 1) {
                ExecDataByConfig(send_data).then((response) => {
                  console.log("新增保存发送参数", this.requestParam);
                  if (response.msg !== "fail") {
                    this.$notify({
                      title: "成功",
                      message: "保存成功",
                      type: "success",
                      duration: 2000,
                    });
                    this.create.dialogFormVisible = false;
                    this.get_table_data();

                    var createId = response.data[0].resultmaps.LastInsertId;
                    var send_weixin_data1 = {
                      name: "getRemindData",
                      parammaps: {
                        userId: Cookies.get("g_userId"),
                        remindId: 1,
                        remindTypeName: "合同",
                        rowId: createId,
                      },
                    };
                    GetDataByName(send_weixin_data1).then((response) => {
                      console.log("微信推送(获取参数)======>", response);
                      if (response.data.message == "ok") {
                        var receiverStr = response.data.list[0].receivers;
                        var receiverArr = receiverStr.split(",");
                        var value1 = response.data.list[0].value1;
                        var value2 = response.data.list[0].value2;
                        var value3 = response.data.list[0].value3;
                        var value4 = response.data.list[0].value4;
                        var send_weixin_data2 = {
                          target: receiverArr,
                          serviceId: 1,
                          content: [
                            { color: "#173177", value: value1 },
                            { color: "#173177", value: value2 },
                            { color: "#173177", value: value3 },
                            { color: "#173177", value: value4 },
                          ],
                        };
                        wxpush(send_weixin_data2).then((response) => {
                          console.log("微信推送(获取参数)======>", response);
                        });
                        // this.tableSumMoney = response.data.list[0].totlePrice
                      } else {
                        // this.$notify({ title: '失败', message: '消息推送失败', type: 'error', duration: 2000 })
                      }
                    });
                  } else {
                    this.$notify({
                      title: "失败",
                      message: "保存失败" + response.data,
                      type: "error",
                      duration: 2000,
                    });
                  }
                });
              } else {
                ExecDataByConfig(send_data).then((response) => {
                  console.log("新增保存发送参数", this.requestParam);
                  if (response.msg !== "fail") {
                    this.$notify({
                      title: "成功",
                      message: "保存成功",
                      type: "success",
                      duration: 2000,
                    });
                    this.create.dialogFormVisible = false;
                    this.get_table_data();
                  } else {
                    this.$notify({
                      title: "失败",
                      message: "保存失败" + response.data,
                      type: "error",
                      duration: 2000,
                    });
                  }
                });
              }
            }
          }
        }
      });
    },
    // 查看
    form_see(row) {
      // this.form_reset()
      this.createSeeTemp = Object.assign({}, row);

      this.concustomerData.id = row.id;
      this.conmoreData.id = row.id;

      console.log("点击了查看");

      // 现场照片
      const urlArray = [];
      const urlArrayId = [];
      const fileList = [];

      if (this.create.temp.picname1 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname1);
        urlArrayId.push(this.create.temp.businessLicense);
      }

      console.log("urlArray", urlArray);
      console.log("urlArrayId", urlArrayId);

      for (let i = 0; i < urlArray.length; i++) {
        var urlObj = {
          url: "",
          response: { execresult: { LastInsertId: "" } },
        };
        urlObj.url = urlArray[i];
        // this.$set(urlObj, 'url', urlArray[i])
        // this.$set(urlObj, 'response', 15)
        urlObj.response.execresult.LastInsertId = urlArrayId[i];
        fileList.push(urlObj);
      }

      this.fileList = fileList;

      console.log("fileList", fileList);

      this.createSee.dialogFormVisible = true;
    },

    // 编辑
    form_edit(row) {
      console.log("点击了编辑", row);

      this.create.temp = Object.assign({}, row);
      this.create.temp.id = row.id;

      // this.create.getdataListParmCust.parammaps.groupId = row.groupId
      // this.get_customer_list()

      this.create.getdataListParmStages.parammaps.id = row.id;
      this.getStagesTableList();

      this.create.getdataListParmStock.parammaps.id = row.id;
      this.getStockTableList();

      this.get_dealNameList(row.customerId);

      // //获取发票信息
      // this.create.getdataListParmInvoice.parammaps.id = row.id
      // this.getInvocieList()

      if (this.create.temp.dealerId && this.create.temp.dealerId !== "") {
        var dearSt = this.create.temp.dealerId;

        this.create.temp.dealerId = parseInt(dearSt);
        console.log(parseInt(dearSt));
      }

      // 营业执照
      const urlArray = [];
      const urlArrayId = [];
      const fileList = [];
      if (this.create.temp.picname1 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname1);
        urlArrayId.push(this.create.temp.businessLicense);
      }

      console.log("urlArray", urlArray);
      console.log("urlArrayId", urlArrayId);

      for (let i = 0; i < urlArray.length; i++) {
        var urlObj = {
          url: "",
          response: { execresult: { LastInsertId: "" } },
        };
        urlObj.url = urlArray[i];
        // this.$set(urlObj, 'url', urlArray[i])
        // this.$set(urlObj, 'response', 15)
        urlObj.response.execresult.LastInsertId = urlArrayId[i];
        fileList.push(urlObj);
      }

      this.fileList = fileList;

      console.log("fileList", fileList);

      if (this.create.temp.applyFileName) {
        var urlObj = {
          name: this.create.temp.applyFileName,
          url: process.env.VUE_APP_BASE_API + this.create.temp.applyFileName,
          response: {
            execresult: { LastInsertId: this.create.temp.applyFileId },
          },
        };
        this.uploadfileList3 = [urlObj];
      } else {
        this.uploadfileList3 = [];
      }

      this.create.dialogStatus = "update";
      this.create.dialogFormVisible = true;

      // console.log(document.getElementById('uploadPic'))
      this.$nextTick(() => {
        //1张图片时，关闭新增的按钮
        if (fileList.length == 1) {
          document.getElementById("uploadPic").lastChild.style.display = "none";
        } else {
          document.getElementById("uploadPic").lastChild.style.display =
            "inline-block";
        }
      });
    },

    // 发票信息
    getInvocieList() {
      GetDataByName(this.create.getdataListParmInvoice).then((response) => {
        console.log("发票信息response.data.list", response.data.list);
        if (response.data.list !== null) {
          // for (let i = 0; i < response.data.list.length; i++) {
          //   var url = process.env.VUE_APP_BASE_API + response.data.list[i].picname
          //   this.$set(response.data.list[i], 'picname', url )
          // }
          // this.tableInvocieList  = response.data.list
          // console.log('发票信息表格数据', response.data.list)
        } else {
          //this.tableInvocieList  = []
        }
      });
    },

    // 编辑保存
    form_edit_save() {
      this.isokDisable = true;
      setTimeout(() => {
        this.isokDisable = false;
      }, 1000);
      this.$refs["temp"].validate((valid) => {
        if (valid) {
          this.isokDisable = true;
          setTimeout(() => {
            this.isokDisable = false;
          }, 1000);

          //   serviceCost  技术服务费：
          //   合同金额  contractMoney
          // 列表货物总价： stockSumPrice

          var serviceCost = this.create.temp.serviceCost;
          var contractMoney = this.create.temp.contractMoney;
          var stockSumPrice = this.stockSumPrice;

          if (serviceCost == "" || serviceCost == null) {
            this.$message({
              type: "error",
              message: "技术服务费不能为空，没有请写0",
              duration: 2000,
            });
            return false;
          }

          if (
            parseFloat(contractMoney) !==
            parseFloat(serviceCost) + parseFloat(stockSumPrice)
          ) {
            console.log(parseFloat(contractMoney));
            console.log(parseFloat(serviceCost) + parseFloat(stockSumPrice));
            this.$message({
              type: "error",
              message: "合同金额填写错误！合同金额=技术服务费+货物总价",
              duration: 2000,
            });
            return false;
          }

          if (this.create.temp.businessLicense == "-1") {
            var isEmpty = false;
          } else {
            var isEmpty = false;
          }

          if (isEmpty) {
            this.$message({
              type: "error",
              message: "请添加照片！",
              duration: 2000,
            });
          } else {
            this.create.temp.createrId = Cookies.get("employeid");

            var id = this.create.temp.id;

            var createrId = Cookies.get("employeid");

            var customerId = this.create.temp.customerId;
            this.tableStockList.map(function (i) {
              return (i.customerId = customerId);
            });

            this.tableStockList.map(function (i) {
              return (i.createrId = createrId);
            });

            this.tableStockList.map(function (i) {
              return (i.id = id);
            });

            this.tableStagesList.map(function (i) {
              return (i.customerId = customerId);
            });
            this.tableStagesList.map(function (i) {
              return (i.createrId = createrId);
            });

            this.tableStagesList.map(function (i) {
              return (i.id = id);
            });

            var send_data = {
              common: { returnmap: "0" },
              data: [
                {
                  name: "insertApproval",
                  type: "e",
                  parammaps: {
                    typeName: "合同提交审核",
                    objectId: this.create.temp.id,
                    statusId: "1",
                    remark: this.create.temp.remark,
                    userId: Cookies.get("g_userId"),
                    stepName: "提交审核",
                  },
                },
                {
                  name: "updateContract",
                  type: "e",
                  parammaps: this.create.temp,
                },
                {
                  name: "delContractCostByCid",
                  type: "e",
                  parammaps: { id: this.create.temp.id },
                },
                {
                  name: "insertApprovalOfYunYangNiu",
                  type: "e",
                  parammaps: {
                    objectId: this.create.temp.id,
                    customerId: this.create.temp.customerId,
                  },
                },
                {
                  name: "insertContractCost",
                  resultmaps: {
                    list: this.tableStagesList,
                  },
                  children: [
                    {
                      name: "insertContractCost",
                      type: "e",
                      parammaps: {
                        contractId: "@insertContractCost.id",
                        customerId: "@insertContractCost.customerId",
                        stages: "@insertContractCost.stages",
                        planCost: "@insertContractCost.planCost",
                        planCostRate: "@insertContractCost.planCostRate",
                        collectionDate: "@insertContractCost.collectionDate",
                        createrId: "@insertContractCost.createrId",
                      },
                    },
                  ],
                },
                {
                  name: "delContractGoodsByCid",
                  type: "e",
                  parammaps: { id: this.create.temp.id },
                },
                {
                  name: "insertContractGoods",
                  resultmaps: {
                    list: this.tableStockList,
                  },
                  children: [
                    {
                      name: "insertContractGoods",
                      type: "e",
                      parammaps: {
                        contractId: "@insertStockupGoods.id",
                        productsId: "@insertStockupGoods.productsId",
                        nums: "@insertStockupGoods.nums",
                        remark: "@insertStockupGoods.remark",
                        customerId: "@insertStockupGoods.customerId",
                        closingPrice: "@insertStockupGoods.closingPrice",
                      },
                    },
                  ],
                },
              ],
            };

            console.log("编辑保存发送参数", send_data);

            var isEmpty = this.tableStockList.find((i) => i.nums == "");
            console.log(isEmpty);
            if (isEmpty) {
              this.$message({
                type: "error",
                message: "货品数量不可为空",
                duration: 2000,
              });
            } else {
              ExecDataByConfig(send_data).then((response) => {
                console.log("编辑保存发送参数", this.requestParam);
                if (response.msg !== "fail") {
                  this.$notify({
                    title: "成功",
                    message: "保存成功",
                    type: "success",
                    duration: 2000,
                  });
                  this.create.dialogFormVisible = false;
                  this.get_table_data();
                } else {
                  this.$notify({
                    title: "失败",
                    message: "保存失败" + response.data,
                    type: "error",
                    duration: 2000,
                  });
                }
              });
            }
          }
        }
      });
    },

    // 删除
    form_delete(row) {
      var me = this;
      MessageBox.confirm("是否确认删除此信息?", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          var send_data = {
            name: "delContractApplication",
            parammaps: { id: row.id },
          };

          var send_data2 = {
            name: "updateCustomeStatusById",
            parammaps: { customerId: row.customerId },
          };

          PostDataByName(send_data).then((response) => {
            if (response.msg === "fail") {
              this.$notify({
                title: "删除失败",
                message: response.data,
                type: "warning",
                duration: 2000,
              });
            } else {
              PostDataByName(send_data2).then((response) => {
                if (response.msg === "fail") {
                  this.$notify({
                    title: "删除失败",
                    message: response.data,
                    type: "warning",
                    duration: 2000,
                  });
                } else {
                  this.$notify({
                    title: "成功",
                    message: "删除成功",
                    type: "success",
                    duration: 2000,
                  });
                  this.get_table_data();
                }
              });
            }
          });
        })
        .catch(() => {
          this.$message({ type: "info", message: "已取消删除" });
        });
    },

    form_down2() {
      var send_data = {
        fileId: this.create.temp.applyFileId,
      };

      var fileName = this.create.temp.applyFileName;

      downloadfileCRM(send_data).then((res) => {
        const content = res;
        const blob = new Blob([content]);

        if ("download" in document.createElement("a")) {
          // 非IE下载
          const elink = document.createElement("a");
          elink.download = fileName;
          elink.style.display = "none";
          elink.href = URL.createObjectURL(blob);
          document.body.appendChild(elink);
          elink.click();
          URL.revokeObjectURL(elink.href); // 释放URL 对象
          document.body.removeChild(elink);
        } else {
          // IE10+下载
          navigator.msSaveBlob(blob, fileName);
        }
      });
    },

    // 提交审核
    form_exam1(row) {
      console.log("提交审核", row);

      var send_data = {
        common: { returnmap: "0" },
        data: [
          {
            name: "insertApproval",
            type: "e",
            parammaps: {
              typeName: "合同提交审核",
              objectId: row.id,
              statusId: "1",
              remark: row.remark,
              userId: Cookies.get("g_userId"),
              stepName: "提交审核",
            },
          },
          {
            name: "submitContract",
            type: "e",
            parammaps: { id: row.id },
          },
          {
            name: "insertApprovalOfYunYangNiu",
            type: "e",
            parammaps: {
              objectId: row.id,
              customerId: row.customerId,
            },
          },
        ],
      };

      this.$confirm("是否提交审核?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          ExecDataByConfig(send_data).then((response) => {
            console.log("审核发送参数", send_data);
            if (response.msg !== "fail") {
              this.$notify({
                title: "成功",
                message: "提交成功",
                type: "success",
                duration: 2000,
              });

              this.get_table_data();

              var send_weixin_data1 = {
                name: "getRemindData",
                parammaps: {
                  userId: Cookies.get("g_userId"),
                  remindId: 1,
                  remindTypeName: "合同",
                  rowId: row.id,
                },
              };
              GetDataByName(send_weixin_data1).then((response) => {
                console.log("微信推送(获取参数)======>", response);
                if (response.data.message == "ok") {
                  var receiverStr = response.data.list[0].receivers;
                  var receiverArr = receiverStr.split(",");
                  var value1 = response.data.list[0].value1;
                  var value2 = response.data.list[0].value2;
                  var value3 = response.data.list[0].value3;
                  var value4 = response.data.list[0].value4;
                  var send_weixin_data2 = {
                    target: receiverArr,
                    serviceId: 1,
                    content: [
                      { color: "#173177", value: value1 },
                      { color: "#173177", value: value2 },
                      { color: "#173177", value: value3 },
                      { color: "#173177", value: value4 },
                    ],
                  };
                  wxpush(send_weixin_data2).then((response) => {
                    console.log("微信推送(获取参数)======>", response);
                  });
                  // this.tableSumMoney = response.data.list[0].totlePrice
                } else {
                  // this.$notify({ title: '失败', message: '消息推送失败', type: 'error', duration: 2000 })
                }
              });
              this.create.dialogFormVisible = false;
            } else {
              this.$notify({
                title: "失败",
                message: "提交失败" + response.data,
                type: "error",
                duration: 2000,
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    form_exam2(row) {
      console.log("提交审核", row);
      var me = this;

      var customerId = row.customerId;
      me.tableStockList.map(function (i) {
        return (i.customerId = customerId);
      });

      var send_data = {
        common: { returnmap: "0" },
        data: [
          {
            name: "insertApproval",
            type: "e",
            parammaps: {
              typeName: "合同提交审核",
              objectId: row.id,
              statusId: "1",
              remark: row.remark,
              userId: Cookies.get("g_userId"),
              stepName: "提交审核",
            },
          },
          {
            name: "submitContract",
            type: "e",
            parammaps: { id: row.id },
          },
          {
            name: "insertApprovalOfYunYangNiu",
            type: "e",
            parammaps: {
              objectId: row.id,
              customerId: row.customerId,
            },
          },
          {
            name: "delContractGoodsByCid",
            type: "e",
            parammaps: { id: row.id },
          },

          {
            name: "insertContractGoods",
            resultmaps: {
              list: me.tableStockList,
            },
            children: [
              {
                name: "insertContractGoods",
                type: "e",
                parammaps: {
                  contractId: row.id,
                  productsId: "@insertStockupGoods.productsId",
                  nums: "@insertStockupGoods.nums",
                  remark: "@insertStockupGoods.remark",
                  customerId: "@insertStockupGoods.customerId",
                  closingPrice: "@insertStockupGoods.closingPrice",
                },
              },
            ],
          },
        ],
      };

      this.$confirm("是否提交审核?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          ExecDataByConfig(send_data).then((response) => {
            console.log("审核发送参数", send_data);
            if (response.msg !== "fail") {
              this.$notify({
                title: "成功",
                message: "提交成功",
                type: "success",
                duration: 2000,
              });

              this.get_table_data();

              var send_weixin_data1 = {
                name: "getRemindData",
                parammaps: {
                  userId: Cookies.get("g_userId"),
                  remindId: 1,
                  remindTypeName: "合同",
                  rowId: row.id,
                },
              };
              GetDataByName(send_weixin_data1).then((response) => {
                console.log("微信推送(获取参数)======>", response);
                if (response.data.message == "ok") {
                  var receiverStr = response.data.list[0].receivers;
                  var receiverArr = receiverStr.split(",");
                  var value1 = response.data.list[0].value1;
                  var value2 = response.data.list[0].value2;
                  var value3 = response.data.list[0].value3;
                  var value4 = response.data.list[0].value4;
                  var send_weixin_data2 = {
                    target: receiverArr,
                    serviceId: 1,
                    content: [
                      { color: "#173177", value: value1 },
                      { color: "#173177", value: value2 },
                      { color: "#173177", value: value3 },
                      { color: "#173177", value: value4 },
                    ],
                  };
                  wxpush(send_weixin_data2).then((response) => {
                    console.log("微信推送(获取参数)======>", response);
                  });
                  // this.tableSumMoney = response.data.list[0].totlePrice
                } else {
                  // this.$notify({ title: '失败', message: '消息推送失败', type: 'error', duration: 2000 })
                }
              });
              this.create.dialogFormVisible = false;
            } else {
              this.$notify({
                title: "失败",
                message: "提交失败" + response.data,
                type: "error",
                duration: 2000,
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    form_quick(row) {
      var send_weixin_data1 = {
        name: "getRemindData",
        parammaps: {
          userId: Cookies.get("g_userId"),
          remindId: 1,
          remindTypeName: "合同",
          rowId: row.id,
        },
      };

      if (row.contractStatus == "一审中") {
        send_weixin_data1.parammaps.remindId = 1;
      }
      if (row.contractStatus == "二审中") {
        send_weixin_data1.parammaps.remindId = 2;
      }
      if (row.contractStatus == "三审中") {
        send_weixin_data1.parammaps.remindId = 3;
      }
      if (row.contractStatus == "四审中") {
        send_weixin_data1.parammaps.remindId = 4;
      }
      if (row.contractStatus == "五审中") {
        send_weixin_data1.parammaps.remindId = 5;
      }

      GetDataByName(send_weixin_data1).then((response) => {
        console.log("微信推送(获取参数)======>", response);
        if (response.data.message == "ok") {
          var receiverStr = response.data.list[0].receivers;
          var receiverArr = receiverStr.split(",");
          var value1 = response.data.list[0].value1;
          var value2 = response.data.list[0].value2;
          var value3 = response.data.list[0].value3;
          var value4 = response.data.list[0].value4;
          var send_weixin_data2 = {
            target: receiverArr,
            serviceId: send_weixin_data1.parammaps.remindId,
            content: [
              { color: "#173177", value: value1 },
              { color: "#173177", value: value2 },
              { color: "#173177", value: value3 },
              { color: "#173177", value: value4 },
            ],
          };

          wxpush(send_weixin_data2).then((response) => {
            console.log("微信推送(获取参数)======>", response);
            if (response.msg == "ok") {
              this.$notify({
                title: "成功",
                message: "消息提醒成功",
                type: "success",
                duration: 2000,
              });
            }
          });
          // this.tableSumMoney = response.data.list[0].totlePrice
        } else {
          // this.$notify({ title: '失败', message: '消息推送失败', type: 'error', duration: 2000 })
        }
      });
    },

    form_auto(row) {
      var createrId = Cookies.get("employeid");
      var send_data = {
        common: { returnmap: "0" },
        data: [
          {
            name: "insertStockup",
            type: "e",
            parammaps: {
              customerId: row.customerId,
              groupId: row.groupId,
              orderDate: parseTime(new Date(), "{y}-{m}-{d}"),
              modifyName: "add",
              receiverChoose: "true",
              contractCode: row.contractCode,
              createrId: createrId,
            },
          },
          {
            name: "autoInsertStockupByContract",
            type: "e",
            parammaps: {
              stockupId: "@insertStockup.LastInsertId",
              useContractId: row.id,
            },
          },
        ],
      };

      this.$confirm("是否一键备货?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          ExecDataByConfig(send_data).then((response) => {
            console.log("备货发送参数", send_data);
            if (response.msg !== "fail") {
              var beiId = response.data[0].resultmaps.LastInsertId;
              this.$notify({
                title: "成功",
                message: "备货成功",
                type: "success",
                duration: 2000,
              });

              this.get_table_data();

              var send_weixin_data1 = {
                name: "getRemindData",
                parammaps: {
                  userId: Cookies.get("g_userId"),
                  remindId: 18,
                  remindTypeName: "备货",
                  rowId: beiId,
                },
              };

              GetDataByName(send_weixin_data1).then((response) => {
                console.log("微信推送(获取参数)======>", response);
                if (response.data.message == "ok") {
                  var receiverStr = response.data.list[0].receivers;
                  var receiverArr = receiverStr.split(",");
                  var value1 = response.data.list[0].value1;
                  var value2 = response.data.list[0].value2;
                  var value3 = response.data.list[0].value3;
                  var value4 = response.data.list[0].value4;
                  var send_weixin_data2 = {
                    target: receiverArr,
                    serviceId: 18,
                    content: [
                      { color: "#173177", value: value1 },
                      { color: "#173177", value: value2 },
                      { color: "#173177", value: value3 },
                      { color: "#173177", value: value4 },
                    ],
                  };

                  wxpush(send_weixin_data2).then((response) => {
                    console.log("微信推送(获取参数)======>", response);
                  });
                  // this.tableSumMoney = response.data.list[0].totlePrice
                } else {
                  // this.$notify({ title: '失败', message: '消息推送失败', type: 'error', duration: 2000 })
                }
              });
            } else {
              this.$notify({
                title: "失败",
                message: "撤销失败" + response.data,
                type: "error",
                duration: 2000,
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 撤销
    form_revoke(row) {
      console.log("点击了撤销", row);
      this.reset_revoke();

      this.revoke.temp.id = row.id;
      this.revoke.dialogFormVisible = true;
      this.revoke.temp.contractStatus = row.contractStatus;
    },
    // 撤销 - 重置
    reset_revoke() {
      this.revoke.temp.revokeReason = "";
    },

    // 撤销 - 确认
    form_revoke_save() {
      this.$refs["revoketemp"].validate((valid) => {
        if (valid) {
          var send_data = {
            common: { returnmap: "0" },
            data: [
              {
                name: "insertApproval",
                type: "e",
                parammaps: {
                  typeName: "合同撤销",
                  objectId: this.revoke.temp.id,
                  statusId: "1",
                  remark: this.revoke.temp.revokeReason,
                  userId: Cookies.get("g_userId"),
                  stepName: "合同撤销",
                },
              },
              {
                name: "revokeContractApplication",
                type: "e",
                parammaps: {
                  id: this.revoke.temp.id,
                  revokeReason: this.revoke.temp.revokeReason,
                },
              },
            ],
          };

          this.$confirm("是否撤销该条记录?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              ExecDataByConfig(send_data).then((response) => {
                console.log("撤销发送参数", send_data);
                if (response.msg !== "fail") {
                  this.$notify({
                    title: "成功",
                    message: "撤销成功",
                    type: "success",
                    duration: 2000,
                  });
                  this.revoke.dialogFormVisible = false;
                  this.get_table_data();

                  var send_weixin_data1 = {
                    name: "getRemindData",
                    parammaps: {
                      userId: Cookies.get("g_userId"),
                      remindId: 2,
                      remindTypeName: "合同",
                      rowId: this.revoke.temp.id,
                    },
                  };
                  if (this.revoke.temp.contractStatus == "一审中") {
                    send_weixin_data1.parammaps.remindId = 8;
                  }
                  if (this.revoke.temp.contractStatus == "二审中") {
                    send_weixin_data1.parammaps.remindId = 9;
                  }
                  if (this.revoke.temp.contractStatus == "三审中") {
                    send_weixin_data1.parammaps.remindId = 10;
                  }
                  if (this.revoke.temp.contractStatus == "审核通过") {
                    send_weixin_data1.parammaps.remindId = 11;
                  }
                  GetDataByName(send_weixin_data1).then((response) => {
                    console.log("微信推送(获取参数)======>", response);
                    if (response.data.message == "ok") {
                      var receiverStr = response.data.list[0].receivers;
                      var receiverArr = receiverStr.split(",");
                      var value1 = response.data.list[0].value1;
                      var value2 = response.data.list[0].value2;
                      var value3 = response.data.list[0].value3;
                      var value4 = response.data.list[0].value4;
                      var send_weixin_data2 = {
                        target: receiverArr,
                        serviceId: 2,
                        content: [
                          { color: "#173177", value: value1 },
                          { color: "#173177", value: value2 },
                          { color: "#173177", value: value3 },
                          { color: "#173177", value: value4 },
                        ],
                      };

                      if (this.revoke.temp.contractStatus == "一审中") {
                        send_weixin_data2.serviceId = 8;
                      }
                      if (this.revoke.temp.contractStatus == "二审中") {
                        send_weixin_data2.serviceId = 9;
                      }
                      if (this.revoke.temp.contractStatus == "三审中") {
                        send_weixin_data2.serviceId = 10;
                      }
                      if (this.revoke.temp.contractStatus == "审核通过") {
                        send_weixin_data2.serviceId = 11;
                      }
                      wxpush(send_weixin_data2).then((response) => {
                        console.log("微信推送(获取参数)======>", response);
                      });
                      // this.tableSumMoney = response.data.list[0].totlePrice
                    } else {
                      // this.$notify({ title: '失败', message: '消息推送失败', type: 'error', duration: 2000 })
                    }
                  });
                } else {
                  this.$notify({
                    title: "失败",
                    message: "撤销失败" + response.data,
                    type: "error",
                    duration: 2000,
                  });
                }
              });
            })
            .catch(() => {
              this.$message({
                type: "info",
                message: "已取消删除",
              });
            });
        }
      });
    },
    // 导出
    form_export(item) {
      this.download.getdataListParm.parammaps =
        this.tableObj.getdataListParm.parammaps;

      GetDataByName(this.download.getdataListParm).then((response) => {
        if (response.data.list !== null) {
          this.download.list = response.data.list;
        } else {
          this.download.list = [];
        }
        var excelDatas = [
          {
            tHeader: [
              "序号",
              "合同编号",
              "合同状态",
              "客户名称",
              "客户集团",
              "合同金额（元）",
              "款项分期",
              "合同开始时间",
              "合同结束时间",
              "创建时间",
              "备注",
            ],
            filterVal: [
              "sort",
              "contractCode",
              "contractStatus",
              "customerName",
              "groupName",
              "contractMoney",
              "moneyStep",
              "contractBeginDate",
              "contractEndDate",
              "createrDate",
              "remark",
            ],
            tableDatas: this.download.list,
            sheetName: "Sheet1",
          },
        ];
        json2excel(excelDatas, "合同申请", true, "xlsx");
      });
    },

    // 导入
    form_inport() {
      console.log("点击了导入");
    },
  },
};
</script>
<style lang="scss" scoped>
.search {
  padding-top: 10px;
  clear: both;
}
.table {
  margin-top: 10px;
}

#uploadPic {
  width: 700px;
}

.ellipsis {
  display: -webkit-box;
  text-overflow: ellipsis;
  overflow: hidden;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.el-popover {
  height: auto;
  color: #fff;
  background: rgba(0, 0, 0, 0.8);
}

// #uploadPic .el-upload-list--picture-card .el-upload-list__item {
//   width: 70px;
//   height: 70px;
// }
// #uploadPic .el-upload--picture-card {
//   width: 70px;
//   height: 70px;
//   line-height: 70px;
// }
// #uploadPic .hide .el-upload--picture-card {
//   display: none;
// }

// // 查看 隐藏删除
// #uploadPicSee {
//   height: 70px;
// }
// #uploadPicSee .el-upload-list--picture-card .el-upload-list__item {
//   width: 70px;
//   height: 70px;
// }
// #uploadPicSee .el-upload--picture-card {
//   width: 70px;
//   height: 70px;
//   line-height: 70px;
// }
// #uploadPicSee
//   .el-upload-list--picture-card
//   .el-upload-list__item-actions
//   .el-upload-list__item-delete {
//   display: none;
// }

/deep/ .el-input.is-disabled .el-input__inner {
  color: #000000 !important;
}
/deep/ .el-textarea.is-disabled .el-textarea__inner {
  color: #000000 !important;
}
/deep/ .el-radio__input.is-disabled + span.el-radio__label {
  color: #000000 !important;
}
/deep/ .el-checkbox__input.is-disabled + span.el-checkbox__label {
  color: #000000 !important;
}
</style>
