<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <customer-transfer :modelValue.sync="selectedTools" :data.sync="tools" :title="['工具列表','已选工具']"/>
  </j-modal>
</template>

<script>

  import RegularToolsForm from './RegularToolsForm'
  import CustomerTransfer from '@comp/CustomerTransfer/index.vue'
  import { getAction } from '@api/manage'
  export default {
    name: 'RegularToolsModal',
    components: {
      CustomerTransfer,
      RegularToolsForm
    },
    data () {
      return {
        title:'检修工器具选择',
        width:'70vw',
        visible: false,
        disableSubmit: false,
        tools:[],
        selectedTools:[],
        url:{
          toolList: '/tool/list'
        }
      }
    },
    methods: {
      loadTools(){
        getAction(this.url.toolList, {
          pageNo: 1,
          pageSize: 1000
        }).then(res => {
          if(res.success){
            this.tools = res.result.records.map(item => {
              return {
                id: item.id,
                name: item.name,
                specification: item.model,
                unitText: item.unit_dictText,
                unit: item.unit
              }
            })

            console.log(this.tools)
          }
        })
      },
      show (data) {
        console.log('tools', data)
        this.selectedTools = data
        this.loadTools()
        this.visible=true
      },
      edit (record) {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.edit(record);
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        this.$emit('ok', this.selectedTools);
        this.visible = false;
      },
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      }
    }
  }
</script>