<template>
  <div class="page-body">
    <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.Name" label="项目名称"
            @clear="resetSearch" maxlength="20" />
        </div>
        <div class="col-3">
          <q-select class="q-pb-lg q-pr-lg" filled stack-label clearable option-value="Id" option-label="Name"
            v-model="msg.Type" ref="Type" :options="studyAbroadList" label="类型" :dense="false" emit-value map-options
            @input="resetSearch">
          </q-select>
        </div>
      </div>
    </div>
    <div class="page-content">
      <q-table :pagination="msg" :loading="loading" no-data-label="暂无相关数据" flat
        class="sticky-column-table sticky-right-column-table" separator="none" :data="dataList" :columns="columns"
        row-key="name" :visible-columns="visibleColumns">
        <template v-slot:top>
          <div class="col-2 q-table__title">留学就业产品</div>
          <q-space />
          <div class="page-option">
            <q-btn color="accent" style="display:none;" size="sm" class="q-mr-md" icon="add" label="创建报价单" @click="createQuotation" />
          </div>
        </template>
        <template v-slot:body-cell-Type="props">
          <q-td>
            {{props.row.Type==1?"留学":"就业"}}
          </q-td>
        </template>
        <template v-slot:body-cell-B2CRatio="props">
          <q-td>
            {{props.row.B2CRatio}}%
          </q-td>
        </template>
        <template v-slot:body-cell-B2CReNewRatio="props">
          <q-td>
            {{props.row.B2CReNewRatio}}%
          </q-td>
        </template>
        <template v-slot:body-cell-B2BRebateRatio="props">
          <q-td>
            {{props.row.B2BRebateRatio}}{{props.row.CommissionReType==1?'%':''}}
          </q-td>
        </template>
        <template v-slot:body-cell-B2BReNewRatio="props">
          <q-td>
            {{props.row.B2BReNewRatio}}{{props.row.CommissionReType==1?'%':''}}
          </q-td>
        </template>
        <template v-slot:body-cell-SchoolRebateRatio="props">
          <q-td>
            {{props.row.SchoolRebateRatio}}{{props.row.CommissionReType==1?'%':''}}
          </q-td>
        </template>
        <template v-slot:body-cell-SchoolReNewRatio="props">
          <q-td>
            {{props.row.SchoolReNewRatio}}{{props.row.CommissionReType==1?'%':''}}
          </q-td>
        </template>
        <template v-slot:body-cell-TransIntroductceRatio="props">
          <q-td>
            {{props.row.TransIntroductceRatio}}{{props.row.CommissionReType==1?'%':''}}
          </q-td>
        </template>
        <template v-slot:body-cell-TransIntroductceReNewRatio="props">
          <q-td>
            {{props.row.TransIntroductceReNewRatio}}{{props.row.CommissionReType==1?'%':''}}
          </q-td>
        </template>
        <template v-slot:body-cell-InnerRecommendRatio="props">
          <q-td>
            {{props.row.InnerRecommendRatio}}{{props.row.CommissionReType==1?'%':''}}
          </q-td>
        </template>
        <template v-slot:body-cell-InnerRecommendReNewRatio="props">
          <q-td>
            {{props.row.InnerRecommendReNewRatio}}{{props.row.CommissionReType==1?'%':''}}
          </q-td>
        </template>
        <template v-slot:body-cell-B2CRbRatio="props">
          <q-td>
            {{props.row.B2CRbRatio}}{{props.row.CommissionReType==1?'%':''}}
          </q-td>
        </template>
        <template v-slot:body-cell-B2CRNRatio="props">
          <q-td>
            {{props.row.B2CRNRatio}}{{props.row.CommissionReType==1?'%':''}}
          </q-td>
        </template>
        <template v-slot:body-cell-PreferentialList="props">
          <q-td :props="props" style="padding-right:0px">
            <div v-for="(x,xIndex) in props.value" :key="xIndex">
              <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.PriceType==0">
                  {{x.PriceMoney}}%
                </template>
                <template v-else>
                  {{x.PriceMoney}} 元
                </template>
              </div>
              <div class="border-bottom" v-if="x.PriceDiscountType == 3">
                双人报名享优惠<template v-if="x.PriceType==0">
                  {{x.PriceMoney }}%
                </template>
                <template v-else>
                  {{x.PriceMoney}} 元
                </template>
              </div>
              <div class="border-bottom" v-if="x.PriceDiscountType == 4">
                续费优惠<template v-if="x.PriceType==0">
                  {{x.PriceMoney}}%
                </template>
                <template v-else>
                  {{x.PriceMoney}} 元
                </template>
              </div>
              <div class="remark-font" v-if="x.PriceDiscountType == 0">
                暂无优惠政策
              </div>
            </div>
            <div v-if="!props.value || props.value.length == 0">
              <div class="remark-font">暂无优惠政策</div>
            </div>
          </q-td>
        </template>
        <template v-slot:body-cell-PreferentialListSellCommission="props">
          <q-td :props="props" style="padding-right:0px;padding-left:0px">
            <div v-for="(x,xIndex) in props.value" :key="xIndex+10000">
              <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="!props.value || props.value.length == 0">
              <div class="remark-font">暂无佣金信息</div>
            </div>
          </q-td>
        </template>
        <template v-slot:body-cell-PreferentialListB2BCommission="props">
          <q-td :props="props" style="padding-left:0px">
            <div v-for="(x,xIndex) in props.value" :key="xIndex+20000">
              <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="!props.value || props.value.length == 0">
              <div class="remark-font">暂无佣金信息</div>
            </div>
          </q-td>
        </template>
        <template v-slot:body-cell-Id="props">
          <q-td :props="props">
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" label="立即下单"
              @click="showOrderForm(props.row)" />
          </q-td>
        </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>
      <q-dialog v-model="showForm" persistent>
        <quotationstudy-form :obj="null" @save="showForm=false"></quotationstudy-form>
      </q-dialog>
      <studyorderForm v-if="isShowOrderForm" :save-obj="studyObj" :orderType="2" :modityOrderType="1"
        @close="cloStudyform" @save="refreshPage()"></studyorderForm>
    </div>
  </div>
</template>

<script>
  import {
    queryStudyAbroadPage
  } from '../../api/studyabroad/index'
  import quotationstudyForm from '../../components/sale/quotationstudy-form'
  import studyorderForm from '../../components/sale/studyOrder-form'
  import {
    mapState
  } from "vuex";

  export default {
    meta: {
      title: "留学就业产品"
    },
    components: {
      quotationstudyForm,
      studyorderForm
    },
    data() {
      return {
        msg: {
          pageIndex: 1,
          pageSize: 10,
          rowsPerPage: 10,
          Name: "",
          IsQPrice: 1,
          Type: "", //项目类型
          SaleState: 3, //已上架
        },
        dataList: [],
        loading: true,
        columns: [{
            name: 'Name',
            label: '项目名称',
            field: 'Name',
            align: 'left'
          },
          {
            name: 'ProductTypeName',
            label: '类型',
            field: 'ProductTypeName',
            align: 'left'
          },
          {
            name: 'StudyCountryName',
            label: '留学国家',
            field: 'StudyCountryName',
            align: 'left'
          },
          {
            name: 'Type',
            label: '项目类型',
            field: 'Type',
            align: 'left'
          },
          {
            name: 'SellPrice',
            label: '实际卖价',
            field: 'SellPrice',
            align: 'left',
            field: row => row.SellPrice.toFixed(2)
          },
          {
            name: "B2CRatio",
            label: "直客优惠",
            align: "left",
            field: (row) => row.B2CRatio
          },
          {
            name: "B2CReNewRatio",
            label: "直客优惠续费",
            align: "left",
            field: (row) => row.B2CReNewRatio
          },
          {
            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: 'Remark',
            label: '备注',
            field: 'Remark',
            align: 'left'
          },
          {
            name: 'SaleStateName',
            label: '销售状态',
            field: 'SaleStateName',
            align: 'left'
          },
          // {
          //   name: 'Id',
          //   label: '操作',
          //   field: 'Id'
          // }
        ],
        //项目类型列表
        studyAbroadList: [{
            Id: 1,
            Name: "留学"
          },
          {
            Id: 2,
            Name: "就业"
          },
        ],
        //表格可见列
        visibleColumns: [], //可见列
        PageCount: 0,
        showForm: false, //是否显示报价单弹窗
        isShowOrderForm: false, //是否显示订单弹窗
        //留学就业对象
        studyObj: {
          SourceId: 0, //留学就业产品编号
          Unit_Price: 0, //留学就业价格
        },
      }
    },
    mounted() {
      this.getList();
    },
    created() {
      if (this.$route.query.Name) {
        this.msg.Name = this.$route.query.Name;
      }
      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_AbroadPrice") {
            isShowPrice = true;
          }
        });
      }
      if(isShowPrice){
        this.visibleColumns = ['Name', 'ProductTypeName', 'StudyCountryName', 'Type', 'SellPrice', 'B2CRatio', 'B2CReNewRatio',
          'B2BRebateRatio', 'B2BReNewRatio', 'SchoolRebateRatio', 'SchoolReNewRatio', 'TransIntroductceRatio', 'TransIntroductceReNewRatio',
          'InnerRecommendRatio', 'InnerRecommendReNewRatio', "B2CRbRatio","B2CRNRatio","SaleStateName"]
      }else{
        this.visibleColumns = ['Name', 'ProductTypeName', 'StudyCountryName', 'Type', 'SaleStateName']
      }
    },
    methods: {
      cloStudyform() {
        this.isShowOrderForm = false;
      },
      //显示下单弹窗
      showOrderForm(item) {
        this.isShowOrderForm = true;
        this.studyObj.Unit_Price = item.SellPrice;
        this.studyObj.SourceId = item.Id;
      },
      //显示报价单弹窗
      createQuotation() {
        this.showForm = true;
      },
      //重新查询
      resetSearch() {
        this.msg.pageIndex = 1;
        this.getList();
      },
      //获取留学分页列表
      getList() {
        this.loading = true;
        queryStudyAbroadPage(this.msg).then(res => {
            this.loading = false;
            this.dataList = res.Data.PageData;
            this.PageCount = res.Data.PageCount;
          })
          .catch(() => {
            this.loading = false;
          });
      },
      changePage(val) {
        this.msg.pageIndex = val;
        this.getList();
      },
      //刷新页面
      refreshPage() {
        this.isShowOrderForm = false;
        this.studyObj.SourceId = 0;
        this.studyObj.Unit_Price = 0;
        this.getList();
      },
    }
  }
</script>
<style scoped>
  .border-bottom {
    border-bottom: 1px dashed #EEE;
    padding-bottom: 5px;
    margin-bottom: 5px;
  }
</style>
<style lang="sass">
  @import url('~assets/css/table.sass')
</style>