<style>
  li {
    list-style-type: none;
  }

  .myoffer ul {
    padding: 0px;
  }

  .myoffer li {
    background: rgba(221, 222, 224, 0.2);
    border-radius: 4px;
    margin-top: 15px;
  }

  .myoffer li .dline {
    display: table;
    width: 100%;
    display: flex;
    flex-direction: row;
  }

  .myoffer li .d1,
  .myoffer li .d2,
  .myoffer li .d3,
  .myoffer li .d4,
  .myoffer li .d5 {
    width: 18%;
    padding: 20px 20px 10px;
  }

  .myoffer li .d7 {
    flex: 1;
    width: 1px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
  }

  .myoffer li .d1 .di-title {
    font-size: 16px;
    color: #111111;
  }

  .myoffer li .d1 .di-c {
    font-size: 14px;
    display: flex;
    line-height: 28px;
    color: #111111;
  }

  .myoffer li .d6 {
    padding: 10px 20px;
    width: 100%;
    height: inherit;
    position: relative;
    border-top: 1px solid #dddee0;
  }

  .myoffer li .d6 .progress {
    width: 100%;
    height: 5px;
    position: absolute;
    left: 0;
    bottom: 0;
  }

  .myoffer li .d2 div {
    margin: 2px 0;
    font-size: 14px;
    color: #111111;
  }

  .myoffer li .d2-n {
    font-size: 12px;
    color: #999999;
    margin-right: 20px;
  }

  .myoffer li .d3 .d3-s {
    color: var(--q-color-negative);
    font-weight: bold;
  }

  .myoffer li .d3 div {
    margin: 2px 0;
    font-size: 14px;
  }

  .myoffer li .d4 div {
    font-size: 14px;
    color: #111111;
    margin: 2px 0;
  }

  .myoffer li .d5 div {
    font-size: 14px;
    color: #111111;
    margin: 2px 0;
  }

  .myoffer .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 myoffer">
    <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-input @input="resetSearch" clearable standout="bg-primary text-white" v-model="msg.SerialNum" label="流水号"
            @clear="resetSearch" maxlength="20" />
        </div>
        <div class="col-3">
          <q-input @input="resetSearch" clearable standout="bg-primary text-white" v-model="msg.CustomerName"
            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" row-key="name">
        <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="editQuotation(null)" />
          </div>
        </template>
        <template v-slot:body-cell-OrderIdList="props">
          <q-td :props="props">
            <span title="点击查看订单" v-for="item in props.row.OrderIdList"
              style="cursor:pointer;color:blue;margin-left:5px;" @click="goOrderList(props.row,item)">{{item}}</span>
          </q-td>
        </template>
        <template v-slot:body-cell-optioned="props">
          <q-td :props="props">
            <div>
              <q-btn v-if="props.row.CustomerStatus==1||props.row.CustomerStatus==2" flat size="xs" icon="edit"
                color="accent" style="font-weight:400" label="编辑" @click="editQuotation(props.row)" />
              <q-btn-dropdown flat size="xs" color="dark" label="更多" style="margin-left:10px;">
                <q-list>
                  <q-item clickable v-close-popup @click="gotoDetails(props.row)">
                    <q-item-section>
                      <q-item-label>详情</q-item-label>
                    </q-item-section>
                  </q-item>
                  <q-item clickable v-close-popup
                    v-if="props.row.CustomerStatus==1||props.row.CustomerStatus==2||props.row.CustomerStatus==6"
                    @click="offerTransOrder(props.row)">
                    <q-item-section>
                      <q-item-label>转订单</q-item-label>
                    </q-item-section>
                  </q-item>
                  <q-item clickable v-close-popup
                    v-if="props.row.CustomerStatus==1||props.row.CustomerStatus==2||props.row.CustomerStatus==6"
                    @click="applyUpdatePrice(props.row)">
                    <q-item-section>
                      <q-item-label>申请改价</q-item-label>
                    </q-item-section>
                  </q-item>
                </q-list>
              </q-btn-dropdown>
            </div>
          </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>
    </div>
    <!-- 新增修改报价单 -->
    <q-dialog v-model="showForm" persistent>
      <quotation-form :obj="offerObj" @save="refreshPage()"></quotation-form>
    </q-dialog>
    <!-- 新增修改留学就业报价单 -->
    <q-dialog v-model="showStudyForm" persistent>
      <quotationstudy-form :obj="offerObj" @save="refreshPage()"></quotationstudy-form>
    </q-dialog>
    <!-- 报价单转订单 -->
    <q-dialog v-model="showOrderForm" persistent>
      <offertransorder-form :obj="offerObj" @save="refreshPage()"></offertransorder-form>
    </q-dialog>
    <!-- 查看报价单 -->
    <viewquotation-form v-if="isShowviewQuo" :rId="rId" :isShowCancle="0" @close="closeQuota">
    </viewquotation-form>
    <!-- 申请改价 -->
    <q-dialog v-model="isShowUpPrice" persistent>
      <q-card style="width: 500px;max-width:500px;" class="CLM-Form">
        <q-card-section>
          <div class="text-h6">申请改价</div>
        </q-card-section>
        <q-card-section class="q-pt-none scroll" style="max-height: 70vh">
          <div class="row wrap">
            <div class="col-12">
              <q-input v-model="uppriceMsg.ApplyReason" filled type="textarea" placeholder="改价原因" />
            </div>
          </div>
        </q-card-section>
        <q-separator />
        <q-card-actions align="right" class="bg-white">
          <q-btn label="取消" flat color="grey-10" style="font-weight:400 !important" @click="isShowUpPrice=false" />
          <q-btn label="保存" color="accent q-px-md" style="font-weight:400 !important" @click="saveUpprice()" />
        </q-card-actions>
      </q-card>
    </q-dialog>
  </div>
</template>
<script>
  import quotationForm from '../../components/sale/quotation-form'
  import offertransorderForm from '../../components/sale/offertransorder-form'
  //留学报价单
  import quotationstudyForm from '../../components/sale/quotationstudy-form'
  import viewquotationForm from '../../components/sale/viewquotation-form'
  import {
    queryCourseOfferPage,
    SetApplyModifyPrice
  } from '../../api/course/index'
  import {
    mapState
  } from "vuex";

  export default {
    meta: {
      title: "我的报价单"
    },
    components: {
      quotationForm,
      quotationstudyForm,
      offertransorderForm,
      viewquotationForm
    },
    data() {
      return {
        currentUrl: "",
        data: [],
        loading: true,
        msg: {
          pageIndex: 1,
          pageSize: 10,
          rowsPerPage: 10,
          Name: "",
          IsGetDetails: 1,
          CreateBy: 0,
          SerialNum: "", //流水号
          CustomerName: "", //客户名称
        },
        pageCount: 0,
        showForm: false, //是否显示报价单弹窗
        offerObj: {}, //报价单信息
        columns: [{
            name: "SerialNum",
            label: "流水号",
            field: "SerialNum",
            align: "left"
          },
          {
            name: "Name",
            label: "名称",
            field: "Name",
            align: "left"
          },
          {
            name: "OfferTypeName",
            label: "类型",
            field: "OfferTypeName",
            align: "left"
          },
          {
            name: "CustomerName",
            required: true,
            label: "客户信息",
            align: "left",
            field: row => row.CustomerName
          },
          {
            name: "CustomerTel",
            required: true,
            label: "客户电话",
            align: "left",
            field: row => row.CustomerTel
          },
          {
            name: "TotalOriginalPrice",
            required: true,
            label: "总原价",
            align: "left",
            field: row => row.TotalOriginalPrice.toFixed(2)
          },
          {
            name: "TotalPrice",
            required: true,
            label: "总价",
            align: "left",
            field: row => row.TotalPrice.toFixed(2)
          },
          {
            name: "TotalDiscountPrice",
            required: true,
            label: "总优惠",
            align: "left",
            field: row => row.TotalDiscountPrice.toFixed(2)
          },
          {
            name: "JoinNum",
            label: "报名人数",
            field: "JoinNum",
            align: "left",
            format: (val, row) => `${val}人`
          },
          {
            name: "CustomerStatusName",
            label: "状态",
            field: "CustomerStatusName",
            align: "left",
            format: (val, row) => `${val}`
          },
          {
            name: "CreateTimeStr",
            label: "报价时间",
            field: "CreateTimeStr",
            align: "left"
          },
          {
            name: "OrderIdList",
            label: "订单号",
            field: "OrderIdList",
          },
          {
            name: 'optioned',
            label: '操作',
            field: 'Id'
          }
        ],
        showOrderForm: false, //是否显示转订单表单
        commonId: 0,
        showEditPrice: false, //是否显示改价表单
        isShowviewQuo: false,
        rId: 0,
        isShowUpPrice: false,
        showStudyForm: false, //是否显示留学就业报价单
        uppriceMsg: {
          Id: 0,
          ApplyReason: ''
        }
      }
    },

    mounted() {
      this.currentUrl = this.$route.path;
      this.msg.CreateBy = this.getLocalStorage().Id;
      this.getcourseofferpage();
    },
    methods: {
      //改价
      applyUpdatePrice(item) {
        this.uppriceMsg.Id = item.Id;
        this.isShowUpPrice = true;
      },
      //提交改价原因
      saveUpprice() {
        if (this.uppriceMsg.ApplyReason == '') {
          this.$q.notify({
            type: 'negative',
            position: "top",
            message: `请填写改价原因`
          })
          return;
        }
        SetApplyModifyPrice(this.uppriceMsg).then(res => {
          this.isShowUpPrice = false;
          this.uppriceMsg.ApplyReason = '';
          this.$q.notify({
            icon: 'iconfont icon-chenggong',
            color: 'accent',
            timeout: 2000,
            message: res.Message,
            position: 'top'
          })
          this.getcourseofferpage();
        }).catch(() => {
          this.loading = false
        })
      },
      closeQuota() {
        this.isShowviewQuo = false;
      },
      //跳转到订单列表
      goOrderList(obj,item) {
        var url = "/sale/myOrder";
        if (obj.OfferType != 1) {
          url = "/sale/studyOrder";
        }
        this.$router.push({
          path: url,
          query: {
            OrderId: item
          }
        });
      },
      //报价单转订单
      offerTransOrder(item) {
        this.offerObj = item;
        this.showOrderForm = true;
      },
      //刷新页面
      refreshPage() {
        this.showForm = false;
        this.showOrderForm = false;
        this.showStudyForm = false;
        this.getcourseofferpage();
      },
      gotoDetails(item) {
        // this.rId = item.Id;
        // this.isShowviewQuo = true;
        this.OpenNewUrl("/sale/quotation", {
          Id: item.Id
        });
      },
      //显示报价单
      editQuotation(item) {
        if (item) {
          if (item.OfferType == 1) {
            this.showForm = true;
          } else {
            this.showStudyForm = true;
          }
        } else {
          this.showForm = true;
        }
        this.offerObj = item;
      },
      //重新查询
      resetSearch() {
        this.msg.pageIndex = 1;
        this.getcourseofferpage();
      },
      //翻页
      changePage(val) {
        this.msg.pageIndex = val;
        this.getcourseofferpage()
      },
      //获取报价单分页列表
      getcourseofferpage() {
        this.loading = true;
        queryCourseOfferPage(this.msg).then(res => {
          this.loading = false
          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>
