main.js 1010 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import Vue from 'vue'
  2. import Main from './main.vue'
  3. import * as Options from './defaultOptions'
  4. import { api } from '~/ui-domain'
  5. let PurchasePlanConstructor = Vue.extend(Main)
  6. let instance
  7. let seed = 1
  8. const PurchasePlan = function(options) {
  9. if (Vue.prototype.$isServer) return
  10. if (instance) instance.close()
  11. return new Promise((resolve, reject) => {
  12. options = options || {}
  13. if (!options.purchasePlanApi) {
  14. options.purchasePlanApi = `${api.admin}/admin/erp/product`
  15. }
  16. let id = 'purchasePlan_picker_' + seed++
  17. options.show = true
  18. instance = new PurchasePlanConstructor({ propsData: options })
  19. instance.id = id
  20. instance.$mount()
  21. instance.resolve = resolve
  22. instance.reject = reject
  23. instance.close = closeInstance
  24. document.body.appendChild(instance.$el)
  25. })
  26. }
  27. function closeInstance() {
  28. instance.$destroy()
  29. instance.$el.parentNode.removeChild(instance.$el)
  30. instance.reject('取消了')
  31. instance = undefined
  32. }
  33. export default PurchasePlan