<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="装配标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入装配标题"
          clearable
          size="small"
          @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-table v-loading="loading" :data="executeDetailList">
      <el-table-column label="模版序号" align="center" prop="orders" />
      <el-table-column label="模版标题" align="center" prop="title"  show-overflow-tooltip/>
      <el-table-column label="装配图片" align="center" prop="imgUrl">
        <template slot-scope="scope">
          <el-image
            v-if="scope.row.imgUrl"
            :src="scope.row.imgUrl"
            :preview-src-list="[scope.row.imgUrl]"
            :z-index="9999"
            style="width: 30px;height: 30px;"
          ></el-image>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="装配视频" align="center" prop="videoUrl">
        <template slot-scope="scope">
          <el-popover
            v-if="scope.row.videoUrl"
            placement="top"
            width="400"
            trigger="click">
            <video style="width: 100%;height: auto;object-fit: contain; " controls :src="scope.row.videoUrl"/>
            <el-button type="text" slot="reference">装配视频</el-button>
          </el-popover>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="装配时间" align="center" prop="createTime" show-overflow-tooltip/>
      <el-table-column label="装配人" align="center" prop="createBy" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleMarkDetail(scope.row)"
          >模版详情</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleUpload(scope.row,'img')"
          >上传图片</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleUpload(scope.row,'video')"
          >上传视频</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getExecuteDetailInfo"
    />

    <!-- 模版详情 -->
    <DetailInfo ref="detail"/>

    <!-- 上传图片 -->
    <Upload ref="upload"/>

  </div>
</template>

<script>
  import { selectDeviceMarkInfoByDeviceId } from "@/api/track/deviceMark";
  import DetailInfo from "../../mark/detail/components/DetailInfo";
  import Upload from "./Upload";
  export default {
    name: "assemble",
    props:{
      param:{
        type:Object
      }
    },
    components:{
      DetailInfo,
      Upload
    },
    data(){
        return{
          executeDetailList: [],
          total: 0,
          // 查询参数
          queryParams: {
            pageNum: 1,
            pageSize: 10,
            title: null
          },
          loading: false
        }
    },
    created(){
      this.queryParams.deviceId = this.param.deviceId;
      this.getExecuteDetailInfo();
    },
    methods:{
      getExecuteDetailInfo(){
        this.loading = true;
        selectDeviceMarkInfoByDeviceId(this.queryParams).then(res =>{
          this.loading = false;
          if(res.code == 200){
              this.total = res.total;
              this.executeDetailList = res.rows;
          }
        })
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getExecuteDetailInfo();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      handleMarkDetail(row){
        this.$refs.detail.getDetailInfo(row.markDetailId);
      },
      handleUpload(row,type){
        row.deviceId =  this.param.deviceId;
        this.$refs.upload.initUploadInfo(row,type);
      }

    }
  }
</script>

<style scoped>

</style>
