fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<template>
    <div>
       <el-dialog :visible.sync="dialogVisible" :title="title" :close-on-click-modal="false" :modal-append-to-body="false" v-if="dialogVisible">
            <el-form size="mini" :model="form" label-width="120px" ref="form" :rules="formRules">
                 <el-form-item label="批次:" prop="batchName">
                     <el-input v-model="form.batchName" placeholder="请输入批次" clearable></el-input>
                 </el-form-item>
                <el-form-item label="批次描述:" prop="batchDesc">
                     <el-input v-model="form.batchDesc"  placeholder="请输入批次描述" clearable></el-input>
                 </el-form-item>
                 <!-- <el-form-item label="关联活动:" prop="promotionName">
                     <el-input v-model="form.promotionName" disabled placeholder="请选择关联活动" clearable>
                         <el-button class="append" @click="selectedActive"  slot="append">防伪页展示的活动入口</el-button>
                     </el-input>
                  </el-form-item> -->
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button size="mini" @click="submit" type="primary"  :loading="loading">保存</el-button>
                <el-button size="mini" @click="dialogVisible = false">取消</el-button>
            </div>
        </el-dialog>
        <proActivity-selected  :show.sync ='selectedDialog.show' :title="selectedDialog.title" :multipleSelected="false">
            <el-table-column>
                  <template slot-scope="scope">
                    <el-button type="success" @click="choiceActive(scope.row)" size="mini">添加</el-button>
                  </template>
            </el-table-column>
        </proActivity-selected>
    </div>
</template>
<script>
import proActivitySelected from '@/views/codeMgt/components/proActivitySelected.vue'
import QRCodeApi from '@/api/QRCode'
export default {
  components: { proActivitySelected },
  props: {
    show: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: '添加批次'
    }
  },
  data () {
    return {
      selectedDialog: {
        show: false,
        title: '选择活动'
      },
      dialogVisible: false,
      form: {
        batchName: null,
        batchDesc: null,
        promotionName: null,
        batchPromotion: null
      },
      formRules: {
        batchName: [{ required: true, message: '请输入批次名称', trigger: 'blur' },
          { max: 100, message: '批次名称最多只能输入 100 个字', trigger: 'blur' }
        ],
        batchDesc: [
          { required: true, message: '请输入批次描述', trigger: 'blur' },
          { max: 100, message: '批次描述最多只能输入 100 个字' }]
        // promotionName: [{ required: true, message: '请选择关联活动' }]
      },
      loading: false
    }
  },
  watch: {
    /**
     * 监控外部显示变量变化
     * 传递到dialog组件
     */
    show: function (newShow, oldShow) {
      this.dialogVisible = newShow
    },
    /**
     * 监控内部显示属性变化
     * 传递到外部调用变量
     */
    dialogVisible: function (newDialogShow, oldDialogShow) {
      this.$emit('update:show', newDialogShow)
      if (!newDialogShow) {
        for (const key in this.form) {
          this.form[key] = null
        }
      }
    }
  },
  methods: {
    /**
       * 选择活动
       */
    selectedActive () {
      this.selectedDialog.show = true
    },
    // 选择商品
    choiceActive (row) {
      this.form.batchPromotion = row.promotionId
      this.form.promotionName = row.promotionName
      this.selectedDialog.show = false
    },
    /**
       * 提交
       */
    submit () {
      this.$refs.form.validate().then(res => {
        this.addInfo() // 新增推送
      })
    },
    /**
     * 增加活动
     */
    addInfo () {
      this.loading = true
      QRCodeApi.batchAdd(this.form).then(res => {
        if (res.data) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.loading = false
          this.$parent.queryData()
          this.dialogVisible = false
        } else {
          this.loading = false
        }
      }).catch(() => {
        this.loading = false
      })
    }
  }
}
</script>