<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="公司名" prop="companyId">
          <el-select  filterable   v-model="queryParams.companyId" placeholder="请选择公司名" clearable size="small">
              <el-option
                v-for="item in companys"
                :key="item.companyId"
                :label="item.companyName"
                :value="item.companyId"
              />
        </el-select>
      </el-form-item>
      <el-form-item label="订单号" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          placeholder="请输入订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="运单号" prop="deliveryId">
        <el-input

          v-model="queryParams.deliveryId"
          placeholder="请输入运单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="userPhone">
        <el-input

          v-model="queryParams.userPhone"
          placeholder="请输入会员手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工姓名" prop="companyUserNickName">
        <el-input

          v-model="queryParams.companyUserNickName"
          placeholder="请输入员工姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="下单时间" prop="createTimeRange">
        <el-date-picker
          style="width:205.4px"
          clearable size="small"
          v-model="createTimeRange"
          type="daterange"
          value-format="yyyy-MM-dd"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </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="warning"
          icon="el-icon-download"
          size="mini"
            @click="handleExport"
        >导出</el-button>
      </el-col>
    </el-row>
    <el-tabs type="card" v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="已付款待审核" name="1"></el-tab-pane>
      <el-tab-pane label="已审核" name="2"></el-tab-pane>
    </el-tabs>
    <el-table  height="500" border v-loading="loading" :data="storeOrderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单号" align="center" prop="orderCode" width="200px" />
      <el-table-column label="所属公司" align="center" prop="companyName" />
      <el-table-column label="所属员工" align="center" prop="companyUserNickName" />
      <el-table-column label="用户昵称" align="center" prop="nickname" width="150px" v-if="false">
          <template slot-scope="scope">
              <span>{{scope.row.nickname}} </span>
          </template>
      </el-table-column>
      <el-table-column label="收件人" align="center" prop="realName" width="150px" v-if="false">
          <template slot-scope="scope">
              <span>{{scope.row.realName}} </span>
          </template>
      </el-table-column>
      <el-table-column label="订单金额" align="center" prop="totalPrice" >
          <template slot-scope="scope">
              <span v-if="scope.row.totalPrice!=null">{{scope.row.totalPrice.toFixed(2)}}</span>
          </template>
      </el-table-column>
       <el-table-column label="应付金额" align="center" prop="payPrice" >
          <template slot-scope="scope">
              <span v-if="scope.row.payPrice!=null">{{scope.row.payPrice.toFixed(2)}}</span>
          </template>
      </el-table-column>
      <el-table-column label="尾款支付金额" align="center" prop="lastPayMoney" >
          <template slot-scope="scope">
              <span v-if="scope.row.lastPayMoney!=null">{{scope.row.lastPayMoney}}</span>
          </template>
      </el-table-column>
      <el-table-column label="物流单号" align="center" prop="deliveryId" />
      <el-table-column label="下单时间" align="center" prop="createTime" />
      <el-table-column label="支付方式" align="center" prop="payType" >
          <template slot-scope="scope">
              <el-tag prop="payType" v-for="(item, index) in payTypeOptions"    v-if="scope.row.payType==item.dictValue">{{item.dictLabel}}</el-tag>
          </template>
      </el-table-column>
      <el-table-column label="订单类型" align="center" prop="orderType" >
          <template slot-scope="scope">
              <el-tag prop="status" v-for="(item, index) in orderTypeOptions"    v-if="scope.row.orderType==item.dictValue">{{item.dictLabel}}</el-tag>
          </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" >
          <template slot-scope="scope">
              <el-tag prop="status" v-for="(item, index) in statusOptions"    v-if="scope.row.status==item.dictValue">{{item.dictLabel}}</el-tag>
          </template>
      </el-table-column>

      <el-table-column label="操作" fixed="right" width="80px" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleDetails(scope.row)"
            v-hasPermi="['store:storeOrder:query']"
          >查看</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
     size="75%"
      :title="show.title" :visible.sync="show.open"
      >
      <product-order  ref="order" />
    </el-drawer>


  </div>
</template>

<script>
import {  listPayRemainOrder,exportStorePayRemainOrder } from "@/api/hisStore/storeOrder";
import productOrder from "../components/productOrder";
import { getCompanyList } from "@/api/company/company";
export default {
  components: { productOrder  },
  name: "HisPayRemainList",
  data() {
    return {
      companys:[],
      orderTypeOptions:[],
      payTypeOptions:[],
      show:{
        open:false,
        title:"订单详情"
      },
      activeName:"1",
      statusOptions:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      storeOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      createTimeRange:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderCode: null,
        extendOrderId: null,
        userId: null,
        realName: null,
        userPhone: null,
        userAddress: null,
        cartId: null,
        freightPrice: null,
        totalNum: null,
        totalPrice: null,
        totalPostage: null,
        payPrice: null,
        payPostage: null,
        deductionPrice: null,
        couponId: null,
        couponPrice: null,
        paid: null,
        payTime: null,
        payType: null,
        status: null,
        refundStatus: null,
        refundReasonWapImg: null,
        refundReasonWapExplain: null,
        refundReasonTime: null,
        refundReasonWap: null,
        refundReason: null,
        refundPrice: null,
        deliverySn: null,
        deliveryName: null,
        deliveryType: null,
        deliveryId: null,
        gainIntegral: null,
        useIntegral: null,
        payIntegral: null,
        backIntegral: null,
        mark: null,
        isDel: null,
        cost: null,
        verifyCode: null,
        storeId: null,
        shippingType: null,
        isChannel: null,
        isRemind: null,
        isSysDel: null,
        isPayRemain:1,

      },
      // 表单参数
      form: {
        addressId:null,
        userId:null,
      },
      // 表单校验
      rules: {
        userId: [
          { required: true, message: "会员信息不能为空" }
        ],
        addressId: [
          { required: true, message: "收货信息不能为空" }
        ],

      },

    };
  },
  created() {
    getCompanyList().then(response => {
        this.companys = response.data;
    });
    this.getDicts("store_order_type").then((response) => {
      this.orderTypeOptions = response.data;
    });

    this.getDicts("store_pay_type").then((response) => {
      this.payTypeOptions = response.data;
    });
    this.getDicts("store_order_status").then((response) => {
      this.statusOptions = response.data;
    });

    this.getList();
  },
  methods: {

    handleDetails(row){
      this.show.open=true;
      const orderId = row.id ;
      setTimeout(() => {
        this.$refs.order.getOrder(orderId);
      }, 500);
    },
    handleClick(tab, event) {
      this.activeName=tab.name;
      this.queryParams.isPayRemain=tab.name
      this.getList();
    },
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      if(this.queryParams.status=='00'){
        this.queryParams.status=null;
      }
      if(this.createTimeRange!=null&&this.createTimeRange.length==2){
        this.queryParams.createTimeRange=this.createTimeRange[0]+"--"+this.createTimeRange[1]
      }
      else{
        this.queryParams.createTimeRange=null;
      }
      listPayRemainOrder(this.queryParams).then(response => {
        this.storeOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        addressId:null,
        userId: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
    },
    /** 导出按钮操作 */
    handleExport() {
      if(this.queryParams.status=='00'){
        this.queryParams.status=null;
      }
      if(this.createTimeRange!=null&&this.createTimeRange.length==2){
        this.queryParams.createTimeRange=this.createTimeRange[0]+"--"+this.createTimeRange[1]
      }
      else{
        this.queryParams.createTimeRange=null;
      }
      const queryParams = this.addDateRange(this.queryParams, this.dateRange);
      this.$confirm('是否确认导出所有售后记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportStorePayRemainOrder(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    },

  }
};
</script>
<style scoped lang="scss">
.items{
  margin: 5px 0px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  .pic{
    width:60px;
    height:60px;
  }
  .goods-content{
    margin-left: 10px;
    max-width: 200px;
    text-align: left;
    .goods-title{

      overflow:hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      -o-text-overflow:ellipsis;
    }
  }
}
.el-message-box__message p{
  max-height: 400px;
  overflow:scroll;
}
.import-msg{
  height: 500px;
  overflow: auto;
}
</style>
<style>
  .el-descriptions-item__label.is-bordered-label{
    font-weight: normal;
  }

</style>

