<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="所属商家" prop="businessId">
        <el-select v-model="queryParams.businessId" filterable placeholder="请选择所属商家" size="small" clearable style="width: 100%">
          <el-option v-for="(v,i) in shopList" :key="i" :label="v.businessName" :value="v.businessId" />
        </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="orderUserPhone">
        <el-input v-model="queryParams.orderUserPhone" maxlength="11" placeholder="请输入下单手机号" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="商品名称" prop="businessProductName">
        <el-input v-model="queryParams.businessProductName" placeholder="请输入商品名称" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="下单时间">
        <el-date-picker v-model="daterangeCreateTime" 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 label="地推手机号" prop="promoterUserPhone">
        <el-input v-model="queryParams.promoterUserPhone" maxlength="11" placeholder="请输入地推手机号" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="分佣状态" prop="distributionStatus">
        <el-select v-model="queryParams.distributionStatus" placeholder="请选择分佣状态" clearable size="small">
          <el-option label="已入账" :value="1" />
          <el-option label="待入账" :value="0" />
        </el-select>
      </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">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="index" width="55" label="序号" align="center">
        <template slot-scope="scope">
          <div>
            {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="订单编号" align="center" prop="orderCode" />
      <el-table-column label="商品名称" align="center" prop="businessProductName" />
      <el-table-column label="销售价格" align="center" prop="sellingPrice" />
      <el-table-column label="购买数" align="center" prop="buyQuantity" />
      <el-table-column label="实付金额" align="center" prop="payMoney" />
      <el-table-column label="下单手机号" align="center" prop="orderUserPhone" />
      <el-table-column label="地推手机号" align="center" prop="promoterUserPhone" />
      <el-table-column label="所属商家" align="center" prop="businessName" />
      <el-table-column label="分佣状态" align="center" prop="distributionStatus">
        <template slot-scope="{row}">
          <el-tag type="success" v-if="!row.distributionStatus">待入账</el-tag>
          <el-tag type="danger" v-if="row.distributionStatus">已入账</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="预计入账金额" align="center" prop="expectAmount" />
      <el-table-column label="实际入账金额" align="center" prop="actualAmount">
        <template slot-scope="{row}">
          {{row.distributionStatus?row.actualAmount:'--'}}
        </template>
      </el-table-column>
      <el-table-column label="下单时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </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" @click="goDetails(scope.row)">查看</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" />

  </div>
</template>

<script>
import { businessList } from '@/api/shop'
import { orderPage } from '@/api/distribute'
export default {
  data () {
    return {
      //按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 测试单表表格数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 创建时间时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        businessId: undefined,
        orderCode: undefined,
        orderUserPhone: undefined,
        businessProductName: undefined,
        promoterUserPhone: undefined,
        distributionStatus: undefined
      },
      shopList: []
    }
  },
  created () {
    this.getShopList();
    this.getList();
  },
  methods: {
    goDetails (row) {
      this.$router.push({ path: '/distribute/distributeOrderDetails', query: { distributionOrderId: row.distributionOrderId } })
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getShopList () {
      businessList().then(res => {
        this.shopList = res.data
      })
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    getList () {
      this.loading = true;
      this.queryParams["createTimeStart"] = undefined;
      this.queryParams["createTimeEnd"] = undefined;
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams["createTimeStart"] = this.daterangeCreateTime[0];
        this.queryParams["createTimeEnd"] = this.daterangeCreateTime[1];
      }
      orderPage(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.adId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
  }
}
</script>

<style lang='scss' scoped>
</style>