index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
  4. <el-form-item label="规则名称" prop="ruleName">
  5. <el-input
  6. v-model="queryParams.ruleName"
  7. placeholder="请输入规则名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="状态" prop="status">
  14. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
  15. <el-option label="启用" :value="1" />
  16. <el-option label="停用" :value="0" />
  17. </el-select>
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  21. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  22. </el-form-item>
  23. </el-form>
  24. <el-row :gutter="10" class="mb8">
  25. <el-col :span="1.5">
  26. <el-button
  27. type="primary"
  28. plain
  29. icon="el-icon-plus"
  30. size="mini"
  31. @click="handleAdd"
  32. >新增</el-button>
  33. </el-col>
  34. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  35. </el-row>
  36. <el-table v-loading="loading" :data="assignRuleList" border>
  37. <el-table-column label="规则名称" align="center" prop="ruleName" />
  38. <el-table-column label="分配类型" align="center" prop="assignType">
  39. <template slot-scope="scope">
  40. <span v-if="scope.row.assignType === 1">轮询</span>
  41. <span v-else-if="scope.row.assignType === 2">依次</span>
  42. <span v-else-if="scope.row.assignType === 3">按权重</span>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="员工数" align="center" prop="qwAssignRuleUsers">
  46. <template slot-scope="scope">
  47. {{ scope.row.qwAssignRuleUsers && Array.isArray(scope.row.qwAssignRuleUsers) ? scope.row.qwAssignRuleUsers.length : 0 }}
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="状态" align="center" prop="status">
  51. <template slot-scope="scope">
  52. <el-tag :type="scope.row.status === 1 ? 'success' : 'danger'">
  53. {{ scope.row.status === 1 ? '启用' : '停用' }}
  54. </el-tag>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="创建时间" align="center" prop="createTime" />
  58. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="280px">
  59. <template slot-scope="scope">
  60. <el-button
  61. size="mini"
  62. type="text"
  63. icon="el-icon-edit"
  64. @click="handleUpdate(scope.row)"
  65. >编辑</el-button>
  66. <el-button
  67. size="mini"
  68. type="text"
  69. @click="handleStatusChange(scope.row)"
  70. >{{ scope.row.status === 1 ? '停用' : '启用' }}</el-button>
  71. <el-button
  72. size="mini"
  73. type="text"
  74. @click="handleDetails(scope.row)"
  75. >分配详情</el-button>
  76. </template>
  77. </el-table-column>
  78. </el-table>
  79. <pagination
  80. v-show="total>0"
  81. :total="total"
  82. :page.sync="queryParams.pageNum"
  83. :limit.sync="queryParams.pageSize"
  84. @pagination="getList"
  85. />
  86. <!-- 添加或修改分配规则对话框 -->
  87. <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body @close="cancel">
  88. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  89. <el-form-item label="规则名称" prop="ruleName">
  90. <el-input v-model="form.ruleName" placeholder="请输入规则名称" />
  91. </el-form-item>
  92. <el-form-item label="分配类型" prop="assignType">
  93. <el-radio-group v-model="form.assignType">
  94. <el-radio :label="3">按权重</el-radio>
  95. </el-radio-group>
  96. </el-form-item>
  97. <el-form-item label="选择员工" prop="qwAssignRuleUsers" style="margin-top: 2%">
  98. <div>
  99. <el-button
  100. size="medium"
  101. icon="el-icon-circle-plus-outline"
  102. plain
  103. @click="handleSelectUser">请选择使用员工</el-button>
  104. </div>
  105. <div style="margin-top: 10px;">
  106. <el-table :data="personnelList" border size="small" style="margin-top: 10px;">
  107. <el-table-column label="企微号" align="center" prop="qwUserId" width="120px" />
  108. <el-table-column label="企微姓名" align="center" prop="qwUserName" width="120px" />
  109. <el-table-column label="权重数" align="center" width="100px">
  110. <template slot-scope="scope">
  111. <el-input v-model.number="scope.row.weight" type="number" size="small" />
  112. </template>
  113. </el-table-column>
  114. <el-table-column label="操作" align="center" width="80px">
  115. <template slot-scope="scope">
  116. <el-button type="danger" size="mini" icon="el-icon-delete" @click="handleRemovePersonnel(scope.row)"></el-button>
  117. </template>
  118. </el-table-column>
  119. </el-table>
  120. </div>
  121. </el-form-item>
  122. </el-form>
  123. <div slot="footer" class="dialog-footer">
  124. <el-button type="primary" @click="submitForm">确 定</el-button>
  125. <el-button @click="cancel">取 消</el-button>
  126. </div>
  127. </el-dialog>
  128. <!-- 分配详情对话框 -->
  129. <el-dialog title="分配详情" :visible.sync="detailsOpen" width="900px" append-to-body>
  130. <el-table :data="detailsPersonnelList" border style="margin-bottom: 20px;">
  131. <el-table-column label="企微号" align="center" prop="qwUserId" />
  132. <el-table-column label="企微姓名" align="center" prop="qwUserName" />
  133. <el-table-column label="权重数" align="center" prop="weight" />
  134. <el-table-column label="今日分配数" align="center" prop="assignNumToDay" />
  135. <el-table-column label="累积分配数" align="center" prop="assignNumCount" />
  136. <el-table-column label="今日添加数" align="center" prop="addNumToDay" />
  137. <el-table-column label="累积添加数" align="center" prop="addNumCount" />
  138. </el-table>
  139. </el-dialog>
  140. <!-- 选择员工对话框 -->
  141. <el-dialog :title="selectUserDialog.title" :visible.sync="selectUserDialog.open" width="1300px" append-to-body>
  142. <qwUserList ref="QwUserList" @selectUserList="selectUserList"></qwUserList>
  143. </el-dialog>
  144. </div>
  145. </template>
  146. <script>
  147. import { listAssignRule, getAssignRule, addOrUpdateAssignRule, enableAssignRule } from "@/api/qw/assignRule";
  148. import qwUserList from '@/views/qw/user/qwUserList.vue'
  149. export default {
  150. name: "AssignRule",
  151. components: { qwUserList },
  152. data() {
  153. return {
  154. loading: true,
  155. showSearch: true,
  156. total: 0,
  157. assignRuleList: [],
  158. title: "",
  159. open: false,
  160. detailsOpen: false,
  161. detailsPersonnelList: [],
  162. queryParams: {
  163. pageNum: 1,
  164. pageSize: 10,
  165. ruleName: null,
  166. status: null,
  167. },
  168. form: {
  169. assignType: 3,
  170. qwAssignRuleUsers: null
  171. },
  172. personnelList: [],
  173. selectUserDialog: {
  174. title: "选择员工",
  175. open: false
  176. },
  177. rules: {
  178. ruleName: [
  179. { required: true, message: "规则名称不能为空", trigger: "blur" }
  180. ]
  181. },
  182. };
  183. },
  184. created() {
  185. this.getList();
  186. },
  187. methods: {
  188. /** 查询分配规则列表 */
  189. getList() {
  190. this.loading = true;
  191. listAssignRule(this.queryParams).then(response => {
  192. this.assignRuleList = response.data.records;
  193. this.total = response.data.total;
  194. this.loading = false;
  195. }).catch(() => {
  196. this.loading = false;
  197. });
  198. },
  199. // ... existing code ...
  200. /** 新增按钮 */
  201. handleAdd() {
  202. this.reset();
  203. this.open = true;
  204. this.title = "新增分配规则";
  205. },
  206. /** 修改按钮 */
  207. handleUpdate(row) {
  208. this.reset();
  209. this.open = true;
  210. this.title = "修改分配规则";
  211. getAssignRule(row.id).then(response => {
  212. this.form = response.data;
  213. if (this.form.qwAssignRuleUsers && Array.isArray(this.form.qwAssignRuleUsers)) {
  214. this.personnelList = this.form.qwAssignRuleUsers;
  215. }
  216. });
  217. },
  218. /** 启用/停用 */
  219. handleStatusChange(row) {
  220. const status = row.status === 1 ? 0 : 1;
  221. const statusText = status === 1 ? "启用" : "停用";
  222. this.$confirm(`确认要${statusText}该分配规则吗?`, "警告", {
  223. confirmButtonText: "确定",
  224. cancelButtonText: "取消",
  225. type: "warning"
  226. }).then(() => {
  227. enableAssignRule(row.id, status).then(response => {
  228. this.msgSuccess(`${statusText}成功`);
  229. this.getList();
  230. });
  231. }).catch(() => {});
  232. },
  233. /** 分配详情 */
  234. handleDetails(row) {
  235. if (row.qwAssignRuleUsers && Array.isArray(row.qwAssignRuleUsers)) {
  236. this.detailsPersonnelList = row.qwAssignRuleUsers;
  237. } else {
  238. this.detailsPersonnelList = [];
  239. }
  240. this.detailsOpen = true;
  241. },
  242. /** 选择员工 */
  243. handleSelectUser() {
  244. this.selectUserDialog.open = true;
  245. this.$nextTick(() => {
  246. this.$refs.QwUserList.getDetails(null, null, null, null);
  247. });
  248. },
  249. /** 接收选中的员工 */
  250. selectUserList(selectUsers) {
  251. this.selectUserDialog.open = false;
  252. if (selectUsers && selectUsers.length > 0) {
  253. selectUsers.forEach(user => {
  254. const exists = this.personnelList.find(p => p.sysQwUserId === user.id);
  255. if (!exists) {
  256. this.personnelList.push({
  257. assignId: this.form.id || null,
  258. sysQwUserId: user.id,
  259. qwUserName: user.qwUserName,
  260. qwUserId: user.qwUserId,
  261. weight: 1,
  262. assignNumToDay: 0,
  263. assignNumCount: 0,
  264. addNumToDay: 0,
  265. addNumCount: 0
  266. });
  267. }
  268. });
  269. }
  270. },
  271. /** 移除员工 */
  272. handleRemovePersonnel(item) {
  273. const index = this.personnelList.findIndex(p => p.qwUserId === item.qwUserId);
  274. if (index > -1) {
  275. this.personnelList.splice(index, 1);
  276. }
  277. },
  278. /** 表单提交 */
  279. submitForm() {
  280. this.$refs.form.validate(valid => {
  281. if (valid) {
  282. if (this.personnelList.length === 0) {
  283. this.$message.error("请选择至少一个员工");
  284. return;
  285. }
  286. // 准备发送的数据,包含 weight
  287. const submitPersonnelList = this.personnelList.map(p => ({
  288. assignId: this.form.id || null,
  289. sysQwUserId: p.sysQwUserId,
  290. qwUserName: p.qwUserName,
  291. qwUserId: p.qwUserId,
  292. weight: p.weight
  293. }));
  294. const data = {
  295. ...this.form,
  296. qwAssignRuleUsers: submitPersonnelList
  297. };
  298. addOrUpdateAssignRule(data).then(response => {
  299. this.msgSuccess(this.form.id ? "修改成功" : "新增成功");
  300. this.open = false;
  301. this.getList();
  302. });
  303. }
  304. });
  305. },
  306. /** 取消 */
  307. cancel() {
  308. this.open = false;
  309. this.reset();
  310. },
  311. /** 表单重置 */
  312. reset() {
  313. this.form = {
  314. id: null,
  315. ruleName: null,
  316. assignType: 3,
  317. qwAssignRuleUsers: null,
  318. status: 1
  319. };
  320. this.personnelList = [];
  321. this.resetForm("form");
  322. },
  323. /** 搜索 */
  324. handleQuery() {
  325. this.queryParams.pageNum = 1;
  326. this.getList();
  327. },
  328. /** 重置 */
  329. resetQuery() {
  330. this.resetForm("queryForm");
  331. this.handleQuery();
  332. }
  333. }
  334. };
  335. </script>