<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="mainData.ruleno"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20230110100103"
        idname="sa_receivableruleid"
        ownertable="sa_receivablerule"
        tags=""
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)"
      >
      <div slot="tags">
      </div>
      <div slot="customOperation" >
        <Edit v-if="tool.checkAuth($route.name,'update')" class="inline-16" :data="mainData" @onSuccess="queryMainData()"/>
        <el-button :disabled="mainData.isdefault === 1" size="mini" v-if="tool.checkAuth($route.name,'delete')" type="primary" @click="onDel">删除</el-button>
      </div>
      <div slot="slot0" >
      </div>
      <div slot="slot1" >
      </div>
    </basicDetails>
  </div>
</template>

<script>
import Edit from '../components/edit'
export default {
  name: "detail",
  data() {
    return {
      mainData:{},
      mainAreaData:{}
    }
  },
  components:{
    Edit
  },
  methods:{
    async queryMainData(id) {
      const res = await this.$api.requested({
        "id":20230110100003,
        "content": {
          "sa_receivableruleid": this.$route.query.id
        }
      })
      this.mainData = res.data
      console.log(this.mainData);
      
      this.changeDataStructure()
    },
    changeDataStructure() {
      this.mainAreaData = [
        {
          label:'账期依据',
          value:this.mainData.point
        },
        {
          label:'编号',
          value:this.mainData.ruleno
        },
        {
          label:'立账额度比率',
          value:this.mainData.amountrate * 100 + '%'
        },
        {
          label:'后置天数',
          value:this.mainData.days
        },
        {
          label:'是否默认条件',
          value:this.mainData.isdefault ? '是' : '否'
        },
        {
          label:'描述',
          value:this.mainData.remarks
        },
      ]
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex,tabIndex) {
      this.flag = false
      tabIndex = this.$route.query.tabIndex
      this.$router.replace({path:'/collectionRuleDetail',query:{id:id,rowindex:rowindex,tabIndex:tabIndex}})
      this.queryMainData(id)
    },
    onSuccess(){
      this.visible = false
      this.queryMainData(this.$route.query.id)
      this.$emit('onSuccess')
    },
    onDel(){
      this.$confirm('确定删除该收款条件吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        closeOnClickModal:false,
        type: 'warning'
      }).then(async() => {
        const res = await this.$api.requested({
          "id":20230110100203,
          "content":{
            "sa_receivableruleids":[this.$route.query.id]
          }
        })
        this.tool.showMessage(res,()=>{
          this.$store.dispatch('changeDetailDrawer',false)
          this.$router.replace({path:'/collectionRule'})
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });


      /*let timer = setTimeout(() => {
        //需要定时执行的代码
        this.$router.replace({path:'/collectionRule'})
      }, 2000)*/
    }
  },
  mounted () {
    this.queryMainData(this.$route.query.id)
  },
  created() {
  }
}
</script>

<style scoped>

</style>