<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="channel">
        <el-input
          v-model="queryParams.channel"
          placeholder="请输入渠道"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="父类目" prop="parentCategory">
        <el-input
          v-model="queryParams.parentCategory"
          placeholder="请输入父类目"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="子类目" prop="sonCategory">
        <el-input
          v-model="queryParams.sonCategory"
          placeholder="请输入子类目"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="时间范围" prop="time">
        <el-input
          v-model="queryParams.time"
          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="['market:daily: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="['market:daily: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="['market:daily: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="['market:daily:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dailyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="渠道" align="center" prop="channel" />
      <el-table-column label="父类目" align="center" prop="parentCategory" />
      <el-table-column label="子类目" align="center" prop="sonCategory" />
      <el-table-column label="时间范围" align="center" prop="time" />
      <el-table-column label="支付金额" align="center" prop="amount" />
      <el-table-column label="搜索热度" align="center" prop="searchHeat" />
      <el-table-column label="搜索人气" align="center" prop="searchPopularity" />
      <el-table-column label="加购人气" align="center" prop="purchasePopularity" />
      <el-table-column label="加购热度" align="center" prop="purchaseHeat" />
      <el-table-column label="收藏热度" align="center" prop="collectionHeat" />
      <el-table-column label="浏览热度" align="center" prop="browsingHeat" />
      <el-table-column label="访问人气" align="center" prop="visitorPopularity" />
      <el-table-column label="收藏人气" align="center" prop="collectionPopularity" />
      <el-table-column label="客群指数" align="center" prop="customerBaseIndex" />
      <el-table-column label="ID" align="center" prop="id" />
      <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="['market:daily:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['market:daily: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="渠道" prop="channel">
          <el-input v-model="form.channel" placeholder="请输入渠道" />
        </el-form-item>
        <el-form-item label="父类目" prop="parentCategory">
          <el-input v-model="form.parentCategory" placeholder="请输入父类目" />
        </el-form-item>
        <el-form-item label="子类目" prop="sonCategory">
          <el-input v-model="form.sonCategory" placeholder="请输入子类目" />
        </el-form-item>
        <el-form-item label="时间范围" prop="time">
          <el-input v-model="form.time" placeholder="请输入时间范围" />
        </el-form-item>
        <el-form-item label="支付金额" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入支付金额" />
        </el-form-item>
        <el-form-item label="搜索热度" prop="searchHeat">
          <el-input v-model="form.searchHeat" placeholder="请输入搜索热度" />
        </el-form-item>
        <el-form-item label="搜索人气" prop="searchPopularity">
          <el-input v-model="form.searchPopularity" placeholder="请输入搜索人气" />
        </el-form-item>
        <el-form-item label="加购人气" prop="purchasePopularity">
          <el-input v-model="form.purchasePopularity" placeholder="请输入加购人气" />
        </el-form-item>
        <el-form-item label="加购热度" prop="purchaseHeat">
          <el-input v-model="form.purchaseHeat" placeholder="请输入加购热度" />
        </el-form-item>
        <el-form-item label="收藏热度" prop="collectionHeat">
          <el-input v-model="form.collectionHeat" placeholder="请输入收藏热度" />
        </el-form-item>
        <el-form-item label="浏览热度" prop="browsingHeat">
          <el-input v-model="form.browsingHeat" placeholder="请输入浏览热度" />
        </el-form-item>
        <el-form-item label="访问人气" prop="visitorPopularity">
          <el-input v-model="form.visitorPopularity" placeholder="请输入访问人气" />
        </el-form-item>
        <el-form-item label="收藏人气" prop="collectionPopularity">
          <el-input v-model="form.collectionPopularity" placeholder="请输入收藏人气" />
        </el-form-item>
        <el-form-item label="客群指数" prop="customerBaseIndex">
          <el-input v-model="form.customerBaseIndex" placeholder="请输入客群指数" />
        </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 { listDaily, getDaily, delDaily, addDaily, updateDaily } from "@/api/market/daily";

export default {
  name: "Daily",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 市场大盘（日）表格数据
      dailyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        channel: null,
        parentCategory: null,
        sonCategory: null,
        time: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询市场大盘（日）列表 */
    getList() {
      this.loading = true;
      listDaily(this.queryParams).then(response => {
        this.dailyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        channel: null,
        parentCategory: null,
        sonCategory: null,
        time: null,
        amount: null,
        searchHeat: null,
        searchPopularity: null,
        purchasePopularity: null,
        purchaseHeat: null,
        collectionHeat: null,
        browsingHeat: null,
        visitorPopularity: null,
        collectionPopularity: null,
        customerBaseIndex: null,
        id: 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
      getDaily(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) {
            updateDaily(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDaily(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 delDaily(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('market/daily/export', {
        ...this.queryParams
      }, `daily_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
