
<template>
  <div>
    <div style="display:flex;align-items:center">
      <el-input
          placeholder="请输入搜索内容"
          suffix-icon="el-icon-search"
          v-model="params.content.where.condition"
          style="width:200px"
          size="mini"
          class="input-with-select inline-16"
          @keyup.native.enter="listData(params.content.pageNumber=1)"
          @clear="clearData"
          clearable>
      </el-input>
      <slot name="addOrder"></slot>
    </div>
    <div style="margin-top: 15px">
      <tableLayout :layout="tablecols" :data="list" :opwidth="200"  :custom="true" :width="false"  :height="tableHieght" fixedName="operation writeoffamount unwriteoffamount">
        <template v-slot:customcol="scope">
          <div v-if="scope.column.columnname == 'type'">
            <span v-if="scope.column.data[[scope.column.columnname]] == '框架'">经销商合作协议</span>
            <span v-else-if="scope.column.data.typemx == '经销'">经销项目协议</span>
            <span v-else-if="scope.column.data.typemx == '直销'">直销项目协议</span>
            <span v-else-if="scope.column.data[[scope.column.columnname]] == '工具借用'">工具使用协议</span>
            <span v-else-if="scope.column.data[[scope.column.columnname]] == '居间'">居间协议</span>
          </div>
           <div v-else-if="scope.column.columnname == 'status'">
            <span style="color:#3874f6" v-if="scope.column.data[[scope.column.columnname]] == '新建'">{{scope.column.data[[scope.column.columnname]]}}</span>
            <span style="color:#52c41a" v-else-if="scope.column.data[[scope.column.columnname]] == '提交'">{{scope.column.data[[scope.column.columnname]]}}</span>
            <span style="color:#333333" v-else-if="scope.column.data[[scope.column.columnname]] == '审核'">{{scope.column.data[[scope.column.columnname]]}}</span>
          </div>
          <p v-else>{{scope.column.data[scope.column.columnname]}}</p>
          <p v-if="!scope.column.data[scope.column.columnname] && scope.column.data[scope.column.columnname] !== 0 && scope.column.columnname != 'operation'">--</p>
        </template>
        <template v-slot:opreation="scope">
          <el-button class="inline-16" type="text" size="mini" @click="save(scope.data)" v-if="currentItem.sa_writeoffbill_orderid == scope.data.sa_writeoffbill_orderid">保 存</el-button>
          <slot name="editOrder" :data="scope.data" v-else></slot>
          <slot name="delOrder" :data="scope.data"></slot>
        </template>
      </tableLayout>
    </div>
    <div style="margin-top:16px;text-align:right">
      <el-pagination
          background
          small
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="params.content.pageNumber"
          :page-size="params.content.pageSize"
          layout="total, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { log } from '@antv/g2plot/lib/utils'
export default {
  props:["data"],
  data () {
    return {
      tableHieght:"600px",
      tablecols:[],
      list:[],
      total:0,
      search:'',
      params:{
        "id": 20221219141702,
        "content": {
            "sys_enterpriseid": 3,
            "pageNumber": 1,
            "pageSize": 20,
            "where": {
                "condition": ""
            }
        }
      },
      options:[
      ],
      productList:'',
      /* 当前正在编辑的数据信息 */
      currentItem:''
    }
  },
  provide () {
    return {
    }
  },
  methods:{
    async save (data) {
      let res = await this.$api.requested({
        "id":20221124090904,
        "content": {
          sa_writeoffbillid:this.$route.query.id,
          writeoffbillOrder: [
            {
              "sa_writeoffbill_orderid": data.sa_writeoffbill_orderid,
                "sa_orderid":data.sa_orderid,
                "sa_orderitemsid":data.sa_orderitemsid,
                "writeoffamount":data.writeoffamount,
                "remarks":""
            }
          ]
        }
      })
      console.log(res);
      this.tool.showMessage(res,() => {
        this.$emit('onSuccess')
        this.listData()
        this.currentItem = ''
      })
    },
    async listData(){
      this.params.content.sys_enterpriseid = this.data.sys_enterpriseid
      const res = await this.$api.requested(this.params)
      this.list = res.data
      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(){
      this.search = ""
      this.params.content.where.condition = this.search
      this.listData()
    },
    queryClick(){
      this.params.content.where.condition = this.search
      this.listData()
    }
  },
  created() {
    this.listData()
    this.tablecols = this.tool.tabelCol(this.$route.name).contractTable.tablecols
  }
}

</script>
<style scoped>

</style>