yaozc
2023-04-28 bdf99bb9ab8b0250c073e85e4d676c3c745aed8b
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div>
        <!-- 搜索 -->
        <el-select v-model="query.businessPlanId" clearable placeholder="所属营业计划" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in businessPlanList"
            :key="item.id"
            :label="item.businessContent"
            :value="item.id"
          />
        </el-select>
        <el-input
          v-model="query.title"
          clearable
          size="small"
          placeholder="商机标题"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-select v-model="query.classification" filterable clearable placeholder="商机分类" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in classifications"
            :key="item.id"
            :label="item.classification"
            :value="item.classification"
          />
        </el-select>
        <el-input v-model="query.place" clearable placeholder="商机地点" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation />
      </div>
      <!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="110px">
          <el-form-item label="所属营业计划" prop="businessPlanId">
            <el-select v-model="form.businessPlanId" placeholder="请选择" filterable clearable style="width: 340px;">
              <el-option
                v-for="item in businessPlanList"
                :key="item.id"
                :label="item.businessContent"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="商机标题" prop="title">
            <el-input v-model="form.title" style="width: 340px;" />
          </el-form-item>
          <el-form-item label="商机分类" prop="classification">
            <el-autocomplete
              v-model="form.classification"
              class="inline-input"
              :fetch-suggestions="querySearch"
              placeholder="请输入内容"
              style="width: 340px;"
              @select="handleSubmit"
            />
          </el-form-item>
          <el-form-item label="商机地点" prop="place">
            <el-input v-model="form.place" style="width: 340px;" />
          </el-form-item>
          <el-form-item label="商机介绍人">
            <el-input v-model="form.introducer" style="width: 340px;" />
          </el-form-item>
          <el-form-item label="记录时间" prop="recordTime">
            <el-date-picker
              v-model="form.recordTime"
              type="datetime"
              placeholder="选择日期时间"
              style="width: 340px;"
              value-format="yyyy-MM-dd HH:mm:ss"
              align="right"
              default-time="09:00:00"
            />
          </el-form-item>
          <el-form-item label="记录内容">
            <el-input v-model="form.recordContent" type="textarea" rows="3" style="width: 340px;" />
          </el-form-item>
          <el-form-item label="是否提醒" prop="remind">
            <el-select v-model="form.remind" clearable style="width: 340px;" @change="remindChange()">
              <el-option
                v-for="item in dict[dictResourceType]"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item v-if="form.remind === dictResourcesTypeRemind" label="提醒类型" prop="resource">
            <el-radio-group v-model="form.resource" @change="remindChange()">
              <el-radio label="立即提醒" />
              <el-radio label="稍后提醒" />
            </el-radio-group>
          </el-form-item>
          <el-form-item v-if="form.remind === dictResourcesTypeRemind && form.resource === resourceTitle" label="提醒时间" prop="openingTime">
            <el-date-picker
              v-model="form.openingTime"
              type="datetime"
              placeholder="选择日期时间"
              style="width: 340px;"
              value-format="yyyy-MM-dd HH:00:00"
              align="right"
              default-time="09:00:00"
            />
          </el-form-item>
          <el-form-item v-if="form.remind === dictResourcesTypeRemind" label="提醒人" prop="remindPeople">
            <el-select v-model="form.remindPeople" filterable multiple placeholder="请选择人员" style="width: 340px;" @change="change">
              <el-option
                v-for="(item, index) in users"
                :key="index"
                :label="item.nickName"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remarks" type="textarea" rows="3" style="width: 340px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="businessPlanContent" label="所属营业计划" show-overflow-tooltip />
        <el-table-column prop="title" label="商机标题" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.title }}
          </template>
        </el-table-column>
        <el-table-column prop="classification" label="商机分类" show-overflow-tooltip />
        <el-table-column prop="place" label="商机地点" show-overflow-tooltip />
        <el-table-column prop="introducer" label="商机介绍人" show-overflow-tooltip />
        <el-table-column prop="recordTime" label="记录时间" show-overflow-tooltip />
        <el-table-column prop="recordContent" label="记录内容" show-overflow-tooltip />
        <el-table-column prop="openingTime" label="提醒时间" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-if="scope.row.openingTime == null" type="info">{{ '不提醒' }}</el-tag>
            <el-tag v-if="scope.row.openingTime != null">{{ scope.row.openingTime }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="remarks" label="备注" show-overflow-tooltip />
        <el-table-column prop="createTime" label="创建时间" show-overflow-tooltip />
        <el-table-column v-if="checkPer(['admin','customerResources:edit','customerResources:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>
 
<script>
import crudCustomerResources from '@/api/system/customerResources'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import crudUser from '@/api/system/user'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import constant from '@/utils/constant'
import crudBusinessPlan from '@/api/business/plan'
 
const defaultForm = { id: null, title: null, classification: null, recordTime: null, recordContent: null, openingTime: null, businessPlanId: null, place: null, introducer: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null, remind: null, resource: [], remindPeople: [], type: null }
export default {
  name: 'CustomerResources',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  // 数据字典
  dicts: [constant.RESOURCES_TYPE],
  cruds() {
    return CRUD({ title: '营业商机', url: 'api/customerResources', idField: 'id', sort: 'id,desc', crudMethod: { ...crudCustomerResources }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'customerResources:add'],
        edit: ['admin', 'customerResources:edit'],
        del: ['admin', 'customerResources:del'],
        download: ['admin', 'customerResources:download']
      },
      rules: {
        businessPlanId: [
          { required: true, message: '所属营业计划不能为空', trigger: 'change' }
        ],
        title: [
          { required: true, message: '商机标题不能为空', trigger: 'blur' },
          { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
        ],
        classification: [
          { required: true, message: '商机分类不能为空', trigger: 'blur' },
          { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
        ],
        place: [
          { required: true, message: '商机地点不能为空', trigger: 'blur' },
          { min: 2, max: 100, message: '长度在 2 到 100 个字符', trigger: 'blur' }
        ],
        introducer: [
          { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
        ],
        recordTime: [
          { required: true, message: '记录时间不能为空', trigger: 'change' }
        ],
        remind: [
          { required: true, message: '是否提醒不能为空', trigger: 'change' }
        ],
        resource: [
          { required: true, message: '提醒类型不能为空', trigger: 'change' }
        ],
        openingTime: [
          { required: true, message: '提醒时间不能为空', trigger: 'change' }
        ],
        remindPeople: [
          { required: true, message: '提醒人不能为空', trigger: 'change' }
        ]
      },
      dictResourceType: constant.RESOURCES_TYPE,
      dictResourcesTypeRemind: constant.RESOURCES_TYPE_REMIND,
      dictResourcesTypeNoRemind: constant.RESOURCES_TYPE_NOREMIND,
      resourceTitle: '稍后提醒',
      resourceTitles: '立即提醒',
      users: [],
      time: ':00:00',
      remindUsers: [],
      classifications: [],
      restaurants: [],
      state: '',
      timeout: null,
      // 营业计划列表
      businessPlanList: []
    }
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      crudUser.getAll().then(res => {
        this.users = res
      })
      crudCustomerResources.getAll().then(res => {
        this.classifications = res
      })
      // 获取营业计划
      crudBusinessPlan.getAll().then(res => {
        // 营业计划列表
        this.businessPlanList = res
      })
      return true
    },
    // 钩子:编辑之前
    [CRUD.HOOK.beforeToEdit]() {
      if (this.form.openingTime !== null) {
        this.form.remind = this.dictResourcesTypeRemind
        if (this.form.openingTime.substring(13, 19) === this.time) {
          this.form.resource = this.resourceTitle
        } else {
          this.form.resource = this.resourceTitles
        }
        crudCustomerResources.getRemindUser(this.form).then(res => {
          const users = []
          res.forEach(data => {
            users.push(data.id)
          })
          this.form.remindPeople = users
        })
      } else {
        this.form.remind = this.dictResourcesTypeNoRemind
      }
    },
    // 改变时间
    remindChange() {
      this.form.openingTime = null
      this.form.remindPeople = []
    },
    // 多选
    change() {
      this.$forceUpdate()
    },
    handleSubmit() {
    },
    // 输入框获取焦点时调用的方法
    querySearch(queryString, cb) {
      let results = []
      if (queryString === null || queryString === '') {
        cb(results)
      } else {
        results = this.classifications
        results = queryString ? results.filter(this.createFilter(queryString)) : results
        cb(results)
      }
    },
    createFilter(queryString) {
      return (item) => {
        item.value = item.classification
        return item.value.toUpperCase().match(queryString.toUpperCase())
      }
    }
  }
}
</script>
 
<style scoped>
 
</style>