<template>
  <kr-print-designer ref="printDesigner" :temp-value="value" :widget-options="widgets" @save="handleSave" />
</template>
<script>
import { OutStockOptions, InStockOptions } from '../data/options'

import {
  getColumnsAttr
} from '../api/base.js'
export default {
  data() {
    return {
      id : '',
      site : '',
      index: '',
      value: {
        title: 'demo',
        width: 750,
        height: 550,
        pageWidth: 750,
        pageHeight: 550,
        tempItems: [],
      },
      widgets: OutStockOptions,
    }
  },

  created() {
    this.index = this.$route.query.index
    this.id = this.$route.query.id
    try {
      let tempList = JSON.parse(localStorage.getItem('tempList')) || []
      this.value = tempList[this.index]
      this.widgets = this.value.type == 1 ? OutStockOptions : InStockOptions
    } catch (err) {
      console.error(err)
    }
    this.getColumnsAttrList()
  },
  methods: {
    getColumnsAttrList(){
      let jsonData = {
        supplierId : 1,
        site : this.site,
      }
      getColumnsAttr(jsonData).then(({data}) =>{
        this.widgets = data.rows
      })
    },
    handleSave(data) {
      // let tempList = JSON.parse(localStorage.getItem('tempList')) || []
      // tempList[this.index] = data
      // localStorage.setItem('tempList', JSON.stringify(tempList))
      this.$router.back()
    },
    // 手动初始话模板数据
    initTemp(){
     // this.$refs.printDesigner.initTemp(this.value,this.widgets)


    }
  },
}
</script>
