<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
<!--      <el-form-item label="所属公司ID" prop="companyId">-->
<!--        <el-input-->
<!--          v-model="queryParams.companyId"-->
<!--          placeholder="请输入所属公司ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="所属公司名" prop="companyName">-->
<!--        <el-input-->
<!--          v-model="queryParams.companyName"-->
<!--          placeholder="请输入所属公司名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="所属管理员ID" prop="userId">-->
<!--        <el-input-->
<!--          v-model="queryParams.userId"-->
<!--          placeholder="请输入所属管理员ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="所属管理员名" prop="userName">-->
<!--        <el-input-->
<!--          v-model="queryParams.userName"-->
<!--          placeholder="请输入所属管理员名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="基站ID" prop="baseStationId">-->
<!--        <el-input-->
<!--          v-model="queryParams.baseStationId"-->
<!--          placeholder="请输入基站ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="基站名" prop="baseStationName">-->
<!--        <el-input-->
<!--          v-model="queryParams.baseStationName"-->
<!--          placeholder="请输入基站名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="摄像头ID" prop="cameraId">-->
<!--        <el-input-->
<!--          v-model="queryParams.cameraId"-->
<!--          placeholder="请输入摄像头ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="摄像头编号" prop="cameraNumber">
        <el-input
          v-model="queryParams.cameraNumber"
          placeholder="请输入摄像头编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="摄像头视频名" prop="cameraVideoName">-->
<!--        <el-input-->
<!--          v-model="queryParams.cameraVideoName"-->
<!--          placeholder="请输入摄像头视频名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="记录时间（年）" prop="recordYear">-->
<!--        <el-input-->
<!--          v-model="queryParams.recordYear"-->
<!--          placeholder="请输入记录时间（年）"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="记录时间（月）" prop="recordMonth">-->
<!--        <el-input-->
<!--          v-model="queryParams.recordMonth"-->
<!--          placeholder="请输入记录时间（月）"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="记录时间（日）" prop="recordDay">-->
<!--        <el-input-->
<!--          v-model="queryParams.recordDay"-->
<!--          placeholder="请输入记录时间（日）"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="记录时间" prop="recordTime">-->
<!--        <el-input-->
<!--          v-model="queryParams.recordTime"-->
<!--          placeholder="请输入记录时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="省份ID" prop="provinceId">-->
<!--        <el-input-->
<!--          v-model="queryParams.provinceId"-->
<!--          placeholder="请输入省份ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="省份名" prop="provinceName">-->
<!--        <el-input-->
<!--          v-model="queryParams.provinceName"-->
<!--          placeholder="请输入省份名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="城市ID" prop="cityId">-->
<!--        <el-input-->
<!--          v-model="queryParams.cityId"-->
<!--          placeholder="请输入城市ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="城市名" prop="cityName">-->
<!--        <el-input-->
<!--          v-model="queryParams.cityName"-->
<!--          placeholder="请输入城市名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="区县ID" prop="areaId">-->
<!--        <el-input-->
<!--          v-model="queryParams.areaId"-->
<!--          placeholder="请输入区县ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="区县名" prop="areaName">-->
<!--        <el-input-->
<!--          v-model="queryParams.areaName"-->
<!--          placeholder="请输入区县名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="地址" prop="address">-->
<!--        <el-input-->
<!--          v-model="queryParams.address"-->
<!--          placeholder="请输入地址"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="相关ID" prop="resId">-->
<!--        <el-input-->
<!--          v-model="queryParams.resId"-->
<!--          placeholder="请输入相关ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="创建时间" prop="createAt">
        <el-input
          v-model="queryParams.createAt"
          placeholder="请输入创建时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="修改时间" prop="updateAt">-->
<!--        <el-input-->
<!--          v-model="queryParams.updateAt"-->
<!--          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="['mall:mallCameraVideo: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="['mall:mallCameraVideo: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="['mall:mallCameraVideo: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="['mall:mallCameraVideo:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="mallCameraVideoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="摄像头视频主键ID" align="center" prop="cameraVideoId" />-->
<!--      <el-table-column label="所属公司ID" align="center" prop="companyId" />-->
<!--      <el-table-column label="所属公司名" align="center" prop="companyName" />-->
<!--      <el-table-column label="所属管理员ID" align="center" prop="userId" />-->
<!--      <el-table-column label="所属管理员名" align="center" prop="userName" />-->
<!--      <el-table-column label="基站ID" align="center" prop="baseStationId" />-->
<!--      <el-table-column label="基站名" align="center" prop="baseStationName" />-->
<!--      <el-table-column label="摄像头ID" align="center" prop="cameraId" />-->
      <el-table-column label="摄像头编号" align="center" prop="cameraNumber" />
      <el-table-column label="摄像头视频名" align="center" prop="cameraVideoName" />
<!--      <el-table-column label="封面图" align="center" prop="coverImage" width="100">-->
<!--        <template slot-scope="scope">-->
<!--          <image-preview :src="scope.row.coverImage" :width="50" :height="50"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="视频" align="center" prop="videoUrl">-->
<!--        <template slot-scope="scope">-->
<!--          <video :src="scope.row.videoUrl"/>-->
<!--        </template>-->
<!--      </el-table-column> -->
      <el-table-column label="视频" align="center" prop="videoUrl">
        <template slot-scope="scope">
          <video :src="scope.row.videoUrl" :width="150" :height="150" controls></video>
        </template>
      </el-table-column>
      <el-table-column label="记录时间（年）" align="center" prop="recordYear" />
      <el-table-column label="记录时间（月）" align="center" prop="recordMonth" />
      <el-table-column label="记录时间（日）" align="center" prop="recordDay" />
      <el-table-column label="记录时间" align="center" prop="recordTime" />
<!--      <el-table-column label="省份ID" align="center" prop="provinceId" />-->
<!--      <el-table-column label="省份名" align="center" prop="provinceName" />-->
<!--      <el-table-column label="城市ID" align="center" prop="cityId" />-->
<!--      <el-table-column label="城市名" align="center" prop="cityName" />-->
<!--      <el-table-column label="区县ID" align="center" prop="areaId" />-->
<!--      <el-table-column label="区县名" align="center" prop="areaName" />-->
<!--      <el-table-column label="地址" align="center" prop="address" />-->
<!--      <el-table-column label="相关ID" align="center" prop="resId" />-->
      <el-table-column label="创建时间" align="center" prop="createAt" />
<!--      <el-table-column label="修改时间" align="center" prop="updateAt" />-->
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['mall:mallCameraVideo:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['mall:mallCameraVideo: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="companyId">
          <el-input v-model="form.companyId" placeholder="请输入所属公司ID" />
        </el-form-item>
        <el-form-item label="所属公司名" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入所属公司名" />
        </el-form-item>
        <el-form-item label="所属管理员ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入所属管理员ID" />
        </el-form-item>
        <el-form-item label="所属管理员名" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入所属管理员名" />
        </el-form-item>
        <el-form-item label="基站ID" prop="baseStationId">
          <el-input v-model="form.baseStationId" placeholder="请输入基站ID" />
        </el-form-item>
        <el-form-item label="基站名" prop="baseStationName">
          <el-input v-model="form.baseStationName" placeholder="请输入基站名" />
        </el-form-item>
        <el-form-item label="摄像头ID" prop="cameraId">
          <el-input v-model="form.cameraId" placeholder="请输入摄像头ID" />
        </el-form-item>
        <el-form-item label="摄像头编号" prop="cameraNumber">
          <el-input v-model="form.cameraNumber" placeholder="请输入摄像头编号" />
        </el-form-item>
        <el-form-item label="摄像头视频名" prop="cameraVideoName">
          <el-input v-model="form.cameraVideoName" placeholder="请输入摄像头视频名" />
        </el-form-item>
        <el-form-item label="封面图">
          <image-upload v-model="form.coverImage"/>
        </el-form-item>
        <el-form-item label="视频地址" prop="videoUrl">
          <el-input v-model="form.videoUrl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="记录时间" prop="recordYear">
          <el-input v-model="form.recordYear" placeholder="请输入记录时间" />
        </el-form-item>
        <el-form-item label="记录时间" prop="recordMonth">
          <el-input v-model="form.recordMonth" placeholder="请输入记录时间" />
        </el-form-item>
        <el-form-item label="记录时间" prop="recordDay">
          <el-input v-model="form.recordDay" placeholder="请输入记录时间" />
        </el-form-item>
        <el-form-item label="记录时间" prop="recordTime">
          <el-input v-model="form.recordTime" placeholder="请输入记录时间" />
        </el-form-item>
        <el-form-item label="省份ID" prop="provinceId">
          <el-input v-model="form.provinceId" placeholder="请输入省份ID" />
        </el-form-item>
        <el-form-item label="省份名" prop="provinceName">
          <el-input v-model="form.provinceName" placeholder="请输入省份名" />
        </el-form-item>
        <el-form-item label="城市ID" prop="cityId">
          <el-input v-model="form.cityId" placeholder="请输入城市ID" />
        </el-form-item>
        <el-form-item label="城市名" prop="cityName">
          <el-input v-model="form.cityName" placeholder="请输入城市名" />
        </el-form-item>
        <el-form-item label="区县ID" prop="areaId">
          <el-input v-model="form.areaId" placeholder="请输入区县ID" />
        </el-form-item>
        <el-form-item label="区县名" prop="areaName">
          <el-input v-model="form.areaName" placeholder="请输入区县名" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="相关ID" prop="resId">
          <el-input v-model="form.resId" placeholder="请输入相关ID" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createAt">
          <el-input v-model="form.createAt" placeholder="请输入创建时间" />
        </el-form-item>
        <el-form-item label="修改时间" prop="updateAt">
          <el-input v-model="form.updateAt" placeholder="请输入修改时间" />
        </el-form-item>
        <el-form-item label="删除标记：0-正常，1-删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标记：0-正常，1-删除" />
        </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>
  </div>
</template>

<script>
import { listMallCameraVideo, getMallCameraVideo, delMallCameraVideo, addMallCameraVideo, updateMallCameraVideo } from "@/api/mall/mallCameraVideo";

export default {
  name: "MallCameraVideo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 摄像头视频表格数据
      mallCameraVideoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyId: null,
        companyName: null,
        userId: null,
        userName: null,
        baseStationId: null,
        baseStationName: null,
        cameraId: null,
        cameraNumber: null,
        cameraVideoName: null,
        coverImage: null,
        videoUrl: null,
        recordYear: null,
        recordMonth: null,
        recordDay: null,
        recordTime: null,
        provinceId: null,
        provinceName: null,
        cityId: null,
        cityName: null,
        areaId: null,
        areaName: null,
        address: null,
        resId: null,
        createAt: null,
        updateAt: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询摄像头视频列表 */
    getList() {
      this.loading = true;
      listMallCameraVideo(this.queryParams).then(response => {
        this.mallCameraVideoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        cameraVideoId: null,
        companyId: null,
        companyName: null,
        userId: null,
        userName: null,
        baseStationId: null,
        baseStationName: null,
        cameraId: null,
        cameraNumber: null,
        cameraVideoName: null,
        coverImage: null,
        videoUrl: null,
        recordYear: null,
        recordMonth: null,
        recordDay: null,
        recordTime: null,
        provinceId: null,
        provinceName: null,
        cityId: null,
        cityName: null,
        areaId: null,
        areaName: null,
        address: null,
        resId: null,
        createAt: null,
        updateAt: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.cameraVideoId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加摄像头视频";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const cameraVideoId = row.cameraVideoId || this.ids
      getMallCameraVideo(cameraVideoId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改摄像头视频";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.cameraVideoId != null) {
            updateMallCameraVideo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMallCameraVideo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const cameraVideoIds = row.cameraVideoId || this.ids;
      this.$modal.confirm('是否确认删除摄像头视频编号为"' + cameraVideoIds + '"的数据项？').then(function() {
        return delMallCameraVideo(cameraVideoIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('mall/mallCameraVideo/export', {
        ...this.queryParams
      }, `mallCameraVideo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
