doum
2026-01-15 c25fecae568a074e338bce625a92960aca859fb8
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<template>
  <GlobalWindow
      :title="title"
      width="60%"
      :visible.sync="visible"
      :confirm-working="isWorking"
      @confirm="confirm"
  >
    <el-form :model="form" ref="form" :rules="rules" label-width="120px" label-suffix=":" inline>
      <el-form-item label="发放对象" prop="applyType">
        <el-radio-group v-model="form.addType">
          <el-radio :label="0">指定会员</el-radio>
          <el-radio :label="1">指定手机号</el-radio>
          <el-radio :label="2">全部会员</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="form.addType===0" label="选择用户" prop="addMemberIds" >
          <el-select  v-model="form.addMemberIds" placeholder="请输入会员昵称/手机号,再选择" clearable     filterable    remote  reserve-keyword    :remote-method="remoteMethod"
              :loading="searchLoading"
                      style="width: 400px;"
          >
            <el-option
                v-for="item in users"
                :key="item.id"
                :label="item.nickname+'  '+(item.phone||'')"
                :value="item.id">
            </el-option>
          </el-select>
      </el-form-item>
      <el-form-item v-if="form.addType===1" label="指定手机号" prop="addMemberPhones" >
        <el-input  style="width: 400px;"  type="textarea"   v-model="form.addMemberPhones"   placeholder="请输入手机号"   v-trim/>
        <p class="tip-warn" style="margin-bottom: 1px;"><i class="el-icon-warning"></i>提醒:多个手机号,请换行输入</p>
      </el-form-item>
      <el-form-item label="发放内容" prop="num">
        <div  style="border: 1px solid #f2f2f2">
          <el-table style="width: 600px;"  :data="form.addCouponList">
            <el-table-column prop="name" label="优惠券" min-width="300px" align="center">
              <template slot-scope="{row}" >
                <el-select v-model="row.couponId" style="width: 200px;margin: 0px 20px" clearable filterable   placeholder="请选择优惠券"  >
                  <el-option v-for="item in couponList"   :label="item.name"  :value="item.id">  </el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column prop="num" label="数量" min-width="200px" align="center">
              <template slot-scope="{row}" >
                <el-input  style="width: 150px;margin: 0px 20px" type="number"   v-model="row.num"   placeholder="请输入数量"   v-trim/>
              </template>
            </el-table-column>
            <el-table-column  label="操作" min-width="100px" align="center">
              <template slot-scope="scope" >
                <el-button style="color: red;border: none;" @click="delCoupon( scope.$index)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-button s type="primary" icon="el-icon-plus" @click="addCoupon()" style="height: 30px;margin: 10px;">添加</el-button>
        </div>
      </el-form-item>
    </el-form>
    <OperaCouponGoodsWindow ref="OperaCouponGoodsWindow" @success="doSelect"/>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import OperaCouponGoodsWindow from '@/components/business/OperaCouponGoodsWindow'
import { allList } from '@/api/business/coupon'
import { findAll, findAll as memberlist } from '@/api/business/member'
export default {
  name: 'OperaCouponWindow',
  extends: BaseOpera,
  components: { GlobalWindow, OperaCouponGoodsWindow },
  data () {
    const couponRules = (rule, value, callback) => {
      if (!this.form.addCouponList || !this.form.addCouponList.length) {
        callback(new Error('请选择优惠券信息'))
      } else {
        var r = true
        this.form.addCouponList.forEach(item => {
          if (!item.id || !item.num) {
            r = false
          }
        })
        if (!r) {
          callback(new Error('请完善优惠券信息'))
        } else {
          callback()
        }
      }
    }
    return {
      searchLoading: false,
      couponList: [],
      users: [],
      // 表单数据
      form: {
        addType: 0,
        addMemberIds: null,
        addMemberPhones: null,
        addCouponList: [{ id: null, num: null }]
      },
      shops: [],
      categorys: [],
      // 验证规则
      rules: {
        addType: [
          { required: true, message: '请选择发放对象' }
        ],
        addCouponList: [
          { required: true, validator: couponRules, tigger: 'blur' }
        ]
      }
    }
  },
  created () {
    this.config({
      api: '/business/memberCoupon',
      'field.id': 'id'
    })
  },
  methods: {
    remoteMethod (query) {
      if (query !== '') {
        this.searchLoading = true
        findAll({
          capacity: 999,
          model: {
            nickname: query,
            status: 0
          }
        })
          .then(res => {
            this.users = res
          })
          .finally(() => {
            this.searchLoading = false
          })
      }
    },
    getCouponList () {
      allList({status:0})
        .then(res => {
          if (res) {
            this.couponList = res || []
          }
        })
    },
    delCoupon (index) {
      this.form.addCouponList.splice(index, 1)
    },
    addCoupon (type) {
      this.form.addCouponList.push({ id: null, num: null })
    },
    open (title, target, type) {
      this.title = title
      this.visible = true
      this.form.addMemberIds=null
      this.form.addMemberPhones=null
      this.form.addType = 0
      this.form.addCouponList = [{id:null,num:null}]
      this.getCouponList()
    }
  }
}
</script>
 
<style lang="scss" scoped>
@import '@/assets/style/alertstyle.scss';
 
.coupon-rule {
  display: flex;
  .discrep {
    padding: 0 10px;
  }
  ::v-deep .el-input {
    width: 160px;
  }
}
.num-style {
  ::v-deep .el-input-number {
    width: 60%;
  }
}
.date-style {
  ::v-deep input {
    text-align: center !important;
  }
}
::v-deep .el-select {
  width: 100%;
  .el-input__inner {
    width: 100%;
  }
}
 
</style>