<template>
  <div id="examArrangement">
    <table-list
      :tableSets="tableSet"
      :tableData="tableData"
      :navText="navText"
      @addClick="addClick"
      :loading="loading"
      @editInfo="editInfo"
    >
      <template slot="customize">
        <el-button size="medium" type="warning" @click="setExamAdress"
          >配置考试地点</el-button
        >
      </template>
      <template slot="btn" slot-scope="props">
        <el-button
          type="text"
          @click="beforeFunc(props.scope.row)"
          >前培设置</el-button
        >
        <el-button
          type="text"
          @click="addClick(props.scope.row, 0)"
          :disabled="props.scope.row.status === 1"
          >修改计划</el-button
        >
        <el-button
          type="text"
          @click="setExams(props.scope.row, 1)"
          :disabled="props.scope.row.status === 1"
          >考点设置</el-button
        >
        <el-button
          type="text"
          @click="setExams(props.scope.row, 2)"
          :disabled="props.scope.row.status === 1"
          >考培设置</el-button
        >
        <el-button
          type="text"
          @click="editGoods(props.scope.row)"
          :disabled="props.scope.row.status === 1"
          >适用商品</el-button
        >
        <el-button type="text" @click="watchs(props.scope.row)">预览</el-button>
        <el-button
          type="text"
          @click="del(props.scope.row, 1)"
          v-if="props.scope.row.status === 0"
          >启用</el-button
        >
        <el-button
          type="text"
          @click="del(props.scope.row, 2)"
          v-if="props.scope.row.status === 1"
          >关闭</el-button
        >
        <el-button type="text" @click="del(props.scope.row, 3)">删除</el-button>
      </template>
    </table-list>
    <pagination
      :total="total"
      :pageSize="pageSize"
      :currentPage="currentPage"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    />
    <el-dialog
      @closed="loadingClose"
      :visible.sync="dialogVisible"
      width="610px"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <div slot="title" class="hearders">
        <div class="leftTitle">
          {{ statusPop === 1 ? "添加" : statusPop === 0 ? "修改" : "详情" }}
        </div>
        <div class="rightBoxs">
          <img src="@/assets/images/Close@2x.png" alt="" @click="close" />
        </div>
      </div>
      <div>
        <el-form
          label-position="right"
          label-width="150px"
          :model="listData"
          :rules="rules"
          ref="listData"
        >
          <el-form-item label="考试封面" prop="applyUrl">
            <div class="dis_fs">
              <img
                class="imgBoxs"
                :src="$methodsTools.splitImgHost(listData.applyUrl)"
                alt="加载失败"
              />
              <label class="btns"
                >修改封面
                <input
                  ref="file"
                  type="file"
                  style="display: none"
                  @change="editImg"
                />
              </label>
            </div>
            <div
              style="
                font-size: 12px;
                color: #999;
                line-height: 20px;
                margin-top: 10px;
              "
            >
              注：请上传小于300kb，尺寸为1920*930的像素图片，支持gif、jpg、jpeg、png等类型
            </div>
          </el-form-item>
          <el-form-item label="考试标题" prop="applyName">
            <el-input
              :disabled="statusPop === 2"
              v-model="listData.applyName"
            ></el-input>
          </el-form-item>
          <el-form-item label="考试简介" prop="applyIntroduce">
            <el-input
              type="textarea"
              :rows="4"
              :disabled="statusPop === 2"
              v-model="listData.applyIntroduce"
            ></el-input>
          </el-form-item>
          <el-form-item label="可报学员" prop="applyStatus">
            <el-checkbox-group
              v-model="listData.applyStatus"
              style="width: 60%; display: inline-block"
            >
              <el-checkbox :label="1">非补考学员</el-checkbox>
              <el-checkbox :label="2">补考学员</el-checkbox>
            </el-checkbox-group>
            <span style="font-size: 12px; color: #999">注：可多选</span>
          </el-form-item>
          <el-form-item label="报名开放时间" required>
            <el-col :span="11">
              <el-form-item prop="applyStartTime">
                <el-date-picker
                  type="datetime"
                  placeholder="开始日期"
                  @change="changeEndTime(1)"
                  v-model="listData.applyStartTime"
                  style="width: 100%"
                  value-format="timestamp"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col class="line" style="text-align: center" :span="2">-</el-col>
            <el-col :span="11">
              <el-form-item prop="applyEndTime">
                <el-date-picker
                  type="datetime"
                  placeholder="结束日期"
                  @change="changeEndTime(2)"
                  v-model="listData.applyEndTime"
                  style="width: 100%"
                  value-format="timestamp"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button
          type="primary"
          :loading="disabledBtn"
          v-if="statusPop !== 2"
          @click="submit('listData')"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      @closed="loadingClose"
      :visible.sync="dialogExamBoxs"
      width="620px"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <div slot="title" class="hearders">
        <div class="leftTitle">
          {{
            intStatus === 1
              ? "设置考试地点"
              : intStatus === 2
              ? "设置考培地点"
              : "未知"
          }}
        </div>
        <div class="rightBoxs">
          <img
            src="@/assets/images/Close@2x.png"
            alt=""
            @click="dialogExamBoxs = false"
          />
        </div>
      </div>
      <div>
        <el-button type="text" @click="openExamPlace">{{
          intStatus === 1
            ? "添加考试地点"
            : intStatus === 2
            ? "添加考前培训地点"
            : "未知"
        }}</el-button>
        <div
          v-for="(item, index) in examPlaces"
          :key="index"
          style="margin-bottom: 10px"
        >
          <div class="dis_fs">
            <div class="bors">
              {{ item.siteAddress }}
              <i
                class="el-icon-error"
                style="
                  color: #f56c6c;
                  font-size: 14px;
                  margin: 0px 6px;
                  cursor: pointer;
                "
                @click="examPlaces.splice(index, 1)"
              ></i>
            </div>
            <el-button
              style="margin-left: 10px"
              type="text"
              size="mini"
              @click="
                item.examApplySiteTime.push({
                  examTime: '',
                  examApplySiteTimeTwo: [{}],
                })
              "
              >{{
                intStatus === 1
                  ? "添加考试时间"
                  : intStatus === 2
                  ? "添加考培时间"
                  : "未知"
              }}</el-button
            >
          </div>
          <div
            v-for="(items, indexs) in item.examApplySiteTime"
            :key="indexs"
            class="dis_fs"
          >
            <div class="mar_bgc">
              <div class="dis_fs jbtw">
                <el-date-picker
                  size="mini"
                  v-model="items.examTime"
                  type="date"
                  placeholder="选择日期"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="timestamp"
                >
                </el-date-picker>
                <el-button
                  size="mini"
                  type="text"
                  @click="items.examApplySiteTimeTwo.push({})"
                  >添加时间点</el-button
                >
              </div>
              <ul>
                <li
                  class="dis_fs"
                  style="margin-bottom: 6px"
                  v-for="(its, ids) in items.examApplySiteTimeTwo"
                  :key="ids"
                >
                  <div class="dis_fs">
                    <el-time-picker
                      style="width: 130px"
                      size="mini"
                      v-model="its.startTime"
                      format="HH:mm"
                      value-format="HH:mm"
                      placeholder="开始时间"
                      @change="
                        its.endTime && its.startTime > its.endTime
                          ? (its.startTime = '')
                          : ''
                      "
                    >
                    </el-time-picker
                    ><span style="margin: 0px 10px">至</span>
                    <el-time-picker
                      style="width: 130px"
                      size="mini"
                      v-model="its.endTime"
                      format="HH:mm"
                      value-format="HH:mm"
                      placeholder="结束时间"
                      @change="
                        its.startTime && its.endTime < its.startTime
                          ? (its.endTime = '')
                          : ''
                      "
                    >
                    </el-time-picker>
                  </div>
                  <div style="margin-left: 14px">
                    人数上限：<el-input-number
                      style="width: 60px"
                      :precision="0"
                      size="mini"
                      :min="1"
                      :max="item.people"
                      v-model="its.num"
                      :controls="false"
                    ></el-input-number
                    ><el-button
                      style="margin-left: 6px"
                      type="text"
                      size="mini"
                      @click="items.examApplySiteTimeTwo.splice(ids, 1)"
                      >删除</el-button
                    >
                  </div>
                </li>
              </ul>
            </div>
            <div style="width: 10%; text-align: center; align-self: start">
              <el-button
                type="text"
                @click="item.examApplySiteTime.splice(indexs, 1)"
                >删除</el-button
              >
            </div>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogExamBoxs = false">取 消</el-button>
        <el-button
          type="primary"
          v-if="statusPop !== 2"
          :loading="disabledBtn"
          @click="submitPla('listData')"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      @closed="loadingClose"
      :visible.sync="dialogExamPlace"
      width="860px"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <div slot="title" class="hearders">
        <div class="leftTitle">考试地点列表</div>
        <div class="rightBoxs">
          <img
            src="@/assets/images/Close@2x.png"
            alt=""
            @click="dialogExamPlace = false"
          />
        </div>
      </div>
      <div>
        <el-table
          ref="multipleTable2"
          :data="boxtableData2"
          border
          @select-all="selectAll2"
          @select="select2"
          :row-key="getRowKeys2"
          :header-cell-style="{
            'background-color': '#eee',
            padding: '8px',
            color: '#333',
          }"
        >
          <el-table-column
            align="center"
            type="selection"
            width="55"
            header-align="center"
            :selectable="checkboxT2"
            :reserve-selection="true"
          >
          </el-table-column>
          <template v-for="(item, index) in tableSetTSBBOX2">
            <el-table-column
              v-if="item.scope !== 'inputs'"
              :width="item.width"
              :key="index"
              :label="item.label"
              align="center"
              :show-overflow-tooltip="true"
              header-align="center"
            >
              <template slot-scope="scope">
                <span v-if="item.scope === 'status'">
                  {{ scope.row[item.prop] === 1 ? "启用" : "关闭" }}
                </span>
                <span v-else>{{ scope.row[item.prop] }}</span></template
              >
            </el-table-column></template
          >
        </el-table>
        <pagination
          :total="total2"
          :pageSize="pageSize2"
          :currentPage="currentPage2"
          @handleSizeChange="handleSizeChange2"
          @handleCurrentChange="handleCurrentChange2"
        />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogExamPlace = false">取 消</el-button>
        <el-button
          type="primary"
          v-if="statusPop !== 2"
          @click="submitPlaces"
          :loading="disabledBtn"
          :disabled="!activeLists.length"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      :visible.sync="dialoginfoWatch"
      width="900px"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <div slot="title" class="hearders">
        <div class="leftTitle">【{{ infoData.applyName }}】预览</div>
        <div class="rightBoxs">
          <img
            src="@/assets/images/Close@2x.png"
            alt=""
            @click="dialoginfoWatch = false"
          />
        </div>
      </div>
      <div>
        <el-form :model="infoData" class="demo-form-inline" label-width="130px">
          <el-row :gutter="20">
            <el-col :span="12" style="border-right: 1px solid #999">
              <el-button type="info" style="margin-bottom: 20px" size="mini"
                >考试计划信息</el-button
              >
              <el-form-item label="考试封面：">
                <div class="imgBoxWatch">
                  <img
                    :src="$methodsTools.splitImgHost(infoData.applyUrl)"
                    alt="加载失败"
                  />
                </div>
              </el-form-item>
              <el-form-item label="考试标题：">
                <span>{{ infoData.applyName }}</span>
              </el-form-item>
              <el-form-item label="考试简介：">
                <span>{{ infoData.applyIntroduce }}</span>
              </el-form-item>
              <el-form-item label="报考学员：">
                <span v-for="(item, index) in infoData.applyStatus" :key="index"
                  >{{ item === 1 ? "非补考学员" : item === 2 ? "补考学员" : ""
                  }}{{
                    index === infoData.applyStatus.length - 1 ? "" : "、"
                  }}</span
                >
              </el-form-item>
              <el-form-item label="报名开放时间：">
                <span>{{
                  $methodsTools.onlyForma(infoData.applyStartTime)
                }}</span>
                至
                <span>{{
                  $methodsTools.onlyForma(infoData.applyEndTime)
                }}</span>
              </el-form-item>
              <el-form-item label="考试地点和时间：">
                <div
                  v-for="(item, index) in infoData.examApplySite"
                  :key="index"
                >
                  <span>{{ item.siteAddress }}({{ item.people }})</span>
                  <div
                    v-for="(items, indexs) in item.examApplySiteTime"
                    :key="indexs"
                    style="
                      margin-bottom: 10px;
                      background-color: #eee;
                      padding: 0px 10px;
                    "
                  >
                    <div
                      v-for="(itemsxs, indexsx) in items.siteTime"
                      :key="indexsx"
                    >
                      {{ $methodsTools.onlyForma(items.examTime, false) }}
                      {{ itemsxs.startTime }}-{{
                        itemsxs.endTime
                      }}
                      (人数上限：{{ itemsxs.num }})
                    </div>
                  </div>
                </div>
              </el-form-item>
              <el-form-item label="考培地点和时间：">
                <div
                  v-for="(item, index) in infoData.examApplySiteTrain"
                  :key="index"
                >
                  <span>{{ item.siteAddress }}({{ item.people }})</span>
                  <div
                    v-for="(items, indexs) in item.examApplySiteTime"
                    :key="indexs"
                    style="
                      margin-bottom: 10px;
                      background-color: #eee;
                      padding: 0px 10px;
                    "
                  >
                    <div
                      v-for="(itemsxs, indexsx) in items.siteTime"
                      :key="indexsx"
                    >
                      {{ $methodsTools.onlyForma(items.examTime, false) }}
                      {{ itemsxs.startTime }}-{{
                        itemsxs.endTime
                      }}
                      (人数上限：{{ itemsxs.num }})
                    </div>
                  </div>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-button type="info" style="margin-bottom: 20px" size="mini"
                >适用商品</el-button
              >
              <el-form-item label="商品类型：">
                <span v-for="(item, index) in $methodsTools.getGoodsType()" :key="index">{{
                  item.value === infoData.goodsType ? item.label : ""
                }}</span>
              </el-form-item>
              <el-form-item label="业务层级：">
                <span
                  >{{ infoData.educationName }}-{{ infoData.projectName }}-{{
                    infoData.businessName
                  }}</span
                >
              </el-form-item>
              <el-form-item label="适用商品：">
                <div
                  v-for="(item, index) in infoData.examNumberGoods"
                  :key="index"
                >
                  {{ index + 1 }}.{{ item.code }}-{{ item.goodsName }}-<span
                    style="color: #f56c6c"
                    >￥{{ item.standPrice }}</span
                  >
                </div>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialoginfoWatch = false">取 消</el-button>
      </span>
    </el-dialog>
    <before-page ref="beforePage" />
    <applicable-products ref="applicableProducts" />
  </div>
</template>

<script>
import searchBox from "@/components/searchBox";
import tableList from "@/components/tableList";
import pagination from "@/components/pagination";
import applicableProducts from "./applicableProducts/index.vue";
import beforePage from './applicableProducts/beforePage.vue';
export default {
  name: "ExamArrangement",
  components: { searchBox, tableList, pagination, applicableProducts, beforePage },
  data() {
    return {
      disabledBtn: false,
      total2: 0,
      pageSize2: 10,
      currentPage2: 1,
      loading: false, //当前表单加载是否加载动画
      navText: {
        title: "考试安排",
        index: 0,
        ch: "条",
        num: true,
        changeWidth: "300px",
        choice: true,
        border: true,
        addHide: false,
        backFatherBtn: {
          status: false,
          title: "未定义",
        },
      },
      // 表单
      tableSet: [
        {
          label: "考试编码",
          prop: "code",
          hidden: true,
        },
        {
          label: "考试标题",
          prop: "applyName",
          hidden: true,
        },
        {
          label: "可报学员",
          prop: "applyStatus",
          hidden: true,
          scope: "morePeople",
        },
        {
          label: "报名开放时间",
          prop1: "applyStartTime",
          prop2: "applyEndTime",
          hidden: true,
          scope: "TimeLists",
          Diszing: false,
        },
        {
          label: "预约/取消(人次)",
          prop: "people",
          prop1: "cancelPeople",
          hidden: true,
          scope: "jumpPeolpe",
          type: 1,
          width: "140px",
        },
      ],
      tableData: [], //表单数据
      total: 0, //一共多少条
      pageSize: 10, //每页多少条数据
      currentPage: 1, //当前页码
      //   弹窗数据
      listData: {
        applyStatus: [],
      },
      statusPop: -1,
      dialogVisible: false,
      //表单验证
      rules: {
        applyUrl: [
          {
            required: true,
            message: "请上传考试封面",
            trigger: "change",
          },
        ],
        applyName: [
          { required: true, message: "请输入考试安排", trigger: "blur" },
        ],
        applyStatus: [
          {
            type: "array",
            required: true,
            message: "请至少选择一个可报学员",
            trigger: "change",
          },
        ],
        applyStartTime: [
          {
            type: "date",
            required: true,
            message: "请选择报名开始时间",
            trigger: "change",
          },
        ],
        applyEndTime: [
          {
            type: "date",
            required: true,
            message: "请选择报名结束时间",
            trigger: "change",
          },
        ],
      },
      dialogExamBoxs: false, //考点
      dialogExamPlace: false, //考试地点列表
      dialogVisiblenew: false,
      examPlaces: [],
      activeLists: [], //当前选中地点
      boxtableData2: [],
      newOpenId: "",
      intStatus: 0, //1考试地点2考培地点
      tableSetTSBBOX2: [
        {
          label: "考试地点编码",
          prop: "code",
          hidden: true,
        },
        {
          label: "考试地点",
          prop: "siteAddress",
          hidden: true,
        },
        {
          label: "同时间可容纳人数",
          prop: "people",
          hidden: true,
        },
        {
          label: "状态",
          prop: "status",
          hidden: true,
          scope: "status",
        },
      ],
      options: [
        {
          label: "视频",
          value: 1,
        },
        {
          label: "题库",
          value: 2,
        },
        {
          label: "补考",
          value: 3,
        },
        {
          label: "前培",
          value: 4,
        },
      ],
      dialoginfoWatch: false,
      infoData: {
        applyStatus: [],
      },
    };
  },
  mounted() {
    this.search();
    this.getExamPlace();
  },
  activated() {
    this.search();
    this.getExamPlace();
  },
  methods: {
    /**
     * 前培设置
     */
    beforeFunc(row){
      this.$refs.beforePage.openBox(row)
    },
    setExamAdress() {
      this.$router.push({
        path: "examPlace",
      });
    },
    loadingClose() {
      this.disabledBtn = false;
    },
    //修改适用商品
    editGoods(row) {
      this.$refs.applicableProducts.openBox(row);
    },
    submitPla() {
      var data = JSON.parse(JSON.stringify(this.examPlaces));
      if (!data.length) {
        if (this.intStatus === 1) {
          this.$message.warning("请添加考试地点");
          return;
        }
        if (this.intStatus === 2) {
          this.$message.warning("请添加考培地点");
          return;
        }
      }
      for (let i = 0; i < data.length; i++) {
        if (this.intStatus === 1) {
          data[i].status = 1;
        }
        if (this.intStatus === 2) {
          data[i].status = 2;
        }
        if (!data[i].examApplySiteTime.length) {
          if (this.intStatus === 1) {
            this.$message.warning("您还有考试日期没有设置考试时间点，请先设置");
            return;
          }
          if (this.intStatus === 2) {
            this.$message.warning("您还有考培日期没有设置考培时间点，请先设置");
            return;
          }
        } else {
          for (let j = 0; j < data[i].examApplySiteTime.length; j++) {
            if (!data[i].examApplySiteTime[j].examTime) {
              if (this.intStatus === 1) {
                this.$message.warning("您还有考试日期没有设置，请先设置");
              }
              if (this.intStatus === 2) {
                this.$message.warning("您还有考培日期没有设置，请先设置");
              }
              return;
            } else {
              data[i].examApplySiteTime[j].examTime =
                this.$methodsTools.time10to13(
                  data[i].examApplySiteTime[j].examTime,
                  1
                );
            }
            if (!data[i].examApplySiteTime[j].examApplySiteTimeTwo.length) {
              if (this.intStatus === 1) {
                this.$message.warning("您还有考试时间点没有设置，请先设置");
              }
              if (this.intStatus === 2) {
                this.$message.warning("您还有考培时间点没有设置，请先设置");
              }
              return;
            } else {
              for (
                let k = 0;
                k < data[i].examApplySiteTime[j].examApplySiteTimeTwo.length;
                k++
              ) {
                if (
                  !data[i].examApplySiteTime[j].examApplySiteTimeTwo[k]
                    .startTime
                ) {
                  this.$message.warning("您还有开始时间没有设置，请先设置");
                  return;
                }
                if (
                  !data[i].examApplySiteTime[j].examApplySiteTimeTwo[k].endTime
                ) {
                  this.$message.warning("您还有结束时间没有设置，请先设置");
                  return;
                }
                if (!data[i].examApplySiteTime[j].examApplySiteTimeTwo[k].num) {
                  this.$message.warning("您还有人数上限没有设置，请先设置");
                  return;
                }
              }
              const stsTime1 = data[i].examApplySiteTime[
                j
              ].examApplySiteTimeTwo.map(
                (val) => val.startTime + "-" + val.endTime
              );
              const idsSet1 = new Set(stsTime1);
              if (idsSet1.size == stsTime1.length) {
              } else {
                if (this.intStatus === 1) {
                  this.$message.warning(
                    "同一考试日期下的时间点，出现重复，请修改"
                  );
                }
                if (this.intStatus === 2) {
                  this.$message.warning(
                    "同一考培日期下的时间点，出现重复，请修改"
                  );
                }
                return;
              }
            }
          }
          const stsTime = data[i].examApplySiteTime.map((val) => val.examTime);
          const idsSet = new Set(stsTime);
          if (idsSet.size == stsTime.length) {
          } else {
            if (this.intStatus === 1) {
              this.$message.warning(
                "同一考试地点下的考试日期，出现重复，请修改"
              );
            }
            if (this.intStatus === 2) {
              this.$message.warning(
                "同一考培地点下的考培日期，出现重复，请修改"
              );
            }
            return;
          }
        }
      }
      this.disabledBtn = true;
      this.$api
        .systemapplyaddSite(data)
        .then((res) => {
          if (this.intStatus === 1) {
            this.$message.success("设置考试地点时间成功");
          }
          if (this.intStatus === 2) {
            this.$message.success("设置考培地点时间成功");
          }
          this.dialogExamBoxs = false;
          this.search();
        })
        .catch(() => {
          this.disabledBtn = false;
        });
    },
    //添加考点地点
    submitPlaces() {
      this.disabledBtn = true;
      let array = [];
      this.activeLists.forEach((item) => {
        array.push({
          applyId: this.newOpenId,
          siteId: item.siteId,
          siteAddress: item.siteAddress,
          people: item.people,
          examApplySiteTime: [{ examTime: "", examApplySiteTimeTwo: [{}] }],
        });
      });
      this.examPlaces = this.examPlaces.concat(array);
      this.dialogExamPlace = false;
    },
    getExamPlace() {
      var data = {
        status: 1,
        pageSize: this.pageSize2,
        pageNum: this.currentPage2,
      };
      this.$api.inquiresystemsite(data).then((res) => {
        this.boxtableData2 = res.rows;
        this.total2 = res.total;
      });
    },
    openExamPlace() {
      this.activeListExamPlace = [];
      this.examPlaces.forEach((item) => {
        this.activeListExamPlace.push(item.siteId);
      });
      this.dialogExamPlace = true;
      this.$nextTick(function () {
        this.activeLists = [];
        this.$refs.multipleTable2.clearSelection();
      });
    },
    //设置考点
    setExams(row, int) {
      this.intStatus = int;
      this.newOpenId = row.applyId;
      this.$api
        .inquirepayservesiteInfo({ addressStatus: int, applyId: row.applyId })
        .then((res) => {
          res.rows.forEach((item) => {
            item.examApplySiteTime.forEach((items) => {
              items.examTime = this.$methodsTools.time10to13(items.examTime, 2);
              items.examApplySiteTimeTwo = JSON.parse(items.siteTime);
            });
          });
          this.examPlaces = res.rows;
          this.dialogExamBoxs = true;
        });
    },
    // 判断选择时间逻辑
    changeEndTime(int) {
      if (this.listData.applyStartTime === this.listData.applyEndTime) {
        this.$message.warning("开始时间与结束时间不允许相同");
        if (int === 1) {
          this.listData.applyStartTime = "";
        }
        if (int === 2) {
          this.listData.applyEndTime = "";
        }
        return;
      }
      if (
        int === 1 &&
        this.listData.applyEndTime &&
        this.listData.applyStartTime > this.listData.applyEndTime
      ) {
        this.$message.warning(
          "当前选择的开始时间大于结束时间，请重新选择开始时间!"
        );
        this.listData.applyStartTime = "";
        return;
      }
      if (
        int === 2 &&
        this.listData.applyStartTime &&
        this.listData.applyEndTime < this.listData.applyStartTime
      ) {
        this.$message.warning(
          "当前选择的结束时间小于开始时间，请重新选择结束时间!"
        );
        this.listData.applyEndTime = "";
        return;
      }
    },
    editInfo(v) {
      this.addClick(v, 0);
    },
    editImg(e) {
      var file = e.target.files[0];
      if (file === undefined) {
        return;
      }
      if (file.size > 0.3 * 1024 * 1024) {
        this.$message.warning("图片不得大于300kb");
        return;
      }
      var type = this.$refs.file.value.toLowerCase().split(".").splice(-1);
      if (
        type[0] != "jpg" &&
        type[0] != "png" &&
        type[0] != "jpeg" &&
        type[0] != "gif"
      ) {
        this.$message.warning("上传格式需为：.jpg/.png/.jpeg/gif");
        this.$refs.file.value = "";
        return;
      }
      this.$upload.upload(file, 0).then((res) => {
        this.listData.applyUrl = res;
      });
    },
    search(v) {
      this.loading = true;
      var data = {
        status: "0,1,2",
        pageSize: this.pageSize,
        pageNum: this.currentPage,
      };
      this.$api
        .inquiresystemapplyList(data)
        .then((res) => {
          this.tableData = res.rows;
          this.total = res.total;
          this.navText.index = res.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    init() {
      this.search();
    },
    watchs(v) {
      this.$api.obtainsystemapply(v.applyId).then((res) => {
        if (res.data.applyStatus) {
          res.data.applyStatus = res.data.applyStatus.split(",").map(Number);
        }
        if (res.data.examApplySite.length) {
          for (let i = 0; i < res.data.examApplySite.length; i++) {
            for (
              let j = 0;
              j < res.data.examApplySite[i].examApplySiteTime.length;
              j++
            ) {
              res.data.examApplySite[i].examApplySiteTime[j].siteTime =
                JSON.parse(
                  res.data.examApplySite[i].examApplySiteTime[j].siteTime
                );
            }
          }
        }
        if (res.data.examApplySiteTrain.length) {
          for (let i = 0; i < res.data.examApplySiteTrain.length; i++) {
            for (
              let j = 0;
              j < res.data.examApplySiteTrain[i].examApplySiteTime.length;
              j++
            ) {
              res.data.examApplySiteTrain[i].examApplySiteTime[j].siteTime =
                JSON.parse(
                  res.data.examApplySiteTrain[i].examApplySiteTime[j].siteTime
                );
            }
          }
        }
        this.infoData = res.data;
        this.dialoginfoWatch = true;
      });
    },
    del(v, int) {
      this.$alert(
        `确定${
          int === 1 ? "启用" : int === 2 ? "关闭" : int === 3 ? "删除" : "xxx"
        }考试计划【${v.applyName}】？<br />${
          int === 1
            ? "启用后，学员端预约考试的入口同步开通，请慎重考虑！"
            : int === 2
            ? "关闭后，学员端预约考试的入口同步关闭，请慎重考虑！"
            : int === 3
            ? "内容删除后将无法恢复，请慎重考虑"
            : "xxx"
        }`,
        "操作提示",
        {
          dangerouslyUseHTMLString: true,
        }
      )
        .then(() => {
          var data = {
            applyId: v.applyId,
          };
          if (int === 1) {
            data.status = 1;
          }
          if (int === 2) {
            data.status = 0;
          }
          if (int === 3) {
            data.status = -1;
          }
          this.$api.editsystemapply(data).then((res) => {
            this.$message.success(
              `${
                int === 1
                  ? "启用"
                  : int === 2
                  ? "关闭"
                  : int === 3
                  ? "删除"
                  : "xxx"
              }成功`
            );
            this.search();
            this.listDataGoods.businessId = "";
            this.$store.commit("EXAMLIST");
          });
        })
        .catch(() => {
          // this.$message({
          //   type: "info",
          //   message: "已取消删除",
          // });
        });
    },
    addClick(v, int) {
      if (v === undefined) {
        this.statusPop = 1;
        this.listData = {
          applyStatus: [],
          applyUrl: "oss/images/avatar/20211013/1634097664410_1397766697",
        };
        this.$nextTick(() => {
          this.$refs.listData.clearValidate();
        });
        this.dialogVisible = true;
      } else {
        this.statusPop = int;
        this.$api.obtainsystemapply(v.applyId).then((res) => {
          if (res.data.applyStatus) {
            res.data.applyStatus = res.data.applyStatus.split(",").map(Number);
          }else{
            res.data.applyStatus = []
          }
          if (res.data.applyStartTime) {
            res.data.applyStartTime = this.$methodsTools.time10to13(
              res.data.applyStartTime,
              2
            );
          }
          if (res.data.applyEndTime) {
            res.data.applyEndTime = this.$methodsTools.time10to13(
              res.data.applyEndTime,
              2
            );
          }
          this.listData = res.data;
          this.$nextTick(() => {
            this.$refs.listData.clearValidate();
          });
          this.dialogVisible = true;
        });
      }
    },
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.rulesTableSumbit();
        } else {
          return false;
        }
      });
    },
    rulesTableSumbit() {
      this.disabledBtn = true;
      var data = JSON.parse(JSON.stringify(this.listData));
      data.applyStatus = data.applyStatus.toString();
      data.applyStartTime = this.$methodsTools.time10to13(
        data.applyStartTime,
        1
      );
      data.applyEndTime = this.$methodsTools.time10to13(data.applyEndTime, 1);
      if (this.statusPop === 1) {
        data.status = 0;
        this.$api
          .appsystemapply(data)
          .then((res) => {
            this.$message.success("新增成功");
            this.dialogVisible = false;
            this.search();
            this.$store.commit("EXAMLIST");
          })
          .catch(() => {
            this.disabledBtn = false;
          });
      }
      if (this.statusPop === 0) {
        this.$api
          .editsystemapply(data)
          .then((res) => {
            this.$message.success("修改成功");
            this.dialogVisible = false;
            this.search();
            this.$store.commit("EXAMLIST");
          })
          .catch(() => {
            this.disabledBtn = false;
          });
      }
    },
    close() {
      this.dialogVisible = false;
    },
    handleSizeChange(v) {
      this.pageSize = v;
      this.currentPage = 1;
      this.search();
    },
    handleCurrentChange(v) {
      this.currentPage = v;
      this.search();
    },

    handleSizeChange2(v) {
      this.pageSize2 = v;
      this.currentPage2 = 1;
      this.getExamPlace();
    },
    handleCurrentChange2(v) {
      this.currentPage2 = v;
      this.getExamPlace();
    },
    selectAll2(value) {
      this.activeLists = value;
    },
    select2(value) {
      this.activeLists = value;
    },
    checkboxT2(row, index) {
      if (this.activeListExamPlace.indexOf(row.siteId) !== -1) {
        return false;
      } else {
        return true;
      }
    },
    getRowKeys2(row) {
      return row.siteId;
    },
  },
};
</script>

<style lang="less" scoped>
.imgBoxWatch {
  width: 200px;
  height: 110px;
  border: 1px solid #eee;
  img {
    width: 100%;
    height: 100%;
  }
}
/deep/.el-button {
  border-radius: 8px;
}
/deep/.el-dialog {
  border-radius: 8px;
  .el-dialog__header {
    padding: 0;
    .hearders {
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0px 18px 0px 20px;
      border-bottom: 1px solid #e2e2e2;
      .leftTitle {
        font-size: 14px;
        font-weight: bold;
        color: #2f4378;
      }
      .rightBoxs {
        display: flex;
        align-items: center;
        img {
          width: 14px;
          height: 14px;
          margin-left: 13px;
          cursor: pointer;
        }
      }
    }
  }
  .el-dialog__footer {
    padding: 0;
    .dialog-footer {
      padding: 0px 40px;
      height: 70px;
      border-top: 1px solid #e2e2e2;
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }
  }
}
.imgBox {
  width: 100%;
  // height: 210px;
  border: 1px solid #e2e2e2;
  border-radius: 8px;
  padding: 8px 8px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  .imgLabel {
    flex: 1;
    width: 100%;
    border: 1px dotted #e2e2e2;
    color: #999;
    font-size: 14px;
    cursor: pointer;
    border-radius: 8px;
    .msPhoto {
      display: flex;
      justify-content: center;
      align-items: center;
      max-width: 100%;
      max-height: 270px;
      img {
        max-width: 100%;
        max-height: 270px;
      }
    }
    .imgbbx {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 100%;
      i {
        font-weight: bold;
        margin: 14px 0;
        font-size: 24px;
      }
    }
  }
  p {
    margin: 5px 0px;
  }
}
.dis_fs {
  display: flex;
  align-items: center;
  .imgBoxs {
    width: 200px;
    height: 130px;
    border: 1px solid #999;
    margin-right: 6px;
  }
  .btns {
    align-self: end;
    border: 1px solid #999;
    font-size: 12px;
    height: 28px;
    line-height: 28px;
    padding: 0px 10px;
    border-radius: 4px;
    cursor: pointer;
  }
}
.jbtw {
  justify-content: space-between;
}
.bors {
  border: 1px solid #999;
  padding: 0px 8px;
  height: 30px;
  line-height: 30px;
  border-radius: 4px;
}
.mar_bgc {
  width: 90%;
  padding: 12px;
  margin-top: 12px;
  background-color: #eee;
}
</style>

