<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任务id" prop="taskId">
        <el-input
          v-model="queryParams.taskId"
          placeholder="请输入任务id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="运动类型" prop="sportsType">
        <el-select v-model="queryParams.sportsType" placeholder="请选择运动类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="消耗卡路里体重" prop="calorie">
        <el-input
          v-model="queryParams.calorie"
          placeholder="请输入消耗卡路里体重"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="步数" prop="step">
        <el-input
          v-model="queryParams.step"
          placeholder="请输入步数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="里程/米" prop="course">
        <el-input
          v-model="queryParams.course"
          placeholder="请输入里程/米"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="步频" prop="cadence">
        <el-input
          v-model="queryParams.cadence"
          placeholder="请输入步频"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="步幅" prop="stride">
        <el-input
          v-model="queryParams.stride"
          placeholder="请输入步幅"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="运动时长/秒" prop="sportsDuration">
        <el-input
          v-model="queryParams.sportsDuration"
          placeholder="请输入运动时长/秒"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否删除0=否1=是" prop="isDelete">
        <el-input
          v-model="queryParams.isDelete"
          placeholder="请输入是否删除0=否1=是"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createAt">
        <el-date-picker clearable size="small"
          v-model="queryParams.createAt"
          type="date"
          value-format="yyyy-MM-dd"
          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="['system:LzydSportLog: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="['system:LzydSportLog: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="['system:LzydSportLog: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="['system:LzydSportLog:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="LzydSportLogList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="用户id" align="center" prop="userId" width="200" />
      <el-table-column label="任务id" align="center" prop="taskId" width="200" />
      <el-table-column label="运动类型" align="center" prop="sportsType" />
      <!-- |0=室外1=室内 -->
      <el-table-column label="卡路里" align="center" prop="calorie" />
      <el-table-column label="步数" align="center" prop="step" />
      <el-table-column label="里程/米" align="center" prop="course" />
      <el-table-column label="步频" align="center" prop="cadence" />
      <el-table-column label="步幅" align="center" prop="stride" />
      <el-table-column label="运动时长/秒" align="center" prop="sportsDuration" />
      <!-- <el-table-column label="运动打点" align="center" prop="points" />
      <el-table-column label="运动打点" align="center" prop="charts" /> -->
      <el-table-column label="预留运动数据记录" align="center" prop="soprtDesc" />
      <el-table-column label="是否删除" align="center" prop="isDelete" />
      <!-- 0=否1=是 -->
      <el-table-column label="创建时间" align="center" prop="createAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <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="['system:LzydSportLog:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:LzydSportLog: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="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="任务id" prop="taskId">
          <el-input v-model="form.taskId" placeholder="请输入任务id" />
        </el-form-item>
        <el-form-item label="运动类型" prop="sportsType">
          <el-select v-model="form.sportsType" placeholder="请选择运动类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="消耗卡路里体重" prop="calorie">
          <el-input v-model="form.calorie" placeholder="请输入消耗卡路里体重" />
        </el-form-item>
        <el-form-item label="步数" prop="step">
          <el-input v-model="form.step" placeholder="请输入步数" />
        </el-form-item>
        <el-form-item label="里程/米" prop="course">
          <el-input v-model="form.course" placeholder="请输入里程/米" />
        </el-form-item>
        <el-form-item label="步频" prop="cadence">
          <el-input v-model="form.cadence" placeholder="请输入步频" />
        </el-form-item>
        <el-form-item label="步幅" prop="stride">
          <el-input v-model="form.stride" placeholder="请输入步幅" />
        </el-form-item>
        <el-form-item label="运动时长/秒" prop="sportsDuration">
          <el-input v-model="form.sportsDuration" placeholder="请输入运动时长/秒" />
        </el-form-item>
        <el-form-item label="运动打点" prop="points">
          <el-input v-model="form.points" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="运动打点" prop="charts">
          <el-input v-model="form.charts" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="预留运动数据记录" prop="soprtDesc">
          <el-input v-model="form.soprtDesc" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否删除" prop="isDelete">
          <el-input v-model="form.isDelete" placeholder="请输入是否删除" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createAt">
          <el-date-picker clearable size="small"
            v-model="form.createAt"
            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>
  </div>
</template>

<script>
import { listLzydSportLog, getLzydSportLog, delLzydSportLog, addLzydSportLog, updateLzydSportLog, exportLzydSportLog } from "@/api/system/LzydSportLog";

export default {
  name: "LzydSportLog",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 运动记录表格数据
      LzydSportLogList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        taskId: null,
        sportsType: null,
        calorie: null,
        step: null,
        course: null,
        cadence: null,
        stride: null,
        sportsDuration: null,
        points: null,
        charts: null,
        soprtDesc: null,
        isDelete: null,
        createAt: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询运动记录列表 */
    getList() {
      this.loading = true;
      listLzydSportLog(this.queryParams).then(response => {
        this.LzydSportLogList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        taskId: null,
        sportsType: null,
        calorie: null,
        step: null,
        course: null,
        cadence: null,
        stride: null,
        sportsDuration: null,
        points: null,
        charts: null,
        soprtDesc: null,
        isDelete: null,
        createAt: 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.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
      getLzydSportLog(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) {
            updateLzydSportLog(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLzydSportLog(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除运动记录编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delLzydSportLog(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有运动记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportLzydSportLog(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
