<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="marksLocation">
        <el-input
          v-model="queryParams.marksLocation"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="留痕用户" prop="createUser">
        <el-input
          v-model="queryParams.createUser"
          placeholder="请输入留痕用户手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="隐患类型" prop="projectType">
        <el-select v-model="queryParams.projectType" placeholder="隐患类型" clearable>
          <el-option
            v-for="dict in dict.type.ssp_zlyhlx"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="留痕时间">
        <el-date-picker
          v-model="daterangeMarksTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </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="['trouble:sspMarks: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="['trouble:sspMarks: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="['trouble:sspMarks: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="['trouble:sspMarks:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="sspMarksList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="40" align="center" />
      <el-table-column label="项目名称" align="center" prop="marksLocation" width="200"  show-overflow-tooltip/>
      <el-table-column label="留痕时间" align="center" prop="marksTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.marksTime, '{y}-{m}-{d} {h}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="留痕图片" align="center" property="path" width="220">
        <template slot-scope="scope">
          <el-image ref="preview"
            style="width: 200px; height: 100px"
            :src="scope.row.marksPicture"
            @click="onPreview(scope.row.smarkUrl)"
            >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="隐患类型" align="center" prop="projectType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ssp_zlyhlx" :value="scope.row.projectType"/>
        </template>
      </el-table-column>
      <el-table-column label="隐患描述" align="center" prop="positionPart" width="150"  show-overflow-tooltip/>
      <el-table-column label="留痕说明" align="center" prop="marksRemark" width="200"  show-overflow-tooltip/>
      <el-table-column label="审核人" align="center" prop="auditorPerson" />
      <el-table-column label="审核人手机号" align="center" prop="auditorPhone" />
      <el-table-column label="审核状态" align="center" prop="checkState">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_check_state" :value="scope.row.checkState"/>
        </template>
      </el-table-column>
      <el-table-column label="留痕用户" align="center" prop="createUser" />
      <el-table-column label="身份证号码" align="center" prop="idcardnum" />
      <el-table-column label="数据状态" align="center" prop="isDel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_common_isdel" :value="scope.row.isDel"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="scope.row.marksVideo != null && scope.row.marksVideo != ''"
            size="mini"
            type="text"
            icon="el-icon-video-play"
            @click="handlePlay(scope.row)"
            v-hasPermi="['trouble:sspMarks:query']"
          >视频</el-button>
          <!-- <el-button v-if="scope.row.checkState == 0"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['trouble:sspMarks:edit']"
          >审核</el-button>-->
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['trouble:sspMarks: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="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="id" prop="id">
          <el-input v-model="form.id" placeholder="请输入id" />
        </el-form-item>
        <el-form-item label="留痕上报地点" prop="marksLocation">
          <el-input v-model="form.marksLocation" placeholder="请输入留痕上报地点" />
        </el-form-item>
        <el-form-item label="留痕时间" prop="marksTime">
          <el-date-picker clearable
            v-model="form.marksTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择留痕时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="留痕图片" prop="marksPicture">
          <el-input v-model="form.marksPicture" placeholder="请输入留痕图片" />
        </el-form-item>
        <el-form-item label="留痕视频" prop="marksVideo">
          <el-input v-model="form.marksVideo" placeholder="请输入留痕视频" />
        </el-form-item>
        <el-form-item label="工程类型" prop="projectType">
          <el-select v-model="form.projectType" placeholder="请选择工程类型">
            <el-option
              v-for="dict in dict.type.ssp_zlyhlx"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="工程名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入工程名称" />
        </el-form-item>
        <el-form-item label="工序名称" prop="processName">
          <el-input v-model="form.processName" placeholder="请输入工序名称" />
        </el-form-item>
        <el-form-item label="隐患描述" prop="positionPart">
          <el-input v-model="form.positionPart" placeholder="请输入隐患描述" />
        </el-form-item>
        <el-form-item label="留痕说明" prop="marksRemark">
          <el-input v-model="form.marksRemark" placeholder="请输入留痕说明" />
        </el-form-item>
        <el-form-item label="审核人" prop="auditorPerson">
          <el-input v-model="form.auditorPerson" placeholder="请输入审核人" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createDate">
          <el-date-picker clearable
            v-model="form.createDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建人" prop="createUser">
          <el-input v-model="form.createUser" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="项目id" prop="projectId">
          <el-input v-model="form.projectId" placeholder="请输入项目id" />
        </el-form-item>
        <el-form-item label="审核人手机号" prop="auditorPhone">
          <el-input v-model="form.auditorPhone" placeholder="请输入审核人手机号" />
        </el-form-item>
        <el-form-item label="审核状态" prop="checkState">
          <el-input v-model="form.checkState" placeholder="请输入审核状态" />
        </el-form-item>
        <el-form-item label="身份证号码" prop="idcardnum">
          <el-input v-model="form.idcardnum" placeholder="请输入身份证号码" />
        </el-form-item>
        <el-form-item label="智能公司展示的图片url" prop="smarkUrl">
          <el-input v-model="form.smarkUrl" placeholder="请输入智能公司展示的图片url" />
        </el-form-item>
        <el-form-item label="同步状态" prop="synchronization">
          <el-input v-model="form.synchronization" placeholder="请输入同步状态" />
        </el-form-item>
        <el-form-item label="删除标识" prop="isDel">
          <el-input v-model="form.isDel" placeholder="请输入删除标识" />
        </el-form-item>
        <el-form-item label="监理人员名称" prop="surveyorName">
          <el-input v-model="form.surveyorName" placeholder="请输入监理人员名称" />
        </el-form-item>
        <el-form-item label="监理身份证号码" prop="surveyorId">
          <el-input v-model="form.surveyorId" placeholder="请输入监理身份证号码" />
        </el-form-item>
        <el-form-item label="监理留痕时间" prop="surveyorTime">
          <el-input v-model="form.surveyorTime" placeholder="请输入监理留痕时间" />
        </el-form-item>
        <el-form-item label="监理留痕说明">
          <editor v-model="form.surveyorContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="更新时间" prop="updateDate">
          <el-date-picker clearable
            v-model="form.updateDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择更新时间">
          </el-date-picker>
        </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-image-viewer v-if="showViewer" :on-close="closeViewer" :url-list="srcList" />
    <el-dialog title="视频播放" :visible.sync="openVideo" width="980px" :before-close="cancelVideo" append-to-body>
      <video ref="video" :src="videoSrc" controls="controls" autoplay="autoplay" poster="../../../assets/images/video_loading.gif" style="max-height: 550px;"/>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelVideo">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSspMarks, getSspMarks, delSspMarks, addSspMarks, updateSspMarks } from "@/api/trouble/sspMarks";
import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
import 'element-ui/lib/theme-chalk/index.css';

export default {
  name: "SspMarks",
  dicts: ['ssp_zlyhlx','sys_common_isdel','sys_check_state'],
  components: { ElImageViewer },
  data() {
    return {
      showViewer: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 质量留痕表格数据
      sspMarksList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openVideo:false,
      videoSrc: null,
      // 更新时间时间范围
      daterangeMarksTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        marksLocation: null,
        marksTime: null,
        projectType: null,
        auditorPerson: null,
        createUser: null,
        projectId: null,
        auditorPhone: null,
        checkState: null,
        idcardnum: null,
        infoType: 1,
        smarkUrl: null,
        synchronization: null,
        isDel: null,
        surveyorName: null,
        surveyorId: null,
        surveyorTime: null,
        surveyorContent: null,
        updateDate: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "id不能为空", trigger: "blur" }
        ],
      },
      srcList: [
        'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg'
      ]
    };
  },
  created() {
    this.getList();
  },
  methods: {
    onPreview(urls) {
      var arrayurls = urls.split(",");
      this.srcList=[];
      arrayurls.forEach((v, i) => {
        this.srcList.push(v);
      });
      this.showViewer = true
    },
    closeViewer() {
      this.showViewer = false
    },
    /** 查询质量留痕列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeMarksTime && '' != this.daterangeMarksTime) {
        this.queryParams.params["beginMarksTime"] = this.daterangeMarksTime[0];
        this.queryParams.params["endMarksTime"] = this.daterangeMarksTime[1];
      }
      listSspMarks(this.queryParams).then(response => {
        this.sspMarksList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    cancelVideo() {
      this.videoSrc=null;
      this.$refs.video.pause();
      this.openVideo = false;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        marksLocation: null,
        marksTime: null,
        marksPicture: null,
        marksVideo: null,
        projectType: null,
        projectName: null,
        processName: null,
        positionPart: null,
        marksRemark: null,
        auditorPerson: null,
        createDate: null,
        createUser: null,
        projectId: null,
        auditorPhone: null,
        checkState: null,
        idcardnum: null,
        infoType: null,
        smarkUrl: null,
        synchronization: null,
        isDel: null,
        surveyorName: null,
        surveyorId: null,
        surveyorTime: null,
        surveyorContent: null,
        updateDate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeMarksTime = [];
      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.open = true;
      this.title = "添加质量留痕";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSspMarks(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) {
            updateSspMarks(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSspMarks(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除质量留痕编号为"' + ids + '"的数据项？').then(function() {
        return delSspMarks(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 播放视频 */
    handlePlay(row) {
      this.videoSrc=row.marksVideo;
      this.openVideo = true;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('trouble/sspMarks/export', {
        ...this.queryParams
      }, `sspMarks_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
.el-dialog__body{
  text-align: center;
}
</style>
