<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="130px"
    >
      <el-form-item label="培训课程编号" prop="trainingItemCode">
        <el-input
          v-model="queryParams.trainingItemCode"
          placeholder="请输入培训课程编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="培训课程名称" prop="trainingItemTitle">
        <el-input
          v-model="queryParams.trainingItemTitle"
          placeholder="请输入培训课程名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="培训课程类型" prop="trainingItemType">
        <el-select
          v-model="queryParams.trainingItemType"
          placeholder="请选择"
          clearable
          style="width: 250px"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:trainingItem:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:trainingItem:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:trainingItem:remove']"
          >删除</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:trainingItem:export']"
          >导出</el-button
        >
      </el-col>-->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      v-loading="loading"
      :data="trainingItemList"
      highlight-current-row
      @selection-change="handleSelectionChange"
      @expand-change="info"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-table
            :data="props.row.selectSubordinateItemlist"
            style="width: 100%"
            :header-cell-style="{ background: '#fff', color: '#606266' }"
          >
            <el-table-column
              prop="trainingItemCode"
              label="培训课程编号"
              width="180"
            >
            </el-table-column>
            <el-table-column
              prop="trainingItemTitle"
              label="培训课程名称"
              width="180"
            >
            </el-table-column>
            <el-table-column
              prop="trainingItemPrice"
              label="培训课程价格"
              width="180"
            >
            </el-table-column>
            <el-table-column
              prop="trainingItemType"
              label="培训课程类型"
              width="180"
            >
              <template slot-scope="scope">
                {{
                  scope.row.trainingItemType == "VIDEO_LEARNING"
                    ? "视频学习"
                    : ""
                }}
                {{
                  scope.row.trainingItemType == "GRAPHIC_LEARNING"
                    ? "图文学习"
                    : ""
                }}
                {{
                  scope.row.trainingItemType == "LIVE_COURSES" ? "直播课程" : ""
                }}
                {{
                  scope.row.trainingItemType == "OFFLINE_TRAINING"
                    ? "线下培训"
                    : ""
                }}
                {{
                  scope.row.trainingItemType == "LEARNING_ITEM_GROUP"
                    ? "学习培训课程组"
                    : ""
                }}
              </template>
            </el-table-column>

            <el-table-column
              prop="trainingShelfFlag"
              label="上架状态"
              width="180"
            >
              <template slot-scope="scope">
                {{ scope.row.trainingShelfFlag == 1 ? "已下架" : "" }}
                {{ scope.row.trainingShelfFlag == 0 ? "已上架" : "" }}
              </template>
            </el-table-column>
            <el-table-column
              prop="trainingItemSort"
              label="培训课程排序"
              width="180"
            >
            </el-table-column>
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"
                  v-hasPermi="['system:trainingItem:edit']"
                  >修改</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                  v-hasPermi="['system:trainingItem:remove']"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="学习培训课程组名称"
        align="center"
        prop="trainingParentName"
      /> -->
      <el-table-column
        label="培训课程编号"
        align="center"
        prop="trainingItemCode"
      />
      <el-table-column
        property="trainingItemTitle"
        label="培训课程名称"
        align="center"
      />
      <el-table-column
        label="培训课程价格"
        align="center"
        prop="trainingItemPrice"
      />
      <el-table-column
        label="培训课程类型"
        align="center"
        prop="trainingItemType"
      >
        <template slot-scope="scope">
          {{ scope.row.trainingItemType == "VIDEO_LEARNING" ? "视频学习" : "" }}
          {{
            scope.row.trainingItemType == "GRAPHIC_LEARNING" ? "图文学习" : ""
          }}
          {{ scope.row.trainingItemType == "LIVE_COURSES" ? "直播课程" : "" }}
          {{
            scope.row.trainingItemType == "OFFLINE_TRAINING" ? "线下培训" : ""
          }}
          {{
            scope.row.trainingItemType == "LEARNING_ITEM_GROUP"
              ? "学习培训课程组"
              : ""
          }}
        </template>
      </el-table-column>
      <el-table-column label="上架状态" align="center" prop="trainingShelfFlag">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.trainingShelfFlag"
            active-color="#13ce66"
            inactive-color="#ff4949"
            @change="uptrainingShelfFlag(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="培训课程日期"
        align="center"
        prop="trainingItemDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.trainingItemDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="培训课程开始时间"
        align="center"
        prop="trainingItemStartTime"
        width="180"
      >
      </el-table-column>
      <el-table-column
        label="培训课程结束时间"
        align="center"
        prop="trainingItemEndTime"
        width="180"
      >
      </el-table-column>-->
      <el-table-column
        label="培训课程排序"
        align="center"
        prop="trainingItemSort"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:trainingItem:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:trainingItem:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 培训课程组 -->
    <el-dialog
      title="选择培训课程组"
      :visible.sync="innerVisiblepd"
      width="1000px"
      append-to-body
      :before-close="innerVisiblecancelpd"
    >
      <el-form
        ref="queryForm"
        :model="trainingParentqueryParams"
        :rules="rules"
        label-width="80px"
        :inline="true"
      >
        <el-form-item
          label="分类编码"
          prop="trainingItemCode"
          label-width="120"
        >
          <el-input
            v-model="trainingParentqueryParams.trainingItemCode"
            placeholder="请输入分类编码"
            clearable
          />
        </el-form-item>
        <el-form-item
          label="培训课程组名称"
          prop="trainingParentName"
          label-width="120"
        >
          <el-input
            v-model="trainingParentqueryParams.trainingParentName"
            placeholder="请输入培训课程组名称"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="trainingParentinfo"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuerylist"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <el-table
        :data="trainingParentlist"
        @cell-dblclick="trainingParentitemlist"
        v-loading="loading"
      >
        <el-table-column label="请选择" width="100" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 15px; height: 15px"
              v-if="form.trainingParentId == scope.row.id"
              circle
              @click="trainingParentitemlist(scope.row)"
            ></el-button>
            <el-button
              v-else
              style="width: 15px; height: 15px"
              circle
              @click="trainingParentitemlist(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column
          property="trainingParentName"
          label="培训课程组名称"
          align="center"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          property="trainingItemCode"
          label="培训分类编码"
          align="center"
        ></el-table-column>
        <el-table-column
          property="trainingItemPrice"
          label="价格"
          align="center"
        ></el-table-column>

        <!-- <el-table-column
          property="trainingItemType"
          label="培训课程类型"
          align="center"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            {{
              scope.row.trainingItemType == "VIDEO_LEARNING" ? "视频学习" : ""
            }}
            {{
              scope.row.trainingItemType == "GRAPHIC_LEARNING" ? "图文学习" : ""
            }}
            {{ scope.row.trainingItemType == "LIVE_COURSES" ? "直播课程" : "" }}
            {{
              scope.row.trainingItemType == "OFFLINE_TRAINING" ? "线下培训" : ""
            }}
            {{
              scope.row.trainingItemType == "LEARNING_ITEM_GROUP"
                ? "学习培训课程组"
                : ""
            }}
          </template>
        </el-table-column>-->
      </el-table>
      <pagination
        v-show="total3 > 0"
        :total="total3"
        :page.sync="trainingParentqueryParams.pageNum"
        :limit.sync="trainingParentqueryParams.pageSize"
        @pagination="trainingParentinfo"
      />
    </el-dialog>
    <!-- 培训分类 -->
    <!-- <el-dialog
      title="选择培训"
      :visible.sync="innerVisible"
      width="1000px"
      append-to-body
      :before-close="innerVisiblecancelzx"
    >
      <el-form
        ref="queryForm"
        :model="trainingCategoryqueryParams"
        :rules="rules"
        label-width="80px"
        :inline="true"
      >
        <el-form-item
          label="培训分类编码"
          prop="trainingCategoryCode"
          label-width="120"
        >
          <el-input
            v-model="trainingCategoryqueryParams.trainingCategoryCode"
            placeholder="请输入培训分类编码"
            clearable
          />
        </el-form-item>
        <el-form-item
          label="培训分类名称"
          prop="trainingCategoryName"
          label-width="120"
        >
          <el-input
            v-model="trainingCategoryqueryParams.trainingCategoryName"
            placeholder="请输入培训分类名称"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="info"
            >搜索</el-button
          >
          <el-button
            icon="el-icon-refresh"
            size="mini"
            @click="addresetQuerylist"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <el-table
        :data="trainingCategoryList"
        @cell-dblclick="nurseclick"
        v-loading="loading"
      >
        <el-table-column label="请选择" width="100" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 15px; height: 15px"
              v-if="form.trainingCategoryId == scope.row.id"
              circle
              @click="nurseclick(scope.row)"
            ></el-button>
            <el-button
              v-else
              style="width: 15px; height: 15px"
              circle
              @click="nurseclick(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column
          property="trainingCategoryCode"
          label="培训分类编码"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="trainingCategoryName"
          label="培训分类名称"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
      </el-table>
      <pagination
        v-show="total2 > 0"
        :total="total2"
        :page.sync="trainingCategoryqueryParams.pageNum"
        :limit.sync="trainingCategoryqueryParams.pageSize"
        @pagination="info"
      />
    </el-dialog>-->
    <!-- 添加或修改学习培训课程信息对话框 -->
    <el-dialog
      :title="!isEditFlag ? '添加学习培训课程信息' : '修改学习培训课程信息'"
      :visible.sync="open"
      width="1300px"
      append-to-body
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="140px"
        :inline="true"
      >
        <el-form-item label="培训课程名称" prop="trainingItemTitle">
          <el-input
            style="width: 250px"
            maxlength="100"
            v-model="form.trainingItemTitle"
            placeholder="请输入培训课程名称"
          />
        </el-form-item>
        <el-form-item label="培训课程类型" prop="trainingItemType">
          <el-select
            v-model="form.trainingItemType"
            placeholder="请选择"
            clearable
            style="width: 250px"
            :disabled="isEditFlag"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="所属培训课程组"
          prop="trainingParentId"
          v-if="
            form.trainingItemType == 'VIDEO_LEARNING' ||
            form.trainingItemType == 'GRAPHIC_LEARNING'
          "
        >
          <el-button
            type
            v-if="form.trainingParentName == '请选择所属培训课程组'"
            @click="trainingParentitem()"
            style="
              width: 250px;
              text-align: left;
              height: 36px;
              color: #c0c4cc;
              overflow: hidden;
            "
            >{{ form.trainingParentName }}</el-button
          >
          <el-button
            @click="trainingParentitem()"
            type
            v-else
            style="
              width: 250px;
              text-align: left;
              height: 36px;
              padding-left: -10px;
              overflow: hidden;
            "
            >{{ form.trainingParentName }}</el-button
          >
        </el-form-item>
        <!-- <el-form-item
          label="所属培训课程分类"
          prop="trainingCategoryId"
          v-if="
            form.trainingItemType == 'VIDEO_LEARNING' ||
            form.trainingItemType == 'GRAPHIC_LEARNING'
          "
        >
          <el-button
            type=""
            :disabled="isEditFlag"
            v-if="form.trainingCategoryName == '请选择培训课程分类'"
            @click="clickitem()"
            style="
              width: 250px;
              text-align: left;
              height: 36px;
              color: #c0c4cc;
              overflow: hidden;
            "
            >{{ form.trainingCategoryName }}</el-button
          >
          <el-button
            :disabled="isEditFlag"
            @click="clickitem()"
            type=""
            v-else
            style="
              width: 250px;
              text-align: left;
              height: 36px;
              padding-left: -10px;
              overflow: hidden;
            "
            >{{ form.trainingCategoryName }}</el-button
          >
        </el-form-item>-->

        <el-form-item label="培训课程价格" prop="trainingItemPrice">
          <el-input
            :change="checkPrice()"
            style="width: 250px"
            v-model="form.trainingItemPrice"
            maxlength="7"
            placeholder="请输入培训课程价格"
            clearable
          />
        </el-form-item>

        <el-form-item label="是否可以购买" prop="buyFlag">
          <el-select
            v-model="form.buyFlag"
            placeholder="请选择"
            clearable
            style="width: 250px"
          >
            <el-option
              v-for="item in option"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="培训课程排序" prop="trainingItemSort">
          <el-input
            oninput="value=value.replace(/[^\d]/g,'')"
            maxlength="8"
            style="width: 250px"
            clearable
            v-model.number="form.trainingItemSort"
            placeholder="值越小,排名越靠前"
          />
        </el-form-item>
        <el-form-item label="培训课程封面图片" prop="trainingItemCoverUrl">
          <stationAcatar
            style="width: 208px"
            @imgUrl="imgUrl2"
            :img="form.trainingItemCoverUrl"
            :type="'trainingItemCoverUrl'"
          />
          <!-- <el-input
            v-model="form.trainingItemCoverUrl"
            type="textarea"
            placeholder="请输入内容"
          />-->
        </el-form-item>
        <el-form-item label="培训课程海报图片" prop="trainingItemPosterUrl">
          <stationAcatar
            style="width: 208px"
            @imgUrl="imgUrl3"
            :img="form.trainingItemPosterUrl"
            :type="'trainingItemPosterUrl'"
          />
          <!-- <el-input
            v-model="form.trainingItemPosterUrl"
            type="textarea"
            placeholder="请输入内容"
          />-->
        </el-form-item>

        <el-form-item
          label="培训课程详情"
          prop="trainingItemDetails"
          v-if="
            form.trainingItemType == 'VIDEO_LEARNING' ||
            form.trainingItemType == 'LIVE_COURSES' ||
            form.trainingItemType == 'LEARNING_ITEM_GROUP'
          "
        >
          <el-input
            type="textarea"
            :rows="5"
            maxlength="300"
            style="width: 840px"
            placeholder="请输入培训课程详情"
            v-model="form.trainingItemDetails"
          ></el-input>
          <!-- <el-input
            style="width: 250px"
            v-model="form.trainingItemDetails"
            placeholder="请输入培训课程详情"
          />-->
        </el-form-item>

        <el-form-item
          :label="
            form.trainingItemType == 'GRAPHIC_LEARNING'
              ? '培训课程内容'
              : form.trainingItemType == 'LEARNING_ITEM_GROUP'
              ? '培训课程介绍'
              : ''
          "
          prop="trainingItemContent"
          v-if="
            this.form.trainingItemType == 'GRAPHIC_LEARNING' ||
            form.trainingItemType == 'LEARNING_ITEM_GROUP'
          "
        >
          <editor
            @imgs="imgs"
            :url="'/common/uploadTrainingItemContentUrl'"
            v-model="form.trainingItemContent"
            :min-height="192"
          />
        </el-form-item>
        <el-form-item
          label="培训课程日期"
          prop="trainingItemDate"
          v-if="
            form.trainingItemType == 'LIVE_COURSES' ||
            form.trainingItemType == 'OFFLINE_TRAINING'
          "
        >
          <el-date-picker
            clearable
            style="width: 250px"
            v-model="form.trainingItemDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择培训课程日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item
          label="培训课程开始时间"
          prop="trainingItemStartTime"
          v-if="
            form.trainingItemType == 'LIVE_COURSES' ||
            form.trainingItemType == 'OFFLINE_TRAINING'
          "
        >
          <el-time-picker
            value-format="HH:mm:ss"
            v-model="form.trainingItemStartTime"
            :picker-options="{
              selectableRange: '00:00:00 - 23:59:59',
            }"
            placeholder="任意时间点"
          ></el-time-picker>
        </el-form-item>
        <el-form-item
          label="培训课程结束时间"
          prop="trainingItemEndTime"
          v-if="
            form.trainingItemType == 'LIVE_COURSES' ||
            form.trainingItemType == 'OFFLINE_TRAINING'
          "
        >
          <el-time-picker
            arrow-control
            value-format="HH:mm:ss"
            v-model="form.trainingItemEndTime"
            :picker-options="{
              selectableRange: '00:00:00 - 23:59:59',
            }"
            placeholder="任意时间点"
          ></el-time-picker>
        </el-form-item>
        <el-form-item
          label="培训课程地址"
          prop="trainingItemAddress"
          v-if="form.trainingItemType == 'OFFLINE_TRAINING'"
        >
          <el-input
            v-model="form.trainingItemAddress"
            placeholder="请输入培训课程地址"
          />
        </el-form-item>
        <el-form-item
          label="报名须知"
          prop="trainingItemNotes"
          v-if="form.trainingItemType == 'OFFLINE_TRAINING'"
        >
          <el-input
            style="width: 250px"
            v-model="form.trainingItemNotes"
            placeholder="请输入报名须知"
          />
        </el-form-item>
        <el-table
          v-if="form.trainingItemType == 'VIDEO_LEARNING'"
          ref="trainingItemDirectoryList"
          style="margin-top: 20px; width: 1250px"
          :data="form.trainingItemDirectoryList"
        >
          <el-table-column label="章节视频" align="center" width="300">
            <template slot-scope="scope">
              <el-form-item
                :prop="
                  'trainingItemDirectoryList.' +
                  scope.$index +
                  '.itemDirectoryUrl'
                "
                :rules="[
                  {
                    required: true,
                    message: '请上传章节视频',
                    trigger: 'blur',
                  },
                ]"
              >
                <trainingAvatar
                  @item="itemDirectoryUrl"
                  :tovideo="scope.row.itemDirectoryUrl"
                  :type="'itemDirectoryUrl'"
                  :item="scope.row"
                />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="章节名称" align="center">
            <template slot-scope="scope">
              <el-form-item
                :prop="
                  'trainingItemDirectoryList.' +
                  scope.$index +
                  '.itemDirectoryName'
                "
                :rules="[
                  {
                    required: true,
                    message: '请输入章节名称',
                    trigger: 'blur',
                  },
                ]"
              >
                <el-input
                  maxlength="100"
                  v-model="scope.row.itemDirectoryName"
                  placeholder="请输入章节名称"
                ></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="章节标题" align="center">
            <template slot-scope="scope">
              <el-form-item
                :prop="
                  'trainingItemDirectoryList.' +
                  scope.$index +
                  '.itemDirectoryTitle'
                "
                :rules="[
                  {
                    required: true,
                    message: '请输入章节标题',
                    trigger: 'blur',
                  },
                ]"
              >
                <el-input
                  maxlength="100"
                  v-model="scope.row.itemDirectoryTitle"
                  placeholder="请输入章节标题"
                ></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="章节内容简介" align="center">
            <template slot-scope="scope">
              <el-form-item
                :prop="
                  'trainingItemDirectoryList.' +
                  scope.$index +
                  '.itemDirectoryIntroduce'
                "
                :rules="[
                  {
                    required: true,
                    message: '请输入章节标题',
                    trigger: 'blur',
                  },
                ]"
              >
                <el-input
                  maxlength="300"
                  type="textarea"
                  :rows="5"
                  style="width: 140px"
                  v-model="scope.row.itemDirectoryIntroduce"
                  placeholder="请输入章节内容简介"
                ></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="章节排序" align="center">
            <template slot-scope="scope">
              <el-input
                oninput="value=value.replace(/[^\d]/g,'')"
                maxlength="5"
                v-model.number="scope.row.itemDirectorySort"
                placeholder="请输入章节排序"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="addPictureUrl"
                >新增</el-button
              >
              <el-button
                size="mini"
                type="text"
                @click="delPictureUrl(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

  <script>
import {
  listTrainingItem,
  listTrainingCategory,
  selectSubordinateItem,
  selectTrainingParent,
  getTrainingItem,
  delTrainingItem,
  addTrainingItem,
  updateTrainingItem,
  updateTrainingShelfFlag,
} from "@/api/system/trainingItem";
import trainingAvatar from "../trainingAvatar/index.vue";
import stationAcatar from "../stationAvatar/index.vue";
import editor from "@/components/Editor";
import { updatePicture } from "@/api/system/station";
export default {
  name: "TrainingItem",
  components: { stationAcatar, editor, trainingAvatar },
  data() {
    return {
      // 遮罩层
      isEditFlag: false,
      idd: 1,
      innerVisiblepd: false,
      loading: true,
      // innerVisible: false,
      trainingParentqueryParams: {
        pageNum: 1,
        pageSize: 10,
        trainingItemCode: "",
        trainingParentName: "",
      },
      trainingCategoryqueryParams: {
        pageNum: 1,
        pageSize: 10,
        trainingCategoryCode: "",
        trainingCategoryName: "",
      },
      option: [
        {
          value: 0,
          label: "是",
        },
        {
          value: 1,
          label: "否",
        },
      ],
      value: "",
      options: [
        {
          value: "GRAPHIC_LEARNING",
          label: "图文学习",
        },
        {
          value: "LEARNING_ITEM_GROUP",
          label: "学习培训课程组",
        },
        {
          value: "VIDEO_LEARNING",
          label: "视频学习",
        },
        // {
        //   value: "LIVE_COURSES",
        //   label: "直播课程",
        // },
        // {
        //   value: "OFFLINE_TRAINING",
        //   label: "线下培训",
        // },
      ],
      // 选中数组
      ids: [],
      total2: 0,
      total3: 0,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学习培训课程信息表格数据
      trainingItemList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        trainingCategoryId: null,
        trainingItemTitle: null,
        trainingItemCode: null,
        trainingItemPrice: null,
        trainingItemCoverUrl: null,
        trainingItemPosterUrl: null,
        trainingItemType: null,
        trainingItemDetails: null,
        trainingItemContent: null,
        trainingItemDate: null,
        trainingItemStartTime: null,
        trainingItemEndTime: null,
        trainingItemAddress: null,
        trainingItemNotes: null,
        trainingItemSort: null,
      },
      // 表单参数
      form: {
        trainingItemDirectoryList: [
          {
            itemDirectoryName: null,
            itemDirectoryTitle: null,
            itemDirectoryUrl: null,
            itemDirectoryIntroduce: null,
            itemDirectorySort: null,
          },
        ],
      },
      imgtwo: "",
      imgone: "",
      imgsurl: { pictureUrlList: [] },
      trainingCategoryList: [],
      trainingParentlist: [],
      // 表单校验
      rules: {
        // buyFlag:[
        // { required: true, message: "请选择是否可以购买", trigger: "blur" },

        // ],
        // trainingCategoryId: [
        //   { required: true, message: "请选择培训分类", trigger: "blur" },
        // ],
        trainingItemTitle: [
          { required: true, message: "请输入培训课程名称", trigger: "blur" },
        ],
        // trainingItemPrice: [
        //   { required: true, message: "请输入培训课程价格", trigger: "blur" },
        // ],
        // trainingItemCoverUrl: [
        //   {
        //     required: true,
        //     message: "请输入培训课程logo图片",
        //     trigger: "blur",
        //   },
        // ],
        // trainingItemPosterUrl: [
        //   {
        //     required: true,
        //     message: "请输入培训课程海报图片",
        //     trigger: "blur",
        //   },
        // ],
        trainingItemType: [
          { required: true, message: "请选择培训课程类型", trigger: "blur" },
        ],
        trainingItemDetails: [
          { required: true, message: "请输入培训课程详情", trigger: "blur" },
        ],
        trainingItemContent: [
          { required: true, message: "请输入培训课程内容", trigger: "blur" },
        ],
        trainingItemDate: [
          { required: true, message: "请输入培训课程日期", trigger: "blur" },
        ],
        trainingItemStartTime: [
          {
            required: true,
            message: "请输入培训课程开始时间",
            trigger: "blur",
          },
        ],
        trainingItemEndTime: [
          {
            required: true,
            message: "请输入培训课程结束时间",
            trigger: "blur",
          },
        ],
        trainingItemAddress: [
          { required: true, message: "请输入培训课程地址", trigger: "blur" },
        ],
        // trainingItemSort: [
        //   { required: true, message: "请输入培训课程排序", trigger: "blur" },
        // ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    info(row) {
      if (!row.expand) {
        // 先判断该行是否已经展开了
        var trainingParentId = row.id;
        selectSubordinateItem(trainingParentId).then((response) => {
          row.selectSubordinateItemlist = response.data;
          this.loading = false;
          row.expand = true; // 设置展开行是打开的
        });
      }
    },
    /**只能输入数字且有小数点最多保留两位*/
    checkPrice() {
      let checkPlan = "" + this.form.trainingItemPrice;
      checkPlan = checkPlan
        .replace(/[^\d.]/g, "") // 清除“数字”和“.”以外的字符
        .replace(/\.{2,}/g, ".") // 只保留第一个. 清除多余的
        .replace(/^\./g, "") // 保证第一个为数字而不是.
        .replace(".", "$#$")
        .replace(/\./g, "")
        .replace("$#$", ".");
      if (checkPlan.indexOf(".") < 0 && checkPlan !== "") {
        // 以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
        checkPlan = parseFloat(checkPlan) + "";
      } else if (checkPlan.indexOf(".") >= 0) {
        checkPlan = checkPlan.replace(/^()*(\d+)\.(\d\d).*$/, "$1$2.$3"); // 只能输入两个小数
      }
      this.form.trainingItemPrice = checkPlan;
    },
    //新增视频列表
    addPictureUrl() {
      this.idd++;
      var obj = {
        itemDirectoryName: null,
        itemDirectoryTitle: null,
        itemDirectoryUrl: null,
        itemDirectoryIntroduce: null,
        itemDirectorySort: null,
        idd: this.idd,
      };
      if (this.form.trainingItemDirectoryList.length >= 5) {
        this.$message.error("最多新增5条");
      } else {
        this.form.trainingItemDirectoryList.push(obj);
      }
    },
    //删除视频列表
    delPictureUrl(item) {
      console.log(item);
      if (item.idd && !item.trainingItemDirectoryId) {
        if (this.form.trainingItemDirectoryList.length == 1) {
          this.$message.error("最后一条不可删除");
        } else {
          this.form.trainingItemDirectoryList =
            this.form.trainingItemDirectoryList.filter(
              (e) => e.idd != item.idd
            );
        }
      } else if (!item.idd && item.trainingItemDirectoryId) {
        if (this.form.trainingItemDirectoryList.length == 1) {
          this.$message.error("最后一条不可删除");
        } else {
          this.form.trainingItemDirectoryList =
            this.form.trainingItemDirectoryList.filter(
              (e) => e.trainingItemDirectoryId != item.trainingItemDirectoryId
            );
        }
      }
      console.log(this.form.trainingItemDirectoryList);
    },
    // 章节视频
    itemDirectoryUrl(item) {
      let items = JSON.parse(item);
      if (items.idd && !items.trainingItemDirectoryId) {
        this.form.trainingItemDirectoryList.forEach((e) => {
          if (e.idd == items.idd) {
            e.itemDirectoryUrl = items.itemDirectoryUrl;
          }
        });
      } else if (!items.idd && items.attributeDetailsId) {
        this.form.trainingItemDirectoryList.forEach((e) => {
          if (e.attributeDetailsId == items.attributeDetailsId) {
            e.itemDirectoryUrl = items.itemDirectoryUrl;
          }
        });
      }
    },
    imgs(item) {
      this.imgsurl.pictureUrlList.push(item);
    },
    // 重置
    // addresetQuerylist() {
    //   this.trainingCategoryqueryParams = {
    //     pageNum: 1,
    //     pageSize: 10,
    //     trainingCategoryCode: "",
    //     trainingCategoryName: "",
    //   };
    //   this.info();
    // },
    // 重置
    resetQuerylist() {
      this.trainingParentqueryParams = {
        pageNum: 1,
        pageSize: 10,
        trainingCategoryCode: "",
        trainingParentName: "",
      };
      this.trainingParentinfo();
    },
    // 培训分类
    // clickitem() {
    //   this.info();
    //   this.innerVisible = true;
    // },
    // 父级课程组
    trainingParentitem() {
      this.trainingParentinfo();
      this.innerVisiblepd = true;
    },
    // innerVisiblecancelzx() {
    //   this.innerVisible = false;
    // },
    innerVisiblecancelpd() {
      this.innerVisiblepd = false;
    },
    // nurseclick(row) {
    //   this.form.trainingCategoryId = row.id;
    //   this.form.trainingCategoryName = row.trainingCategoryName;
    //   this.innerVisible = false;
    // },
    // 父级课程组
    trainingParentitemlist(row) {
      this.form.trainingParentId = row.id;
      this.form.trainingParentName = row.trainingParentName;
      this.innerVisiblepd = false;
    },
    // info() {
    //   this.loading = true;
    //   listTrainingCategory(this.trainingCategoryqueryParams).then(
    //     (response) => {
    //       this.trainingCategoryList = response.rows;
    //       this.total2 = response.total;
    //       this.loading = false;
    //     }
    //   );
    // },
    // 父级课程组
    trainingParentinfo() {
      this.loading = true;
      selectTrainingParent(this.trainingParentqueryParams).then((response) => {
        console.log(response);
        this.trainingParentlist = response.rows;
        this.total3 = response.total;
        this.loading = false;
      });
    },
    imgUrl(imgUrl) {
      this.form.trainingCategoryPictureUrl = imgUrl;
    },
    // 图片
    imgUrl2(imgUrl) {
      this.form.trainingItemCoverUrl = imgUrl;
    },
    imgUrl3(imgUrl) {
      this.form.trainingItemPosterUrl = imgUrl;
    },
    //上架
    uptrainingShelfFlag(row) {
      console.log(row);
      if (row.trainingShelfFlag == false) {
        var obj = {
          id: row.id,
          trainingShelfFlag: 1,
          trainingItemType: row.trainingItemType,
        };
      } else if (row.trainingShelfFlag == true) {
        var obj = {
          id: row.id,
          trainingShelfFlag: 0,
          trainingItemType: row.trainingItemType,
        };
      }
      updateTrainingShelfFlag(obj).then((res) => {
        if (obj.trainingShelfFlag == 0) {
          this.$modal.msgSuccess("已修改上架状态为上架");
        } else {
          this.$modal.msgSuccess("已修改上架状态为未上架");
        }
        this.getList();
      });
    },
    /** 查询学习培训课程信息列表 */
    getList() {
      this.loading = true;
      listTrainingItem(this.queryParams).then((response) => {
        console.log(response);
        response.rows.forEach((e) => {
          e.selectSubordinateItemlist = []; // 先给一个空值
          e.expand = false; // 表示当前行是闭合的，不设置这个等下展开后就没法闭合了
          if (e.trainingShelfFlag == 0) {
            e.trainingShelfFlag = true;
          } else if (e.trainingShelfFlag == 1) {
            e.trainingShelfFlag = false;
          }
        });
        this.trainingItemList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      var obj = { pictureUrlList: [] };
      if (this.imgone != this.form.trainingItemCoverUrl) {
        obj.pictureUrlList.push(this.form.trainingItemCoverUrl);
      }
      if (this.imgtwo != this.form.trainingItemPosterUrl) {
        obj.pictureUrlList.push(this.form.trainingItemPosterUrl);
      }
      if (obj.pictureUrlList.length > 0) {
        updatePicture(obj).then((res) => {});
      }
      if (this.imgsurl.pictureUrlList.length > 0) {
        updatePicture(this.imgsurl).then((res) => {});
      }
      this.imgsurl = { pictureUrlList: [] };

      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        trainingItemDirectoryList: [
          {
            itemDirectoryName: null,
            itemDirectoryTitle: null,
            itemDirectoryUrl: null,
            itemDirectoryIntroduce: null,
            itemDirectorySort: null,
            idd: this.idd,
          },
        ],
        trainingParentId: "",
        id: null,
        trainingCategoryName: "请选择培训课程分类",
        trainingCategoryId: null,
        trainingItemTitle: "",
        trainingParentName: "请选择所属培训课程组",
        trainingItemCode: null,
        trainingItemPrice: null,
        trainingItemCoverUrl: null,
        trainingItemPosterUrl: null,
        trainingItemType: null,
        trainingItemDetails: null,
        trainingItemContent: null,
        trainingItemDate: null,
        trainingItemStartTime: null,
        trainingItemEndTime: null,
        trainingItemStartTimeStr: "00:00:00", //下午开始
        trainingItemEndTimeStr: "00:00:00", //下午结束
        trainingItemAddress: null,
        trainingItemNotes: null,
        trainingItemSort: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.trainingItemType = "";
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.form.trainingParentName = "请选择所属培训课程组";
      this.form = {
        trainingItemDirectoryList: [
          {
            itemDirectoryName: null,
            itemDirectoryTitle: null,
            itemDirectoryUrl: null,
            itemDirectoryIntroduce: null,
            itemDirectorySort: null,
          },
        ],
      };
      this.reset();
      this.open = true;
      this.isEditFlag = false;
      this.title = "添加学习培训课程信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getTrainingItem(id).then((response) => {
        var obj = {
          itemDirectoryName: null,
          itemDirectoryTitle: null,
          itemDirectoryUrl: null,
          itemDirectoryIntroduce: null,
          itemDirectorySort: null,
        };
        if (response.data.trainingItemDirectoryList.length == 0) {
          response.data.trainingItemDirectoryList.push(obj);
        }
        this.form = response.data;
        this.imgone = this.form.trainingItemCoverUrl;
        this.imgtwo = this.form.trainingItemPosterUrl;
        this.open = true;
        this.title = "修改学习培训课程信息";
        this.isEditFlag = true;
      });
    },
    /** 提交按钮 */
    submitForm() {
      if (this.form.trainingItemPrice) {
        this.form.trainingItemPrice = Number(this.form.trainingItemPrice);
      } else {
        this.form.trainingItemPrice = null;
      }
      if (!this.form.trainingItemSort) {
        this.form.trainingItemSort = null;
      }
      if (this.form.buyFlag === "") {
        this.form.buyFlag = null;
      }
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.trainingItemStartTime) {
            this.form.trainingItemStartTimeStr =
              this.form.trainingItemStartTime;
          } else {
            this.form.trainingItemStartTimeStr = "00:00:00";
          }
          if (
            this.form.trainingItemType == "GRAPHIC_LEARNING" ||
            this.form.trainingItemType == "LEARNING_ITEM_GROUP"
          ) {
            this.form.trainingItemDirectoryList = [];
          }
          if (this.form.trainingItemId != null) {
            updateTrainingItem(this.form).then((response) => {
              var obj = { pictureUrlList: [] };
              if (this.imgone != this.form.trainingItemCoverUrl) {
                obj.pictureUrlList.push(this.imgone);
              }
              if (this.imgtwo != this.form.trainingItemPosterUrl) {
                obj.pictureUrlList.push(this.imgtwo);
              }
              this.imgsurl = { pictureUrlList: [] };
              if (obj.pictureUrlList.length > 0) {
                updatePicture(obj).then((res) => {});
              }
              if (response.code == 200) {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addTrainingItem(this.form).then((response) => {
              if (response.code == 200) {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      const trainingItemTitles =
        row.trainingItemTitle || this.trainingItemTitles;
      this.$modal
        .confirm(
          '是否确认删除培训课程名称为"' + trainingItemTitles + '"的数据项？'
        )
        .then(function () {
          return delTrainingItem(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/trainingItem/export",
        {
          ...this.queryParams,
        },
        `trainingItem_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .wihi {
  text-align: left !important;
  // width: 208px !important;
  // height: 208px !important;
  background: none;
}
::v-deep .wihi:hover:after {
  transform: translate(0%, 40%);
}
::v-deep .video-avatar {
  transform: translateX(-25%);
}
</style>
