<style>
  li {
    list-style-type: none;
  }

  .courseList ul {
    padding: 0px;
  }

  .courseList li {
    background: rgba(221, 222, 224, 0.2);
    border-radius: 4px;
    margin-top: 15px;
  }

  .courseList li .dline {
    display: table;
    width: 100%;
    display: flex;
    flex-direction: row;
  }

  .courseList li .d1,
  .courseList li .d2,
  .courseList li .d3,
  .courseList li .d4,
  .courseList li .d5 {
    width: 18%;
    padding: 20px 20px 10px;
  }

  .courseList li .d7 {
    flex: 1;
    width: 1px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
  }

  .courseList li .d1 .di-title {
    font-size: 16px;
    color: #111111;
  }

  .courseList li .d1 .di-c {
    font-size: 14px;
    display: flex;
    line-height: 28px;
    color: #111111;
  }

  .courseList li .d6 {
    padding: 10px 20px;
    width: 100%;
    height: inherit;
    position: relative;
    border-top: 1px solid #dddee0;
  }

  .courseList li .d6 .progress {
    width: 100%;
    height: 5px;
    position: absolute;
    left: 0;
    bottom: 0;
  }

  .courseList li .d2 div {
    margin: 2px 0;
    font-size: 14px;
    color: #111111;
  }

  .courseList li .d2-n {
    font-size: 12px;
    color: #999999;
    margin-right: 20px;
  }

  .courseList li .d3 .d3-s {
    color: var(--q-color-negative);
    font-weight: bold;
  }

  .courseList li .d3 div {
    margin: 2px 0;
    font-size: 14px;
  }

  .courseList li .d4 div {
    font-size: 14px;
    color: #111111;
    margin: 2px 0;
  }

  .courseList li .d5 div {
    font-size: 14px;
    color: #111111;
    margin: 2px 0;
  }

  .courseList .myCourseNName {
    width: 25px;
    height: 25px;
    border-radius: 50%;
    color: #fff !important;
    text-align: center;
    line-height: 25px;
    background-color: #004d40;
  }

</style>
<template>
  <div class="page-body courseList">
    <div class="page-search row items-center">
      <div class="col row wrap q-mr-lg q-col-gutter-md">
        <div class="col-3">
          <q-input @input="resetSearch" clearable standout="bg-primary text-white" v-model="msg.CourseName" label="课程名称"
            @clear="resetSearch" maxlength="20" />
        </div>
      </div>
    </div>
    <div class="page-content">
      <q-table :pagination="msg" :loading="loading" no-data-label="暂无相关数据" flat class="sticky-tow-column-table"
        separator="none" :data="data" :columns="columns" row-key="name">
        <template v-slot:top="props">
          <div class="col-2 q-table__title">课程报价表</div>
          <q-space />
          <div class="page-option">
            <q-btn color="accent" size="sm" class="q-mr-md" icon="add" label="创建报价单" @click="createQuotation" />
          </div>
        </template>
        <template v-slot:body="props">
          <q-tr :props="props">
            <q-td auto-width>
              <q-btn size="sm" color="accent" round dense @click="props.row.expand = !props.row.expand"
                :icon="props.row.expand ? 'remove' : 'add'" />
            </q-td>
            <template v-for="col in props.cols">
              <q-td v-if="col.name == 'CoverImg'">
                <q-img :src="col.value" spinner-color="white" style="height: 54px; max-width: 100px"
                  class="rounded-borders">
                </q-img>
              </q-td>
              <q-td v-else-if="col.name == 'PreferentialList'" style="padding-right:0px">
                <div v-for="x in col.value">
                  <div class="border-bottom" v-if="x.PriceDiscountType == 1">
                    买{{ x.BuyNum }}送{{ x.SendNum }}
                  </div>
                  <div class="border-bottom" v-if="x.PriceDiscountType == 2">
                    单人报名享{{ 100 - x.PriceMoney }}折优惠
                  </div>
                  <div class="border-bottom" v-if="x.PriceDiscountType == 3">
                    双人报名享{{ 100 - x.PriceMoney }}折优惠
                  </div>
                  <div class="border-bottom" v-if="x.PriceDiscountType == 4">
                    续费享{{ 100 - x.PriceMoney }}折优惠
                  </div>
                  <div class="remark-font" v-if="x.PriceDiscountType == 0">
                    暂无优惠政策
                  </div>
                </div>
                <div v-if="!col.value || col.value.length == 0">
                  <div class="remark-font">暂无优惠政策</div>
                </div>
              </q-td>
              <q-td v-else-if="col.name == 'PreferentialListSellCommission'" style="padding-right:0px;padding-left:0px">
                <div v-for="x in col.value">
                  <div class="border-bottom" style="padding-left: 16px;padding-right: 16px"
                    :class="{'text-red':x.SaleCommissionType==1}" v-if="x.PriceDiscountType!=0">
                    {{x.SaleCommissionType==1?'￥':''}}{{x.SaleCommissionMoney}}{{x.SaleCommissionType==0?'%':''}}</div>
                  <div v-if="x.PriceDiscountType == 0">
                    <div class="remark-font">暂无佣金信息</div>
                  </div>
                </div>
                <div v-if="!col.value || col.value.length==0">
                  <div class="remark-font">暂无佣金信息</div>
                </div>
              </q-td>
              <q-td v-else-if="col.name == 'PreferentialListB2BCommission'" style="padding-left:0px">
                <div v-for="x in col.value">
                  <div class="border-bottom" style="padding-left: 16px" :class="{'text-red':x.B2BCommissionType==1}"
                    v-if="x.PriceDiscountType!=0">
                    {{x.B2BCommissionType==1?'￥':''}}{{x.B2BCommissionMoney}}{{x.B2BCommissionType==0?'%':''}}</div>

                  <div v-if="x.PriceDiscountType == 0">
                    <div class="remark-font">暂无佣金信息</div>
                  </div>
                </div>
                <div v-if="!col.value || col.value.length==0">
                  <div class="remark-font">暂无佣金信息</div>
                </div>
              </q-td>
              <q-td v-else-if="col.name == 'TeacherList'">
                <div v-for="x in col.value">
                  <q-chip>
                    <q-avatar color="green-1" text-color="green">
                      <img :src="x.TeacherHead" v-if="x.TeacherHead" />
                      <span>{{ x.TeacherName.substring(0, 1) }}</span>
                    </q-avatar>
                    {{ x.TeacherName }}
                  </q-chip>
                </div>
              </q-td>
              <q-td v-else-if="col.name=='CourseIntro'">
                <q-btn flat color="primary" label="查看详情" @click="showContentDialog(col.value)" />
              </q-td>
              <q-td v-else-if="col.name != 'CourseFeature'" :key="col.name" :props="props">
                {{ col.value }}
              </q-td>
            </template>
          </q-tr>
          <q-tr v-show="props.row.expand" :props="props">
            <q-td colspan="100%" class="bg-grey-2">
              <div class="flex row items-start">
                <q-badge color="negative" class="q-mr-md">
                  课程特色
                </q-badge>
                <div v-html="props.row.CourseFeature" class="text-left col text-negative"></div>
              </div>
            </q-td>
          </q-tr>
        </template>
        <template v-slot:bottom>
          <q-pagination class="full-width justify-end" v-model="msg.pageIndex" color="primary" :max="pageCount"
            :input="true" @input="changePage" />
        </template>
      </q-table>
    </div>
    <q-dialog v-model="carousel">
      <q-card style="width: 600px;max-height:70vh;" class="q-px-sm q-pb-md scroll">
        <q-card-section>
          <div class="text-h6">课程详情</div>
        </q-card-section>
        <q-card-section>
          <div v-html="showContent"></div>
        </q-card-section>
      </q-card>
    </q-dialog>
    <q-dialog v-model="showForm" persistent>
      <quotation-form :obj="null" @save="showForm=false"></quotation-form>
    </q-dialog>
  </div>
</template>
<script>
  import {
    queryCoursePage
  } from "../../api/course/index";
  import quotationForm from '../../components/sale/quotation-form'
  export default {
    meta: {
      title: "课程预览"
    },
    components: {
      quotationForm
    },
    data() {
      return {
        currentUrl: "",
        data: [],
        loading: true,
        carousel: false,
        showContent: '',
        showForm: false,
        columns: [{
            name: "CourseFeature",
            label: "课程特色",
            field: "CourseFeature",
            align: "left"
          },
          {
            name: "CoverImg",
            label: "课程封面",
            field: "CoverImg",
            align: "left"
          },
          {
            name: "CourseName",
            required: true,
            label: "课程名称",
            align: "left",
            field: row => row.CourseName
          },
          {
            name: "CateName",
            required: true,
            label: "系列",
            align: "left",
            field: row => row.CateName
          },
          {
            name: "OriginalPrice",
            required: true,
            label: "原价",
            align: "left",
            field: row => row.OriginalPrice.toFixed(2)
          },
          {
            name: "SellPrice",
            required: true,
            label: "售价",
            align: "left",
            field: row => row.SellPrice.toFixed(2)
          },
          {
            name: "PreferentialList",
            required: true,
            label: "优惠政策",
            align: "left",
            field: row => row.PreferentialList
          },
          {
            name: "PreferentialListSellCommission",
            required: true,
            label: "销售佣金",
            align: "left",
            field: row => row.PreferentialList
          },
          {
            name: "PreferentialListB2BCommission",
            required: true,
            label: "同行佣金",
            align: "left",
            field: row => row.PreferentialList
          },
          {
            name: "TeacherList",
            label: "教师团队",
            field: row => row.TeacherList,
            align: "left"
          },
          {
            name: "ClassHours",
            label: "课时长度",
            field: "ClassHours",
            align: "left",
            format: (val, row) => `${val}课时`
          },
          {
            name: "CourseIntro",
            label: "课程详情",
            field: "CourseIntro",
            align: "left"
          },
          {
            name: "UpdateTimeStr",
            label: "更新时间",
            field: "UpdateTimeStr",
            align: "left"
          }
        ],
        msg: {
          pageIndex: 1,
          pageSize: 12,
          rowsPerPage: 12,
          CourseName: "",
          QCateIds: "",
          Status: "0",
          IsQPrice: 1, //是否查询优惠价格设置
          IsQTeacher: 1 //是否查询课程讲师
        },
        pageCount: 0
      };
    },
    mounted() {
      this.currentUrl = this.$route.path;
      this.getcourselist();
    },
    methods: {
      createQuotation() {
        this.showForm = true;
      },
      showContentDialog(content) {
        this.showContent = content;
        this.carousel = true
      },
      //重新查询
      resetSearch() {
        this.msg.pageIndex = 1;
        this.getcourselist();
      },
      //翻页
      changePage(val) {
        this.msg.pageIndex = val;
        this.getcourselist();
      },
      //获取菜单分页列表
      getcourselist() {
        this.loading = true;
        queryCoursePage(this.msg)
          .then(res => {
            this.loading = false;
            res.Data.PageData.forEach(x => {
              x.expand = false;
              x.CourseFeature = x.CourseFeature.replace(
                new RegExp("\n", "gm"),
                "<br/>"
              );
            });
            this.data = res.Data.PageData;
            this.pageCount = res.Data.PageCount;
          })
          .catch(() => {
            this.loading = false;
          });
      }
    }
  };

</script>
<style lang="sass">
  @import url('~assets/css/table.sass')

</style>
