<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 class="col-3">
          <q-select class="q-pb-lg q-pr-lg" filled stack-label option-value="Id" option-label="Name"
            v-model="msg.AuditState" ref="AuditState" :options="AuditStateList" 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 />
        </template>
        <template v-slot:body-cell-SupplierName="props">
          <q-td>
            <div>{{props.row.SupplierName}}</div>
            <div>
              <a :href="props.row.SupplierContract" target="_blank" style="color:#2961FE;text-decoration:none;"
                v-if="props.row.SupplierContract&&isHaveViewContractAction">
                查看合同
              </a>
            </div>
          </q-td>
        </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">
            <!--部门主管审核-->
            <template v-if="AuditType==1">
              <q-btn v-if="props.row.SaleState==2&&props.row.DirectorStatus==0" flat size="xs" icon="edit"
                color="accent" style="font-weight:400" label="审核" @click="AuditStudy(props.row)" />
            </template>
            <!--部门负责人审核-->
            <template v-if="AuditType==2">
              <q-btn v-if="props.row.SaleState==2&&props.row.DirectorStatus==1&&props.row.ManagerStatus==0" flat
                size="xs" icon="edit" color="accent" style="font-weight:400" label="审核"
                @click="AuditStudy(props.row)" />
            </template>
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" label="详情"
              @click="getviewInfo(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>
      <studyproaudit-form v-if="isShowStudyAudit" :Id="studyObj.Id" @close="closeStudyForm" @success="refreshPage()">
      </studyproaudit-form>
      <studyproauditinfo-form v-if="isShowInfo" :Id="studyObj.Id" @close="closeStudyInfo"></studyproauditinfo-form>
    </div>
  </div>
</template>

<script>
  import {
    queryStudyAbroadAuditPage
  } from '../../api/studyabroad/index'
  import studyproauditForm from '../../components/studyAbroad/studyproaudit-form'
  import studyproauditinfoForm from '../../components/studyAbroad/studyproauditinfo-form'
  import {
    mapState
  } from "vuex";

  export default {
    meta: {
      title: "留学产品审核"
    },
    components: {
      studyproauditForm,
      studyproauditinfoForm
    },
    data() {
      return {
        msg: {
          pageIndex: 1,
          pageSize: 10,
          rowsPerPage: 10,
          Name: "",
          IsQPrice: 1,
          Type: "", //项目类型
          AuditState: 1, //审核状态(1-待审核,2-已审核)
        },
        dataList: [],
        loading: true,
        columns: [{
            name: 'Name',
            label: '项目名称',
            field: 'Name',
            align: 'left'
          },
          {
            name: 'Type',
            label: '项目类型',
            field: 'Type',
            align: 'left'
          },
          {
            name: 'SupplierName',
            label: '供应商',
            field: 'SupplierName',
            align: 'left'
          },
           {
            name: 'SchoolName',
            label: '所属校区',
            field: 'SchoolName',
            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', 'SupplierName',
        ], //可见列
        PageCount: 0,
        isShowStudyAudit: false, //是否显示留学就业审核弹窗
        isShowInfo: false, //是否显示详情
        studyObj: {}, //留学就业申请对象
        AuditType: 1, //1-部门主管审核,2-部门负责人审核
      }
    },
    computed: mapState({
      //是否有查看合同权限
      isHaveViewContractAction(state) {
        if (state.user.userInfo && state.user.userInfo.ActionMenuList && state.user.userInfo.ActionMenuList.length >
          0) {
          let action = state.user.userInfo.ActionMenuList.find(x => {
            if (x.FunctionCode == "View_Supplier_Contract") {
              return x;
            }
          });
          return action && action.FunctionCode;
        }
        return false;
      },
      //是否有查看供应商权限
      isHaveViewSupplierAction(state) {
        if (state.user.userInfo && state.user.userInfo.ActionMenuList && state.user.userInfo.ActionMenuList.length >
          0) {
          let action = state.user.userInfo.ActionMenuList.find(x => {
            if (x.FunctionCode == "View_Supplier") {
              return x;
            }
          });
          return action && action.FunctionCode;
        }
        return false;
      }
    }),
    mounted() {
      this.getList();
    },
    created() {
      let userInfo = this.getLocalStorage();
      let StudyAbroadObj = userInfo.StudyAbroadObj;
      // if (StudyAbroadObj && StudyAbroadObj.length > 0) {
      //   StudyAbroadObj.forEach(x => {
      //     if (x.Id === userInfo.Id) {
      //       this.AuditType = x.AuditType
      //     }
      //   })
      // }
      if (!this.isHaveViewSupplierAction) {
        this.visibleColumns.splice(this.visibleColumns.length - 1, 1);
      }
    },
    methods: {
      //重新查询
      resetSearch() {
        this.msg.pageIndex = 1;
        this.getList();
      },
      //获取留学分页列表
      getList() {
        this.loading = true;
        queryStudyAbroadAuditPage(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.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>
