<template>
  <div id="distributionOrder">
    <search-box-new
      ref="searchBox"
      :formData="formData"
      :formList="formList"
      @search="search"
      @init="init"
    />
    <table-list
      rowKey="id"
      ref="tableList"
      :tableSets="tableSet"
      :tableData="tableData"
      :navText="navText"
      :loading="loading"
    >
      <template slot="btn" slot-scope="props">
        <el-button type="text" @click="editClick(props.scope.row)"
          >详情</el-button
        >
      </template>
    </table-list>
    <pagination
      :total="total"
      :pageSize="formData.pageSize"
      :currentPage="formData.pageNum"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    />
    <BaseDialog
      width="1000px"
      :isShow.sync="isShow"
      title="业务员分销订单"
      @close="close"
      @submit="submit"
      :isShowFooter="false"
    >
      <template>
        <table-list
          rowKey="orderGoodsId"
          ref="tableList"
          :tableSets="tableSetOther"
          :tableData="tableDataOther"
          :navText="navTextOther"
          :loading="loadingOther"
        >
        </table-list>
      </template>
    </BaseDialog>
  </div>
</template>

<script>
import searchBoxNew from "@/components/searchBoxNew";
import tableList from "@/components/tableList";
import pagination from "@/components/pagination";
export default {
  // name: "DistributionOrder",
  components: { searchBoxNew, tableList, pagination },
  data() {
    return {
      disabledBtn: false,
      loading: false, //当前表单加载是否加载动画
      loadingOther: false,
      navText: {
        title: "分销订单列表",
        index: 0,
        ch: "条",
        num: true,
        choice: false,
        addHide: true,
        openCheckMore: true,
        changeWidth: "100px",
        backFatherBtn: {
          status: false,
          title: "配置下单填选模板",
        },
      },
      navTextOther: {
        tableHide: true,
        title: "分销订单详情",
        index: 0,
        ch: "条",
        num: true,
        choice: false,
        addHide: true,
        openCheckMore: true,
        changeWidth: "100px",
        backFatherBtn: {
          status: false,
          title: "配置下单填选模板",
        },
      },
      //搜索
      formList: [
        {
          prop: "tenantId",
          placeholder: "请选择机构",
          scope: "systemtenantlist",
        },
        {
          prop1: "startTime",
          prop2: "endTime",
          placeholder1: "开始时间",
          placeholder2: "结束时间",
          scope: "moreDataPicker",
        },
        {
          lable: "业务员姓名",
          prop: "sellerName",
          placeholder: "请输入业务员姓名",
        },
        {
          lable: "订单号",
          prop: "orderSn",
          placeholder: "请输入订单号",
        },
        {
          prop: "status",
          placeholder: "状态",
          scope: "select",
          options: [
            { label: "已支付", value: 1 },
            { label: "未支付", value: 2 },
            { label: "已退款", value: 3 },
          ],
        },
      ],
      formData: {
        pageSize: 10,
        pageNum: 1,
      },
      // 表单
      tableSet: [
        {
          label: "订单号",
          prop: "orderSn",
          hidden: true,
        },
        {
          label: "订单价格",
          prop: "orderPrice",
          hidden: true,
        },
        {
          label: "所属活动",
          prop: "distributionName",
          hidden: true,
        },
        {
          label: "手机号",
          prop: "telphone",
          hidden: true,
        },
        {
          label: "下单人",
          prop: "orderUserName",
          hidden: true,
        },
        {
          label: "所属机构",
          prop: "tenantName",
          hidden: true,
        },
        {
          label: "交易时间",
          prop: "orderTime",
          hidden: true,
          scope: "aTimeList",
        },
        {
          label: "支付状态",
          prop: "payStatus",
          hidden: true,
          scope: "isOptions",
          options: [
            {
              label: "未收费",
              value: 1,
            },
            {
              label: "部分收费",
              value: 2,
            },
            {
              label: "完全收费",
              value: 3,
            },
            {
              label: "免费",
              value: 4,
            },
          ],
        },
      ],
      tableData: [], //表单数据
      total: 0, //一共多少条
      tableSetOther: [
        {
          label: "佣金类型",
          prop: "cashType",
          hidden: true,
          scope: "isOptions",
          options: [
            {
              label: "百分比",
              value: 1,
            },
            {
              label: "固定金额（元）",
              value: 2,
            },
          ],
        },
        {
          label: "佣金比例",
          prop: "cashRatio",
          hidden: true,
          scope:"cashRatio"
        },
        {
          label: "业务员",
          prop: "sellerName",
          hidden: true,
        },
        {
          label: "时间",
          prop: "cashTime",
          hidden: true,
          scope: "aTimeList",
        },
        {
          label: "金额",
          prop: "cash",
          hidden: true,
        },
        {
          label: "佣金状态",
          prop: "cashStatus",
          hidden: true,
          scope: "isOptions",
          options: [
            {
              label: "冻结",
              value: 1,
            },
            {
              label: "正常",
              value: 2,
            },
            {
              label: "退款",
              value: 3,
            },
          ],
        },
      ],
      tableDataOther: [],
      isShow: false,
    };
  },
  created() {
    this.formData.tenantId = this.$route.params.id || "";
    this.search();
  },
  methods: {
    close() {},
    submit() {},
    statusChange() {
      switch (this.formData.status) {
        case 1:
          this.formData.refundStatus = 0;
          this.formData.payStatus = "3,4";
          break;
        case 2:
          this.formData.refundStatus = 0;
          this.formData.payStatus = 1;
          break;
        case 3:
          this.formData.refundStatus = 2;
          this.formData.payStatus = 3;
          break;
        default:
          this.formData.refundStatus = undefined;
          this.formData.payStatus = undefined;
          break;
      }
    },
    editClick(e) {
      this.isShow = true;
      this.navTextOther.index = e.cashVoList.length;
      console.log(e.cashVoList);
      this.tableDataOther = e.cashVoList;
      console.log("详情", e);
    },
    search(v) {
      this.loading = true;
      if (v === 2) {
        this.formData = {
          pageSize: 10,
          pageNum: 1,
        };
      }
      this.statusChange();
      var data = JSON.parse(JSON.stringify(this.formData));
      if (this.formData.startTime) {
        data.startTime = parseInt(data.startTime / 1000);
      }
      if (this.formData.endTime) {
        data.endTime = parseInt(data.endTime / 1000);
      }
      this.$api
        .distributiontemporgorder(data)
        .then((res) => {
          this.tableData = res.rows;
          this.total = res.total;
          this.navText.index = res.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    init() {
      this.search(2);
    },

    handleSizeChange(v) {
      this.formData.pageSize = v;
      this.formData.pageNum = 1;
      this.search();
    },
    handleCurrentChange(v) {
      this.formData.pageNum = v;
      this.search();
    },
  },
};
</script>

<style lang="scss" scoped>
/deep/.el-button {
  border-radius: 8px;
}
/deep/.el-dialog {
  border-radius: 8px;
  .el-dialog__header {
    padding: 0;
    .hearders {
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0px 18px 0px 20px;
      border-bottom: 1px solid #e2e2e2;
      .leftTitle {
        font-size: 14px;
        font-weight: bold;
        color: #2f4378;
      }
      .rightBoxs {
        display: flex;
        align-items: center;
        img {
          width: 14px;
          height: 14px;
          margin-left: 13px;
          cursor: pointer;
        }
      }
    }
  }
  .el-dialog__footer {
    padding: 0;
    .dialog-footer {
      padding: 0px 40px;
      height: 70px;
      border-top: 1px solid #e2e2e2;
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }
  }
}
.imgBox {
  width: 100%;
  // height: 210px;
  border: 1px solid #e2e2e2;
  border-radius: 8px;
  padding: 8px 8px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  .imgLabel {
    flex: 1;
    width: 100%;
    border: 1px dotted #e2e2e2;
    color: #999;
    font-size: 14px;
    cursor: pointer;
    border-radius: 8px;
    .msPhoto {
      display: flex;
      justify-content: center;
      align-items: center;
      max-width: 100%;
      max-height: 270px;
      img {
        max-width: 100%;
        max-height: 270px;
      }
    }
    .imgbbx {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 100%;
      i {
        font-weight: bold;
        margin: 14px 0;
        font-size: 24px;
      }
    }
  }
  p {
    margin: 5px 0px;
  }
}
.numInputs {
  width: 150px;
}
</style>
