<!--
 * @Descripttion:
 * @version:
 * @Author: kBank
 * @Date: 2022-10-24 15:45:01
-->
<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="moren"
    />
    <div class="main">
      <div class="form_all">
        <el-form ref="select" :model="select" label-width="auto">
          <el-row :gutter="10">
            <el-col :span="4">
              <el-form-item label="开始编号">
                <el-input
                  v-model="select.sourceMemberCode"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="开始姓名">
                <el-input
                  v-model="select.sourceMemberName"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="接入编号">
                <el-input
                  v-model="select.targetMemberCode"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="接入姓名">
                <el-input
                  v-model="select.targetMemberName"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="会员编号">
                <el-input v-model="select.memberCode" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="会员姓名">
                <el-input v-model="select.memberName" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="'创建日期'" prop="code">
                <el-date-picker
                  v-model="creationTime"
                  type="daterange"
                  range-separator="——"
                  :start-placeholder="'开始时间'"
                  :end-placeholder="'结束日期'"
                  value-format="yyyy-MM-dd"
                  :unlink-panels="true"
                  @change="changeTime"
                />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button type="primary" @click="getDataList">
                {{ '搜索' }}</el-button>
              <el-button type="" @click="reset"> {{ '重置' }}</el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="maintop">
        <div class="mainbtn">
          <el-button
            v-hasButtons="['MissionAdd']"
            size="small"
            class="addBtn"
            @click="openDig"
          >{{ '添加' }}</el-button>
          <el-button
            size="small"
            :disabled="selectData.length == 0"
            style="background-color: #ffad41"
            class="thebtn1"
            @click="fixedData"
          >
            修改</el-button>
          <el-button
            size="small"
            style="background-color: #c8161d"
            class="thebtn1"
            :disabled="selectData.length == 0"
            @click="deleteTable"
          >删除</el-button>
        </div>
      </div>
      <div class="maintable">
        <el-table
          ref="multipleTable"
          v-loading="loading"
          :data="tableData"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
          @select-all="onSelectAll"
          @select="selected"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column
            align="center"
            prop="sourceMemberCode"
            label="开始编号"
          />
          <el-table-column
            align="center"
            prop="sourceMemberName"
            label="开始姓名"
          />
          <el-table-column
            align="center"
            prop="targetMemberCode"
            label="接入编号"
          />
          <el-table-column
            align="center"
            prop="targetMemberName"
            label="接入姓名"
          />
          <el-table-column align="center" prop="memberCode" label="会员编号">
            <template slot-scope="scope">
              <div
                v-for="(item, index) in scope.row.cuMemberSwingNetDetailExtList"
                :key="index"
              >
                {{ item.memberCode }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="memberName" label="会员姓名">
            <template slot-scope="scope">
              <div
                v-for="(item, index) in scope.row.cuMemberSwingNetDetailExtList"
                :key="index"
              >
                {{ item.memberName }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="targetMemberName"
            label="接入部门"
          >
            <template slot-scope="scope">
              <div
                v-for="(item, index) in scope.row.cuMemberSwingNetDetailExtList"
                :key="index"
              >
                {{ item.placeDeptVal }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="firstAchieveRatio"
            label="首购上传比例"
          >
            <template slot-scope="scope">
              <div
                v-for="(item, index) in scope.row.cuMemberSwingNetDetailExtList"
                :key="index"
              >
                {{ item.firstAchieveRatio }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="firstReachPoint"
            label="首购奖金达标业绩"
          >
            <template slot-scope="scope">
              <div
                v-for="(item, index) in scope.row.cuMemberSwingNetDetailExtList"
                :key="index"
              >
                {{ item.firstReachPoint }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="repurchaseAchieveRatio"
            label="复购上传比例"
          >
            <template slot-scope="scope">
              <div
                v-for="(item, index) in scope.row.cuMemberSwingNetDetailExtList"
                :key="index"
              >
                {{ item.repurchaseAchieveRatio }}
              </div>
            </template>
          </el-table-column>

          <el-table-column
            align="center"
            prop="repurchaseReachPoint"
            label="复购奖金达标业绩"
          >
            <template slot-scope="scope">
              <div
                v-for="(item, index) in scope.row.cuMemberSwingNetDetailExtList"
                :key="index"
              >
                {{ item.repurchaseReachPoint }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="creationTime" label="创建时间" />
          <el-table-column align="center" prop="creationTime" label="操作">
            <template slot-scope="scope">
              <div
                style="color: #ffad41; cursor: pointer"
                @click="goodsDetails(scope.row)"
              >
                查看详情
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getDataList"
    />
    <el-dialog
      title="添加"
      :visible.sync="addCode"
      :close-on-click-modal="false"
      width="30%"
      center
      :before-close="handleCloseCode"
    >
      <el-form ref="form" :rules="rules" :model="form" label-width="auto">
        <el-row>
          <el-col :span="12">
            <el-form-item label="开始编号" prop="sourceMemberCode">
              <el-input v-model="form.sourceMemberCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开始姓名">
              <el-input
                v-model="form.sourceMemberName"
                clearable
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="接入编号" prop="targetMemberCode">
              <el-input v-model="form.targetMemberCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="接入姓名">
              <el-input
                v-model="form.targetMemberName"
                clearable
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleCloseCode">{{ '取消' }}</el-button>
        <el-button type="primary" @click="sureCode">{{
          '确认'
        }}</el-button>
      </span>
    </el-dialog>
    <!-- 选择会员 -->
    <el-dialog
      title="选择会员"
      :visible.sync="addList"
      :close-on-click-modal="false"
      width="30%"
      center
      :before-close="handleCloseList"
    >
      <div class="allTab">
        <el-table
          :data="digTable"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
          @selection-change="handleSelectList"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column align="center" prop="memberCode" label="会员编号" />
          <el-table-column align="center" prop="memberName" label="会员姓名" />
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleCloseList">{{ '取消' }}</el-button>
        <el-button type="primary" @click="sureList">{{
          '确认'
        }}</el-button>
      </span>
    </el-dialog>
    <!-- 新增 -->
    <el-dialog
      title="确认"
      :visible.sync="addData"
      :close-on-click-modal="false"
      width="60%"
      center
      :before-close="handleCloseData"
    >
      <el-form ref="form" :rules="rules" :model="form" label-width="auto">
        <el-row>
          <el-col :span="12">
            <el-form-item label="开始编号" prop="sourceMemberCode">
              <el-input
                v-model="form.sourceMemberCode"
                clearable
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开始姓名">
              <el-input
                v-model="form.sourceMemberName"
                clearable
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="接入编号" prop="targetMemberCode">
              <el-input
                v-model="form.targetMemberCode"
                clearable
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="接入姓名">
              <el-input
                v-model="form.targetMemberName"
                clearable
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="disFlex">
        <el-button
          size="small"
          class="addBtn"
          @click="toAddObj1"
        >新增</el-button>
        <el-button
          size="small"
          class="addBtn"
          @click="changeAllData"
        >批量操作</el-button>
      </div>
      <el-table
        :data="selectRow"
        style="width: 100%"
        :header-cell-style="{ background: '#EEEEEE' }"
        :row-class-name="tableRowClassName"
        @selection-change="handleSelectionChange"
      >
        <el-table-column align="center" prop="memberCode" label="会员编号" />
        <el-table-column align="center" prop="memberName" label="会员姓名" />
        <el-table-column align="center" prop="placeDept" label="接入部门">
          <template slot="header" slot-scope="scope">
            <div>接入部门</div>
            <el-select v-model="changeData.placeDept" clearable placeholder="">
              <el-option
                v-for="item in deptList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </template>
          <template slot-scope="scope">
            <el-select v-model="scope.row.placeDept" clearable placeholder="">
              <el-option
                v-for="item in deptList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="firstAchieveRatio"
          label="首购上传比例"
        >
          <template slot="header" slot-scope="scope">
            <div>首购上传比例</div>
            <el-input
              v-model="changeData.firstAchieveRatio"
              clearable
            />
          </template>
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.firstAchieveRatio"
              clearable
            />
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="repurchaseAchieveRatio"
          label="复购上传比例"
        >
          <template slot="header" slot-scope="scope">
            <div>复购上传比例</div>
            <el-input
              v-model="changeData.repurchaseAchieveRatio"
              clearable
            />
          </template>
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.repurchaseAchieveRatio"
              clearable
            />
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="firstReachPoint"
          label="首购奖金达标业绩"
        >
          <template slot="header" slot-scope="scope">
            <div>首购奖金达标业绩</div>
            <!-- <el-select v-model="changeData.firstCalculate"
                       :placeholder="'请选择'">
              <el-option v-for="item in yesNo"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select> -->
            <el-input v-model="changeData.firstReachPoint" clearable />
          </template>
          <template slot-scope="scope">
            <el-input v-model="scope.row.firstReachPoint" clearable />
          </template>
          <!-- <template slot-scope="scope">
            <el-select v-model="scope.row.firstCalculate"
                       :placeholder="'请选择'">
              <el-option v-for="item in yesNo"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select>
          </template> -->
        </el-table-column>
        <el-table-column
          align="center"
          prop="repurchaseAchieveRatio"
          label="复购奖金达标业绩"
        >
          <template slot="header" slot-scope="scope">
            <div>复购奖金达标业绩</div>
            <!-- <el-select v-model="changeData.repurchaseAchieveRatio"
                       :placeholder="'请选择'">
              <el-option v-for="item in yesNo"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select> -->
            <el-input
              v-model="changeData.repurchaseReachPoint"
              clearable
            />
          </template>
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.repurchaseReachPoint"
              clearable
            />
            <!-- <el-select v-model="scope.row.repurchaseCalculate"
                       :placeholder="'请选择'">
              <el-option v-for="item in yesNo"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select> -->
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleCloseData">{{ '取消' }}</el-button>
        <el-button type="primary" @click="sureData">{{
          '确认'
        }}</el-button>
      </span>
    </el-dialog>
    <!-- 修改 -->
    <el-dialog
      title="修改"
      :visible.sync="addUp"
      :close-on-click-modal="false"
      width="60%"
      center
      :before-close="handleCloseUp"
    >
      <el-form ref="form" :rules="rules" :model="form" label-width="auto">
        <el-row>
          <el-col :span="12">
            <el-form-item label="开始编号" prop="sourceMemberCode">
              <el-input
                v-model="upDataObj.sourceMemberCode"
                clearable
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开始姓名">
              <el-input
                v-model="upDataObj.sourceMemberName"
                clearable
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="接入编号" prop="targetMemberCode">
              <el-input
                v-model="upDataObj.targetMemberCode"
                clearable
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="接入姓名">
              <el-input
                v-model="upDataObj.targetMemberName"
                clearable
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div class="disFlex">
        <el-button
          size="small"
          class="addBtn"
          @click="toAddObj"
        >新增</el-button>
        <el-button
          size="small"
          class="addBtn"
          @click="changeAllData1"
        >批量操作</el-button>
      </div>
      <el-table
        :data="upDataObj.cuMemberSwingNetDetailExtList"
        style="width: 100%"
        :header-cell-style="{ background: '#EEEEEE' }"
        :row-class-name="tableRowClassName"
        @selection-change="handleSelectionChange"
      >
        <el-table-column align="center" prop="memberCode" label="会员编号" />
        <el-table-column align="center" prop="memberName" label="会员姓名" />
        <el-table-column
          align="center"
          prop="firstAchieveRatio"
          label="接入部门"
        >
          <template slot="header" slot-scope="scope">
            <div>接入部门</div>
            <el-select v-model="changeData.placeDept" clearable placeholder="">
              <el-option
                v-for="item in deptList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </template>
          <template slot-scope="scope">
            <el-select v-model="scope.row.placeDept" clearable placeholder="">
              <el-option
                v-for="item in deptList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="firstAchieveRatio"
          label="首购上传比例"
        >
          <template slot="header" slot-scope="scope">
            <div>首购上传比例</div>
            <el-input
              v-model="changeData.firstAchieveRatio"
              clearable
            />
          </template>
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.firstAchieveRatio"
              clearable
            />
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="repurchaseAchieveRatio"
          label="复购上传比例"
        >
          <template slot="header" slot-scope="scope">
            <div>复购上传比例</div>
            <el-input
              v-model="changeData.repurchaseAchieveRatio"
              clearable
            />
          </template>
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.repurchaseAchieveRatio"
              clearable
            />
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="firstCalculate"
          label="首购奖金达标业绩"
        >
          <template slot="header" slot-scope="scope">
            <div>首购奖金达标业绩</div>
            <!-- <el-select v-model="changeData.firstCalculate"
                       :placeholder="'请选择'">
              <el-option v-for="item in yesNo"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select> -->
            <el-input v-model="changeData.firstReachPoint" clearable />
          </template>
          <template slot-scope="scope">
            <!-- <el-select v-model="scope.row.firstCalculate"
                       :placeholder="'请选择'">
              <el-option v-for="item in yesNo"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select> -->
            <el-input v-model="scope.row.firstReachPoint" clearable />
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="repurchaseAchieveRatio"
          label="复购奖金达标业绩"
        >
          <template slot="header" slot-scope="scope">
            <div>复购奖金达标业绩</div>
            <!-- <el-select v-model="changeData.repurchaseAchieveRatio"
                       :placeholder="'请选择'">
              <el-option v-for="item in yesNo"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select> -->
            <el-input
              v-model="changeData.repurchaseReachPoint"
              clearable
            />
          </template>
          <template slot-scope="scope">
            <!-- <el-select v-model="scope.row.repurchaseCalculate"
                       :placeholder="'请选择'">
              <el-option v-for="item in yesNo"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select> -->
            <el-input
              v-model="scope.row.repurchaseReachPoint"
              clearable
            />
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="repurchaseAchieveRatio"
          label="操作"
        >
          <template slot-scope="scope">
            <div
              style="color: #c8161d; font-size: 12px; cursor: pointer"
              @click="delRow(scope.$index)"
            >
              删除
            </div>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleCloseUp">{{ '取消' }}</el-button>
        <el-button type="primary" @click="sureUp">{{
          '确认'
        }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import * as api from '@/api/specialBusiness.js'
export default {
  name: 'Bzpz',
  components: {
    topBar
  },
  data() {
    return {
      isAdd: false,
      changeData: {},
      addCode: false,
      addData: false,
      addList: false,
      addUp: false,
      selectRow: [],
      rules: {
        sourceMemberCode: [
          { required: true, validator: this.getName1, trigger: 'blur' }
        ],
        targetMemberCode: [
          { required: true, validator: this.getName2, trigger: 'blur' }
        ]
      },
      digTable: [],
      form: {},
      select: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      addOrEdit: '',
      total: 0,
      dialogVisible: false,
      tableData: [],
      loading: false,
      yesNo: [],
      moren: 'accessCode',
      topList: [
        {
          name: '空单注册',
          path: 'emptyOrder',
          changed: false
        },
        {
          name: '修改直推',
          path: 'modifyDirectpush',
          changed: false
        },
        {
          name: '修改安置',
          path: 'modifyPlacement',
          changed: false
        },
        {
          name: '注水业绩',
          path: 'waterPv',
          changed: false
        },
        {
          name: '修改编号',
          path: 'modifyCode',
          changed: false
        },
        {
          name: '真实奖衔控制',
          path: 'awardControl',
          changed: false
        },
        {
          name: '修改结算国家',
          path: 'modifySettleCountry',
          changed: false
        },
        {
          name: '政策币业务',
          path: 'policyMoney',
          changed: false
        },
        {
          name: '分红配置',
          path: 'bonusConfig',
          changed: false
        },
        {
          name: '甩网配置',
          path: 'accessCode',
          changed: false
        }
      ],
      colSpanArr: [],
      rowIndexArr: [],
      selectData: '',
      upDataObj: {},
      deptList: [],
      creationTime: []
    }
  },
  mounted() {
    // 获取列表
    this.getDataList()
    this.getData()
  },
  methods: {
    goodsDetails(row) {
      this.$router.push({
        path: 'accessCodeDetails',
        query: {
          data: row.pkId
        }
      })
    },
    changeAllData() {
      this.digTable.forEach((item) => {
        if (
          this.changeData.firstAchieveRatio ||
          this.changeData.firstAchieveRatio == 0
        ) {
          item.firstAchieveRatio = this.changeData.firstAchieveRatio
        }
        if (
          this.changeData.repurchaseAchieveRatio ||
          this.changeData.repurchaseAchieveRatio == 0
        ) {
          item.repurchaseAchieveRatio = this.changeData.repurchaseAchieveRatio
        }
        if (
          this.changeData.firstReachPoint ||
          this.changeData.firstReachPoint == 0
        ) {
          item.firstReachPoint = this.changeData.firstReachPoint
        }
        if (
          this.changeData.repurchaseReachPoint ||
          this.changeData.repurchaseReachPoint == 0
        ) {
          item.repurchaseReachPoint = this.changeData.repurchaseReachPoint
        }
        this.$set(item, 'placeDept', this.changeData.placeDept)
      })
    },
    changeAllData1() {
      this.upDataObj.cuMemberSwingNetDetailExtList.forEach((item) => {
        if (
          this.changeData.firstAchieveRatio ||
          this.changeData.firstAchieveRatio == 0
        ) {
          item.firstAchieveRatio = this.changeData.firstAchieveRatio
        }
        if (
          this.changeData.repurchaseAchieveRatio ||
          this.changeData.repurchaseAchieveRatio == 0
        ) {
          item.repurchaseAchieveRatio = this.changeData.repurchaseAchieveRatio
        }
        if (
          this.changeData.firstReachPoint ||
          this.changeData.firstReachPoint == 0
        ) {
          item.firstReachPoint = this.changeData.firstReachPoint
        }
        if (
          this.changeData.repurchaseReachPoint ||
          this.changeData.repurchaseReachPoint == 0
        ) {
          item.repurchaseReachPoint = this.changeData.repurchaseReachPoint
        }
        this.$set(item, 'placeDept', this.changeData.placeDept)
      })
    },
    toAddObj() {
      console.log(
        'toAddObj',
        this.upDataObj.targetMemberCode,
        this.form.targetMemberCode
      )
      api
        .queryMemberParent({
          memberCode: this.upDataObj.targetMemberCode
        })
        .then((res) => {
          if (res.code == 200) {
            this.digTable = res.data
          }
        })
      this.addList = true
      // this.upDataObj.cuMemberSwingNetDetailExtList.push({
      //   firstAchieveRatio: '',
      //   firstCalculate: 0,
      //   memberCode: '',
      //   memberName: '',
      //   repurchaseAchieveRatio: '',
      //   repurchaseCalculate: 0,
      // })
    },
    toAddObj1() {
      console.log(123)
      api
        .queryMemberParent({
          memberCode: this.form.targetMemberCode
        })
        .then((res) => {
          if (res.code == 200) {
            this.digTable = res.data
          }
        })
      this.addList = true
    },
    delRow(index) {
      this.upDataObj.cuMemberSwingNetDetailExtList.splice(index, 1)
    },
    getData() {
      api.getEYesNoList().then((res) => {
        this.yesNo = res.data
      })
      api.getPlacedeptList().then((res) => {
        this.deptList = res.data
      })
    },
    changeTime(val) {
      this.select.startCreationTime = val ? val[0] : ''
      this.select.endCreationTime = val ? val[1] : ''
    },
    getName1(rule, value, callback) {
      if (!value) {
        callback(new Error('请输入联系电话'))
      } else {
        api
          .queryMember({
            memberCode: value
          })
          .then((res) => {
            if (res.code == 200) {
              this.$set(this.form, 'sourceMemberName', res.data.memberName)
              this.$set(this.form, 'pkSourceMember', res.data.pkId)
              callback()
            } else {
              callback(new Error(res.msg))
            }
          })
      }
    },
    getName2(rule, value, callback) {
      if (!value) {
        callback(new Error('请输入联系电话'))
      } else {
        api
          .queryMember({
            memberCode: value
          })
          .then((res) => {
            if (res.code == 200) {
              this.$set(this.form, 'targetMemberName', res.data.memberName)
              this.$set(this.form, 'pkTargetMember', res.data.pkId)
              callback()
            } else {
              callback(new Error(res.msg))
            }
          })
      }
    },
    reset() {
      this.select = {}
      this.creationTime = []
      this.getDataList()
    },
    // 点击修改
    toFixed(id) {
      this.$router.push({
        path: 'missionDetails',
        query: {
          pkId: id
        }
      })
    },

    handleClose() {
      this.dialogVisible = false
      this.$refs['form'].clearValidate()
      this.$refs['form'].resetFields()
    },
    deleteTable() {
      const pkId = this.selectData.pkId
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        api.deleteNet(pkId).then((res) => {
          this.getDataList()
        })
      })
    },
    openDig() {
      this.isAdd = true
      this.addCode = true
    },

    handleCloseUp() {
      this.changeData = {}
      this.addUp = false
    },
    handleCloseCode() {
      this.addCode = false
    },
    handleCloseList() {
      this.addList = false
    },
    handleCloseData() {
      this.changeData = {}
      this.addData = false
    },
    handleSelectList(row) {
      this.selectRow = row
    },
    // 选择会员确认
    sureList() {
      if (this.selectRow.length > 0) {
        if (this.isAdd) {
          this.addData = true
          this.addList = false
        } else {
          this.upDataObj.cuMemberSwingNetDetailExtList.forEach(
            (item, index) => {
              this.selectRow = this.selectRow.filter((ctem) => {
                return ctem.memberCode != item.memberCode
              })
            }
          )
          this.selectRow.forEach((item) => {
            this.upDataObj.cuMemberSwingNetDetailExtList.push({
              firstAchieveRatio: 0,
              firstReachPoint: 0,
              pkMember: item.pkId,
              memberCode: item.memberCode,
              memberName: item.memberName,
              repurchaseAchieveRatio: 0,
              repurchaseReachPoint: 0,
              placeDept: 1
            })
          })
          this.addList = false
        }
      } else {
        this.$message({
          message: '请选择',
          type: 'warning'
        })
      }
    },
    // 修改
    sureUp() {
      api.saveNet(this.upDataObj).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: res.msg,
            type: 'success'
          })
          this.addUp = false
          this.getDataList()
        }
      })
    },
    // 提交确认
    sureData() {
      const arr = []
      this.selectRow.forEach((item) => {
        arr.push({
          pkMember: item.pkId,
          firstAchieveRatio: item.firstAchieveRatio,
          repurchaseAchieveRatio: item.repurchaseAchieveRatio,
          firstReachPoint: item.firstReachPoint,
          repurchaseReachPoint: item.repurchaseReachPoint,
          placeDept: item.placeDept
        })
      })
      api
        .saveNet(
          Object.assign({}, this.form, { cuMemberSwingNetDetailExtList: arr })
        )
        .then((res) => {
          if (res.code == 200) {
            this.$message({
              message: res.msg,
              type: 'success'
            })
            this.addData = false
            this.getDataList()
          }
        })
    },
    // 输入编号query
    sureCode() {
      api
        .queryMemberParent({
          memberCode: this.form.targetMemberCode
        })
        .then((res) => {
          if (res.code == 200) {
            this.digTable = res.data
          }
        })
      // this.addData = true
      this.addList = true
      this.addCode = false
    },
    // 修改弹框
    fixedData() {
      const pkId = this.selectData.pkId
      api.queryNet({ pkId: pkId }).then((res) => {
        this.upDataObj = res.rows[0]
        this.addUp = true
        this.isAdd = false
      })
    },
    getDataList() {
      this.loading = true
      api
        .queryNet(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.loading = false
          this.tableData = res.rows
          this.total = res.total
        })
    },
    onSelectAll() {
      this.$refs.multipleTable.clearSelection()
    },
    selected(selection, row) {
      this.selectData = selection[0] || ''
      // 清除 所有勾选项
      this.$refs.multipleTable.clearSelection()
      if (selection.length == 0) return
      this.$refs.multipleTable.toggleRowSelection(row, true)
    },
    handleSelectionChange(val) {},
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((_) => {
        this.download(
          '/system/manage/ho-enterprise-mission/export',
          Object.assign({}, this.queryParams, this.select),
          `${'企业使命'}${new Date().getTime()}.xlsx`
        )
      })
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return 'warning-row'
      } else if (rowIndex % 2 == 0) {
        return 'success-row'
      }
      return ''
    }
  }
}
</script>
<style scoped lang="scss">
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-select {
  width: 100%;
}
.uploadIcon ::v-deep .el-upload--picture-card {
  display: none !important; /* 上传按钮隐藏 */
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    .form_all {
      padding: 0px 20px 0 20px;
      // margin-bottom: 20px;
      background: #fff;
      border-radius: 8px;
    }
    .maintop {
      display: flex;
      padding: 0px 0px;
      justify-content: space-between;
      align-items: center;

      background: #f8f8f8;
      .mainbtn {
        .thebtn1 {
          background: #3181e5;
          color: #ffffff;
        }
        .thebtn2 {
          background: #ffad41;
          color: #ffffff;
        }
      }
      .maintitle {
        font-size: 10px;
        font-family: MicrosoftYaHei;
        color: #999999;
      }
    }
  }
  .tem {
    display: flex;
    align-items: center;
    justify-content: center;
    img {
      width: 28px;
      height: 20px;
      margin-right: 3px;
    }
  }
  .isRed {
    color: #ed1d25;
  }
  .isGreen {
    color: #1ab62b;
  }
  .bgImg {
    width: 48px;
    height: 48px;
  }
}
.openClose {
  text-align: right;
  margin-right: 10px;
  color: #3181e5;
}
.dizhi {
  ::v-deep .el-cascader {
    width: 100%;
  }
}
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: auto;
}
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: auto;
}
.form_all ::v-deep .el-input__suffix {
  top: 0px !important;
}
.form_all ::v-deep .el-select .el-input .el-select__caret.is-reverse {
  transform: translateY(0px) !important;
}
::v-deep .el-input__suffix {
  top: -3px;
}
::v-deep .el-select .el-input__suffix {
  top: 5px;
}
::v-deep .el-select .el-input .el-select__caret.is-reverse {
  transform: translateY(-8px);
}
::v-deep .el-cascader .el-input__suffix {
  top: 0px;
}
::v-deep .el-input__clear {
  margin-bottom: 20px !important;
}
.disFlex {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.allTab {
  max-height: 600px;
  overflow-y: auto;
}
</style>
