<template>
  <div class="index" v-if="detailData">
    <div class="normal-card">
      <!--提报上传-->
      <submit-action 
                    ref="submitAction" 
                    :detailData="detailData" 
                    :editData.sync="editData" 
                    :disabled.sync="disabled"
                    v-if="tool.checkAuth($route.name,'insert')"></submit-action>
      <img src="@/assets/refresh.png" alt="" style="cursor:pointer" @click="$router.go(0)">
    </div>
    <div class="normal-card">
      <p>{{detailData.title}}</p>
      <p>时间: {{detailData.createdate}}</p>
      <p>提报要求: {{detailData.notes}}</p>
      <p v-if="detailData.attinfos && detailData.attinfos.length > 0">附件下载</p>
        <file-item :isDownLoad="true" 
                   :itemStyle="itemStyle" 
                   :fileData="detailData.attinfos">
        </file-item>
    </div>
    <!--提报明细详情-->
    <submit-item-info ref="submitDetail" 
                      :fileData="calcList(detailData.submitedit)" 
                      @submitEdit="submitEdit" 
                      v-if="tool.checkAuth($route.name,'read')">
      <pagination v-if="detailData.submitedit && $route.query.type == 'more'" :total="detailData.submitedit.length"
                  :pageSize="pageSize"
                  :currentPage="currentIndex"
                  @pageChange="pageChange"
                  slot="page">
        </pagination>
    </submit-item-info>
  </div>
</template>

<script>
import FileItem from '@/components/file-block/index'
import SubmitItemInfo from '@/SManagement/submitedit_details/components/SubmiteditItemInfo'
import SubmitAction from '@/SManagement/submitedit_details/components/SubmiteditAction'
import Pagination from '@/components/pagination/Pagination'
export default {
  name: 'index',
  data() {
    return {
      param: {
          "classname": "saletool.submitedit.submitedit",
          "method": "select_submitdetailed",
          "content": {
              "nochche":true,
              "sat_submiteditmodelid":""
          }
      },
      itemStyle: {
        itemWidth:366,
        margin: 16,
        img: {
          width:29,
          height:29
        },
        title:14,
        descript: 10
      },
      detailData:[],
      //编辑数据
      editData:[],
      currentIndex: 1,
      pageSize:6,
      disabled:this.$route.query.history != 1
    };
  },
  components: {
    FileItem,
    SubmitItemInfo,
    SubmitAction,
    Pagination
  },
  computed:{
  },
  watch:{
  },
  created() {
    this.getDetailData()
  },
  methods: {
    async getDetailData() {
      this.param.content.sat_submiteditmodelid = this.$route.query.id
      let res = await this.$api.requested(this.param)
      this.detailData = res.data
      console.log('2222',this.detailData);
      
      //删除未提报记录明细
      this.deteleNoSubmit()
      this.detailData.attinfos = this.fileType.fileList(this.detailData.attinfos)
    },
    //删除未提报的提报记录
    deteleNoSubmit() {
      this.detailData.submitedit.forEach( async element => {
        if(element.status == '未提报') {
          let param = {
              "classname": "saletool.submitedit.submitedit",
              "method": "delete_submitdetailed",
              "content": {
                  "sat_submiteditid":element.sat_submiteditid
              }
          }
          let res = await this.$api.requested(param)
          this.detailData.submitedit = this.detailData.submitedit.filter(item => item.status != '未提报')
        }
      })
    },
    submitEdit(data) {
      data.attinfos = this.fileType.fileList(data.attinfos)
      this.editData = data
      this.$refs.submitAction.isFileInfoPanlShow = true
    },
    pageChange(n) {
      this.currentIndex = n
    },
    calcList(list) {
      if(list) {
        return list.slice((this.currentIndex - 1) * this.pageSize,this.currentIndex * this.pageSize)
      }
    }
  },
};
</script>

<style scoped>
  * {
    box-sizing: border-box;
  }
  .index {
    min-height: 100%;
  }
  .index .normal-card {
    margin-bottom: 10px;
  }
  .index .normal-card:nth-child(1) {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .index .normal-card:nth-child(2) p {
    margin-bottom: 10px;
  }
  .index .normal-card:nth-child(2) p:nth-child(1) {
    font-size: 14px;
    font-weight: bold;
    color: #333333;
  }
  .index .normal-card:nth-child(2) p:nth-child(2) {
    font-size: 14px;
    font-weight: 400;
    color: #666666;

  }
  .index .normal-card:nth-child(2) p:nth-child(3) {
    font-size: 14px;
    font-weight: 400;
    color: #666666;
  }
  .index .normal-card:nth-child(2) p:nth-child(4) {
    font-size: 14px;
    font-weight: bold;
    color: #333333;
    margin: 20px 0 10px 0;
  }
  .index .normal-card:nth-child(2) .file {
    display: flex;
    flex-wrap: wrap;
  }

  
</style>
