<template>
  <div class="app-container">
    <el-table  :data="datawarehouseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单id" align="center" prop="orderId" />
      <el-table-column label="订单编号" align="center" prop="orderBian" />
      <el-table-column label="下单时间" align="center" prop="orderTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="商品名称" align="center" prop="shopName" />
      <el-table-column label="姓名" align="center" prop="orderName" />
      <el-table-column label="联系方式" align="center" prop="phone" />
      <el-table-column label="金额" align="center" prop="orderScore" />
      <el-table-column label="支付方式" align="center" prop="payway" />
    </el-table>

  </div>
</template>

<script>
import { listDatawarehouse, getDatawarehouse, delDatawarehouse, addDatawarehouse, updateDatawarehouse } from "/src/api/ruleEngine/datawarehouse";

export default {
  name: "Datawarehouse",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单详情表格数据
      datawarehouseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderBian: null,
        orderTime: null,
        userId: null,
        shopName: null,
        orderName: null,
        phone: null,
        orderScore: null,
        payway: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单详情列表 */
    getList() {
      getDatawarehouse().then(response=>{
        this.datawarehouseList = response.data;
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderId: null,
        orderBian: null,
        orderTime: null,
        userId: null,
        shopName: null,
        orderName: null,
        phone: null,
        orderScore: null,
        payway: 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.orderId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单详情";
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderIds = row.orderId || this.ids;
      this.$modal.confirm('是否确认删除订单详情编号为"' + orderIds + '"的数据项？').then(function() {
        return delDatawarehouse(orderIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ruleEngine/datawarehouse/export', {
        ...this.queryParams
      }, `datawarehouse_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
