<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">
                  {{ 100 - 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">
                  {{ 100 - 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">
                  {{ 100 - 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>

      <studyorder-form v-if="isShowOrderForm" :saveObj="studyObj" @save="refreshPage()"></studyorder-form>

    </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'
          }
        ],
        //审核类型
        AuditStateList: [{
            Id: 1,
            Name: "待审核"
          },
          {
            Id: 2,
            Name: "已审核"
          },
        ],
        //项目类型列表
        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: {}, //留学就业对象
      }
    },
    mounted() {
      this.getList();
    },
    created() {

    },
    methods: {
      //显示下单弹窗
      showOrderForm(item) {
        this.isShowOrderForm = true;
        this.studyObj = item;
      },
      //显示报价单弹窗
      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();
      },
      //关闭弹窗
      closeStudyForm() {
        this.isShowStudyAudit = false;
      },
      closeStudyInfo() {
        this.isShowInfo = false;
      },
      //留学就业审核
      AuditStudy(obj) {
        this.studyObj = obj;
        this.isShowStudyAudit = true;
      },
      //刷新页面
      refreshPage() {
        this.showForm = false;
        this.isShowOrderForm = false;
        this.studyObj = {};
        this.getList();
      },
      //审核详情
      getviewInfo(obj) {
        this.studyObj = obj;
        this.isShowInfo = true;
      }
    }
  }

</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>
