
<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="addProwerArea"></slot>
    </div>
    <div style="margin-top: 15px">
      <tableLayout :layout="tablecols" :data="list" :opwidth="200"  :custom="true" :width="false"  :height="tableHieght" fixedName="operation">
        <template v-slot:customcol="scope">
          <div v-if="scope.column.columnname == 'limitamount'">
            <el-input size="small" v-if="currentArea.sa_promotion_authid == scope.column.data.sa_promotion_authid" v-model="scope.column.data.limitamount"></el-input>
            <span v-else>{{scope.column.data.limitamount}}</span>
          </div>
          <div v-else-if="scope.column.columnname == 'limitgroupqty'">
            <el-input size="small" v-if="currentArea.sa_promotion_authid == scope.column.data.sa_promotion_authid" v-model="scope.column.data.limitgroupqty"></el-input>
            <span v-else>{{scope.column.data.limitgroupqty}}</span>
          </div>
          <div v-else-if="scope.column.columnname == 'limitordercount'">
            <el-input size="small" v-if="currentArea.sa_promotion_authid == scope.column.data.sa_promotion_authid" v-model="scope.column.data.limitordercount"></el-input>
            <span v-else>{{scope.column.data.limitordercount}}</span>
          </div>
          <div v-else-if="scope.column.columnname == 'islimit'">
            <div v-if="currentArea.sa_promotion_authid == scope.column.data.sa_promotion_authid">
              <el-checkbox v-model="scope.column.data.islimit" :true-label="1" :false-label="0"></el-checkbox>
            </div>
            <span v-else>
              <span v-if="scope.column.data.islimit">是</span>
              <span v-else>否</span>
            </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="currentArea.sa_promotion_authid == scope.data.sa_promotion_authid">保 存</el-button>
          <slot v-else name="editArea" :data="scope.data"></slot>
          <slot name="product" :data="scope.data"></slot>
          <slot name="delArea" :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>
export default {
  props:["data"],
  data () {
    return {
      tableHieght:"calc(100vh - 380px)",
      tablecols:[],
      list:[],
      total:0,
      params:{
        "id": 20230102102903,
        "version":1,
        "content": {
            "sa_promotionid":'',
            "where":{
              "condition":''
            }
        }
      },
      options:[
      ],
      productList:'',
      currentArea:{}
    }
  },
  provide () {
    return {
    }
  },
  methods:{
    async save (data) {
      let res = await this.$api.requested({
        "id": 20230102095903,
        "version":1,
        "content": {
            "sa_promotionid":this.$route.query.id,     //sat_notice_classid<=0时 为新增
            "enterpriseinfos":[
              {
                  "sa_promotion_authid":data.sa_promotion_authid,
                  "sys_enterpriseid":data.sys_enterpriseid,
                  "islimit":data.islimit,
                  "limitamount":data.limitamount,
                  "limitgroupqty":data.limitgroupqty,
                  "limitordercount":data.limitordercount
              },
            ]
        }
      })
      this.tool.showMessage(res,() => {
        this.$emit('onSuccess')
        this.listData()
        this.currentArea = ''
      })
    },
    async listData(){
      this.params.content.sa_promotionid = this.$route.query.id
      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.listData()
    },
    queryClick(){
      this.listData()
    }
  },
  created() {
    this.listData()
    this.tablecols = this.tool.tabelCol(this.$route.name).promotionModelPowerAreaTable.tablecols
  }
}

</script>
<style scoped>

</style>