<template>
  <div class="inline-16">
    <el-button type="text" size="mini" @click="productBtn">促 销 价 格</el-button>
    <el-drawer
        title="促销价格明细"
        :visible.sync="drawer"
        size="70%"
        direction="rtl"
        append-to-body
        @close="drawer = false"
        :show-close="false">
      <div class="drawer__panel">
        <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="listData(params.content.where.condition='')"
              clearable>
          </el-input>
          <slot name="addProduct"></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 == 'price'">
                <el-input size="small" v-if="currentProduct.sa_promotion_itempriceid == scope.column.data.sa_promotion_itempriceid" v-model="scope.column.data.price"></el-input>
                <span v-else>{{tool.formatAmount(scope.column.data.price,2)}}</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 type="text" size="mini" @click="save(scope.data)" v-if="currentProduct.sa_promotion_itempriceid == scope.data.sa_promotion_itempriceid">保 存</el-button>
              <el-button :disabled="!isEdit()" v-else size="mini" type="text" @click="edit(scope.data)">编 辑</el-button>
              <!-- <slot v-else name="editPrice" :data="scope.data"></slot> -->
              <slot name="delRemit" :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 class="fixed__btn__panel">
          <el-button size="small" @click="drawer = false" class="normal-btn-width">取 消</el-button>
          <el-button size="small" type="primary" @click="submit" class="normal-btn-width">确 定</el-button>
        </div>
      </div>
    </el-drawer>
  </div>
</template>

<script>
export default {
  name: '',
  props:['data'],
  inject:['isEdit'],
  data() {
    return {
      aaa:1,
      currentProduct:{},
      drawer:false,
      tableHieght:"calc(100vh - 380px)",
      tablecols:[],
      list:[],
      total:0,
      params:{
        "id": 20230102163103,
        "version":1,
        "content": {
          "sa_promotionid":'',
          "sa_promotion_itemsid":'',
          "pageNumber":1,
          "pageSize":20,
          "where":{
              "condition":""
          }
        }
      },
    };
  },
  computed:{
  },
  methods: {
    edit (data) {
      this.currentProduct = data
      console.log(this.currentProduct);
    },
    async save (data) {
      let res = await this.$api.requested({
        "id": 20230102163003,
        "content": {
            "sa_promotion_itempriceid":data.sa_promotion_itempriceid,     //sat_notice_classid<=0时 为新增
            "sa_promotionid": data.sa_promotionid,
            "price":data.price
        }
      })
      this.tool.showMessage(res,() => {
        this.$emit('onSuccess')
        this.listData()
        this.currentProduct = {}
      })
    },
    async listData(){
      this.params.content.sa_promotionid = this.$route.query.id
      this.params.content.sa_promotion_itemsid = this.data.sa_promotion_itemsid
      const res = await this.$api.requested(this.params)
      this.list = res.data
      this.total = res.total
      console.log(this.list)
    },
    submit () {
      
    },
    productBtn () {
      this.drawer = true
      this.listData()
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.content.pageNumber = val
      this.listData()
    },
  },
  created () {
    this.tablecols = this.tool.tabelCol(this.$route.name).promotionPriceTable.tablecols
  }
};
</script>

<style scoped>

</style>
