<template>
  <div>
    <el-table border v-loading="listLoading" :data="list" :element-loading-text="elementLoadingText" @row-dblclick="rowdbClick" :header-cell-style="{background: 'linear-gradient(#6cb3ff, #1873d4)',color:'#eeeeee'}">
      <el-table-column show-overflow-tooltip align="center" min-width="80" prop="docTypeName" label="类别">
        <template slot-scope="scope">
          <div>{{scope.row.isAddition==1?'(补)':''}}{{scope.row.docTypeName}}</div>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip align="center" min-width="80" prop="orderStatu" label="状态">
        <template slot-scope="scope">
          <el-tag :type="scope.row.orderStatu==0?'success':scope.row.orderStatu==0?'danger':''">
            {{scope.row.orderStatu==0?'正常':scope.row.orderStatu==1?'作废':'反审核'}}
          </el-tag>
        </template>
      </el-table-column>
      <!-- <el-table-column show-overflow-tooltip align="center" min-width="100" label="支付方式">
        <template slot-scope="scope">
          <span>{{ scope.row.rechargeConsumeList.length?'卡付':'现金' }}</span>
        </template>
      </el-table-column> -->
      <el-table-column show-overflow-tooltip align="center" label="单据">
        <el-table-column show-overflow-tooltip align="center" min-width="100" prop="docNum" label="单据号"></el-table-column>
        <el-table-column show-overflow-tooltip align="center" min-width="115" prop="inputDate" label="时间">
          <template slot-scope="scope">
            <div>{{scope.row.isAddition==1?'(补)':''}}{{scope.row.inputDate}}</div>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip align="center" min-width="130" prop="storeName" label="门店名称"></el-table-column>
      </el-table-column>
      <el-table-column show-overflow-tooltip align="center" label="交易">
        <el-table-column show-overflow-tooltip align="center" min-width="100" prop="accountNum" label="编码"></el-table-column>
        <el-table-column show-overflow-tooltip align="center" min-width="130" prop="tradeName" label="名称"></el-table-column>
        <el-table-column show-overflow-tooltip align="center" min-width="80" prop="price" label="单价">
          <template slot-scope="scope">
            <div>
              {{scope.row.price?scope.row.price:'--'}}
            </div>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip align="center" min-width="80" prop="tradeCount" label="数量">
          <template slot-scope="scope">
            <div>
              {{scope.row.tradeCount?scope.row.tradeCount:'--'}}
            </div>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip align="center" min-width="80" prop="tradeMoney" label="成交金额"></el-table-column>
        <el-table-column show-overflow-tooltip align="center" min-width="80" prop="debtMoney" label="欠款金额"></el-table-column>
      </el-table-column>
      <!-- <el-table-column show-overflow-tooltip align="center" min-width="90" prop="cashMoney" label="现付总金额"></el-table-column>
      <el-table-column show-overflow-tooltip align="center" min-width="90" prop="cardMoney" label="卡付总金额"></el-table-column> -->
      <el-table-column show-overflow-tooltip align="center" min-width="90" prop="cashMoney" label="现付总金额"></el-table-column>
      <el-table-column show-overflow-tooltip align="center" min-width="90" prop="cardMoney" label="卡付总金额"></el-table-column>
      <el-table-column show-overflow-tooltip align="center" label="剩余">
        <el-table-column show-overflow-tooltip align="center" min-width="80" prop="accountRestCount" label="次数">
          <template slot-scope="scope">
            <div>
              {{scope.row.accountRestCount?scope.row.accountRestCount:'--'}}
            </div>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip align="center" min-width="80" prop="accountRestMoney" label="金额"></el-table-column>
      </el-table-column>
      <el-table-column show-overflow-tooltip align="center" label="可用">
        <el-table-column show-overflow-tooltip align="center" min-width="80" prop="accountConsumeCount" label="次数">
          <template slot-scope="scope">
            <div>
              {{scope.row.accountConsumeCount?scope.row.accountConsumeCount:'--'}}
            </div>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip align="center" min-width="80" prop="accountConsumeMoney" label="金额"></el-table-column>
      </el-table-column>
      <el-table-column show-overflow-tooltip align="center" min-width="80" prop="inputBy" label="录单人"></el-table-column>
    </el-table>
    <div class="block margin-top-xs">
      <!-- 分页组件 -->
      <el-pagination align="left" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryForm.pageNum" :page-sizes="[10,20,30,40,50]" :page-size="queryForm.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
    </div>
    <orderdetail ref="orderdetail"></orderdetail>
  </div>
</template>

<script>
import { listByMembers } from "@/api/eashier";
import orderdetail from "@/components/order/detail.vue";
export default {
  components: { orderdetail },
  data() {
    return {
      itemList: [
        //单据全部类型

        {
          docType: "upgrade_out",
          docTypeName: "升级转出",
        },
        {
          docType: "upgrade_in",
          docTypeName: "升级充值",
        },
        {
          docType: "demotion_out",
          docTypeName: "降级转出",
        },
        {
          docType: "demotion_in",
          docTypeName: "降级充值",
        },
        {
          docType: "store_room",
          docTypeName: "前台收银",
        },
        {
          docType: "init",
          docTypeName: "初始化",
        },
        {
          docType: "card_recharge",
          docTypeName: "充值开卡",
        },

        {
          docType: "recharge_roll_course",
          docTypeName: "疗程转充值卡",
        },
        {
          docType: "card_change",
          docTypeName: "加价转疗程",
        },
        {
          docType: "card_use",
          docTypeName: "疗程开卡",
        },
        {
          docType: "store_cash",
          docTypeName: "收银",
        },
        {
          docType: "card_repay",
          docTypeName: "还款",
        },
        {
          docType: "refund_recharge",
          docTypeName: "充值退款",
        },
        {
          docType: "refund_course",
          docTypeName: "疗程退款",
        },
        {
          docType: "refund_cash",
          docTypeName: "消费退款",
        },
        {
          docType: "promotion",
          docTypeName: "促销活动",
        },
        {
          docType: "promotion_card_repay",
          docTypeName: "促销还款",
        },
      ],
      form: {}, //主对象
      list: [], //主数组
      total: 0, //分页总条数
      listLoading: false, //list加载提示开启动画
      elementLoadingText: "加载中...", //list加载提示文字
      queryForm: {
        //查询对象
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  methods: {
    //列表数组双击方法
    rowdbClick(row) {
      this.$refs.orderdetail.show(row);
    },
    //组件传值
    show(form) {
      this.form = { ...form };
      this.getData();
    },
    //分页方法
    handleSizeChange(val) {
      this.queryForm.pageSize = val;
      this.getData();
      //console.log(val);
    },
    handleCurrentChange(val) {
      this.queryForm.pageNum = val;
      this.getData();
      //console.log(val);
    },
    //获取数据
    async getData() {
      this.queryForm.inputDate = this.formatTime(
        new Date(),
        "YYYY-MM-DD hh:mm:ss"
      );
      if (this.form.month) {
        this.queryForm.inputDate = this.formatTime(
          this.form.month,
          "YYYY-MM-DD hh:mm:ss"
        );
      } else {
        this.queryForm.inputDate = this.formatTime(
          new Date(),
          "YYYY-MM-DD hh:mm:ss"
        );
      }
      this.queryForm.memberId = this.form.id;
      this.queryForm.memberName = this.form.memberName;
      this.queryForm.memberPhone = this.form.mobilePhone;

      listByMembers(this.queryForm).then((res) => {
        if (res.code == "000000") {
          res.pageInfo.list.forEach((item) => {
            this.itemList.forEach((items) => {
              if (item.docType == items.docType) {
                item.docTypeName = items.docTypeName;
              }
            });
          });
          res.pageInfo.list.forEach((item) => {
            if (item.type == "card_repay") {
              item.docTypeName = "还款";
            }
            if (item.type == "card_repay") {
              if (item.orderType == "course") {
                item.docTypeName = "疗程" + item.docTypeName;
              }
              if (item.orderType == "recharge") {
                item.docTypeName = "充值" + item.docTypeName;
              }
            }
            if (item.docType == "refund_cash_room") {
              if (item.accountType == "refund_cash_unaudit_room") {
                item.docTypeName = "房间退反审核";
              }
              if (item.accountType == "refund_cash_audit_room") {
                item.docTypeName = "房间消费退";
              }
            }
            if (item.docType == "recharge_Transition") {
              if (item.accountType == "recharge_Transition_out") {
                item.docTypeName = "充值卡内调转出";
              }
              if (item.accountType == "recharge_Transition_out_cancel") {
                item.docTypeName = "充值内调作废";
              }
              if (item.accountType == "recharge_Transition_in") {
                item.docTypeName = "充值卡内调转入";
              }
              if (item.accountType == "recharge_Transition_in_cancel") {
                item.docTypeName = "充值内调作废";
              }
              if (item.accountType == "recharge_Transition_out_cancel") {
                item.docTypeName = "充值转出反审核";
              }
            }

            if (item.accountType == "recharge_in") {
              item.docTypeName = "转卡充值卡包转入";
            }
            if (item.accountType == "recharge_out") {
              item.docTypeName = "转卡充值卡包转出";
            }
            if (item.accountType == "recharge_in_cancel") {
              item.docTypeName = "转卡充值卡包转入";
            }
            if (item.accountType == "recharge_out_cancel") {
              item.docTypeName = "转卡充值卡包转出";
            }
            if (item.accountType == "project_in") {
              item.docTypeName = "转卡疗程账户转出";
            }
            if (item.accountType == "project_out") {
              item.docTypeName = "转卡疗程账户转入";
            }
            if (item.accountType == "project_in_cancel") {
              item.docTypeName = "转卡疗程账户转出";
            }
            if (item.accountType == "project_out_cancel") {
              item.docTypeName = "转卡疗程账户转入";
            }
            if (item.type == "turn_card_use") {
              if (item.orderType == "project_in ") {
                item.docTypeName = "转卡转入";
              }
            }
          });
          this.list.forEach((item)=>{
             item.tradeMoney=item.cashMoney+item.cardMoney
          })
          this.list = res.pageInfo.list;

          this.total = res.pageInfo.total;
        } else {
          this.$alert(res.message, "查询会员疗程", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
  },
};
</script>

<style>
</style>
