xialaxuanz.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. var i = 0
  2. export default function (option, placeholder = '请选择', errMsg = '请先选择数据') {
  3. return new Promise((r, j) => {
  4. const h = this.$createElement
  5. const refName = `selectView${++i}`
  6. var _this = this
  7. var done_ = null
  8. this.$msgbox({
  9. title: placeholder,
  10. message: h(
  11. 'el-select',
  12. {
  13. style: {
  14. width: '100%'
  15. },
  16. props: {
  17. value: '',
  18. filterable: true,
  19. clearable: true,
  20. size: 'mini'
  21. },
  22. ref: refName,
  23. on: {
  24. change: e => {
  25. _this.$refs[refName].value = e
  26. }
  27. }
  28. },
  29. [
  30. option.map(it => {
  31. return h('el-option', {
  32. props: {
  33. key: it.value,
  34. label: it.label,
  35. value: it.value
  36. }
  37. })
  38. })
  39. ]
  40. ),
  41. beforeClose: function (action, instance, done) {
  42. if (action === 'confirm') {
  43. if (_this?.$refs?.[refName]?.value) {
  44. done()
  45. } else {
  46. done_ = done
  47. this.$message({
  48. message: errMsg,
  49. type: 'warning'
  50. })
  51. }
  52. } else {
  53. done()
  54. }
  55. },
  56. showCancelButton: true,
  57. closeOnClickModal: false,
  58. confirmButtonText: '确定',
  59. cancelButtonText: '取消'
  60. })
  61. .then(_ => {
  62. if (_this?.$refs?.[refName]?.value) {
  63. r(_this?.$refs?.[refName]?.value)
  64. done_?.()
  65. } else {
  66. j()
  67. }
  68. })
  69. .catch(_ => {
  70. j()
  71. })
  72. })
  73. }