import { findBySelectSup } from '@/api/api'
import { getAction } from '@/api/manage'

export const MaterialModalMixins = {
  data() {
    return {
      supList: [],
      depotList: [],
      quickBtn: {
        vendor: false,
        depot: false,
      },
    }
  },
  methods: {
    addVendor() {
      this.$refs.vendorModalForm.add()
      this.$refs.vendorModalForm.title = '新增供应商'
      console.log('this.$refs.vendorModalForm------------', this.$refs.vendorModalForm)
      this.$refs.vendorModalForm.disableSubmit = false
    },
    addDepot() {
      this.$refs.depotModalForm.add()
      this.$refs.depotModalForm.title = '新增仓库'
      this.$refs.depotModalForm.disableSubmit = false
    },
    vendorModalFormOk() {
      this.initSupplier(1)
    },
    depotModalFormOk() {
      this.initDepot()
    },
    initSupplier() {
      let that = this
      findBySelectSup({}).then((res) => {
        if (res) {
          that.supList = res
        }
      })
    },
    initDepot() {
      let that = this
      getAction('/depot/findDepotByCurrentUser').then((res) => {
        if (res.code === 200) {
          let arr = res.data
          that.depotList = arr.map((item) => {
            return {
              value: item.id + '',
              text: item.depotName,
              title: item.depotName,
            }
          })
        }
      })
    },
    //初始化下拉选项
    initSelectOpts() {
      this.initSupplier()
      this.initDepot()
    },
  },
}
