<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="创建时间" prop="">
        <el-date-picker
          v-model="queryParams.createTimeStart"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期"
          @change="changecreateTimeStart"
          :picker-options="pickerStartTime"
        >
        </el-date-picker>
        -
        <el-date-picker
          v-model="queryParams.createTimeEnd"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期"
          @change="changecreateTimeEnd"
          :picker-options="pickerEndTime"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="宣教类型" prop="propagandaType">
        <el-select v-model="queryParams.propagandaType" placeholder="请选择">
          <el-option
            v-for="item in optionstype"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="宣教来源" prop="hospitalAgencyId">
        <el-select
          v-model="queryParams.hospitalAgencyId"
          filterable
          placeholder="请选择医院"
          style="width: 200px"
          clearable
        >
          <el-option
            v-for="item in hospitalAgencylist"
            :key="item.id"
            :label="item.agencyName"
            :value="item.id"
          >
          </el-option>
        </el-select>
        <!-- <el-input
          v-model="queryParams.hospitalAgencyId"
          placeholder="请输入宣教来源"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
      </el-form-item>
      <el-form-item label="宣教状态" prop="propagandaStatus">
        <el-select v-model="queryParams.propagandaStatus" placeholder="请选择">
          <el-option
            v-for="item in optionsstate"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <!-- <el-input
          v-model="queryParams.diseaseTypeName"
          placeholder="请输入所属病种名称"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
      </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="['manage:propaganda:add']"
          >新增</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="5">
        <div class="leftpro" ref="box">
          <div class="name">科室名称</div>
          <div>
            <el-input
              v-model="name"
              placeholder="请输入科室名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </div>
          <div class="listitem">
            <div
              :class="itemname == null ? 'allactive' : 'all'"
              @click="itemdata()"
            >
              全部
            </div>
            <span class="count">{{ count }}</span>
          </div>
          <div
            class="listitem"
            v-for="(item, index) in DepartmentoList"
            :key="index"
            @click="itemdata(item)"
          >
            <div :class="itemname == item.id ? 'allactive' : 'all'">
              {{ item.departmentName }}
            </div>
            <span class="count">{{ item.countNum }}</span>
          </div>
        </div>
      </el-col>
      <el-col :span="19">
        <el-table
          v-loading="loading"
          :data="propagandaList"
          @selection-change="handleSelectionChange"
        >
          <!-- <el-table-column type="selection" width="55" align="center" /> -->
          <el-table-column label="序号" align="center" prop="id" type="index" />
          <el-table-column
            label="宣教名称"
            align="center"
            prop="propagandaTitle"
            :show-overflow-tooltip="true"
          >
          </el-table-column>
          <el-table-column
            label="宣教类型"
            align="center"
            prop="propagandaType"
          >
            <template slot-scope="scope">
              {{
                scope.row.propagandaType == "MEDICATION_KNOWLEDGE"
                  ? "用药知识"
                  : ""
              }}
              {{
                scope.row.propagandaType == "DISEASE_POPULARIZATION"
                  ? "疾病科普"
                  : ""
              }}
              {{
                scope.row.propagandaType == "SPORT_NUTRITION" ? "运动营养" : ""
              }}
              {{
                scope.row.propagandaType == "OTHER_KNOWLEDGE" ? "其他知识" : ""
              }}
              {{
                scope.row.propagandaType == "CUSTOMIZED_CONTENT"
                  ? "定制内容"
                  : ""
              }}
            </template>
          </el-table-column>
          <el-table-column
            label="宣教ID"
            align="center"
            prop="propagandaCode"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="宣教状态"
            align="center"
            prop="propagandaStatus"
          >
            <template slot-scope="scope">
              {{
                scope.row.propagandaStatus == "CREATE_PROCESS" ? "创作中" : ""
              }}
              {{
                scope.row.propagandaStatus == "CREATE_COMPLETE"
                  ? "创作完成"
                  : ""
              }}
              {{ scope.row.propagandaStatus == "IN_REVIEW" ? "审核中" : "" }}
              {{ scope.row.propagandaStatus == "APPROVED" ? "审核通过" : "" }}
              {{
                scope.row.propagandaStatus == "REVIEW_FAILED"
                  ? "审核不通过"
                  : ""
              }}
              <div></div>
            </template>
          </el-table-column>
          <el-table-column
            label="宣教来源"
            align="center"
            prop="hospitalAgencyName"
          />
          <el-table-column label="创建时间" align="center" prop="createTime" />
          <el-table-column label="更新时间" align="center" prop="updateTime" />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="300%"
          >
            <template slot-scope="scope">
              <el-button
                type="text"
                icon="el-icon-zoom-in"
                size="mini"
                @click="Preview(scope.row)"
                >预览</el-button
              >
              <el-button
                type="text"
                icon="el-icon-tickets"
                size="mini"
                @click="copyUrl(scope.row)"
                >复制</el-button
              >

              <el-button
                size="mini"
                type="text"
                icon="el-icon-aim"
                v-if="scope.row.propagandaStatus == 'CREATE_COMPLETE'"
                @click="examine(scope.row)"
                >审核</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['manage:propaganda:edit']"
                >修改</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['manage:propaganda:remove']"
                >删除</el-button
              >
              <!-- <el-button
                size="mini"
                type="text"
                icon="el-icon-copy-document"
                @click="copylink(scope.row)"
                >复制链接</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-col>
    </el-row>

    <!-- 添加或修改患者宣教信息对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1000px"
      append-to-body
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="100px"
        :inline="true"
      >
        <el-form-item label="宣教标题" prop="propagandaTitle">
          <el-input
            v-model="form.propagandaTitle"
            placeholder="请输入宣教标题"
          />
        </el-form-item>
        <el-form-item label="宣教ID" prop="propagandaCode">
          <el-input
            v-model="form.propagandaCode"
            placeholder="请输入宣教ID"
            onKeyUp="value=value.replace(/[\W]/g,'')"
          />
        </el-form-item>
        <el-form-item label="宣教类型" prop="propagandaType">
          <el-select
            v-model="form.propagandaType"
            placeholder="请选择"
            style="width: 206px"
          >
            <el-option
              v-for="item in optionstype"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="医院名称" prop="hospitalAgencyName">
          <el-select
            v-model="form.hospitalAgencyName"
            filterable
            placeholder="请选择医院"
            style="width: 200px"
            clearable
            @change="changehospitalAgency"
          >
            <el-option
              v-for="item in hospitalAgencylist"
              :key="item.id"
              :label="item.agencyName"
              :value="item.id"
            >
            </el-option>
          </el-select>
          <!-- <el-input
            v-model="form.hospitalAgencyName"
            placeholder="请输入医院名称"
          /> -->
        </el-form-item>

        <el-form-item label="科室名称" prop="departmentId">
          <el-select
            v-model="form.departmentName"
            filterable
            placeholder="请选择医院"
            style="width: 200px"
            clearable
            @change="changeDepartment"
            @focus="onBlur"
          >
            <el-option
              v-for="item in Departmentdata"
              :key="item.id"
              :label="item.departmentName"
              :value="item.id"
            >
            </el-option>
          </el-select>

          <!-- <el-button
            type=""
            v-if="departmentName == '请选择科室'"
            @click="clickinnerVisible()"
            style="
              width: 206px;
              text-align: left;
              height: 36px;
              color: #c0c4cc;
              overflow: hidden;
            "
            >{{ departmentName }}</el-button
          >
          <el-button
            @click="clickinnerVisible()"
            type=""
            v-else
            style="
              width: 206px;
              text-align: left;
              height: 36px;
              padding-left: -10px;
              overflow: hidden;
            "
            >{{ departmentName }}</el-button
          > -->
        </el-form-item>
        <el-form-item label="病种名称" prop="diseaseTypeName">
          <el-button
            type=""
            v-if="diseaseTypeName == '请选择病种'"
            @click="clickdisease()"
            style="
              width: 206px;
              text-align: left;
              height: 36px;
              color: #c0c4cc;
              overflow: hidden;
            "
            >{{ diseaseTypeName }}</el-button
          >
          <el-button
            @click="clickdisease()"
            type=""
            v-else
            style="
              width: 206px;
              text-align: left;
              height: 36px;
              padding-left: -10px;
              overflow: hidden;
            "
            >{{ diseaseTypeName }}</el-button
          >
        </el-form-item>

        <el-form-item label="语音播报" prop="voicebroadcast">
          <el-input
            v-model="form.voicebroadcast"
            type="textarea"
            style="width: 206px"
            placeholder="请输入语音播报"
          />
        </el-form-item>
        <el-form-item label="文章摘要" prop="articleSummary">
          <el-input
            v-model="form.articleSummary"
            type="textarea"
            style="width: 206px"
            placeholder="请输入文章摘要"
            maxlength="300"
          />
        </el-form-item>
        <el-form-item label="添加封面" prop="propagandaCoverPath">
          <stationAcatar
            v-if="open"
            @imgUrl="imgUrl"
            :img="form.propagandaCoverPath"
            :type="'propagandaCoverUrl'"
          />
        </el-form-item>
        <el-form-item label="素材选择" prop="imgPath">
          <div class="propagandaselect" @click="material" v-if="!form.imgPath">
            <div class="add">+</div>
          </div>
          <img
            @click="material"
            class="propagandaselect"
            :src="baseUrl + form.imgPath"
            alt=""
            v-else-if="
              form.imgPath && querymaterial.materialsType == 'IMAGE_TEXT'
            "
          />
          <video
            @click="material"
            style="height: 200px; width: 300px"
            v-else-if="form.imgPath && querymaterial.materialsType == 'VIDEO'"
            ref="myVideo"
            :src="baseUrl + form.imgPath"
            controls
          ></video>
        </el-form-item>
        <el-form-item label="正文内容" prop="propagandaContent">
          <editor
            v-model="form.propagandaContent"
            :min-height="192"
            style="width: 800px"
            @input="checkContentLength"
          />
        </el-form-item>
      </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>
    <!-- 科室弹框 -->
    <el-dialog
      title=""
      :visible.sync="innerVisibleshow"
      width="1000px"
      append-to-body
      :before-close="innerVisiblecancel"
    >
      <el-form
        ref="queryForm"
        :model="informationqueryParams"
        :rules="rules"
        label-width="80px"
        :inline="true"
      >
        <el-form-item label="科室名称" prop="departmentName" label-width="120">
          <el-input
            v-model="informationqueryParams.departmentName"
            placeholder="请输入科室名称"
            clearable
          />
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="informationInfoinfo"
            >搜索</el-button
          >
          <el-button
            icon="el-icon-refresh"
            size="mini"
            @click="addresetQuerylist"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <el-table
        :data="infolist"
        @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.departmentId == scope.row.departmentCode"
              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="departmentName"
          label="科室名称"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
      </el-table>
      <pagination
        v-show="totaldepartment > 0"
        :total="totaldepartment"
        :page.sync="informationqueryParams.pageNum"
        :limit.sync="informationqueryParams.pageSize"
        @pagination="informationInfoinfo"
      />
    </el-dialog>
    <!-- 病种弹框 -->
    <el-dialog
      title=""
      :visible.sync="diseaseshowst"
      width="1000px"
      append-to-body
      :before-close="canceldiseases"
    >
      <el-form
        ref="queryForm"
        :model="querydisease"
        :rules="rules"
        label-width="80px"
        :inline="true"
      >
        <el-form-item label="病种名称" prop="diseaseTypeName" label-width="120">
          <el-input
            v-model="querydisease.diseaseTypeName"
            placeholder="请输入病种名称"
            clearable
          />
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="infodisease"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetdisease"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <el-table
        :data="listdisease"
        @cell-dblclick="nurseclickdisease"
        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.diseaseTypeId == scope.row.id"
              circle
              @click="nurseclickdisease(scope.row)"
            ></el-button>
            <el-button
              v-else
              style="width: 15px; height: 15px"
              circle
              @click="nurseclickdisease(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column
          property="diseaseTypeName"
          label="病种名称"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
      </el-table>
      <pagination
        v-show="diseasetotal > 0"
        :total="diseasetotal"
        :page.sync="querydisease.pageNum"
        :limit.sync="querydisease.pageSize"
        @pagination="infodisease"
      />
    </el-dialog>
    <!-- 审核弹框 -->
    <el-dialog
      title="提示"
      :visible.sync="dialogexamine"
      width="30%"
      :before-close="handleClose"
      center
    >
      <span style="font-size: 18px; margin-left: 55px">是否同意审核？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelamine">同意</el-button>
        <el-button type="primary" @click="submitamine">不同意</el-button>
      </span>
    </el-dialog>
    <!-- 预览弹框 -->
    <el-dialog
      title="预览"
      :visible.sync="dialogview"
      width="30%"
      :before-close="handleview"
    >
      <div class="titletop">文章模板:{{ formview.propagandaTitle }}</div>
      <div class="bodytop">
        <div class="titledata">{{ formview.propagandaTitle }}</div>
        <!-- <div class="audiotop">
          <audio controls="controls" ref="audio"></audio>
        </div> -->
        <div>
          <img :src="baseUrl + formview.propagandaCoverPath" alt="" />
          <div class="know">知识卡片</div>
          <div class="knowlist">
            <Editorxj
            v-model="formview.propagandaContent"
            :min-height="192"
            style="width: 800px"
          />

            <!-- {{ formview.propagandaContent }} -->
            <!-- 二甲双胍的用药安全性良好，已经过多年临床用药实践论证。但不用于10岁以下患者、肝功能不全患者(尤其转氨酶高于3倍正常值的患者)、肾功能异 -->
          </div>
        </div>
      </div>
    </el-dialog>
    <!-- 素材选择弹框 -->
    <el-dialog
      title="请选择素材"
      :visible.sync="dialogmaterial"
      width="900px"
      :before-close="materialClose"
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
        <el-form-item label="素材名称" prop="materialsName">
          <el-input
            v-model="querymaterial.materialsName"
            placeholder="请输入素材名称"
            clearable
            @keyup.enter.native="handleQuerysc"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuerysc"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuerysc"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <el-tabs
        v-model="querymaterial.materialsType"
        type="card"
        @tab-click="handleClick"
      >
        <el-tab-pane label="图片" name="IMAGE_TEXT"></el-tab-pane>
        <el-tab-pane label="视频" name="VIDEO"></el-tab-pane>
      </el-tabs>
      <div class="bodytopxj">
        <div class="bodylist" v-for="item in materialsList" :key="item.id">
          <!-- <el-checkbox
            v-model="item.checked"
            @change="changecheck($event, item)"
          ></el-checkbox> -->
          <div @click.stop="viewshow(item)">
            <img
              :src="baseUrl + item.materialsFilePath"
              alt=""
              v-if="item.materialsFilePath && !item.videoCoverFilePath"
            />
            <img
              :src="baseUrl + item.videoCoverFilePath"
              alt=""
              v-if="item.videoCoverFilePath && item.materialsFilePath"
            />
            <div class="texttitle">{{ item.materialsName }}</div>
            <div class="dataliat">
              创建人/创建时间：<span>{{ item.createBy }}</span
              >/<span>{{ item.createTime }}</span>
            </div>
            <!-- <div class="dataliat">素材来源：</div> -->
            <!-- <div class="dataliat">标签：暂无</div> -->
            <div
              class="dataliat bq"
              v-if="
                item.indications ||
                item.drugName ||
                item.applicableDiseases ||
                item.surgicalName ||
                item.inspectionItems ||
                item.checkItems
              "
            >
              标签：

              <span v-if="item.indications">{{ item.indications }}，</span>
              <span v-if="item.drugName">{{ item.drugName }}，</span>
              <span v-if="item.applicableDiseases"
                >{{ item.applicableDiseases }}，</span
              >
              <span v-if="item.surgicalName">{{ item.surgicalName }}，</span>
              <span v-if="item.inspectionItems"
                >{{ item.inspectionItems }}，</span
              >
              <span v-if="item.checkItems">{{ item.checkItems }}，</span>
            </div>
            <div class="dataliat bq" v-else>标签：暂无</div>
          </div>

          <div class="label" @click.stop="labelchange(item)">加到文章</div>
        </div>
      </div>

      <pagination
        v-show="totalmaterial > 0"
        :total="totalmaterial"
        :page.sync="querymaterial.pageNum"
        :limit.sync="querymaterial.pageSize"
        @pagination="getmaterial"
      />
    </el-dialog>
    <!-- 预览弹框 -->
    <el-dialog title="预览" :visible.sync="openview" width="60%">
      <div class="viewbody">
        <div class="left">
          <video
            v-if="querymaterial.materialsType == 'VIDEO'"
            ref="myVideo"
            :src="baseUrl + viewform.materialsFilePath"
            controls
          ></video>
          <img
            :src="baseUrl + viewform.materialsFilePath"
            alt=""
            v-if="querymaterial.materialsType == 'IMAGE_TEXT'"
          />
        </div>
        <div class="right">
          <div class="nametitle">素材名称</div>
          <div class="nameitem">{{ viewform.materialsName }}</div>
          <div class="nametitle">创建人员</div>
          <div class="nameitem">{{ viewform.createBy }}</div>
          <div class="nametitle">创建时间</div>
          <div class="nameitem">{{ viewform.createTime }}</div>
          <div class="nametitle">素材摘要</div>
          <div class="nameitem">{{ viewform.materialsAbstract }}</div>
          <div class="nametitle">素材标签</div>
          <div class="nameitem">适用症状：{{ viewform.indications }}</div>
          <div class="nameitem">药物名称：{{ viewform.drugName }}</div>
          <div class="nameitem">
            适用疾病：{{ viewform.applicableDiseases }}
          </div>
          <div class="nameitem">手术名称：{{ viewform.surgicalName }}</div>
          <div class="nameitem">检验项目：{{ viewform.inspectionItems }}</div>
          <div class="nameitem">检查项目：{{ viewform.checkItems }}</div>
          <div class="nameitem">人群：{{ viewform.crowName }}</div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPropaganda, getPropaganda, delPropaganda, addPropaganda, updatePropaganda, selectNumByDept, copy, updateStatus } from "@/api/manage/propaganda";
import { listMaterials } from "@/api/manage/materials";
import { selectAgencyList, getDepartmentList } from "@/api/manage/selectAgencyList";

import stationAcatar from "../../system/stationAvatar/index.vue";
import Editorxj from "../../system/Editorxj/index.vue";
import { department, listDisease } from "@/api/manage/script";
export default {
  name: "Propaganda",
  components: { stationAcatar ,Editorxj},
  data() {
    //验证身份证
    var isimgPath = (rule, value, callback) => {
      console.log(value)
      if (!this.form.imgPath) {
        callback(new Error("素材选择不能为空"));
      } else {
        callback();
      }
    };
    return {
      maxLength: 20000,
      itemname: null,
      departmentName: null,
      diseaseTypeName: null,
      name: '',
      departmentId: null,
      count: '',//全部
      DepartmentoList: [],//左侧数组
      // 左侧传值
      querydepartmen: {
        departmentName: "",
        // pageNum: 1,
        // pageSize: 10,

      },


      innerVisibleshow: false, //科室弹框
      // 科室
      informationqueryParams: {
        pageNum: 1,
        pageSize: 10,
        departmentName: null,
      },
      infolist: [],
      totaldepartment: 0,

      diseaseshowst: false,//病种弹框
      querydisease: {
        pageNum: 1,
        pageSize: 10,
        diseaseTypeName: null,
        departmentId: null,
      },
      listdisease: [],
      diseasetotal: 0,


      dialogexamine: false,//审核
      dialogview: false,//预览
      formview: {
        articleSummary: null,
        propagandaTitle: null,

      },//预览数据
      copyid: null,//复制id
      examineid: null,//审核id

      optionstype: [{
        value: 'MEDICATION_KNOWLEDGE',
        label: '用药知识'
      }, {
        value: 'DISEASE_POPULARIZATION',
        label: '疾病科普'
      }, {
        value: 'SPORT_NUTRITION',
        label: '运动营养'
      }, {
        value: 'OTHER_KNOWLEDGE',
        label: '其他知识'
      }, {
        value: 'CUSTOMIZED_CONTENT',
        label: '定制内容'
      }],
      value: '',
      optionsstate: [{
        value: 'CREATE_PROCESS',
        label: '创作中'
      }, {
        value: 'CREATE_COMPLETE',
        label: '创作完成'
      }, {
        value: 'IN_REVIEW',
        label: '审核中'
      }, {
        value: 'APPROVED',
        label: '审核通过'
      }, {
        value: 'REVIEW_FAILED',
        label: '审核不通过'
      }],
      // 素材弹框
      dialogmaterial: false,
      // 素材信息表格数据
      materialsList: [],
      // 查询参数
      querymaterial: {
        pageNum: 1,
        pageSize: 10,
        materialsType: 'IMAGE_TEXT',
        materialsName: null,
        materialsStatus: null,
        createTime: null,
      },
      totalmaterial: 0,
      baseUrl: process.env.VUE_APP_BASE_API,
      openview: false,
      viewform: [],
      //医院list
      hospitalAgencylist: [],
      Departmentdata: [],
      value: '',
      // 遮罩层
      // loading: true,
      loading: false,

      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 患者宣教信息表格数据
      propagandaList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        patientId: null,
        propagandaId: null,
        departmentName: null,
        createTimeStart: null,
        createTimeEnd: null,
        propagandaTitle: null,
        propagandaType: null,
        propagandaCode: null,
        propagandaContent: null,
        propagandaCoverPath: null,
        articleSummary: null,
        voicebroadcast: null,
        diseaseTypeName: null,
        propagandaLink: null,
        propagandaBarcodePath: null,
      },
      // 表单参数
      form: {
        materialsInfoList: [],
      },
      // 表单校验
      rules: {
        hospitalAgencyName: [
          { required: true, message: "医院名称不能为空", trigger: "blur" }
        ],
        departmentId: [
          { required: true, message: "科室名称不能为空", trigger: "blur" }
        ],
        propagandaType: [
          { required: true, message: "宣教类型不能为空", trigger: "blur" }
        ],
        propagandaCoverPath: [
          { required: true, message: "封面不能为空", trigger: "blur" }
        ],
        imgPath: [
          { required: true, message: "", validator: isimgPath, trigger: "blur" }
        ],
      },
    };
  },
  computed: {
    pickerStartTime() {
      return {
        disabledDate: (time) => {
          if (this.queryParams.createTimeEnd) {
            let edtTime = this.queryParams.createTimeEnd.replace(/-/g, "/");
            return time.getTime() > new Date(edtTime);
          }
        },
      };
    },
    pickerEndTime() {
      return {
        disabledDate: (time) => {
          if (this.queryParams.createTimeStart) {
            let startTime = this.queryParams.createTimeStart.replace(/-/g, "/");
            return time.getTime() < new Date(startTime);
          }
        },
      };
    },
  },
  created() {
    this.Departmentlist();
    this.getList();
    this.selectAgencyinfo();
  },
  watch: {
    name(val) {
      this.querydepartmen.departmentName = val
      this.Departmentlist();
    }
  },
  methods: {
    checkContentLength() {
      // console.log(this.form.propagandaContent.length, 'this.form.propagandaContent.length')
      if (this.form.propagandaContent.length - 7 > this.maxLength) {
        this.$message({
          type: "error",
          message: "已达到最大输入长度"
        });
      }
    },
    //获取医院list
    selectAgencyinfo() {
      let query = {
        nodeType: 'HOSPITAL',
      }
      selectAgencyList(query).then(res => {
        this.hospitalAgencylist = res.data
      })
    },
    // 医院
    changehospitalAgency(e) {
      console.log(e,'00000')
      this.form.hospitalAgencyName = this.hospitalAgencylist.find(f => f.id == e).agencyName
      this.form.hospitalAgencyId = e
      this.form.departmentName = ''
      this.form.departmentId = ''
      this.diseaseTypeName = '请选择病种'
      this.form.diseaseTypeId = '';
      let query = {
        nodeType: 'DEPARTMENT',
        hospitalAgencyId: e,
      }
      getDepartmentList(query).then(res => {
        this.Departmentdata = res.data
      })
    },
    // 科室点击事件
    changeDepartment(e) {
      this.form.departmentId = e
      this.form.departmentName = this.Departmentdata.find(f => f.id == e).departmentName
      this.diseaseTypeName = '请选择病种'
      this.form.diseaseTypeId = '';
      console.log(this.form)



    },
    onBlur() {
      console.log(this.form, '------------------')
      if (!this.form.hospitalAgencyName) {
        this.$modal.msgError("请先选择医院");
      }

    },
    // 素材选择
    material() {
      this.dialogmaterial = true
      this.querymaterial.materialsType = 'IMAGE_TEXT',
        this.getmaterial()

    },
    // 关闭素材
    materialClose() {
      this.dialogmaterial = false
    },
    // 复选框点击事件
    // changecheck(e, item) {
    //   this.ids = this.materialsList.map(item => item.checked ? item.id : undefined).filter(e => e)
    //   if (this.ids.length > 0) {
    //     this.multiple = false
    //   } else {
    //     this.multiple = true
    //   }
    // },
    // 图片/视频
    handleClick(e) {
      this.querymaterial.materialsType = e.name
      this.getmaterial()
    },
    // 加到文章
    labelchange(item) {
      this.form.materialsInfoList = []
      this.form.imgPath = item.materialsFilePath
      this.form.materialsInfoList.push(item)

      this.dialogmaterial = false
      console.log(item)

    },
    // 预览
    viewshow(item) {
      this.openview = true
      this.viewform = item

    },
    /** 查询素材信息列表 */
    getmaterial() {
      this.loading = true;
      this.querymaterial.params = {};
      listMaterials(this.querymaterial).then(response => {
        this.materialsList = response.rows;
        this.totalmaterial = response.total;
        this.loading = false;
      });
    },
    // 开始时间
    changecreateTimeStart(e) {
      this.queryParams.createTimeStart = e
      console.log(e)

    },
    // 结束时间
    changecreateTimeEnd(e) {
      this.queryParams.createTimeEnd = e
    },
    // 复制
    copyUrl(row) {
      this.copyid = row.id
      console.log(this.copyid, '00000')
      this.$confirm('确定复制该文章内容?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        console.log(this.copyid)
        copy(this.copyid).then(response => {
          this.$message({
            type: "success",
            message: "复制成功"
          });
          this.getList()
          this.Departmentlist()

        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消复制'
        });
      });
    },
    // 复制链接
    copylink() {

    },
    // 预览
    Preview(row) {
      console.log(row)
      const id = row.id || this.ids
      getPropaganda(id).then(response => {
        this.formview = response.data;
        this.dialogview = true


      });
    },
    // 关闭预览
    handleview() {
      this.dialogview = false
    },
    // 审核
    examine(row) {
      this.examineid = row.id
      this.dialogexamine = true
    },
    // 审核同意按钮

    cancelamine() {
      var formexmine = {
        id: this.examineid,
        propagandaStatus: 'APPROVED'

      }
      updateStatus(formexmine).then(response => {
        this.$message({
          type: "success",
          message: "审核通过"
        });
        this.getList()
      });
      this.dialogexamine = false

    },
    // 审核关闭按钮

    handleClose() {
      this.dialogexamine = false
    },
    // 审核不同意按钮

    submitamine() {
      var formexmine = {
        id: this.examineid,
        propagandaStatus: 'REVIEW_FAILED'

      }
      updateStatus(formexmine).then(response => {
        this.$message({
          type: "success",
          message: "审核不通过"
        });
        this.getList()
      });

      this.dialogexamine = false
    },
    // 左侧科室列表
    Departmentlist() {
      this.loading = true;
      selectNumByDept(this.querydepartmen).then(response => {
        this.DepartmentoList = response.data;
        let sum = 0;
        this.DepartmentoList.forEach((item) => {
          if (item.countNum != null) {
            console.log(item.countNum)
            sum += item.countNum;
          }
          this.count = sum;
        });
        this.loading = false;
      });
    },
    // 左侧科室
    itemdata(item) {
      if (item) {
        this.itemname = item.id
        // this.departmentName = item.departmentName
        this.loading = true;
        this.queryParams.departmentId = item.id
        this.getList()
      } else {
        this.queryParams.departmentId = ''
        this.itemname = null
        this.getList()

      }
    },


    /** 查询患者宣教信息列表 */
    getList() {
      this.loading = true;
      listPropaganda(this.queryParams).then(response => {
        this.propagandaList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 点击科室
    clickinnerVisible() {
      this.innerVisibleshow = true;
      if (this.itemname) {
        this.informationqueryParams.departmentId = this.itemname

      } else {
        this.informationqueryParams.departmentId = null
      }
      this.informationInfoinfo();
    },
    // 科室列表
    informationInfoinfo() {
      department(this.informationqueryParams).then((response) => {
        this.infolist = response.rows;
        this.totaldepartment = response.total;
        this.loading = false;
      });
      // this.informationqueryParams.page = 1;
    },
    // 科室名称重置
    addresetQuerylist() {
      this.informationqueryParams = {
        pageNum: 1,
        pageSize: 10,
      };
      this.informationInfoinfo();
    },
    innerVisiblecancel() {
      this.innerVisibleshow = false;
    },
    // 科室名称圆点按钮
    nurseclick(row) {
      this.form.departmentId = row.departmentCode;
      this.departmentName = row.departmentName;
      this.form.diseaseTypeId = '';
      this.diseaseTypeName = '请选择病种';
      this.innerVisibleshow = false;
    },

    // 病种列表
    infodisease() {
      listDisease(this.querydisease).then((response) => {
        this.listdisease = response.rows;
        this.diseasetotal = response.total;
        this.loading = false;
      });
    },
    // 点击病种
    clickdisease() {
      if (!this.form.departmentName) {
        this.$modal.msgError("请先选择科室");
      } else {
        this.diseaseshowst = true;
        this.querydisease.departmentId = this.form.departmentId
        this.infodisease()
      }
    },
    // 病种名称圆点按钮
    nurseclickdisease(row) {
      this.form.diseaseTypeId = row.id;
      this.diseaseTypeName = row.diseaseTypeName;
      this.diseaseshowst = false;
    },
    // 重置
    resetdisease() {
      querydisease = {
        pageNum: 1,
        pageSize: 10,
      };
      this.infodisease()
    },

    canceldiseases() {
      this.diseaseshowst = false;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        imgPath: null,
        materialsInfoList: [],
        hospitalAgencyId: null,
        id: null,
        patientId: null,
        propagandaId: null,
        propagandaStatus: null,
        departmentName: null,
        propagandaTitle: null,
        propagandaCode: null,
        departmentId: null,
        propagandaType: null,
        propagandaCode: null,
        propagandaContent: null,
        propagandaCoverPath: null,
        articleSummary: null,
        voicebroadcast: null,
        diseaseTypeName: null,
        propagandaLink: null,
        propagandaBarcodePath: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleQuerysc() {
      this.querymaterial.pageNum = 1;
      this.getmaterial();
    },
    resetQuerysc() {
      this.querymaterial.materialsName = null
      this.handleQuerysc()

    },

    /** 重置按钮操作 */
    resetQuery() {
      // this.queryParams.departmentId = null;
      this.queryParams.createTimeEnd = null,
        this.queryParams.createTimeStart = null,
        this.itemname = null;
      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.reset();
      this.selectAgencyinfo();
      this.form.propagandaStatus = 'CREATE_COMPLETE'
      this.diseaseTypeName = "请选择病种"
      this.Departmentdata = []
      this.open = true;
      this.title = "新增宣教";
      console.log(this.form, '90909090')
    },
    /** 修改按钮操作 */
    handleUpdate(row) {

      this.reset();
      const id = row.id || this.ids
      getPropaganda(id).then(response => {
        this.form = response.data;
        this.form.suitTaskTypeIds = response.data.suitTaskTypeIds
        this.diseaseTypeName = response.data.diseaseTypeName
        // this.form.agencyName = response.data.hospitalAgencyName
        this.form.imgPath = response.data.materialsInfoList[0]?.materialsFilePath
        this.querymaterial.materialsType = response.data.materialsInfoList[0]?.materialsType
        this.open = true;
        this.title = "修改患者宣教信息";
      });
      // }
    },
    // 上传封面
    imgUrl(imgUrl) {
      this.form.propagandaCoverPath = imgUrl;
    },
    /** 提交按钮 */
    submitForm() {
      // return
      console.log(this.form)
      if(this.form.propagandaContent && this.form.propagandaContent.length - 7 > this.maxLength){
        // if (this.form.propagandaContent.length - 7 > this.maxLength) {
        this.$message({
          type: "error",
          message: "已达到最大输入长度"
        });

      // }

      }else{

      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {

            this.form.diseaseTypeName = this.diseaseTypeName
            updatePropaganda(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            if (this.diseaseTypeName == '请选择病种') {
              this.form.diseaseTypeName = null
            } else if (this.diseaseTypeName) {
              this.form.diseaseTypeName = this.diseaseTypeName
            }
            addPropaganda(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
              this.Departmentlist()
            });

          }
        }
      });
    }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除该宣教信息？').then(function () {
        return delPropaganda(ids);
      }).then(() => {
        this.getList();
        this.Departmentlist()
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('manage/propaganda/export', {
        ...this.queryParams
      }, `propaganda_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>
// ::v-deep .el-form-item--medium .el-form-item__content{
//   width: 800px;

// }
.propagandaselect {
  width: 100px;
  height: 100px;
  background: #fafafa;
  .add {
    color: #b6b6b7;
    font-size: 22px;
    line-height: 100px;
    text-align: center; //水平居中
    // margin: 0 auto;
  }
}

.leftpro {
  height: 760px;
  overflow: auto;
  .name {
    font-weight: 700;
    margin-bottom: 10px;
  }
  .listitem {
    width: 100%;
    height: 50px;
    border-bottom: 1px solid #dcdfe6;
    .count {
      display: inline-block;
      position: relative;
      // right: -172px;
      left: 210px;
      color: #a4a6aa;
      top: -35px;
      font-size: 13px;
    }
    .all {
      height: 50px;
      line-height: 50px;
      padding-left: 13px;
    }
    .allactive {
      background: #e8f4ff;
      height: 50px;
      line-height: 50px;
      padding-left: 13px;
      border-left: 3px solid #4d9de7;
    }
  }
}
.button {
  display: inline-block;
  position: relative;
  left: 20px;
  top: -11px;
}
audio {
  width: 350px;

  // background: #4d9de7;
}
.titletop {
  font-size: 16px;
  font-weight: 700;
}
.bodytop {
  position: relative;
  top: 20px;
  height: 500px;
  overflow: auto;
  border: 1px solid #e2e2e2;
  .titledata {
    margin: 30px 0px 15px 30px;
    top: 14px;
    font-size: 20px;
  }
  .audiotop {
    margin: 10px 0px 10px 30px;
  }
  img {
    // width: 100%;
    // width: 362px;
    // height: 127px;
    margin: 0px 0px 0px 30px;
  }
  .know {
    margin: 11px 0px 10px 30px;
    font-size: 16px;
  }
  .knowlist {
    margin: 10px 0px 10px 30px;
    font-size: 16px;
  }
}

.viewbody {
  width: 100%;
  height: 500px;
  // background: #409eff;
  display: flex;
  .left {
    overflow: auto;
    width: 77%;
    height: 500px;
    // background: #989992;
    video {
      height: 500px;
      width: 100%;
    }
  }
  img {
    // height: 100%;
    // width: 100%;
  }
  .right {
    width: 20%;
    // background: red;
    overflow: auto;
    margin-left: 30px;
    .nametitle {
      font-size: 14px;
      font-weight: 600;
    }
    .nameitem {
      color: #959595;
      margin: 13px;
    }
  }
}
.bodytopxj {
  width: 100%;
  display: flex;
  white-space: wrap;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-start;
  // align-content: space-between;
  .bodylist {
    width: 31%;
    height: 221px;
    border: 2px solid #e2e3e5;
    border-radius: 10px;
    position: relative;
    // margin-bottom: 10px;
    margin: 6px;
    .texttitle {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      font-weight: 700;
      margin: 5px 0px 5px 10px;
    }
    //
    .dataliat {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin: 0px 0px 5px 10px;
      font-size: 12px;
      color: #989992;
    }
    .bq {
      width: 155px;
    }
    img {
      width: 100%;
      height: 100px;
    }
    .label {
      position: absolute;
      right: 0px;
      right: 18px;
      color: #409eff;
      bottom: 23px;
      font-size: 13px;
    }
  }
}
</style>
