peng
2026-03-18 b89df58e3b783f3d718bd85a3e4c6a3bd9ee353c
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<template>
  <a-modal
    :title="title"
    :width="drawerWidth"
    :visible="visible"
    @cancel="close"
    @ok="handleSubmit"
    style="overflow: auto; padding-bottom: 53px"
  >
    <a-spin :spinning="confirmLoading">
      <div>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="客户类型">
          <a-input
            style="width: 300px"
            :disabled="clientConfigsList.id == 1 || clientConfigsList.id == 2"
            placeholder="请输入客户类型"
            v-model="clientConfigsList.clientName"
          ></a-input>
        </a-form-item>
        <div v-for="(subItem, subIndex) in clientConfigsList.clientConfigs" :key="subIndex">
          <div style="display: flex">
            <div>条件{{ subIndex + 1 }}:</div>
            <a-popconfirm
              v-show="clientConfigsList.clientConfigs.length > 1"
              title="确定删除?"
              ok-text="确认"
              cancel-text="取消"
              @confirm="delConditions(subIndex)"
            >
              <a style="color: red" href="#">删除</a>
            </a-popconfirm>
          </div>
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="时间范围">
            <a-select
              style="width: 300px"
              v-model="subItem.timeStr"
              @change="timeChange($event, subIndex)"
              placeholder="请选择"
            >
              <a-select-option value="7,DAYS"> 近7天 </a-select-option>
              <a-select-option value="30,DAYS"> 近30天 </a-select-option>
              <a-select-option value="3,MONTHS"> 近3月 </a-select-option>
              <a-select-option value="6,MONTHS"> 近6月 </a-select-option>
              <a-select-option value="1,YEARS"> 近1年 </a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="加油频次">
            <a-select
              :disabled="subItem.timeStr == '7,DAYS' || subItem.timeStr == '30,DAYS'"
              style="width: 300px"
              v-model="subItem.countType"
              placeholder="请选择"
            >
              <a-select-option :value="1"> 累计 </a-select-option>
              <a-select-option :value="2"> 每月 </a-select-option>
            </a-select>
            <div style="display: flex">
              <a-select style="width: 150px" v-model="subItem.countRef" placeholder="请选择">
                <a-select-option :value="1"> 大于 </a-select-option>
                <a-select-option :value="0"> 等于 </a-select-option>
                <a-select-option :value="-1"> 小于 </a-select-option>
              </a-select>
              <a-input
                style="width: 150px"
                placeholder="请输入次数"
                onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
                onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}"
                v-model="subItem.countNum"
              ></a-input>
            </div>
          </a-form-item>
        </div>
        <div style="text-align: center">
          <a-button type="primary" @click="addConditions"> 增加条件 </a-button>
        </div>
      </div>
    </a-spin>
  </a-modal>
</template>
 
<script>
import pick from 'lodash.pick'
import { postAction, putAction } from '@tievd/cube-block/lib/api/manage'
import moment from 'moment'
 
export default {
  name: 'ActivityModal',
 
  data() {
    return {
      form: this.$form.createForm(this),
      title: '操作',
      visible: false,
      drawerWidth: 700,
      model: {},
      validatorRules: {
        clientName: {
          rules: [{ required: true, message: '活动名称不能为空' }],
        },
      },
      clientConfigsList: [
        {
          clientName: '',
          clientConfigs: [],
        },
      ],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      orgCodes: '',
      confirmLoading: false,
    }
  },
 
  methods: {
    moment,
    //删除条件
    delConditions(index) {
      console.log(index)
      this.clientConfigsList.clientConfigs.splice(index, 1)
    },
    timeChange(e, index) {
      if (e == '7,DAYS' || e == '30,DAYS') {
        this.clientConfigsList.clientConfigs[index].countType = 1
      }
    },
    //新增条件
    addConditions(index) {
      console.log(index)
      this.clientConfigsList.clientConfigs.push({})
    },
    disabledDate(current) {
      // Can not select days before today and today
 
      return current && current < moment().startOf('day')
    },
    // 根据屏幕变化,设置抽屉尺寸
    resetScreenSize() {
      let screenWidth = document.body.clientWidth
      if (screenWidth < 500) {
        this.drawerWidth = screenWidth
      } else {
        this.drawerWidth = 700
      }
    },
    add() {
      this.edit({
        clientName: '',
        clientConfigs: [{}],
      })
    },
    edit(record) {
      console.log(record)
      this.resetScreenSize() // 调用此方法,根据屏幕宽度自适应调整抽屉的宽度
      this.form.resetFields()
      // if (record.id !== undefined) {
      //  // 新增编辑的特殊操作写在这里
      // }
      this.visible = true
      this.model = Object.assign({}, record)
      this.clientConfigsList = record
    },
    close() {
      this.$emit('close')
      this.visible = false
      this.disableSubmit = false
      this.model = {}
      this.orgCodes = ''
    },
    handleSubmit() {
      console.log(this.clientConfigsList)
      if (this.clientConfigsList.clientName.length == 0) {
        this.$message.error('请填写客户类型')
        return
      }
      var isEmpty = false
      this.clientConfigsList.clientConfigs.map((el) => {
        if (JSON.stringify(el) == '{}') {
          isEmpty = true
        }
        for (let k in el) {
          if (el[k] == '' || el[k].length == '0') {
            isEmpty = true
          }
        }
        if (!el.timeStr || !el.countRef || !el.countType || !el.countNum) {
          isEmpty = true
          if (el.countRef == 0 || el.countNum == 0) {
            isEmpty = false
          }
        }
      })
      if (isEmpty) {
        this.$message.error('请完整填写数据')
        return
      }
 
      // 触发表单验证
      this.form.validateFields(async (err, values) => {
        if (!err) {
          try {
            this.confirmLoading = true
            let formData = Object.assign(this.clientConfigsList, values)
            let res = null
            if (!this.model.id) {
              // 新增
              res = await postAction('/jyz/clientConfig/add', formData)
            } else {
              // 编辑
              res = await putAction('/jyz/clientConfig/edit', formData)
            }
            if (res.success) {
              this.$message.success(res.message)
              this.$emit('ok')
            }
          } catch (err) {
            this.$message.error(err.message)
          } finally {
            this.confirmLoading = false
            this.close()
          }
        }
      })
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>
 
<style scoped lang="less"></style>