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
317
318
319
320
321
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.businessPlace" clearable placeholder="营业地" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-input v-model="query.businessContent" clearable placeholder="营业内容" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.businessStatus" filterable clearable placeholder="营业状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[businessStatus]"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <rrOperation :crud="crud" />
      </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="600px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="营业地" prop="businessPlace">
            <el-input v-model="form.businessPlace" style="width: 470px;" />
          </el-form-item>
          <el-form-item label="营业内容" prop="businessContent">
            <el-input v-model="form.businessContent" :rows="3" type="textarea" style="width: 470px;" />
          </el-form-item>
          <el-form-item label="营业状态" prop="businessStatus">
            <el-select v-model="form.businessStatus" filterable placeholder="请选择" style="width: 470px;">
              <el-option
                v-for="item in dict[businessStatus]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-button size="mini" type="primary" icon="el-icon-plus" style="position: relative; left: 464px;" @click="personnelAdd()" />
          <el-table ref="table" :data="form.businessPlanPersonnelDtoList" size="small" style="width: 100%;">
            <el-table-column :show-overflow-tooltip="true" prop="userNickName" label="所属用户" />
            <el-table-column :show-overflow-tooltip="true" prop="businessPlanStartDate" label="营业计划开始日期">
              <template slot-scope="scope">
                {{ crud.toDate(scope.row.businessPlanStartDate) }}
              </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" prop="businessPlanEndDate" label="营业计划结束日期">
              <template slot-scope="scope">
                {{ crud.toDate(scope.row.businessPlanEndDate) }}
              </template>
            </el-table-column>
            <el-table-column label="操作" width="150px" align="center">
              <template slot-scope="scope">
                <el-button size="mini" type="primary" icon="el-icon-edit" @click="personnelEdit(scope.row)" />
                <el-button size="mini" type="danger" icon="el-icon-delete" @click="personnelDelete(scope.row)" />
              </template>
            </el-table-column>
          </el-table>
          <el-form-item label="备注" style="margin-top: 20px;">
            <el-input v-model="form.remarks" :rows="3" type="textarea" style="width: 470px;" />
          </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 type="expand">
          <template slot-scope="props">
            <el-table :data="props.row.businessPlanPersonnelDtoList" style="margin: 10px 20px 10px 105px; width: calc(100% - 20px - 105px);">
              <el-table-column :show-overflow-tooltip="true" prop="userNickName" label="所属用户" />
              <el-table-column :show-overflow-tooltip="true" prop="businessPlanStartDate" label="营业计划开始日期">
                <template slot-scope="scope">
                  {{ crud.toDate(scope.row.businessPlanStartDate) }}
                </template>
              </el-table-column>
              <el-table-column :show-overflow-tooltip="true" prop="businessPlanEndDate" label="营业计划结束日期">
                <template slot-scope="scope">
                  {{ crud.toDate(scope.row.businessPlanEndDate) }}
                </template>
              </el-table-column>
              <el-table-column :show-overflow-tooltip="true" prop="remarks" label="备注" />
            </el-table>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="businessPlace" label="营业地" />
        <el-table-column :show-overflow-tooltip="true" prop="businessContent" label="营业内容" />
        <el-table-column :show-overflow-tooltip="true" prop="businessStatus" label="营业状态">
          <template slot-scope="scope">
            <el-tag>{{ dict.label[businessStatus][scope.row.businessStatus] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="remarks" label="备注" />
        <el-table-column :show-overflow-tooltip="true" prop="createTime" label="创建时间" />
        <el-table-column v-if="checkPer(['admin','businessPlan:edit','businessPlan:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="personnelCancel" :visible.sync="personnelStatus" :title="personnelTitle" width="600px">
        <el-form ref="personnelForm" :model="personnelForm" :rules="personnelRules" size="small" label-width="140px">
          <el-form-item label="所属用户" prop="userId">
            <el-select v-model="personnelForm.userId" placeholder="请选择" filterable clearable style="width: 410px;" @change="personnelFormUserIdChange">
              <el-option
                v-for="item in userList"
                :key="item.id"
                :label="item.nickName"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="营业计划开始日期" prop="businessPlanStartDate">
            <el-date-picker v-model="personnelForm.businessPlanStartDate" type="date" style="width: 410px;" />
          </el-form-item>
          <el-form-item label="营业计划结束日期" prop="businessPlanEndDate">
            <el-date-picker v-model="personnelForm.businessPlanEndDate" type="date" style="width: 410px;" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="personnelForm.remarks" :rows="3" type="textarea" style="width: 410px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="personnelCancel">取消</el-button>
          <el-button :loading="personnelLoading" type="primary" @click="personnelSubmit('personnelForm')">确认</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
 
<script>
import crudBusinessPlan from '@/api/business/plan'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
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 crudUser from '@/api/system/user'
 
const defaultForm = { id: null, businessPlace: null, businessContent: null, businessStatus: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null, businessPlanPersonnelDtoList: [] }
export default {
  name: 'BusinessPlan',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: [constant.BUSINESS_STATUS],
  cruds() {
    return CRUD({ title: '营业计划', url: 'api/businessPlan', idField: 'id', sort: 'id,desc', crudMethod: { ...crudBusinessPlan }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'businessPlan:add'],
        edit: ['admin', 'businessPlan:edit'],
        del: ['admin', 'businessPlan:del'],
        download: ['admin', 'businessPlan:download']
      },
      rules: {
        businessPlace: [
          { required: true, message: '营业地不能为空', trigger: 'blur' },
          { min: 2, max: 100, message: '长度在 2 到 100 个字符', trigger: 'blur' }
        ],
        businessContent: [
          { required: true, message: '营业内容不能为空', trigger: 'blur' }
        ],
        businessStatus: [
          { required: true, message: '营业状态不能为空', trigger: 'change' }
        ]
      },
      queryTypeOptions: [
        { key: 'businessPlace', display_name: '营业地' },
        { key: 'businessContent', display_name: '营业内容' },
        { key: 'businessStatus', display_name: '营业状态' }
      ],
      // 字典:营业状态
      businessStatus: constant.BUSINESS_STATUS,
      // 营业计划人员弹窗状态
      personnelStatus: false,
      // 营业计划人员弹窗标题
      personnelTitle: '营业计划人员',
      // 营业计划人员弹窗表单
      personnelForm: {},
      // 营业计划人员弹窗验证
      personnelRules: {
        businessPlanId: [
          { required: true, message: '所属营业计划不能为空', trigger: 'change' }
        ],
        userId: [
          { required: true, message: '所属用户不能为空', trigger: 'change' }
        ],
        businessPlanStartDate: [
          { required: true, message: '营业计划开始日期不能为空', trigger: 'change' }
        ],
        businessPlanEndDate: [
          { required: true, message: '营业计划结束日期不能为空', trigger: 'change' }
        ]
      },
      // 营业计划人员弹窗操作
      personnelExecute: {},
      // 营业计划人员弹窗加载
      personnelLoading: false,
      // 用户列表
      userList: []
    }
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      // 获取用户
      this.getUser()
      return true
    },
    // 获取用户
    getUser() {
      // 获取用户
      crudUser.getAll().then(res => {
        // 用户列表
        this.userList = res
      })
    },
    // 营业计划人员弹窗用户ID变更
    personnelFormUserIdChange() {
      // 指针重定义
      const _this = this
      // 筛选用户列表
      const personnelInfo = this.userList.filter(function(item) {
        return item.id === _this.personnelForm.userId
      })
      // 营业计划人员弹窗表单
      this.personnelForm.userNickName = personnelInfo[0].nickName
    },
    // 营业计划人员弹窗新增
    personnelAdd() {
      // 指针重定义
      const _this = this
      // 营业计划人员弹窗表单
      this.personnelForm = {}
      // 营业计划人员弹窗状态
      this.personnelStatus = true
      // 营业计划人员弹窗操作
      this.personnelExecute = {}
      // 表单清空
      setTimeout(function() {
        _this.$refs['personnelForm'].clearValidate()
      }, 3)
    },
    // 营业计划人员弹窗修改
    personnelEdit(data) {
      // 营业计划人员弹窗表单
      this.personnelForm = JSON.parse(JSON.stringify(data))
      // 营业计划人员弹窗状态
      this.personnelStatus = true
      // 营业计划人员弹窗操作
      this.personnelExecute = JSON.parse(JSON.stringify(data))
    },
    // 营业计划人员弹窗删除
    personnelDelete(data) {
      // 指针重定义
      const _this = this
      // 筛选营业计划人员
      const personnelInfo = this.crud.form.businessPlanPersonnelDtoList.filter(function(item) {
        return item.userId === data.userId && _this.crud.toDate(item.businessPlanStartDate) === _this.crud.toDate(data.businessPlanStartDate) && _this.crud.toDate(item.businessPlanEndDate) === _this.crud.toDate(data.businessPlanEndDate)
      })
      // 获取下标
      const subscript = this.crud.form.businessPlanPersonnelDtoList.indexOf(personnelInfo[0])
      // 营业计划人员移除元素
      this.crud.form.businessPlanPersonnelDtoList.splice(subscript, 1)
    },
    // 营业计划人员弹窗关闭
    personnelCancel() {
      // 营业计划人员弹窗状态
      this.personnelStatus = false
    },
    // 营业计划人员弹窗提交
    personnelSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // 判断营业计划人员弹窗操作
          if (this.personnelExecute.userId !== undefined) {
            // 营业计划人员弹编辑
            // 指针重定义
            const _this = this
            // 筛选营业计划人员弹
            const personnelInfo = this.crud.form.businessPlanPersonnelDtoList.filter(function(item) {
              return item.userId === _this.personnelExecute.userId && _this.crud.toDate(item.businessPlanStartDate) === _this.crud.toDate(_this.personnelExecute.businessPlanStartDate) && _this.crud.toDate(item.businessPlanEndDate) === _this.crud.toDate(_this.personnelExecute.businessPlanEndDate)
            })
            // 营业计划人员弹更新
            personnelInfo[0].userId = this.personnelForm.userId
            personnelInfo[0].userNickName = this.personnelForm.userNickName
            personnelInfo[0].businessPlanStartDate = this.personnelForm.businessPlanStartDate
            personnelInfo[0].businessPlanEndDate = this.personnelForm.businessPlanEndDate
            personnelInfo[0].remarks = this.personnelForm.remarks
          } else {
            // 营业计划人员新增
            this.crud.form.businessPlanPersonnelDtoList.push(this.personnelForm)
          }
          // 营业计划人员弹窗关闭
          this.personnelCancel()
        } else {
          return false
        }
      })
    }
  }
}
</script>
 
<style scoped>
 
</style>