
<template>
  <div>
    <div >
      <add v-if="tool.checkAuth($route.name,'quotationManage') && data.disabled" class="inline-16" :data="data" @addSuccess="onSuccess"></add>
      <el-input
          placeholder="请输入搜索内容"
          suffix-icon="el-icon-search"
          v-model="search"
          style="width:200px"
          size="small"
          class="input-with-select inline-16"
          @keyup.native.enter="queryClick"
          @clear="clearData"
          clearable>
      </el-input>
    </div>
    <div style="margin-top: 15px">
      <tableLayout :layout="tablecols" :data="list" :opwidth="200" :custom="true"  :height="tableHieght" fixedName="operation">
        <template v-slot:customcol="scope">
          <div v-if="scope.column.columnname === 'invaliddate'">
            {{scope.column.data.begdate?scope.column.data.begdate + '至' + scope.column.data.enddate:'--'}}
          </div>
          <div v-else-if="scope.column.columnname === 'specialoffer'">
            <span>{{scope.column.data[scope.column.columnname] === 0?'否':'是'}}</span>
          </div>
          <div v-else-if="scope.column.columnname === 'operation'">
            <span>{{scope.column.data[scope.column.columnname]}}</span>
          </div>
          <p v-else>{{(scope.column.data[scope.column.columnname])?scope.column.data[scope.column.columnname]:'--'}}</p>
        </template>
        <template v-slot:opreation="scope">
          <el-button  :disabled="!tool.checkAuth($route.name,'quotationManage')" size="mini" type="text" @click="detailGo(scope.data)">详 情</el-button>
        </template>
      </tableLayout>
    </div>
    <div style="margin-top:16px;text-align:right">
      <el-pagination
          background
          small
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="params.content.pageSize"
          layout="total, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import buillDetail from './modules/buillDetail'
import add from './modules/add'
export default {
  props:["data"],
  data () {
    return {
      tableHieght:"600px",
      tablecols:[],
      list:[],
      total:0,
      currentPage:0,
      search:'',
      params:{
        "id": 20221124190702,
        "content": {
          "sa_projectid": 1,
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
            "condition": ""
          }
        }
      },
      options:[
        {
          label:'全部',
          value:''
        },
        {
          label:'新建',
          value:'新建'
        },{
          label:'提交',
          value:'提交'
        },
        {
          label:'审核',
          value:'审核'
        }
      ],
      productList:''
    }
  },
  provide () {
    return {
      productList:() => this.productList
    }
  },
  components:{buillDetail,add},
  methods:{
    detailGo(row){
      console.log(row)
      let route = this.$route
      if (route.path !== '/quotedPriceDetail') {
        this.oldRoute = {path:route.path,query:route.query}
        this.$store.dispatch('setHistoryRouter',this.oldRoute)
      }
      this.$router.push({
        path:'/quotedPriceDetail',
        query:{
          id:row.sa_quotedpriceid,
          rowindex:row.rowindex
        }
      })
    },
    async submit (data) {
      let res = await this.$api.requested({
        "id": 20221020165303,
        "version":1,
        "content": { 
            "sa_quotedpriceid":data.sa_quotedpriceid
        }
      })
      this.tool.showMessage(res,() => {
        this.$refs.basicLayout.listData()
      })
    },
    async check (data) {
      let res = await this.$api.requested({
          "id": 20221020165403,
          "version":1,
          "content": { 
            "sa_quotedpriceid":data.sa_quotedpriceid
          }
      })
      this.tool.showMessage(res,() => {
        this.$refs.basicLayout.listData()
      })
    },
    /* 获取可添加的商品 */
    async getProductList () {
      let res = await this.$api.requested({
        "id": 20221020164903,
        "version":1,
        "content": {
            "sa_projectid":this.$route.query.id
        }
      })
      this.productList = res.data
    },
    async listData(){
      console.log(this.data,'项目商机')
      this.params.content.sa_projectid = this.data.sa_projectid
      const res = await this.$api.requested(this.params)
      this.list = res.data
      res.data.forEach((item,index)=>{
        /*this.list[index].begdate = new Date(e.begdate).getFullYear() +*/
      })
      this.total = res.total
      console.log(this.list,"报价单")
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.content.pageNumber = val
      this.listData()
    },
    clearData(){
      console.log("执行")
      this.search = ""
      this.params.content.where.condition = this.search
      this.listData()
    },
    queryClick(){
      this.params.content.where.condition = this.search
      this.listData()
    },
    onSuccess(){
      this.listData()
    }
  },
  created() {
    /*this.getProductList()*/
    this.listData()
    this.tablecols = this.tool.tabelCol(this.$route.name).quotationTable.tablecols
  }
}

</script>
<style scoped>
/* /deep/.el-table__cell .cell {
  display: flex;
  justify-content: s;
} */
</style>