<template>
  <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item>
          <el-date-picker
            v-model="dateRange"
            size="small"
            style="width: 240px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="queryParams.orderStatus"
            placeholder="订单状态"
            clearable
            size="small"
            style="width: 240px"
          >
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="queryParams.payChannel"
            placeholder="支付方式"
            clearable
            size="small"
            style="width: 240px"
          >
            <el-option
              v-for="dict in payStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="queryParams.account"
            placeholder="客户账号"
            clearable
            size="small"
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="queryParams.orderNo"
            placeholder="请输入订单编号"
            clearable
            size="small"
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="cyan" 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-table v-loading="loading" :data="list">
        <el-table-column label="序号" type="index" width="50" align="center" />
        <el-table-column label="下单时间" align="center" prop="createTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单编号" align="center" prop="orderNo" />
        <el-table-column label="客户账号" align="center" prop="account"/>
        <el-table-column label="客户名称" align="center" prop="customerName"/>
        <el-table-column label="支付方式" align="center" prop="payChannel"/>
        <el-table-column label="实付金额（¥）" align="center" prop="payAmount"/>
        <el-table-column label="购买碳汇量（kg）" align="center" prop="orderCarbonAmount"/>
        <el-table-column label="订单状态" align="center" prop="orderStatus"></el-table-column>
        <el-table-column
          label="操作"
          align="center"
          width="190"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="warning"
              v-if="scope.row.statusNum == 2"
              @click="handleCertificate(scope.row)"
              v-hasPermi="['order:baseOrder:certView']"
            >证书查看</el-button>
            <el-button
              size="mini"
              type="success"
              @click="handleView(scope.row)"
              v-hasPermi="['order:baseOrder:orderView']"
            >查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNo"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <card-show
        v-if="modal.cardShow.visibleModal"
        :title="modal.cardShow.title"
        :visible="modal.cardShow.visibleModal"
        :selectRow="modal.cardShow.selectRow"
        @closeCardShowModal="closeCardShowModal"
      ></card-show>
  </div>
</template>
<script>
import CardShow from '@/components/CardShow'
import { listOrder } from "@/api/order/baseOrder";
export default {
  name: "baseOrder",
  components:{
    CardShow
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: null,
      // 状态数据字典
      statusOptions: [],
      payStatusOptions:[],
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      //弹出层
      modal:{
        cardShow:{
          title:'',
          visibleModal:false,
          selectRow:null
        }
      },
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10
      }
    };
  },
  created() {
    //申请状态字典
    this.getDicts("order_base_status").then(response => {
      this.statusOptions = response.data;
    });
    //支付方式
    this.getDicts("order_base_playpaytype").then(response => {
      this.payStatusOptions = response.data;
    });
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listOrder(this.addDateRange(this.queryParams, this.dateRange)).then(res => {
          if(res.retHead.errCode == 0){
            this.list = res.retBody
            this.total = res.retHead.total;
          }
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.dateRange = null
      this.queryParams = {
        pageNo: 1,
        pageSize: 10
      }
      this.handleQuery();
    },
    /**订单查看**/
    handleView(item){
      this.$router.push({path:"/order/baseOrderDetail/",query:{id:item.guid}})
    },
    /**证书查看**/
    handleCertificate(item){
      this.modal.cardShow.visibleModal = true
      this.modal.cardShow.title = '证书查看'
      this.modal.cardShow.selectRow = item
    },
    //窗口关闭
    closeCardShowModal(){
      this.modal.cardShow.visibleModal = false
    }
  }
};
</script>
