com-goods-form.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template id="com-goods-form">
  2. <div class="com-goods-form">
  3. <el-tag @close="deleteValue" v-if="value"
  4. :key="value.name"
  5. :disable-transitions="true"
  6. style="margin-right: 10px;"
  7. closable>
  8. {{value.name}}
  9. </el-tag>
  10. <el-button type="button" size="mini" @click="open">{{title}}</el-button>
  11. <el-dialog :title="title" :visible.sync="dialog" width="30%">
  12. <el-card shadow="never" flex="dir:left" style="flex-wrap: wrap" v-loading="loading">
  13. <el-radio-group v-model="checked">
  14. <el-radio style="padding: 10px;" v-for="item in list"
  15. :label="item" :key="item.id">{{item.name}}
  16. </el-radio>
  17. </el-radio-group>
  18. </el-card>
  19. <div slot="footer" class="dialog-footer">
  20. <el-button @click="cancel">取 消</el-button>
  21. <el-button type="primary" @click="confirm">确 定</el-button>
  22. </div>
  23. </el-dialog>
  24. </div>
  25. </template>
  26. <script>
  27. Vue.component('com-goods-form', {
  28. template: '#com-goods-form',
  29. props: {
  30. value: Array | Object,
  31. title: String,
  32. url: String,
  33. },
  34. data() {
  35. return {
  36. dialog: false,
  37. list: [],
  38. checked: {},
  39. loading: false,
  40. };
  41. },
  42. methods: {
  43. open() {
  44. this.dialog = true;
  45. this.loadData();
  46. },
  47. loadData() {
  48. this.loading = true;
  49. request({
  50. params: {
  51. r: this.url
  52. }
  53. }).then(response => {
  54. this.loading = false;
  55. if (response.data.code == 0) {
  56. this.list = response.data.data.list;
  57. } else {
  58. this.$message.error(response.data.msg);
  59. }
  60. }).catch(response => {
  61. console.log(response);
  62. });
  63. },
  64. cancel() {
  65. this.dialog = false;
  66. this.checked = {};
  67. },
  68. confirm() {
  69. this.$emit('selected', this.checked);
  70. this.cancel();
  71. },
  72. deleteValue() {
  73. this.$emit('selected', null);
  74. }
  75. }
  76. });
  77. </script>