main.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 = options.isAdmin
  15. ? `${api.admin}/admin/purchasePlan/shopping-purchasePlans`
  16. : `${api.admin}/seller/purchasePlan/shopping-purchasePlans`
  17. }
  18. let id = 'purchasePlan_picker_' + seed++
  19. options.show = true
  20. instance = new PurchasePlanConstructor({ propsData: options })
  21. instance.id = id
  22. instance.$mount()
  23. instance.resolve = resolve
  24. instance.reject = reject
  25. instance.close = closeInstance
  26. document.body.appendChild(instance.$el)
  27. })
  28. }
  29. // 扩展列
  30. PurchasePlan.columns = {
  31. general: Options.generalColumns
  32. }
  33. function closeInstance() {
  34. instance.$destroy()
  35. instance.$el.parentNode.removeChild(instance.$el)
  36. instance.reject('取消了')
  37. instance = undefined
  38. }
  39. export default PurchasePlan