<template>
  <j-modal
    title="检修物料选择"
    :width="width"
    :visible="visible"
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <customer-transfer :modelValue.sync="selectedMaterials" :data.sync="materials" :title="['物料列表','已选物料']"/>
  </j-modal>
</template>

<script>

  import RegularMaterialForm from './RegularMaterialForm'
  import CustomerTransfer from '@comp/CustomerTransfer/index.vue'
  import { getAction } from '@api/manage'
  export default {
    name: 'RegularMaterialModal',
    components: {
      CustomerTransfer,
      RegularMaterialForm
    },
    data () {
      return {
        selectedMaterials:[],
        materials:[],
        title:'',
        width:'70vw',
        visible: false,
        disableSubmit: false,
        url:{
          materialList: '/material/buMaterialInfo/list'
        }
      }
    },
    methods: {
      loadMaterials () {
          getAction(this.url.materialList,{
            pageNo: 1,
            pageSize: 1000
          }).then((res) => {
            console.log(res)
            if(res.success) {
              this.materials = res.result.records.map(item => {
                return {
                  id: item.id,
                  name: item.name,
                  specification: item.specifaction,
                  unitText: item.unit_dictText,
                  unit: item.unit
                }
              });
              console.log(this.materials);
            }
          })
      },
      show (data) {
        this.loadMaterials()
        this.selectedMaterials = data;
        this.visible=true
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        this.$emit('ok', this.selectedMaterials);
        this.visible = false;
      },
      handleCancel () {
        this.close()
      }
    }
  }
</script>