<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="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="游记状态" prop="stateType">
        <el-select v-model="queryParams.stateType" placeholder="请选择游" clearable>
          <el-option
            v-for="dict in dict.type.tuya_publish_state"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="游玩时间" prop="travelDate">
        <el-input
          v-model="queryParams.travelDate"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="游玩天数" prop="travelDay">
        <el-input
          v-model="queryParams.travelDay"
          placeholder="请输入游玩天数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="人均消费" prop="capita">
        <el-input
          v-model="queryParams.capita"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="时节" prop="season">
        <el-input
          v-model="queryParams.season"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="目的地" prop="destination">
        <el-input
          v-model="queryParams.destination"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="建档日期" prop="jdrq">
        <el-date-picker clearable
                        v-model="queryParams.jdrq"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="请选择">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="人数" prop="peopleAll">
        <el-input
          v-model="queryParams.peopleAll"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="游记标题" prop="titleTravel">
        <el-input
          v-model="queryParams.titleTravel"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地点标题" prop="titleDayName">
        <el-input
          v-model="queryParams.titleDayName"
          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-item>
        <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
      </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="['tuya:travel: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="['tuya:travel: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="['tuya:travel: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="['tuya:travel:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList">
      </right-toolbar>
    </el-row>

    <!--    <el-row :gutter="24">-->
    <!--      <el-checkbox-group v-model="checkedIds" @change="handleCheckedCitiesChange">-->
    <!--      <el-col :span="4" v-for="item in travelList" :key="item.id">-->
    <!--        <el-card :body-style="{ padding: '0px' }" class="item-card">-->
    <!--          <el-checkbox class="card_checkbox" :label="item.id">{{""}}</el-checkbox>-->
    <!--          <img :src="item.titleImg" class="image">-->
    <!--          <div style="padding: 14px;">-->
    <!--            <div class="card-txt">{{item.titleTravel}}</div>-->
    <!--            <div class="bottom clearfix">-->
    <!--              <time class="time">创建时间:{{item.jdrq|formatDate}}</time>-->
    <!--              <el-button type="text" class="button" icon="el-icon-edit"></el-button>-->
    <!--              <el-button type="text"-->
    <!--                         class="button"-->
    <!--                         @click="handleDeleteCard(item.id)"-->
    <!--                         v-hasPermi="['tuya:travel:remove']"-->
    <!--                         icon="el-icon-delete"-->
    <!--              >-->
    <!--              </el-button>-->
    <!--            </div>-->
    <!--          </div>-->
    <!--        </el-card>-->
    <!--      </el-col>-->
    <!--      </el-checkbox-group>-->
    <!--    </el-row>-->


    <el-table v-loading="loading" :data="travelList" @selection-change="handleSelectionChange">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="用户编号">
              <span>{{ props.row.code }}</span>
            </el-form-item>
            <el-form-item label="uuid">
              <span>{{ props.row.uuid }}</span>
            </el-form-item>
            <el-form-item label="简介">
              <span>{{ props.row.synopsis }}</span>
            </el-form-item>
            <el-form-item label="游玩时间">
              <span>{{ props.row.travelDate }}</span>
            </el-form-item>
            <el-form-item label="游玩天数">
              <span>{{ props.row.travelDay }}</span>
            </el-form-item>
            <el-form-item label="人均消费">
              <span>{{ props.row.capita }}</span>
            </el-form-item>
            <el-form-item label="人物">
              <span>{{ props.row.figure }}</span>
            </el-form-item>
            <el-form-item label="玩法">
              <span>{{ props.row.playType }}</span>
            </el-form-item>
            <el-form-item label="时节">
              <span>{{ props.row.season }}</span>
            </el-form-item>
            <el-form-item label="目的地">
              <span>{{ props.row.destination }}</span>
            </el-form-item>
            <el-form-item label="人数">
              <span>{{ props.row.peopleAll }}</span>
            </el-form-item>
            <el-form-item label="金额">
              <span>{{ props.row.amount }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="标题" align="center" prop="title" :show-overflow-tooltip="true"/>
      <el-table-column label="头部图片" align="center" prop="titleImg" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <image-preview :src="scope.row.titleImg" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="游记标题" align="center" prop="titleTravel" :show-overflow-tooltip="true"/>
      <el-table-column label="需求编号" align="center" prop="demandUuid" :show-overflow-tooltip="true"/>
      <el-table-column label="查看数量" align="center" prop="lookNum" :show-overflow-tooltip="true"/>
      <el-table-column label="地点标题" align="center" prop="titleDayName" :show-overflow-tooltip="true"/>
      <el-table-column label="简介图片" align="center" prop="imgUrl" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <image-preview :src="scope.row.imgUrl" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="视频" align="center" prop="videoUrl" width="90">
        <template slot-scope="scope">
          <el-button
            @click="openVideo(scope.row)"
            size="small"
          >查看视频
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="游记状态" align="center" prop="stateType" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tuya_publish_state" :value="scope.row.stateType"/>
        </template>
      </el-table-column>
      <el-table-column label="建档日期" align="center" prop="jdrq" width="180"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['tuya:travel:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['tuya:travel: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="1200px" append-to-body @close='closeDialog'>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row :gutter="24">
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="用户编号" prop="code">
                <el-input v-model="form.code" placeholder="" :disabled="true"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="需求编号" prop="demandUuid">
                <el-input v-model="form.demandUuid" placeholder="" :disabled="true"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="简介标题" prop="title">
                <el-input v-model="form.title" placeholder="请输入"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="游玩时间" prop="travelDate">
                <el-input v-model="form.travelDate" placeholder="请输入"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="游玩天数" prop="travelDay">
                <el-input-number v-model="form.travelDay" controls-position="right" :min="0" :precision="1"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="人均消费" prop="capita">
                <el-input-number v-model="form.capita" controls-position="right" :min="0" :precision="2"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="玩法" prop="playType">
                <el-input v-model="form.playType" placeholder="请输入"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="人物" prop="figure">
                <el-input v-model="form.figure" placeholder="请输入"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="时节" prop="season">
                <el-input v-model="form.season" placeholder="请输入"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="目的地" prop="destination">
                <el-input v-model="form.destination" placeholder="请输入"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="人数" prop="peopleAll">
                <el-input-number v-model="form.peopleAll" controls-position="right" :min="0"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="金额" prop="amount">
                <el-input-number v-model="form.amount" controls-position="right" :min="0" :precision="2"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="游记标题" prop="titleTravel">
                <el-input v-model="form.titleTravel" placeholder="请输入"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="地点标题" prop="titleDayName">
                <el-input v-model="form.titleDayName" placeholder="请输入"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="24">
            <div class="grid-content bg-purple">
              <el-form-item label="头部图片" prop="titleImg" v-loading="loading">
                <div class="update-Img">
                  <el-upload
                    action="#"
                    list-type="picture-card"
                    :limit="1"
                    :auto-upload="false"
                    :on-change="(file,fileList) => {uploadImage(file, fileList, 1)}"
                    :on-remove="(file,fileList) => {handeRemove(file, fileList, 1)}"
                    :on-exceed="handleExceed"
                    :on-preview="handlePictureCardPreview"
                    :file-list="fileList"
                    accept=".jpg, .jpeg, .gif, .webp, .png"
                  >
                    <i class="el-icon-plus"></i>
                  </el-upload>
                  <el-dialog :visible.sync="dialogVisible">
                    <img width="100%" v-if="imageUrl" :src="imageUrl" alt="">
                  </el-dialog>
                </div>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="24">
            <div class="grid-content bg-purple">
              <el-form-item label="简介图片" prop="imgUrl" v-loading="loading">
                <div class="update-Img">
                  <el-upload
                    action="#"
                    list-type="picture-card"
                    :limit="7"
                    :auto-upload="false"
                    :on-change="(file,fileList2) => {uploadImage(file, fileList2, 2)}"
                    :on-remove="(file,fileList2) => {handeRemove(file, fileList2, 2)}"
                    :on-exceed="handleExceed"
                    :on-preview="handlePictureCardPreview"
                    :file-list="fileList2"
                    accept=".jpg, .jpeg, .gif, .webp, .png"
                  >
                    <i class="el-icon-plus"></i>
                  </el-upload>
                  <el-dialog :visible.sync="dialogVisible">
                    <img width="100%" v-if="imageUrl" :src="imageUrl" alt="">
                  </el-dialog>
                </div>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="简介视频" prop="videoUrl" v-loading="loading">
                <div class="update-video">
                  <el-input v-model="form.videoUrl" placeholder="请输入"/>
                  <el-upload
                    class="video-uploader"
                    action="#"
                    :on-change="uploadVideo"
                    :limit="1"
                    :auto-upload="false"
                    :show-file-list="false"
                    accept=".mp4"
                  >
                    <el-button class="uploader-button" size="small">
                      选择
                      <i class="el-icon-upload el-icon--right"></i>
                    </el-button>
                  </el-upload>
                </div>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="游记状态" prop="stateType">
                <el-radio-group v-model="form.stateType">
                  <el-radio
                    v-for="dict in dict.type.tuya_publish_state"
                    :key="dict.value"
                    :label="dict.value"
                  >{{ dict.label }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="24">
            <div class="grid-content bg-purple">
              <el-form-item label="简介" prop="synopsis">
                <el-input type="textarea" v-model="form.synopsis" placeholder="请输入" :rows="5"/>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
      </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
      :visible.sync="videoDialog"
      width="70%"
      center
      class="videoPlayer"
    >
      <div>
        <video-player
          style="width: 100%; height: 500px"
          class="video-player vjs-custom-skin"
          ref="videoPlayer"
          :playsline="false"
          :options="playerOptions"
        ></video-player>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listTravel, getTravel, delTravel, addTravel, updateTravel} from "@/api/tuya/travel";
import {uploadAvatar} from "@/api/tuya/stiesinfo";
import {videoPlayer} from "vue-video-player";
import "video.js/dist/video-js.css";

export default {
  name: "Travel",
  dicts: ['sys_normal_disable', 'sys_user_sex', 'tuya_publish_state'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 平台游记表格数据
      travelList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        titleImg: null,
        synopsis: null,
        videoUrl: null,
        imgUrl: null,
        uuid: null,
        stateType: null,
        travelDate: null,
        travelDay: null,
        capita: null,
        figure: null,
        playType: null,
        season: null,
        destination: null,
        jdrq: null,
        peopleAll: null,
        title: null,
        titleTravel: null,
        demandUuid: null,
        lookNum: null,
        titleDayName: null,
        amount: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      checkedIds: [],
      checkAll: false,
      isIndeterminate: true,
      allids: [],
      fileList: [],
      fileList2: [],
      //图片地址
      imageUrl: "",
      dialogVisible: false,
      videoDialog: false,
      srcList: [],
      playerOptions: {
        playbackRates: [0.7, 1.0, 1.5, 2.0], // 播放速度
        autoplay: false, // 如果true,浏览器准备好时开始回放。
        controls: true, //  控制条
        muted: false, // 默认情况下将会消除任何音频。
        loop: false, // 导致视频一结束就重新开始。
        preload: "auto", // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
        language: "zh-CN",
        aspectRatio: "16:9", // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        sources: [
          {
            type: "video/mp4", // 这里的种类支持很多种：基本视频格式、直播、流媒体等，具体可以参看git网址项目
            src: "", // url地址
          },
        ],
        // poster: "../../../../static/full_res.jpg", // 你的封面地址
        width: document.documentElement.clientWidth, // 播放器宽度
        notSupportedMessage: "此视频暂无法播放，请稍后再试", // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
        controlBar: {
          timeDivider: true,
          durationDisplay: true,
          remainingTimeDisplay: false,
          fullscreenToggle: true, // 全屏按钮
        },
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    openVideo(row) {
      this.videoDialog = true;
      this.row = row;
      this.playerOptions.sources[0].src = row.videoUrl;
    },
    // 上传图片
    uploadImage(file, fileList, i) {
      const isJPG = file.raw.type === "image/jpg";
      const isJPEG = file.raw.type === "image/jpeg";
      const isPNG = file.raw.type === "image/png";
      const isGIF = file.raw.type === "image/gif";
      const isBMP = file.raw.type === "image/bmp";
      const isLt2M = file.size / 1024 / 1024 < 5;
      if (!isJPG && !isJPEG && !isPNG && !isGIF && !isBMP) {
        this.$message.error("只能上传图片格式为jpg,jpeg,png,gif,bmp！");
      } else if (!isLt2M) {
        this.$message.error('图片大小不能超过 5MB!');
      } else {
        this.loading = true;
        let fd = new FormData()
        fd.append('file', file.raw)
        uploadAvatar(fd).then(response => {
          if (response.msg == '200') {
            if (i == 1) {
              if (this.form.titleImg.charAt(this.form.titleImg.length - 1) == ",") {
                this.form.titleImg += response.data + ",";
              } else {
                this.form.titleImg += "," + response.data + ",";
              }
            }
            if (i == 2) {
              if (this.form.imgUrl.charAt(this.form.imgUrl.length - 1) == ",") {
                this.form.imgUrl += response.data + ",";
              } else {
                this.form.imgUrl += "," + response.data + ",";
              }
            }
          }
        });
        this.loading = false;
      }
    },
    //图片预览
    handlePictureCardPreview(file) {
      this.imageUrl = file.url;
      this.dialogVisible = true;
    },
    // 文件个数超出
    handleExceed() {
      this.$modal.msgError(`上传图片数量不能超过1个!`);
    },
    handeRemove(file, fileList, i) {
      let UrlList = "";
      for (let item of fileList) {
        UrlList += item.url + ",";
      }
      if (i == 1) {
        this.form.titleImg = "";
        this.form.titleImg = UrlList;
      }
      if (i == 2) {
        this.form.imgUrl = "";
        this.form.imgUrl = UrlList;
      }
    },
    // 上传视频
    uploadVideo(file) {
      const isMP4 = file.raw.type === "video/mp4";
      const isLt2M = file.size / 1024 / 1024 < 50;
      if (!isMP4) {
        this.$message.error("只能上传视频格式为mp4！");
      } else if (!isLt2M) {
        this.$message.error('图片大小不能超过 10MB!');
      } else {
        this.loading = true;
        let fd = new FormData()
        fd.append('file', file.raw)
        uploadAvatar(fd).then(response => {
          this.form.videoUrl = response.data;
        });
        this.loading = false;
      }
    },
    handleDeleteCard(e) {
      const ids = e || this.checkedIds;
      this.$modal.confirm('是否确认删除平台游记编号为"' + ids + '"的数据项？').then(function () {
        return delTravel(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    handleCheckAllChange(val) {
      this.checkedIds = val ? this.allids : [];
      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.allids.length;
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.allids.length;
    },
    /** 查询平台游记列表 */
    getList() {
      this.loading = true;
      listTravel(this.queryParams).then(response => {
        this.travelList = response.rows;
        this.total = response.total;
        for (let i in response.rows) {
          this.allids.push(response.rows[i].id);
        }
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.fileList = [];
      this.fileList2 = [];
    },
    closeDialog() {
      this.reset();
      this.fileList = [];
      this.fileList2 = [];
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: null,
        titleImg: null,
        synopsis: null,
        videoUrl: null,
        imgUrl: null,
        uuid: null,
        stateType: null,
        travelDate: null,
        travelDay: null,
        capita: null,
        figure: null,
        playType: null,
        season: null,
        destination: null,
        jdrq: null,
        peopleAll: null,
        title: null,
        titleTravel: null,
        demandUuid: null,
        lookNum: null,
        titleDayName: null,
        amount: null
      };
      this.fileList = [];
      this.fileList2 = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      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();
      this.fileList = [];
      this.fileList2 = [];
      const id = row.id || this.ids
      getTravel(id).then(response => {
        this.form = response.data;
        if (response.data.titleImg != '' && response.data.titleImg != null) {
          let imgUrls = response.data.titleImg.split(",");
          for (let item of imgUrls) {
            this.fileList.push({url: item})
          }
        }
        if (response.data.imgUrl != '' && response.data.imgUrl != null) {
          let imgUrls2 = response.data.imgUrl.split(",");
          for (let item of imgUrls2) {
            this.fileList2.push({url: item})
          }
        }
        this.open = true;
        this.title = "修改游记";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            if (this.form.titleImg.charAt(this.form.titleImg.length - 1) == ",") {
              this.form.titleImg = this.form.titleImg.substring(0, this.form.titleImg.lastIndexOf(','));
            }
            if (this.form.imgUrl.charAt(this.form.imgUrl.length - 1) == ",") {
              this.form.imgUrl = this.form.imgUrl.substring(0, this.form.imgUrl.lastIndexOf(','));
            }
            updateTravel(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTravel(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 delTravel(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('tuya/tuyatravel/export', {
        ...this.queryParams
      }, `travel_${new Date().getTime()}.xlsx`)
    }
  },
  filters: {
    formatDate(time) {
      let date = new Date(time);
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let dateN = date.getDate();
      return year + "-" + month + "-" + dateN;
    }
  },
};
</script>
<style scoped lang="scss">
.item-card {
  position: relative;
}

.card_checkbox {
  position: absolute;
  left: 2px;
  top: 2px;
}

.card-txt {
  width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: bold;
}

.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  margin-left: 5px;
  float: right;
}

.image {
  width: 100%;
  height: 150px;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}

::v-deep .demo-table-expand {
  font-size: 0;
}

::v-deep .demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

::v-deep .demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 25%;
}

.update-video {
  display: flex;
  align-items: center;
}

.video-uploader {
  padding-left: 13px;
}

.uploader-button {
  height: 37px;
}

.my-img:hover { //使鼠标悬浮在图片上时出现手的形状
  cursor: pointer;
}

.video-js .vjs-icon-placeholder {
  width: 50%;
  height: 50%;
  display: block;
}

.videoPlayer ::v-deep .el-dialog,
.el-pager li {
  background: none !important;
  margin-top: 6vh !important;
}

.my-img:hover {
  cursor: pointer;
}
</style>

