<!--
 * @Description: 详情弹框
 * @Author: Sugar.
 * @Date: 2023-11-24 13:55:00
 * @LastEditors: Sugar.
 * @LastEditTime: 2023-11-24 13:55:00
 * @FilePath: \cattle_webui\src\views\team\applicationMr\applicationDetails.vue
 * @Copyright: Copyright (c) 2016~2023 by Sugar., All Rights Reserved.
-->
<template>
  <el-dialog
    :title="title"
    :visible.sync="open"
    :width="detailsType?'95%':'800px'"
    append-to-body
    :close-on-click-modal="false"
    @close="cancel"
  >
    <div v-loading="initLoading" class="dialog dialog-bbb" :style="{'--widdd': detailsType?'500px':'100%'}" v-if="form">
      <div>
        <!--   基础信息   -->
        <div class="title-class" style="margin-top: 0">基础信息</div>
        <el-row>
          <el-col :span="12">
            <div class="grid-content bg-purple item-class">团队名称: <span>{{ details.teamName || ''}}</span></div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple item-class">团队类型: <span><dict-tag style="display: inline-block" :options="dict.type.team_type" :value="details.teamType"/></span></div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple item-class">预约场馆: <span>{{ details.theatreName || '' }}</span></div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple item-class">预约演出厅: <span>{{ details.auditoriumName || '' }}</span></div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple item-class">预约剧目: <span>{{ details.performName || '' }}</span></div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple item-class">票务名称: <span>{{ details.goodsName || '' }}</span></div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple item-class">座位类型: <span>{{ details.seatTypeName || '' }}</span></div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple item-class">团购单价: <span>￥{{ details.price || '' }}</span></div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple item-class">预约时间: <span>{{ details.performDate || '' }}日 {{ details.performTimeStart +'  --' || '' }} {{ details.performTimeEnd || '' }}</span></div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple item-class">报名时间: <span>{{ details.createTime || '' }}</span></div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple item-class">负责人: <span>{{ details.teamContact || '' }}</span></div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple item-class">联系电话: <span>{{ details.teamMobile || '' }}</span></div>
          </el-col>
          <el-col :span="12" v-if="details.errReason">
            <div class="grid-content bg-purple item-class">驳回原因: <span style="color: red;">{{ details.errReason || '' }}</span></div>
          </el-col>
        </el-row>


        <!--   观影人员信息   -->
        <div class="title-class">观影人员信息-{{ details.viewersList && details.viewersList.length }}人</div>
        <el-row>
          <el-col :span="24">
            <el-table size="mini" ref="tables" :data="details.viewersList" border>
              <el-table-column label="序号" align="center" type="index" width="60"></el-table-column>
              <el-table-column label="姓名" align="center" prop="name" />
              <el-table-column label="身份证号码" align="center" prop="cardId" />
            </el-table>
          </el-col>
        </el-row>
      </div>
      <div class="dialog-bbb_2" v-if="detailsType">
        <seatBox 
          ref="seatBox" 
          :seatTypeLimit="configStockNumObj"
          :queryParams="applyMap"
          @selectSeat="selectSeat"
          height="100%"
          channelType="group"
          />
      </div>
    </div>

    <span slot="footer" class="dialog-footer" v-if="!detailsType">
      <el-button type="primary" @click="cancel">关闭</el-button>
    </span>

    <span slot="footer" class="dialog-footer" v-if="detailsType">
      <el-button
        type="primary"
        @click="submitPass"
        :loading="loading"
      >
        <span v-if="loading">提交中...</span>
        <span v-else>通过</span>
      </el-button>
      <el-button type="danger" @click="setRejectOpen" >驳回</el-button>
    </span>


    <!--  审核驳回  -->
    <el-dialog
      title="审核驳回"
      :visible.sync="rejectOpen"
      width="700px"
      append-to-body
      :close-on-click-modal="false"
      @close="rejectOpen = false"
    >
      <div class="dialog">
        <el-form :model="rejectForm" ref="refRejectForm" :rules="rejectRules" label-width="90px">
          <el-form-item label="驳回原因:" prop="errReason">
            <el-input
              type="textarea"
              placeholder="请输入驳回原因"
              v-model="rejectForm.errReason"
              maxlength="300"
              show-word-limit
            >
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
      <el-button @click="rejectOpen = false">取消</el-button>
      <el-button
        type="primary"
        @click="submitForm"
        v-loading.fullscreen.lock="loading"
        element-loading-text="提交中..."
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.8)"
      >
        <span v-if="loading">提交中...</span>
        <span v-else>保存</span>
      </el-button>
    </span>
    </el-dialog>
  </el-dialog>
</template>

<script>
import { getSelectById, teamApplyAudit, querySeatList } from '@/api/team/applicationMr'
import { 
  querySeatListNew,
  querySeatList as querySeatListNew1
 } from '@/api/windowTicketSales/ticketingSales'
import { countBySeatTyp } from '@/api/ticketMr/InventoryTemplate'
import { pageList as getSeatType } from '@/api/seatTypeMr/seatTypeMr'
import seatBox from '@/components/seatBox/index.vue';
export default {
  name: "applicationDetails",
  components: {
    seatBox
  },
  props: {
    dict: {
      type: Object,
      default: () => [],
    },
  },
  data() {
    return {
      title: "编辑",
      model: "EDIT",
      open: false,
      
      initLoading: false,
      loading: false,
      passLoading: false,
      form: {
        id: undefined,
      },
      details: {},
      performerVisible: false,
      performerList: [],
      refund: false,
      // 驳回表单
      rejectOpen: false,
      rejectRules: {
        errReason: [{ required: true, message: "请输入驳回原因", trigger: ["change","blur"] }],
      },
      rejectForm: {
        status: 2
      },
      detailsType: false,


      applyId: '', // 申请单id
      applyMap: {},
      //setList: [],
      seatSelectList: [],

      merchantTheatreAuditoriumListS: [], // 演出厅
        merchantPerformTimeListS: [], // 场次
        querySeatListS: [], // 座位
        goodsPageListS: [], // 票务
        goodsPageListSAll: [], // 票务全部
        setList: [],
        seatMapList: {},
        seatMapListKey: [], // key
        seatSelectList: [],

        lockOrUnLockLoading: false,

        performId: '',// 剧目ID
        scaleNum: 30,

        width: 0,
        justifyContent: false,
        activeName: 'first',
        seatTypeList: [],
      
        configStockNumObj: {},
        countBySeatTypList:[],
        seatTypeListAll: [],
        seatLoading: false,
        seatLoadText: '获取座位中...',
    };
  },
  created() {
    this.getSeatTypeList()
  },
  methods: {
    /**
     * 打开弹框
     * @date 2023-11-22
     * @param {any} obj
     * @returns {any}
     */
    async openDialog(title, obj, type) {
      try {
        this.initLoading = true
        this.open = true;
        this.rejectOpen = false;
        this.applyId = obj.id;
        this.applyMap = obj;
        this.querySeatListS = [];
        this.setList = [];
        this.seatSelectList = [];
        this.flag = false
        this.isMousemovs = false
        if(type) {
          this.detailsType = true
          this.title = '审核'
          
        } else {
          this.detailsType = false
          this.title = '详情'
        }
        await this.countBySeatTypFun(obj.auditoriumId)
        await this.getSelectByIdApi(obj);
        this.initLoading = false
      } catch (error) {
        this.initLoading = false
      }
      
    },
    /** 获取全部座位类型 */
    getSeatTypeList() {
      getSeatType({
        pageNum: 1,
        pageSize: 999,
      })
      .then(response => {
        this.seatTypeList = response.data.rows;
      });
    },
    /** 获取剧目的座位类型  */
    async countBySeatTypFun(value) {
      try {
        if(!value) return
        let res = await countBySeatTyp({auditoriumId: value})
        this.countBySeatTypList = res.data ? res.data : []
        let obj = {}
        this.countBySeatTypList.forEach((item,index)=>{
          obj['seatNum_'+item.seatTypeId] = {
            stockTotal: item.stock,
            stockSelect: item.stock,
            stockYes: item.stock,
            stockNo: 0,
            isNoSelect: true,
          }
          if(item.seatTypeId == this.applyMap.seatTypeId){
            obj['seatNum_'+item.seatTypeId].stockYes = item.stock-this.applyMap.viewerNum
            obj['seatNum_'+item.seatTypeId].isNoSelect = false
          }
        })
        this.configStockNumObj = obj
      } catch (error) {
        console.error("error1====",error)
      }
    },
    /** 获取详情 */
    async getSelectByIdApi(row) {
      try {
        const id = row.id
        let res = await getSelectById(id)
        this.details = {}
        this.details = res.data;
        if(this.detailsType){
          let res1 = await querySeatListNew({
            auditoriumId: this.applyMap.auditoriumId,
            timeId: this.applyMap.performTimeId,
            goodsId: this.applyMap.goodsId,
            channelType: 'group'
          })
          let list1 = []
          res1.data.forEach((item,index)=>{
            list1.push({
              ...item,
              isSame: item.seatTypeId != this.applyMap.seatTypeId
            })
          })
          this.setList = list1;
          let list = []
          let list3 = []
          this.countBySeatTypList.forEach((item,index)=>{
            list3.push(item.seatTypeId)
          })
          let list4 = []
          this.seatTypeList.forEach((item,index)=>{
            if(list3.includes(item.id)) {
              list4.push({...item})
            }
          })
          this.$nextTick(() =>{
            this.$refs.seatBox.querySeatListFun(true,this.setList,list,list4)
          })
        }
      } catch (error) {
      }
      
    },
    /** 获取座位信息 */
    getSeatApi(row) {
      let map = {
        auditoriumId: this.applyMap.auditoriumId,
        seatTypeId: this.applyMap.seatTypeId,
        timeId: this.applyMap.performTimeId,
      }
      querySeatList(map).then(response => {
        this.setList = response.data;
        if(this.setList && this.setList.length > 0) {
          this.setSeatMapList(this.setList);
        }
      });
    },
    /**
     * 驳回提交
     * @date 2023-11-22
     * @returns {any}
     */
     submitForm() {
      this.$refs["refRejectForm"].validate(async (valid) => {
        if (valid) {
          try {
            this.loading = true;
            setTimeout(() => {
              this.loading = false;
            }, 3000)
            this.rejectForm.applyId = this.details.id || this.applyId;
            const { code } = await teamApplyAudit({ ...this.rejectForm });
            if (code === 200) {
              this.loading = false;
              this.rejectOpen = false;
              this.$message.success("操作成功!");
              this.$emit("getList");
              this.cancel();
            }
          } catch (error) {
            this.loading = false;
          } finally {
          }
        }
      });
    },
    // 审核通过 - 座位选择保存
    submitPass() {
      try {
      let seatList = this.seatSelectList
      if(!seatList || this.seatSelectList.length < this.details.viewersList.length ) {
        this.$message.error(`请选择 ${ this.details.viewersList.length } 座位!`);
        return
      } 
      this.passLoading = true;
        let postMap = {
          applyId: this.details.id || this.applyId,
          status: 1,
          seatList: seatList
        }
        teamApplyAudit(postMap).then((res) => {
          this.passLoading = false;
          if (res.code == 200) {
            this.$message.success("操作成功!");
            this.$emit("getList");
            this.cancel();
          }
        }).catch(()=>{
          this.passLoading = false;
        })
      } catch (error) {
        this.passLoading = false;
      } finally {
      }
    },
    /**
     * 关闭弹框
     * @date 2023-11-22
     * @returns {any}
     */
    cancel() {
      this.open = false;
    },
    /**
     * 打开驳回表单 
     * 
     */
    setRejectOpen() {
      this.rejectOpen = true
      this.$set(this.rejectForm,'errReason','')
      this.$nextTick(()=>{
        this.$refs.refRejectForm.clearValidate('errReason')
      })
    },

     /** 选择座位  */
    selectSeat(list) {
      let list1 = []
      list.forEach((item)=>{
        list1.push({
          seatId: item.id,
          seatName: item.name
        })
      })
      this.seatSelectList = list1
      console.log("已选择的====",list)
    },
  },
};
</script>

<style lang="scss" scoped>
.dialog {
  width: 100%;
  height: 70vh;
}

.dialog-bbb {
  width: 100%;
  display: flex;
  
  >div:first-child {
    width: var(--widdd);
    flex-shrink: 0;
    overflow-y: auto;
    padding: 0 0 10px 0;
    margin-right: 10px;
  }
  .dialog-bbb_2 {
    width: calc( 100% - var(--widdd) );
    height: 100%;
  }
}

.dialog {
  .upload-btn {
    width: 100px;
    height: 100px;
    background-color: #fbfdff;
    border: dashed 1px #c0ccda;
    border-radius: 5px;
    i {
      font-size: 30px;
      margin-top: 20px;
    }
    &-text {
      margin-top: -10px;
    }
  }
  .avatar {
    cursor: pointer;
  }
  .title-class{
    font-size: 16px;
    font-weight: bold;
    color: black;
    margin-bottom: 20px;
    margin-top: 20px;
  }
  .item-class{
    margin-bottom: 20px;
  }
  .seat-box-class1{
    width: 800px;
    height: auto;
    padding: 5px;
    border-radius: 10px;
    border: 1px  solid #323333;
    .disabled-class{
      background-color: #aaabad;
    }
    .select-class{
      background-color: #e85353 !important;
      color: #eceaea !important;
    }
    .seat-item-class{
      display: block;
      float: left;
      width: 60px;
      height: 60px;
      margin: 5px;
      border: 1px solid #4c4d4d;
      border-radius: 3px;
      cursor: pointer;
      position: relative;
      &:hover{
        opacity: 0.6;
      }

      .text-class{
        font-size: 12px;
        padding: 5px;
        line-height: 16px;
        margin: 0;
      }
    }
  }
}

.dialog-bbb_2 {
  
}

#moveSelected_1{
    position:absolute;
    background-color: blue;
    opacity:0.3;
    border:1px dashed #d9d9d9;
    top:0;
    left:0;
}
</style>
