<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-select @input="resetSearch" standout="bg-primary text-white" v-model="msg.CourseSubject"
            :options="CourseSubjectList" option-label="SubjectName" option-value="Id" emit-value map-options label="所属科目"
            clearable />
        </div>
        <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" :visible-columns="visibleColumns" row-key="name">
        <template v-slot:top>
          <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'" :key="col.name">
                <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" :key="col.name">
                <div v-for="(x,index) in col.value" :key="index">
                  <div class="border-bottom" v-if="x.PriceDiscountType == 1">
                    买{{ x.BuyNum }}送{{ x.SendNum }}
                  </div>
                  <div class="border-bottom" v-if="x.PriceDiscountType == 2">
                    <template v-if="x.PriceMoney>0">
                      单人报名优惠{{x.PriceMoney}}%
                    </template>
                    <template v-else>
                      单人报名无优惠
                    </template>
                  </div>
                  <div class="border-bottom" v-if="x.PriceDiscountType == 3">
                    <template v-if="x.PriceMoney>0">
                      双人报名优惠{{x.PriceMoney}}%
                    </template>
                    <template v-else>
                      双人报名无优惠
                    </template>
                  </div>
                  <div class="border-bottom" v-if="x.PriceDiscountType == 4">
                    <template v-if="x.PriceMoney>0">
                      续费享优惠{{x.PriceMoney}}%
                    </template>
                    <template v-else>
                      续费无优惠
                    </template>
                  </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" :key="col.name">
                <div v-for="(x,index) in col.value" :key="index">
                  <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" :key="col.name">
                <div v-for="(x,index) in col.value" :key="index">
                  <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 == 'B2CRatio'" style="padding-left:0px" :key="col.name">
                {{col.value}}%
              </q-td>
              <q-td v-else-if="col.name == 'B2CReNewRatio' " style="padding-left:0px" :key="col.name">
                {{col.value}}%
              </q-td>
               <q-td v-else-if="col.name == 'CommissionReType' " style="padding-left:0px" :key="col.name">
                <span v-if="col.value==1">比例返佣</span>
                <span v-if="col.value==2">固定金额</span>
              </q-td>
              <q-td v-else-if="col.name=='B2BRebateRatio'" :key="col.name">
                <span>{{col.value}}%</span>
              </q-td>
              <q-td v-else-if="col.name=='B2BReNewRatio'" :key="col.name">
                <span>{{col.value}}%</span>
              </q-td>
              <q-td v-else-if="col.name=='SchoolRebateRatio'" :key="col.name">
                <span>{{col.value}}%</span>
              </q-td>
              <q-td v-else-if="col.name=='SchoolReNewRatio'" :key="col.name">
                <span>{{col.value}}%</span>
              </q-td>
              <q-td v-else-if="col.name=='TransIntroductceRatio'" :key="col.name">
                <span>{{col.value}}%</span>
              </q-td>
              <q-td v-else-if="col.name=='TransIntroductceReNewRatio'" :key="col.name">
                <span>{{col.value}}%</span>
              </q-td>
              <q-td v-else-if="col.name=='InnerRecommendRatio'" :key="col.name">
                <span>{{col.value}}%</span>
              </q-td>
              <q-td v-else-if="col.name=='InnerRecommendReNewRatio'" :key="col.name">
                <span>{{col.value}}%</span>
              </q-td>
              <q-td v-else-if="col.name == 'TeacherList'" :key="col.name">
                <div v-for="(x,index) in col.value" :key="index">
                  <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'" :key="col.name">
                <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,
    getCourseSubject
  } from "../../api/course/index";
  import quotationForm from '../../components/sale/quotation-form'
  import { mapState } from "vuex";
  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: "CourseSubjectName",
            label: "所属科目",
            align: "left",
            field: (row) => row.CourseSubjectName,
          },
          {
            name: "CourseName",
            label: "课程名称",
            align: "left",
            field: row => row.CourseName
          },
          {
            name: "CateName",
            label: "系列",
            align: "left",
            field: row => row.CateName
          },
          {
            name: "OriginalPrice",
            label: "原价",
            align: "left",
            field: row => row.OriginalPrice.toFixed(2)
          },
          {
            name: "SellPrice",
            label: "售价",
            align: "left",
            field: row => row.SellPrice.toFixed(2)
          },
          // {
          //   name: "PreferentialList",
          //   required: true,
          //   label: "优惠政策",
          //   align: "left",
          //   field: row => row.PreferentialList
          // },
          {
            name: "PreferentialListSellCommission",
            label: "销售佣金",
            align: "left",
            field: row => row.PreferentialList
          },
          {
            name: "PreferentialListB2BCommission",
            label: "同行佣金",
            align: "left",
            field: row => row.PreferentialList
          },
          // 12月15号新增参数
           {
            name: "B2CRatio",
            label: "直客优惠比例",
            align: "left",
            field: (row) => row.B2CRatio
          },
          {
            name: "B2CReNewRatio",
            label: "直客优惠续费比例",
            align: "left",
            field: (row) => row.B2CReNewRatio
          },
          {
            name: "CommissionReType",
            label: "返佣类型",
            align: "left",
            field: (row) => row.CommissionReType
          },
          
          {
            name: "B2BRebateRatio",
            label: "一般同行返佣比例",
            align: "left",
            field: (row) => row.B2BRebateRatio
          },
          {
            name: "B2BReNewRatio",
            label: "一般同行续费返佣比例",
            align: "left",
            field: (row) => row.B2BReNewRatio
          },
          {
            name: "SchoolRebateRatio",
            label: "校园同行返佣比例",
            align: "left",
            field: (row) => row.SchoolRebateRatio
          },
          {
            name: "SchoolReNewRatio",
            label: "校园同行续费返佣比例",
            align: "left",
            field: (row) => row.SchoolReNewRatio
          },
          {
            name: "TransIntroductceRatio",
            label: "转介返佣比例",
            align: "left",
            field: (row) => row.TransIntroductceRatio
          },
          {
            name: "TransIntroductceReNewRatio",
            label: "转介续费返佣比例",
            align: "left",
            field: (row) => row.TransIntroductceReNewRatio
          },
          {
            name: "InnerRecommendRatio",
            label: "内推返佣比例",
            align: "left",
            field: (row) => row.InnerRecommendRatio
          },
          {
            name: "InnerRecommendReNewRatio",
            label: "内推续费返佣比例",
            align: "left",
            field: (row) => row.InnerRecommendReNewRatio
          },
          {
            name: "B2CRbRatio",
            label: "直客返佣",
            align: "left",
            field: (row) => row.B2CRbRatio
          },
          {
            name: "B2CRNRatio",
            label: "直客续费返佣",
            align: "left",
            field: (row) => row.B2CRNRatio
          },

          {
            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"
          }
        ],
        //表格可见列
        visibleColumns: [],
        msg: {
          pageIndex: 1,
          pageSize: 12,
          rowsPerPage: 12,
          CourseName: "",
          QCateIds: "",
          Status: "0",
          IsQPrice: 1, //是否查询优惠价格设置
          IsQTeacher: 1, //是否查询课程讲师
          CourseSubject: "", //所属科目
        },
        pageCount: 0,
        CourseSubjectList: [], //科目列表
      };
    },
    created(){
      var localStorageData = window.localStorage["loginUserInfo"];
      let ActionMenuList = JSON.parse(localStorageData).data.ActionMenuList;
      var isShowPrice=false;
      if (ActionMenuList && ActionMenuList.length > 0) {
        ActionMenuList.forEach((x) => {
          if (x.FunctionCode == "IsShow_CoursePrice") {
            isShowPrice = true;
          }
        });
      }
      if(isShowPrice){
        this.visibleColumns = ['CourseFeature', 'CoverImg', 'CourseSubjectName', 'CourseName', 'CateName', 'OriginalPrice', 'SellPrice', 'PreferentialListSellCommission', 
          'PreferentialListB2BCommission', 'B2CRatio', 'B2CReNewRatio' , 'CommissionReType' , 'B2BRebateRatio' , 'B2BReNewRatio' ,'SchoolRebateRatio',
          'SchoolReNewRatio','TransIntroductceRatio','TransIntroductceReNewRatio','InnerRecommendRatio','InnerRecommendReNewRatio','B2CRbRatio',
          'B2CRNRatio','TeacherList','ClassHours','CourseIntro','UpdateTimeStr']
      }else{
        this.visibleColumns = ['CourseFeature', 'CoverImg', 'CourseSubjectName', 'CourseName', 'CateName','TeacherList','ClassHours','CourseIntro','UpdateTimeStr']
      }
    },
    mounted() {
      this.queryCourseSubject()
      this.currentUrl = this.$route.path;
      this.getcourselist();
    },
    methods: {
      queryCourseSubject() {
        getCourseSubject({}).then(res => {
          if (res.Code == 1) {
            this.CourseSubjectList = res.Data;
          }
        })
      },
      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>