<template>
  <div class="inline-16">
    <el-button type="text" size="mini" @click="productBtn">商 品</el-button>
    <el-drawer
        title="促销模块商品明细"
        :visible.sync="drawer"
        size="80%"
        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" :data="data"></slot>
        </div>
        <div style="margin-top: 15px">
          <tableLayout :layout="tablecols" :data="list1" :opwidth="200"  :custom="true" :width="false"  :height="tableHieght" fixedName="operation">
            <template v-slot:customcol="scope">
              <!-- <div v-if="scope.column.columnname == 'amount'">
                <el-input size="small" v-if="currentItem.sa_paybilldetailid == scope.column.data.sa_paybilldetailid" v-model="scope.column.data.amount"></el-input>
                <span v-else>{{scope.column.data.amount}}</span>
              </div> -->
              <div v-if="scope.column.columnname == 'spec'">
                {{scope.column.data.model}}/{{scope.column.data.spec}}
              </div>
              <div v-else-if="scope.column.columnname == 'groupqty'">
                <el-input size="small" v-if="currentProduct.sa_promotion_itemsid == scope.column.data.sa_promotion_itemsid" v-model="scope.column.data.groupqty"></el-input>
                <span v-else>{{scope.column.data.groupqty}}</span>
              </div>
              <div v-else-if="scope.column.columnname == 'orderaddqty'">
                <el-input size="small" v-if="currentProduct.sa_promotion_itemsid == scope.column.data.sa_promotion_itemsid" v-model="scope.column.data.orderaddqty"></el-input>
                <span v-else>{{scope.column.data.orderaddqty}}</span>
              </div>
              <div v-else-if="scope.column.columnname == 'orderminqty'">
                <el-input size="small" v-if="currentProduct.sa_promotion_itemsid == scope.column.data.sa_promotion_itemsid" v-model="scope.column.data.orderminqty"></el-input>
                <span v-else>{{scope.column.data.orderminqty}}</span>
              </div>
              <div v-else-if="scope.column.columnname == 'groupqty'">
                <el-input size="small" v-if="currentProduct.sa_promotion_itemsid == scope.column.data.sa_promotion_itemsid" v-model="scope.column.data.groupqty"></el-input>
                <span v-else>{{scope.column.data.groupqty}}</span>
              </div>
              <div v-else-if="scope.column.columnname == 'islimit'">
                <div v-if="currentProduct.sa_promotion_itemsid == scope.column.data.sa_promotion_itemsid">
                  <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="currentProduct.sa_promotion_itemsid == scope.data.sa_promotion_itemsid">保 存</el-button>
              <slot name="promotionPrice" :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" class="normal-btn-width">确 定</el-button>
        </div>
      </div>
    </el-drawer>
  </div>
</template>

<script>
export default {
  name: '',
  props:['data'],
  data() {
    return {
      drawer:false,
      tableHieght:"calc(100vh - 380px)",
      tablecols:[],
      list1:[],
      total:0,
      currentProduct:{},
      params:{
        "id": 20230102142503,
        "version":1,
        "content": {
          "nocache":true,
          "sa_promotionid":'',
          "sa_promotion_itemgroupid":'',
          "pageNumber":1,
          "pageSize":20,
          "where":{
              "condition":""
          }
        }
      },
    };
  },
  computed:{
  },
  watch:{
  },
  methods: {
    async listData(id){
      this.params.content.sa_promotionid = this.data.sa_promotionid
      this.params.content.sa_promotion_itemgroupid = id ? id : this.data.sa_promotion_itemgroupid
      const res = await this.$api.requested(this.params)
      this.list1 = res.data
      this.total = res.total
      console.log(this.list1,this.total)
    },
    async save (data) {
      let res = await this.$api.requested({
        "id": 20230102142403,
        "version":1,
        "content": {
          "sa_promotionid":this.$route.query.id,
          "sa_promotion_itemgroupid":this.data.sa_promotion_itemgroupid,
          "iteminfos":[
            {
              "sa_promotion_itemsid":data.sa_promotion_itemsid,
              "itemid":data.itemid,
              "islimit":data.islimit,
              "groupqty":data.groupqty,
              "orderaddqty":data.orderaddqty,
              "orderminqty":data.orderminqty
            },
          ]
        }
      })
      this.tool.showMessage(res,() => {
        this.$emit('onSuccess')
        this.listData()
        this.currentProduct = {}
      })
    },
    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).modelProductTable.tablecols
    this.tablecols.shift()
  }
};
</script>

<style scoped>

</style>
