<template>
  <div>
    <!-- <basicLayout 
      ref="basicLayout" 
      formPath="productMoneyOdd/productOddDetail" 
      tableName="productDetailTable" 
      idName="sa_itempriceadjustid" 
      :apiId="{query:20221025160904,del:20221025095404}" 
      :options="options"
      @listCreate="list"
      customTitle="调整单明细">
      <div slot="titleRight">
        <priceHelper/>
      </div>
      <div slot="custom">
      </div>
      <template v-slot:tbList="scope">
        <div v-if="scope.data.column.data[scope.data.column.columnname] === ''">
        --
        </div>
        <div v-else-if="scope.data.column.columnname == 'province'">
        {{`${scope.data.column.data['province']}、${scope.data.column.data['city']}、${scope.data.column.data['county']}`}}
      </div>
        <div v-else>
          {{scope.data.column.data[[scope.data.column.columnname]]}}
        </div>
      </template>
      <template v-slot:tbOpreation="scope">
        <editPrice v-if="tool.checkAuth($route.name,'update')" class="inline-16" :data="scope.data.data"/>
        <delete-btn @deleteCreate="deleteCreate" v-if="tool.checkAuth($route.name,'delete')" :id="scope.data.data.sa_itempriceadjust_itemsid" @deleteSuccess="$refs.basicLayout.listData()" nameId="20221025095404" nameKey="sa_itempriceadjust_itemsids"/>
      </template>
    </basicLayout> -->
    <el-input type="text" size="small" class="inline-16" style="width:200px;margin-bottom:10px" clearable @clear="getDetailList" v-model="params.content.where.condition" placeholder="请输入搜索内容" @keyup.native.enter="getDetailList(params.content.pageNumber=1)"></el-input>
    <addPrice class="inline-16" v-if="tool.checkAuth($route.name,'update')" @onSuccess="getDetailList(params.content.pageNumber=1)"/>
    <priceHelper class="inline-16" v-if="tool.checkAuth($route.name,'priceHelp')" @onSuccess="getDetailList"/>
    <re-set 
          @deleteCreate="getDetailList" 
          v-if="tool.checkAuth($route.name,'resetPriceOdd')" 
          :id="$route.query.id" 
          @deleteSuccess="getDetailList"
          :disabled="!!isEdit()"
          nameId="202212003011904" 
          nameKey="sa_itempriceadjustid"
        />
    <tableLayout :layout="tablecols" :data="list" :opwidth="200" :custom="true" :fixedName="'operation'" height="400px">
      <template v-slot:customcol="scope">
        <p>{{scope.column.data[scope.column.columnname]}}</p>
      </template>
      <template v-slot:opreation="scope">
        <editPrice v-if="tool.checkAuth($route.name,'update')" class="inline-16" @onSuccess="getDetailList" :data="scope.data"/>
        <delete-btn 
          @deleteCreate="deleteCreate" 
          v-if="tool.checkAuth($route.name,'delete')" 
          :id="scope.data.sa_itempriceadjust_itemsid" 
          @deleteSuccess="getDetailList"
          :disabled="!!isEdit()"
          nameId="20221025095404" 
          nameKey="sa_itempriceadjust_itemsids"
        />
      </template>
    </tableLayout>
    <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 priceHelper from '../components/priceHelper'
import editPrice from '../components/editPrice'
import addPrice from '../components/add'
import reSet from '../components/reSet'
import { log } from '@antv/g2plot/lib/utils'

export default {
  inject:['isEdit'],
  components:{priceHelper,editPrice,addPrice,reSet},
  name: "index",
  data() {
    return {
      options:[],
      productList:'',
      tablecols:[],
      total:0,
      list:[],
      params: {
        "id":20221025160904,
        "content":{
          "pageNumber":1,
          "pageSize":20,
          "where": {
            "condition":""
          }
        }
      }
    }
  },
  provide () {
    return {
      productList:() => this.productList
    }
  },
  mounted () {
    this.tablecols = this.tool.tabelCol(this.$route.name)['productDetailTable'].tablecols
    // this.getProductList()
    this.getDetailList()
  },
  methods: {
    async getDetailList () {
      this.params.content.sa_itempriceadjustid = this.$route.query.id
      let res = await this.$api.requested(this.params)
      this.list = res.data
      this.total = res.total
      console.log(res);
    },
    deleteCreate (param) {
      param.content.sa_itempriceadjustid = this.$route.query.id
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.content.pageSize = val
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.content.pageNumber = val
    },
    /* 获取可添加的商品 */
    async getProductList () {
      let res = await this.$api.requested({
          "id": 20221028154004,
          "content": {
              "pageNumber": 1,
              "pageSize": 20,
              "where": {
                  "condition": ""
              },
              "sa_itempriceadjustid":this.$route.query.id
          }
      })
      this.productList = res.data
      console.log(this.productList);
    },
  }
}
</script>

<style scoped>
/deep/.el-table__fixed-body-wrapper {
  top: 36px !important;
}
</style>