<template>
  <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <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-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.customerName"
            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-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            size="mini"
            @click="handleCreate"
            v-hasPermi="['order:inlineOrder:create']"
          >新增订单</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
      <el-table v-loading="loading" :data="list">
        <el-table-column label="序号" type="index" width="50" align="center" />
        <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="payAmount"/>
        <el-table-column label="购买碳汇量（kg）" align="center" prop="orderCarbonAmount"/>
        <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="orderType"/>
        <el-table-column label="订单状态" align="center" prop="orderStatus"></el-table-column>
        <el-table-column
          label="操作"
          align="center"
          width="320"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              v-if="scope.row.status == 1"
              @click="handlePay(scope.row)"
              v-hasPermi="['order:inlineOrder:realpay']"
            >确认收款</el-button>
            <el-button
              size="mini"
              type="warning"
              v-if="scope.row.status == 2"
              v-hasPermi="['order:inlineOrder:certView']"
              @click="handleCertificate(scope.row)"
            >证书查看</el-button>
            <el-button
              size="mini"
              type="success"
              v-hasPermi="['order:inlineOrder:orderView']"
              @click="handleView(scope.row)"
            >查看详情</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"
      />
      <add-mobiel
      			v-if="modal.create.visibleModal"
      			:title="modal.create.title"
      			:action="modal.create.action"
      			:visible="modal.create.visibleModal"
      			@closeCreateModal="closeCreateModal">
      		</add-mobiel>
      <pay-mobiel
          v-if="modal.playpay.visibleModal"
          :title="modal.playpay.title"
          :action="modal.playpay.action"
          :visible="modal.playpay.visibleModal"
          :selectRow="modal.playpay.selectRow"
          @closePlaypayModal="closePlaypayModal"
      ></pay-mobiel>
      <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 { listOrder , delApplyItem , areaTree} from "@/api/order/inlineOrder";
import CardShow from '@/components/CardShow'
import addMobiel from './modal/addMobiel'
import payMobiel from './modal/payMobiel'
export default {
  name: "inlineOrder",
  components: {
    addMobiel,
    payMobiel,
    CardShow
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: null,
      // 状态数据字典
      statusOptions: [],
      // 表单参数
      form: {},
      //弹出层
      modal:{
        create:{
          action:'',
          title:'',
          visibleModal:false,
        },
        playpay:{
          action:'',
          title:'',
          visibleModal:false,
          selectRow:null
        },
        cardShow:{
          title:'',
          visibleModal:false,
          selectRow:null
        }
      },
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10
      }
    };
  },
  created() {
    //申请状态字典
    this.getDicts("order_inlineOrder_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).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.queryParams = {
        pageNo: 1,
        pageSize: 10
      }
      this.handleQuery();
    },
    /** 查看按钮操作 */
    handleCreate(item){
        this.modal.create.visibleModal = true
        this.modal.create.title = '新增订单'
        this.modal.create.action = 'edit'
    },
    /*确定收款*/
    handlePay(item){
      this.modal.playpay.visibleModal = true
      this.modal.playpay.title = '确认收款'
      this.modal.playpay.action = 'add'
      this.modal.playpay.selectRow = item
    },
    /**订单查看**/
    handleView(item){
      this.$router.push({path:"/order/orderDetail/",query:{id:item.guid}})
    },
    /**证书查看**/
    handleCertificate(item){
      this.modal.cardShow.visibleModal = true
      this.modal.cardShow.title = '证书查看'
      this.modal.cardShow.selectRow = item
    },
    //窗口关闭
    closeCreateModal(flag = false){
      this.modal.create.visibleModal = false
      flag && this.getList()
    },
    closePlaypayModal(flag = false){
      this.modal.playpay.visibleModal = false
      flag && this.getList()
    },
    closeCardShowModal(){
      this.modal.cardShow.visibleModal = false
    }
  }
};
</script>
