<template>
  <div>
    <el-input style="width:200px;" placeholder="输入搜索内容" :suffix-icon="param.content.where.condition?param.content.where.condition.length > 0?'':'':'el-icon-search'" v-model="param.content.where.condition" @keyup.native.enter="listData(param.content.pageNumber = 1)" @clear="listData(param.content.pageNumber = 1)" size="small" class="mt-10 input-with-select inline-16 layout_search__panel" clearable>
    </el-input>
    <addPriceDiff ref="priceDiff" class="inline-16" :data="data" @adjustSuccess="adjustSuccess"></addPriceDiff>
    <table-detail  :layout="tablecols" :data="list" :custom="true" :width="true" :height="tableHieght">
      <template v-slot:customcol="scope" >
        <div v-if="scope.column.columnname == 'orderratio'">
          {{scope.column.data[[scope.column.columnname]]?Math.round((scope.column.data[[scope.column.columnname]] * 100)*100)/100 + '%':scope.column.data[[scope.column.columnname]] == 0?'0%':'--'}}
        </div>
        <div v-else-if="scope.column.columnname == 'amount'">
          {{scope.column.data[[scope.column.columnname]]?tool.formatAmount(scope.column.data[[scope.column.columnname]],2):scope.column.data[[scope.column.columnname]] == 0?'0.00':'--'}}
        </div>
        <div v-else-if="scope.column.columnname == 'rebate'" style="color: red">
          {{scope.column.data[[scope.column.columnname]]?tool.formatAmount(scope.column.data[[scope.column.columnname]],2):scope.column.data[[scope.column.columnname]] == 0?'0.00':'--'}}
        </div>
        <div v-else>
          {{ scope.column.data[[scope.column.columnname]] || scope.column.columnname === 'operation' ? scope.column.data[[scope.column.columnname]] : '--' }}
        </div>
      </template>
      <template v-slot:opreation="scope">
        <el-button type="text" @click="adjustClick(scope.data)" size="mini">调整</el-button>
        <el-button type="text" size="mini" @click="goDetail(scope.data)">详 情</el-button>
      </template>
    </table-detail>
    <div  class="container normal-panel" style="text-align:right;padding-bottom: 0!important;">
      <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[50, 100, 150, 200]"
          :page-size="50"
          layout="total,sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import addPriceDiff from "./addPriceDiff"
export default {
  name: "index",
  props:["data"],
  components:{addPriceDiff},
  data(){
    return {
      tableHieght:'calc(100vh - 380px)',
      tablecols:[],
      list:[],
      currentPage:0,
      total:0,
      pageTotal:0,
      listqueryid:'',
      param:{
        "id": 20240829103004,
        "content": {
          "sa_contractid": "",
          "pageNumber": 1,
          "pageSize": 50,
          "where": {
            "condition": ""
          }
        }
      }
    }
  },
  methods:{
    async listData(){
      this.param.content.sa_contractid = this.$route.query.id
      const res = await this.$api.requested(this.param)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
      this.pageTotal = res.pageTotal
      this.listqueryid = res.listqueryid
      sessionStorage.setItem('total',res.total)
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.param.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.param.content.pageNumber = val
      this.listData()
    },
    adjustClick(data){
      this.$refs.priceDiff.drawerFormVisible = true
      this.$refs.priceDiff.editBtn(data)
    },
    adjustSuccess(){
      this.listData(this.param.content.pageNumner = 1)
      this.$emit('adjustSuccess')
    },
    goDetail(data){
      sessionStorage.setItem('listqueryid',this.listqueryid)
      sessionStorage.setItem('rowindexOld',data.rowindex)
      sessionStorage.setItem('listqueryidOld',this.$route.query.listqueryid)
      sessionStorage.setItem('contractId',this.$route.query.id)
      sessionStorage.setItem('typeOld',this.$route.query.type)
      sessionStorage.setItem('totalOld',this.total)
      sessionStorage.setItem('total',this.total)
      sessionStorage.setItem('isGo','1')
      this.$store.dispatch('changeDetailDrawer',false)
      setTimeout(()=>{
        this.$router.push({path:'/contractDetail',
          query:{
            id:data.sa_contractid,
            rowindex:data.rowindex,
            listqueryid:this.listqueryid,
            type:'居间',
            fieldname:'sa_contract'
          }})
        this.$store.dispatch('changeDetailDrawer',true)
      },500)
    }
  },
  mounted() {
    this.listData()
  },
  created() {
    this.tablecols = this.tool.tabelCol(this.$route.name).priceDifferenceTable.tablecols
  }
}
</script>

<style scoped>

</style>
