<template>
  <div>
    <el-collapse style="width: 100%" v-model="recColl" accordion>
      <el-collapse-item title="项目：" :name="1">
        <el-table :data="list" max-height="350" @row-dblclick="rowClick" stripe>
          <el-table-column show-overflow-tooltip min-width="120" align="left" prop="courseProjectName" label="项目名称"></el-table-column>
          <el-table-column show-overflow-tooltip min-width="75" align="center" prop="price" label="项目单价"></el-table-column>
          <el-table-column show-overflow-tooltip min-width="75" align="center" prop="courseRestCount" label="剩余次数"></el-table-column>
          <el-table-column show-overflow-tooltip min-width="75" align="center" prop="courseRestPrice" label="剩余金额"></el-table-column>
          <el-table-column show-overflow-tooltip min-width="75" align="center" prop="courseConsumeCount" label="可用次数"></el-table-column>
          <el-table-column show-overflow-tooltip min-width="75" align="center" prop="courseConsumePrice" label="可用金额"></el-table-column>
          <el-table-column show-overflow-tooltip min-width="105" align="center" prop="endTime" label="到期日期"></el-table-column>
          <el-table-column show-overflow-tooltip min-width="75" align="center" prop="storeName" label="所属门店"></el-table-column>
        </el-table>
      </el-collapse-item>
      <el-collapse-item title="不可用项目：" :name="2">
        <el-table :data="lists" max-height="350" stripe>
          <el-table-column show-overflow-tooltip min-width="120" align="left" prop="courseProjectName" label="项目名称"></el-table-column>
          <el-table-column show-overflow-tooltip min-width="75" align="center" prop="price" label="项目单价"></el-table-column>
          <el-table-column show-overflow-tooltip min-width="75" align="center" prop="courseRestCount" label="剩余次数"></el-table-column>
          <el-table-column show-overflow-tooltip min-width="75" align="center" prop="courseRestPrice" label="剩余金额"></el-table-column>
          <el-table-column show-overflow-tooltip min-width="75" align="center" prop="courseConsumeCount" label="可用次数"></el-table-column>
          <el-table-column show-overflow-tooltip min-width="75" align="center" prop="courseConsumePrice" label="可用金额"></el-table-column>
          <el-table-column show-overflow-tooltip min-width="105" align="center" prop="endTime" label="到期日期"></el-table-column>
          <el-table-column show-overflow-tooltip min-width="75" align="center" prop="storeName" label="所属门店"></el-table-column>
        </el-table>
      </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script>
import { couAccountList, couAccountListDisable } from "@/api/eashier.js";
export default {
  data() {
    return {
      recColl: 1,
      list: [], //主数组
      lists: [],
      form: {}, //主对象
    };
  },
  methods: {
    //点击选中
    rowClick(row) {
    
      if (row.courseConsumeCount > 0) {
        row.courseAccountId = row.id;
        if (row.courseConsumeCount == 1) {
          this.list.forEach((item) => {
            if (row.id == item.id) {
              item.courseRestCount = 0;
              item.courseConsumeCount = 0;
            }
          });
        }
        this.$emit("courseData", row);
      } else {
        this.$message.warning({ message: "可用次数小于1" });
      }
    },
    //组件传值
    show(form) {
     
      if (form) {
        this.form = { ...form };
        this.getData();
      } else {
        this.list = [];
      }
    },
    //获取数据
    async getData() {
      var ids = {
        memberId: this.form.id,
      };
      couAccountList(ids).then((res) => {
        if (res.code == "000000") {
          this.list = res.rows;
        } else {
          this.$alert(res.message, "查询会员疗程", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
      couAccountListDisable(ids).then((res) => {
        if (res.code == "000000") {
          this.lists = res.rows;
        } else {
          this.$alert(res.message, "查询会员疗程", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
  },
};
</script>

<style></style>
