<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="装置名称" prop="plants">
        <el-select v-model="plantIds"  size="small"  @change="handleCommand" multiple collapse-tags :placeholder="$t('请选择') + $t('装置')">
          <el-checkbox v-model="checked" @change="selectAll"> ALL</el-checkbox>
          <el-option
            v-for="item in plantOptions"
            :key="item.name"
            :label="item.name"
            :value="item.name">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="周排查日期" prop="checkDate">
        <el-date-picker
          v-model="chooseDate"
          @change="handleQuery"
          type="daterange"
          style="width: 508px"
          align="right"
          unlink-panels
          :range-separator="$t('至')"
          :start-placeholder="$t('开始日期')"
          :end-placeholder="$t('结束日期')"
          value-format="yyyy-MM-dd"
          :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item>
<!--      <el-form-item label="人员" prop="cPerson">-->
<!--        <el-select v-model="queryParams.cPerson" placeholder="请选择人员" clearable size="small">-->
<!--          <el-option label="请选择字典生成" value=""/>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="设备本体" prop="cDevice">-->
<!--        <el-select v-model="queryParams.cDevice" placeholder="请选择设备本体" clearable size="small">-->
<!--          <el-option label="√" value="√"/>-->
<!--          <el-option label="×" value="×"/>-->
<!--        </el-select>-->
<!--      </el-form-item>-->

      <el-form-item>
        <el-button type="cyan" 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"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['safecheck:dailycheck:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['safecheck:dailycheck:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['safecheck:dailycheck:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          :disabled="multiple"
          @click="handleDownload"
        >批量下载Word
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          :disabled="multiple"
          @click="handleDownloadPdf"
        >批量下载PDF
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleBatchConfirm"
          v-hasPermi="['safecheck:weekcheck:edit']"
        >批量锁定</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleBatchCancel"
          v-hasPermi="['safecheck:weekcheck:edit']"
        >取消锁定</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <u-table v-loading="loading" :data="dailycheckList"
              use-virtual
              showBodyOverflow="title"
              :row-height="60"
              @selection-change="handleSelectionChange"
              :height="clientHeight" border>
      <u-table-column type="selection" width="55" align="center"/>
      <u-table-column label="装置名称" align="center" prop="plantCode" :show-overflow-tooltip="true"/>
      <u-table-column label="检查日期" align="center" prop="checkDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkDate, '{y}-{m}-{d}') }}</span>
        </template>
      </u-table-column>
<!--      <u-table-column label="状态" align="center" prop="isConfirm" :show-overflow-tooltip="true" :formatter="isConfirmFormat"/>-->

      <u-table-column label="安全员" align="center" prop="checkerName" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.agentId">{{ scope.row.checkerName}} 代 {{ scope.row.agentName}}</span>
          <span v-else>{{ scope.row.checkerName}}</span>
        </template>
      </u-table-column>
      <u-table-column label="人员" align="center" prop="cPerson" :show-overflow-tooltip="true" :formatter="itemFormat"/>
      <u-table-column label="设备本体" align="center" prop="cDevice" :show-overflow-tooltip="true" :formatter="itemFormat"/>
      <u-table-column label="安全附件或安全保护装置" align="center" prop="cSafety" :show-overflow-tooltip="true" :formatter="itemFormat"/>
      <u-table-column label="政府监督、通报、预警" align="center" prop="cGov" :show-overflow-tooltip="true" :formatter="itemFormat"/>
      <u-table-column label="投诉举报" align="center" prop="cComplaint" :show-overflow-tooltip="true" :formatter="itemFormat"/>
      <u-table-column label="舆情信息" align="center" prop="cOpinion" :show-overflow-tooltip="true" :formatter="itemFormat"/>
      <u-table-column label="其他" align="center" prop="cOther" :show-overflow-tooltip="true" :formatter="itemFormat"/>
      <u-table-column label="说明" align="center" prop="explain" :show-overflow-tooltip="true" />
      <u-table-column label="操作" align="center" fixed="right" width="120" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.isConfirm == 0"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['safecheck:dailycheck:edit']"
          >修改
          </el-button>
          <el-button
            v-if="scope.row.isConfirm == 0"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['safecheck:dailycheck:remove']"
          >删除
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="wordView(scope.row)"
          >预览
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="handleDoc(scope.row)"
          >附件
          </el-button>
        </template>
      </u-table-column>
    </u-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :page-sizes="[20,100,300,500]"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改每日安全检查对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item :label="$t('装置')" prop="plantCode">
          <el-select v-model="form.plantCode" :placeholder="$t('请选择')+ $t('装置')" filterable clearable size="small"
          >
            <el-option
              v-for="dict in plantOptions"
              :key="dict.name"
              :label="dict.name"
              :value="dict.name"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="检查日期" prop="checkDate">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.checkDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择检查日期">
          </el-date-picker>
        </el-form-item>
        <div class="checklist-table">
          <table cellpadding="10" cellspacing="0" border="1" style="width:100%">
            <tr>
              <th>序号</th>
              <th>检查项目</th>
              <th>检查内容</th>
              <th>检查结果</th>
            </tr>
            <tr>
              <td>1</td>
              <td>人员</td>
              <td>按检查项目细化，如:人员配备、违章作业、安全教育等</td>
              <td>
                <el-radio-group v-model="form.cPerson">
                  <el-radio label="√">√</el-radio>
                  <el-radio label="×">X</el-radio>
                </el-radio-group>
              </td>
            </tr>
            <tr>
              <td>2</td>
              <td>设备本体</td>
              <td>设备定期检验、自行检查、设备本体有无事故隐患等</td>
              <td style="width: 150px;">
                <div class="radio-group-horizontal">
                  <el-radio-group v-model="form.cDevice">
                    <el-radio label="√">√</el-radio>
                    <el-radio label="×">X</el-radio>
                  </el-radio-group>
                </div>
              </td>
            </tr>
            <tr>
              <td>3</td>
              <td>安全附件或安全保护装置</td>
              <td>安全阀、爆破片等</td>
              <td>
                <el-radio-group v-model="form.cSafety">
                  <el-radio label="√">√</el-radio>
                  <el-radio label="×">X</el-radio>
                </el-radio-group>
              </td>
            </tr>
            <tr>
              <td>5</td>
              <td>政府监督、通报、预警</td>
              <td>发现不合格项</td>
              <td>
                <el-radio-group v-model="form.cGov">
                  <el-radio label="√">√</el-radio>
                  <el-radio label="×">X</el-radio>
                </el-radio-group>
              </td>
            </tr>
            <tr>
              <td>6</td>
              <td>投诉举报</td>
              <td>发现不合格项</td>
              <td>
                <el-radio-group v-model="form.cComplaint">
                  <el-radio label="√">√</el-radio>
                  <el-radio label="×">X</el-radio>
                </el-radio-group>
              </td>
            </tr>
            <tr>
              <td>7</td>
              <td>舆情信息</td>
              <td>发现不合格项</td>
              <td>
                <el-radio-group v-model="form.cOpinion">
                  <el-radio label="√">√</el-radio>
                  <el-radio label="×">X</el-radio>
                </el-radio-group>
              </td>
            </tr>
            <tr>
              <td>8</td>
              <td>其它</td>
              <td>锅炉、压力容器、压力管道、电梯、起重机械场车六大类特种设备可能危及安全的其它情况</td>
              <td>
                <el-radio-group v-model="form.cOther">
                  <el-radio label="√">√</el-radio>
                  <el-radio label="×">X</el-radio>
                </el-radio-group>
              </td>
            </tr>
            <tr>
              <!--            <td colspan="4">-->
              <!--              不合格情况说明及采取的防范措施:-->
              <!--              <el-form-item label="不合格情况说明及采取的防范措施:" prop="explain">-->
              <!--                <el-input v-model="form.explain" type="textarea" placeholder="请输入内容" />-->
              <!--              </el-form-item>-->
              <!--            </td>-->
            </tr>
          </table>
        </div>
        <el-form-item label="不合格情况说明及采取的防范措施" prop="explain">
          <el-input v-model="form.explain" :rows="5" type="textarea" placeholder="请输入内容"/>
        </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="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-checkbox v-model="upload.updateSupport"/>
          是否更新已经存在的用户数据
          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :close-on-click-modal="false" v-loading="loadingFlash" element-loading-background="rgba(0,0,0,0.2)"
               v-dialogDrag :title="pdf.title"
               :visible.sync="pdf.open" width="1300px" :center="true" append-to-body>
      <div style="margin-top: -60px;float: right;margin-right: 40px;">
        <el-button size="mini" type="text" @click="openPdf">{{ $t('新页面打开PDF') }}</el-button>
      </div>
      <div style="margin-top: -30px">
        <iframe id="iFrame" class="iframe-html" :src="pdf.pdfUrl" frameborder="0" width="100%" height="700px"
                v-if="ppt"></iframe>
      </div>
      <div style="padding: 30px; width: 100%; height: 100%;">
        <el-carousel class="" ref="carousel" arrow="always" v-if="pptView"
                     height="700px" trigger="click" :autoplay="false" indicator-position="outside">
          <el-carousel-item class="lun_img" v-for="item in imgs" v-bind:key="item">
            <img :src="item" width="100%" height="100%" object-fit="cover"/>
          </el-carousel-item>
        </el-carousel>
      </div>
    </el-dialog>
    <form ref="downloadForm2" :action="downloadWordAction" target="FORMSUBMIT">
      <input name="id" v-model="downloadForm2.id" hidden/>
    </form>
    <form ref="downloadFormPdf" :action="downloadWordActionPdf" target="FORMSUBMIT">
      <input name="id" v-model="downloadFormPdf.id" hidden/>
    </form>
    <Attachment ref="childRef"></Attachment>
  </div>
</template>

<script>
import {
  wordView,
  batchConfirm,
  listDailycheck,
  getDailycheck,
  delDailycheck,
  addDailycheck,
  updateDailycheck,
  exportDailycheck,
  importTemplate, batchCancel
} from "@/api/sems/safecheck/dailycheck";
import {treeselect} from "@/api/system/dept";
import {getToken} from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {mylistPlant} from "@/api/system/plant";
import Attachment from '@/views/components/file/attachment.vue'

export default {
  name: "Dailycheck",
  components: {Treeselect,Attachment},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      dataListSelections: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 每日安全检查表格数据
      dailycheckList: [],
      // 弹出层标题
      title: "",
      pptView: false,
      ppt: false,
      loadingFlash: false,
      // 部门树选项
      deptOptions: undefined,
      plantOptions: [],
      plantIds: [],
      clientHeight: 300,
      // 是否显示弹出层
      open: false,
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/safecheck/dailycheck/importData"
      },
      pdf: {
        title: '',
        pdfUrl: '',
        numPages: null,
        open: false,
        pageNum: 1,
        pageTotalNum: 1,
        loadedRatio: 0,
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 500,
        plantCode: null,
        checkDate: null,
        cPerson: null,
        cDevice: null,
        cSafety: null,
        cEnv: null,
        cGov: null,
        cComplaint: null,
        cOpinion: null,
        cOther: null,
        explain: null
      },
      //日期快速选择
      pickerOptions: {
        shortcuts: [{
          text: this.$t('最近一周'),
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: this.$t('最近一个月'),
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: this.$t('最近三个月'),
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      //日期选择器
      chooseDate: [],
      // 表单参数
      form: {},
      downloadForm2: {
        id: '',
      },
      downloadWordAction: process.env.VUE_APP_BASE_API + '/safecheck/dailycheck/downloadDailycheck',
      downloadFormPdf: {
        id: '',
      },
      downloadWordActionPdf: process.env.VUE_APP_BASE_API + '/safecheck/dailycheck/downloadDailycheckPdf',
      // 表单校验
      rules: {
        plantCode: [
          {required: true, message: "装置名称不能为空", trigger: "blur"}
        ],
      }
    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    //设置表格高度对应屏幕高度
    this.$nextTick(() => {
      this.clientHeight = document.body.clientHeight - 250
    })
    this.getList();
    this.getTreeselect();
    let plantParams = {
      pType: 1
    }
    mylistPlant(plantParams).then(response => {
      this.plantOptions = response.data;
    });
  },
  methods: {
    /** 查询每日安全检查列表 */
    getList() {
      this.loading = true;
      listDailycheck(this.queryParams).then(response => {
        this.dailycheckList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 字典翻译
    isConfirmFormat(row, column) {
      let type = 'info';
      if (row.isConfirm == 0) {
        let s = '未锁定'
        return <el-tag type={type}>{s}</el-tag>;
      }
      if (row.isConfirm == 1) {
        let s = '已锁定'
        type = 'success';
        return <el-tag type={type}>{s}</el-tag>;
      }
    },
    itemFormat(row, column, cellValue, index) {
      let type = 'danger';
      if (cellValue == '×') {
        return <el-tag type={type}>{cellValue}</el-tag>;
      }
      return cellValue;
    },
    // 取
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        plantCode: null,
        delFlag: null,
        createrCode: null,
        createdate: null,
        updaterCode: null,
        updatedate: null,
        checkDate: null,
        checkerId: null,
        cPerson: "0",
        cDevice: "0",
        cSafety: "0",
        cEnv: "0",
        cGov: "0",
        cComplaint: "0",
        cOpinion: "0",
        cOther: "0",
        explain: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.chooseDate == null) {
        this.chooseDate = []
      }
      this.queryParams.startDate = this.chooseDate[0]
      this.queryParams.endDate = this.chooseDate[1]
      this.queryParams.plants = this.plantIds.join(',')
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.chooseDate = "";
      this.plantIds = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
      this.dataListSelections = selection
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加每日安全检查";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      var rows = this.dataListSelections.map(item => {
        return item
      })
      for (let i = 0; i < rows.length; i++) {
        if (rows[i].isConfirm != 0) {
          this.$alert("已锁定，无法修改", this.$t('提示'), {
            type: 'warning'
          })
          return
        }
      }
      getDailycheck(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改每日安全检查";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDailycheck(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDailycheck(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      var rows = this.dataListSelections.map(item => {
        return item
      })
      for (let i = 0; i < rows.length; i++) {
        if (rows[i].isConfirm != 0) {
          this.$alert("已锁定，无法删除", this.$t('提示'), {
            type: 'warning'
          })
          return
        }
      }

      this.$confirm('是否确认删除?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delDailycheck(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    handleDownload() {
      const ids = this.ids;
      this.downloadForm2.id = ids.join(',')
      this.$nextTick(() => {
        this.$refs['downloadForm2'].submit()
      })
    },
    handleDownloadPdf() {
      const ids = this.ids;
      this.downloadFormPdf.id = ids.join(',')
      this.$nextTick(() => {
        this.$refs['downloadFormPdf'].submit()
      })

    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有每日安全检查数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportDailycheck(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      importTemplate().then(response => {
        this.download(response.msg);
      });
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", {dangerouslyUseHTMLString: true});
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    wordView(row) {
      wordView(row.id).then(response => {
        console.log(response.msg)
        this.handleSee("每日检查记录", response.msg)
      });
    },
    handleSee(fileName, url) {
      //office预览
      this.loadingFlash = true
      this.pdf.open = true
      this.pdf.title = fileName
      this.pdf.pdfUrl = ""
      this.pptView = false
      this.ppt = true
      //如果是PDF等直接可以打开的就不调接口，否则调用接口
      if (fileName.endsWith('pdf')) {
        this.pdf.pdfUrl = process.env.VUE_APP_BASE_API + '/pdf/web/viewer.html?file=' + process.env.VUE_APP_BASE_API + url
        this.loadingFlash = false
      } else {
        const formatDate = new FormData();
        formatDate.append("filepath", url)
        //调用文件预览api
        let res = this.officeConvert.bookConvertCommon(formatDate)
        //查看接受全局方法的返回结果 console.log(res)
        //利用.then方法接受Promise对象
        res.then((result) => {
          //关闭加载中
          this.loadingFlash = false
          if (result.msg.includes("csv")) {
            this.pdf.pdfUrl = process.env.VUE_APP_BASE_API + result.data
            this.$alert(result.msg, this.$t('检查乱码'), {dangerouslyUseHTMLString: true});
            //    this.$message({message: result.msg, center: true,type:'warning',  offset:400, });
          } else if (result.msg.includes("不存在")) {
            //文件不存在时提示
            this.pdf.pdfUrl = ""
            this.$alert(result.msg, this.$t('预览失败'), {dangerouslyUseHTMLString: true});
            //    this.$message({message: result.msg, center: true,type:'warning',  offset:400, });
            this.pdf.open = false
          } else if (result.msg.includes("不支持此格式")) {
            this.pdf.pdfUrl = ""
            this.$alert(result.msg, this.$t('预览失败'), {dangerouslyUseHTMLString: true});
            //    this.$message({message: result.msg, center: true,type:'warning',  offset:400, });
            this.pdf.open = false
          } else {
            //成功时直接给地址
            this.pdf.pdfUrl = process.env.VUE_APP_BASE_API + result.data
          }
        }).catch(result => {
          //请求失败，关闭loading，pdf地址直接为为空，不显示
          this.pdf.pdfUrl = ""
          this.loadingFlash = false;
        })
      }
    },
    //文件预览
    openPdf() {
      //ppt就跳路由预览，office就直接打开文件新页面
      const didi = {imgs: this.imgs}
      if (this.pptView == true && this.ppt == false) {
        let routeUrl = this.$router.resolve({
          path: "/cpms/index.html#/pptyulan",
          query: didi
        });
        window.open("/cpms/index.html#/pptyulan?id=" + this.pdf.pdfUrl, '_blank')
        console.log(this.imgs)
      } else {
        window.open(this.pdf.pdfUrl)
      }
    },
    /** 报告附件按钮操作 */
    handleDoc(row) {
      // 通过ref引用子组件
      const child = this.$refs.childRef;
      // 调用子组件的方法并传递参数
      child.handleDoc(row , 'dailycheck');
    },
    /** 批量按钮操作 */
    handleBatchConfirm(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否锁定?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return batchConfirm(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("操作成功");
      })
    },
    /** 批量按钮操作 */
    handleBatchCancel(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否取消锁定?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return batchCancel(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("操作成功");
      })
    },
    selectAll() {
      this.plantIds = []
      if (this.checked) {
        this.plantOptions.map((item) => {
          this.plantIds.push(item.name)
        })
      } else {
        this.plantIds = []
      }
      if (this.plantIds.length == 0) {
        this.plantIds = ['']
      }
    },
    handleCommand(val) {
      if (this.plantIds.length == 0) {
        this.plantIds = ['']
      }
      val.forEach((item,index)=>{
        if(item===''){
          val.splice(index,1)
        }
      })
      if (val.length === this.plantOptions.length) {
        this.checked = true
      } else {
        this.checked = false
      }
    },
  }
};
</script>
<style scoped>

.checklist-table {
  margin-top: 20px;
  margin-bottom: 20px;
}

.checklist-table table {
  width: 100%;
  border-collapse: collapse;
}

.checklist-table th,
.checklist-table td {
  padding: 10px;
  border: 1px solid #ccc;
  text-align: center;
}

.checklist-table th {
  background-color: #f5f5f5;
}

.radio-group-horizontal {
  display: flex;
  justify-content: space-around;
  align-items: center;
}
</style>
