<!--
 * @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="700px"
    append-to-body
    :close-on-click-modal="false"
    @close="cancel"
  >
    <div class="dialog" v-if="form">
      <!--   基础信息   -->
      <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">观影人员信息</div>
      <el-row>
        <el-col :span="24">
          <el-table 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>

    <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="passOpenEven" style="margin-right: 20px">通过</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
      title="选择座位"
      :visible.sync="passOpen"
      width="910px"
      append-to-body
      :close-on-click-modal="false"
      @close="passOpen = false"
    >
      <!--  座位排版  -->
      <div class="dialog">
        <div class="seat-box-class clearfix" v-if="seatMapList && seatMapList.length > 0">
          <div class="seat-item-class" :class="item.isDisabled ? 'disabled-class' : item.isSelect ? 'select-class' : ''" v-for="(item, index) in seatMapList" @click.stop="seatClick(item)" :key="index">
            <p class="text-class">{{item.name ? item.name : (item.rowNo + '排' + item.columnNo + '座')}}</p>
          </div>
        </div>
      </div>
      <div style="margin-top: 5px; margin-left: 30px">已勾选：{{ seatSelectList.length }}个座位</div>
      <span slot="footer" class="dialog-footer">
      <el-button @click="passOpen = false">取消</el-button>
      <el-button
        type="primary"
        @click="submitPass"
        v-loading.fullscreen.lock="passLoading"
        element-loading-text="提交中..."
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.8)"
      >
        <span v-if="passLoading">提交中...</span>
        <span v-else>保存</span>
      </el-button>
    </span>
    </el-dialog>

  </el-dialog>
</template>

<script>
import { getSelectById, teamApplyAudit, querySeatList } from '@/api/team/applicationMr'
import { updateStatus } from '@/api/team/ticketMr'
export default {
  name: "applicationDetails",
  props: {
    dict: {
      type: Object,
      default: () => [],
    },
  },
  data() {
    return {
      title: "编辑",
      model: "EDIT",
      open: false,
      rejectOpen: false,
      passOpen: false,
      loading: false,
      passLoading: false,
      form: {
        id: undefined,
      },
      details: {},
      performerVisible: false,
      performerList: [],
      refund: false,
      rejectRules: {
        errReason: [{ required: true, message: "请输入驳回原因", trigger: ["change","blur"] }],
      },
      dataList: [],
      rejectForm: {
        status: 2
      },
      detailsType: false,
      seatMapList: [], // 座位集合
      applyId: '', // 申请单id
      applyMap: {},
      setList: [],
      seatSelectList: []
    };
  },
  methods: {
    /**
     * 打开弹框
     * @date 2023-11-22
     * @param {any} obj
     * @returns {any}
     */
    openDialog(title, obj, type) {
      this.open = true;
      this.rejectOpen = false;
      this.passOpen = false;
      this.applyId = obj.id;
      this.applyMap = obj;
      if(type) {
        this.detailsType = true
        this.title = '审核'
      } else {
        this.detailsType = false
        this.title = '详情'
      }
      this.getSelectByIdApi(obj);
    },
    /** 获取详情 */
    getSelectByIdApi(row) {
      const id = row.id
      getSelectById(id).then(response => {
        this.details = {}
        this.details = response.data;
      });
    },
    /** 获取座位信息 */
    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);
        }
      });
    },
    // 设置座位集合
    setSeatMapList(list) {
      if(list && list.length > 0) {
        list.forEach(item => {
          item.isDisabled = (item.occupyStatus != null && (item.occupyStatus == 0 || item.occupyStatus == 1) ? true : false); // 座位是否已被选择
          item.isSelect = false;
          this.seatMapList.push(item)
        })
      }
    },
    // 座位点击事件
    seatClick(row) {
      if(row.isDisabled){
        return false
      }
      if(this.seatSelectList.length >= this.details.viewersList.length ){
        if(row.isSelect) {
          let indexs = null;
          this.seatSelectList.forEach((item, index) =>{
            if(item.id == row.id){
              indexs = index;
            }
          })
          if(indexs != null) {
            row.isSelect = !row.isSelect;
            this.seatSelectList.splice(indexs, 1)
          }
        } else {
          this.$message.error("观影人数限制" + this.details.viewersList.length + "人!");
        }
        return false
      }
      row.isSelect = !row.isSelect
      this.seatSelectList = this.seatMapList.filter(item => item.isSelect);
      this.$forceUpdate()
    },
    // 审核通过
    passOpenEven() {
      this.passOpen = true;
      this.seatMapList = [];
      this.seatSelectList = [];
      this.getSeatApi();
      this.setSeatMapList()
    },
    /**
     * 保存
     * @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 {
        this.passLoading = true;
        setTimeout(() => {
          this.passLoading = false;
        }, 3000)
        let seatList = this.seatMapList.filter(item => item.isSelect);
        if(seatList && seatList.length > 0) {
          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.passOpen = false;
              this.$emit("getList");
              this.cancel();
            }
          });
        } else {
          this.$message.error("请选择座位!");
        }
      } 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')
      })
    }
  },
};
</script>

<style lang="scss" scoped>
.dialog {
  padding: 0 30px;
  max-height: 65vh;
  overflow-y: auto;
}
.dialog {
  padding: 0 30px;
  .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-class{
    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;
      }
    }
  }
}
</style>
