<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="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-cell-Type="props">
          <q-td>
            {{props.row.Type==1?"留学":"就业"}}
          </q-td>
        </template>
        <template v-slot:body-cell-PreferentialList="props">
          <q-td :props="props" style="padding-right:0px">
            <div v-for="x in props.value">
              <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 in props.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="!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 in props.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="!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: 'Type',
            label: '项目类型',
            field: 'Type',
            align: 'left'
          },
          {
            name: 'SuggestPrice',
            label: '建议卖价',
            field: 'SuggestPrice',
            align: 'left',
            field: row => row.SuggestPrice.toFixed(2)
          },
          {
            name: 'SellPrice',
            label: '实际卖价',
            field: 'SellPrice',
            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: '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: [
          'Name', 'Type', 'SuggestPrice', 'SellPrice', "PreferentialList", "PreferentialListSellCommission",
          "PreferentialListB2BCommission",
          "EducationCommission", 'SaleStateName', 'Id',
        ], //可见列
        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;
      }
    },
    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>
