<template>
  <div>
    <el-button size="mini" type="primary" @click="dialogFormVisible=true">新 建</el-button>
    <el-dialog title="新 建" append-to-body :visible.sync="dialogFormVisible" width="50%">
      <div slot="title" style="font-size: 15px">
        商品新增
      </div>
      <basicLayout 
        ref="basicLayout" 
        formPath="none" 
        tableName="productList" 
        idName="itemid" 
        :apiId="{query:20221028154004,del:''}" 
        :options="options"
        @checkboxCallBack="checkboxCallBack"
        customTitle="商品选择列表">
        <div slot="custom"></div>
        <template v-slot:tbList="scope">
          <div>
            {{scope.data.column.data[[scope.data.column.columnname]]}}
          </div>
        </template>
      </basicLayout>
      <div class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" @click="onSubmit" :disabled="selectProduct.length == 0" class="normal-btn-width btn-warning">确 定</el-button>
      </div>
    </el-dialog>
    
  </div>
</template>

<script>
export default {
  components:{},
  name: "index",
  data() {
    return {
      options:[],
      dialogFormVisible: false,
      productList:[],
      selectProduct:[]
    }
  },
  provide () {
    return {
    }
  },
  mounted () {
    this.getProductList()
  },
  methods: {
    /* 提交 */
    async onSubmit () {
      let content = this.selectProduct.map(item => {
        return {
          "sa_itempriceadjust_itemsid":0,
          "itemid":item.itemid,
          "remarks":""
        }
      })
      let res = await this.$api.requested({
        "id": "20221025095104",
        "content": {
            "sa_itempriceadjustid": this.$route.query.id,
            "sa_itempriceadjust_items": content
        }
      })
      this.tool.showMessage(res,() => {
        this.$emit('onSuccess')
        this.dialogFormVisible = false
      })
    },
    checkboxCallBack (data) {
      this.selectProduct = data
    },
    /* 获取可添加的商品 */
    async getProductList () {
      let res = await this.$api.requested({
          "id": 20221028154004,
          "content": {
              "pageNumber": 1,
              "pageSize": 20,
              "where": {
                  "condition": ""
              },
              "sa_itempriceadjustid":this.$route.query.id
          }
      })
      return console.log(res,'商品');
      
      this.productList = res.data
      console.log(this.productList);
    },
  }
}
</script>

<style scoped>

</style>