<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="veteransId">-->
<!--        <el-input-->
<!--          v-model="queryParams.veteransId"-->
<!--          placeholder="请输入军人ID"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="店铺ID" prop="shopsId">-->
<!--        <el-input-->
<!--          v-model="queryParams.shopsId"-->
<!--          placeholder="请输入店铺ID"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @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="['orderinfo:orderinfo: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="['orderinfo:orderinfo: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="['orderinfo:orderinfo:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['orderinfo:orderinfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderinfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键" align="center" prop="orderId" />-->
      <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="原金额" align="center" prop="orderPriceOld" />
      <el-table-column label="优惠金额" align="center" prop="orderPriceVip" />
      <el-table-column label="姓名" align="center" prop="veteransName" />
      <el-table-column label="店铺名称" align="center" prop="goodsName" />
      <el-table-column label="照片" align="center" prop="picUrlList">
        <template slot-scope="scope">
          <el-image
            v-if="scope.row.picUrlList!=null"
            style="width: 100px; height: 100px"
            :src="image(scope.row.picUrlList[0])"
            :preview-src-list="scope.row.picUrlList">
          </el-image>
        </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-search"
                    @click="getDetailed(scope.row)"
                  >查看明细</el-button>
                </template>
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['orderinfo:orderinfo:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['orderinfo:orderinfo: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-drawer
      title="消费明细!"
      :visible.sync="table"
      :with-header="false"
      direction="rtl"
      size="50%">
    <el-table :data="gridData">
      <el-table-column property="shopsName" label="商品名称" width="150"></el-table-column>
      <el-table-column property="shopsNum" label="数量" width="200"></el-table-column>
      <el-table-column property="priceOld" label="原金额"></el-table-column>
      <el-table-column property="priceVip" label="优惠金额"></el-table-column>
    </el-table>
    </el-drawer>
    <!-- 添加或修改身份认证对话框 -->
    <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="orderTime">
          <el-date-picker clearable size="small"
            v-model="form.orderTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择认证时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="消费金额" prop="orderPrice">
          <el-input v-model="form.orderPrice" placeholder="请输入消费金额" />
        </el-form-item>
        <el-form-item label="店铺金额" prop="orderShopsId">
          <el-input v-model="form.orderShopsId" placeholder="请输入店铺金额" />
        </el-form-item>
        <el-form-item label="商品ID" prop="orderGoodsId">
          <el-input v-model="form.orderGoodsId" placeholder="请输入商品ID" />
        </el-form-item>
        <el-form-item label="原金额" prop="orderPriceOld">
          <el-input v-model="form.orderPriceOld" placeholder="请输入原金额" />
        </el-form-item>
        <el-form-item label="优惠金额" prop="orderPriceVip">
          <el-input v-model="form.orderPriceVip" placeholder="请输入优惠金额" />
        </el-form-item>
        <el-form-item label="军人ID" prop="veteransId">
          <el-input v-model="form.veteransId" placeholder="请输入军人ID" />
        </el-form-item>
        <el-form-item label="姓名" prop="veteransName">
          <el-input v-model="form.veteransName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="店铺ID" prop="shopsId">
          <el-input v-model="form.shopsId" placeholder="请输入店铺ID" />
        </el-form-item>
        <el-form-item label="店铺名称" prop="goodsName">
          <el-input v-model="form.goodsName" 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 { listOrderinfo,getDetailed, getOrderinfo, delOrderinfo, addOrderinfo, updateOrderinfo, exportOrderinfo } from "@/api/orderinfo/orderinfo";

export default {
  name: "Orderinfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 身份认证表格数据
      orderinfoList: [],
      //明细表格数据
      gridData: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //明细表格
      table: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        veteransId: null,
        shopsId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询身份认证列表 */
    getList() {
      this.loading = true;
      listOrderinfo(this.queryParams).then(response => {
        this.orderinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    image(e) {
      return process.env.VUE_APP_BASE_API+ e;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        orderTime: null,
        orderPrice: null,
        orderShopsId: null,
        orderGoodsId: null,
        orderPriceOld: null,
        orderPriceVip: null,
        veteransId: null,
        veteransName: null,
        shopsId: null,
        goodsName: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /**
     * 明细表格
     * @param row
     */
    getDetailed(row){
      getDetailed(row.orderId).then(response => {
        this.table = true;
        this.gridData = response.data;
      });
    },
    /** 重置按钮操作 */
    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 = "添加身份认证";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderId = row.orderId || this.ids
      getOrderinfo(orderId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改身份认证";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderId != null) {
            updateOrderinfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrderinfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderIds = row.orderId || this.ids;
      this.$modal.confirm('是否确认删除身份认证编号为"' + orderIds + '"的数据项？').then(function() {
        return delOrderinfo(orderIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有身份认证数据项？').then(() => {
        this.exportLoading = true;
        return exportOrderinfo(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
