<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item :label="$t('table.commodityName')">
		<el-input  v-model="queryParams.commodityName" :placeholder="$t('placeholder.commodityName')"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{$t('btn.search')}}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{$t('btn.Reset')}}</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="['order:order: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="['order:order: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="['order:order: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="['order:order:export']"
        >导出</el-button>
      </el-col> -->
      <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
	  <el-table-column :label="$t('table.SerialNumber')" width="50px" align="center">
		<template slot-scope="scope">
			{{ scope.$index + (queryParams.pageNum - 1) * queryParams.pageSize + 1 }}
		</template>
	  </el-table-column>
	  <el-table-column :label="$t('table.commodityName')" align="center" prop="commodityName" />
	  <el-table-column :label="$t('dialog.couponName')" align="center" prop="couponName" />
	  <el-table-column :label="$t('table.userNum')" align="center" prop="buyNum" />
      <el-table-column :label="$t('table.operation')" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row.id)"
            v-hasPermi="['commodityCoupon:commodityCoupon:statisList']"
          >{{$t('table.detail')}}</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>
      <el-table v-loading="loading" :data="orderList2" >
	  <el-table-column :label="$t('table.SerialNumber')" width="50px" align="center">
		<template slot-scope="scope">
			{{ scope.$index + (queryParams.pageNum - 1) * queryParams.pageSize + 1 }}
		</template>
	  </el-table-column>
	  <el-table-column :label="$t('system.userName')" align="center" prop="name" />
	  <el-table-column :label="$t('system.phonenumber')" align="center" prop="phone" />
	  <el-table-column :label="$t('table.userTime')" align="center" prop="payDate" />
    </el-table>
    
    <pagination
      v-show="total2>0"
      :total="total2"
      :page.sync="queryParams2.pageNum"
      :limit.sync="queryParams2.pageSize"
      @pagination="getList2"
    />
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
        <el-button @click="cancel">{{$t('btn.cancel')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCommodityCoupon,statisDetailList } from "@/api/couponManagement/couponManagement";

export default {
  name: "Order",
  data() {
    return {
      // 遮罩层
      loading: true,
	  loading2: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
	  total2: 0,
      // 订单管理表格数据
      orderList: [],
	  orderList2 : [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
	  // 商品类型列表
	  commodityTypeList:[],  
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        commodityName: null,
      },
	  queryParams2: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单管理列表 */
    getList() {
      this.loading = true;
      listCommodityCoupon(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
	getList2() {
      this.loading2 = true;
	  this.orderList2 =[]
      statisDetailList(this.queryParams2).then(response => {
        this.orderList2 = response.rows;
        this.total2 = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderyNo: null,
        customerId: null,
        commodityId: null,
        departurePlace: null,
        departureDate: null,
        isCoupon: null,
        adultNum: null,
        childNum: null,
        orderMoney: null,
        aipayNo: null,
        status: "0",
        deptId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: 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(id) {
    //   this.reset();
    //   const id = row.id || this.ids
		this.queryParams2.id = id
		this.open = true;
		this.getList2()
     
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认取消此订单？').then(function() {
        return newDelOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("取消成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('order/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
