index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="群活码" prop="liveCodeId">
  5. <el-select v-model="queryParams.liveCodeId" placeholder="请选择群活码" clearable size="small" @change="handleQuery">
  6. <el-option
  7. v-for="item in groupLiveCodeList"
  8. :key="item.id"
  9. :label="item.groupName"
  10. :value="item.id"
  11. />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item label="群名称" prop="groupName">
  15. <el-input
  16. v-model="queryParams.groupName"
  17. placeholder="请输入群名称"
  18. clearable
  19. size="small"
  20. @keyup.enter.native="handleQuery"
  21. />
  22. </el-form-item>
  23. <el-form-item label="状态" prop="status">
  24. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
  25. <el-option label="启用" :value="1" />
  26. <el-option label="停用" :value="0" />
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item>
  30. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  31. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  32. </el-form-item>
  33. </el-form>
  34. <el-row :gutter="10" class="mb8">
  35. <el-col :span="1.5">
  36. <el-button
  37. type="primary"
  38. plain
  39. icon="el-icon-plus"
  40. size="mini"
  41. @click="handleAdd"
  42. >新增</el-button>
  43. </el-col>
  44. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  45. </el-row>
  46. <el-table v-loading="loading" :data="groupActualList" border>
  47. <el-table-column label="群名称" align="center" prop="groupName" />
  48. <el-table-column label="实际群二维码" align="center" prop="groupUrl">
  49. <template slot-scope="scope">
  50. <el-image
  51. v-if="scope.row.groupUrl"
  52. :src="scope.row.groupUrl"
  53. :preview-src-list="[scope.row.groupUrl]"
  54. style="width: 80px; height: 80px;"
  55. />
  56. <span v-else>-</span>
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="分配数" align="center" prop="assignNum" />
  60. <el-table-column label="状态" align="center" prop="status">
  61. <template slot-scope="scope">
  62. <el-tag :type="scope.row.status === 1 ? 'success' : 'danger'">
  63. {{ scope.row.status === 1 ? '启用' : '停用' }}
  64. </el-tag>
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="创建时间" align="center" prop="createTime" />
  68. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  69. <template slot-scope="scope">
  70. <el-button
  71. size="mini"
  72. type="text"
  73. icon="el-icon-edit"
  74. @click="handleUpdate(scope.row)"
  75. >编辑</el-button>
  76. <el-button
  77. size="mini"
  78. type="text"
  79. @click="handleStatusChange(scope.row)"
  80. >{{ scope.row.status === 1 ? '停用' : '启用' }}</el-button>
  81. </template>
  82. </el-table-column>
  83. </el-table>
  84. <pagination
  85. v-show="total>0"
  86. :total="total"
  87. :page.sync="queryParams.pageNum"
  88. :limit.sync="queryParams.pageSize"
  89. @pagination="getList"
  90. />
  91. <!-- 添加或修改群实际码对话框 -->
  92. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body @close="cancel">
  93. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  94. <el-form-item label="群活码" prop="liveCodeId">
  95. <el-select v-model="form.liveCodeId" placeholder="请选择群活码">
  96. <el-option
  97. v-for="item in groupLiveCodeList"
  98. :key="item.id"
  99. :label="item.groupName"
  100. :value="item.id"
  101. />
  102. </el-select>
  103. </el-form-item>
  104. <el-form-item label="群名称" prop="groupName">
  105. <el-input v-model="form.groupName" placeholder="请输入群名称" />
  106. </el-form-item>
  107. <el-form-item label="群二维码" prop="groupUrl">
  108. <image-upload v-model="form.groupUrl" :limit="1" />
  109. </el-form-item>
  110. <el-form-item label="有效期" prop="efficientTime">
  111. <el-date-picker v-model="form.efficientTime" type="date" placeholder="请选择有效期" value-format="yyyy-MM-dd" />
  112. </el-form-item>
  113. <el-form-item label="分配数" prop="assignNum">
  114. <el-input-number v-model="form.assignNum" :min="0" />
  115. </el-form-item>
  116. </el-form>
  117. <div slot="footer" class="dialog-footer">
  118. <el-button type="primary" @click="submitForm">确 定</el-button>
  119. <el-button @click="cancel">取 消</el-button>
  120. </div>
  121. </el-dialog>
  122. </div>
  123. </template>
  124. <script>
  125. import { listGroupActual, getGroupActual, addOrUpdateGroupActual, delGroupActual } from "@/api/qw/groupActual";
  126. import { listGroupLiveCode } from "@/api/qw/groupLiveCode";
  127. import ImageUpload from "@/components/ImageUpload";
  128. export default {
  129. name: "GroupActual",
  130. components: {
  131. ImageUpload
  132. },
  133. data() {
  134. return {
  135. loading: true,
  136. showSearch: true,
  137. total: 0,
  138. groupActualList: [],
  139. groupLiveCodeList: [],
  140. title: "",
  141. open: false,
  142. liveCodeId: null,
  143. queryParams: {
  144. pageNum: 1,
  145. pageSize: 10,
  146. liveCodeId: null,
  147. groupName: null,
  148. status: null,
  149. },
  150. form: {},
  151. rules: {
  152. groupName: [
  153. { required: true, message: "群名称不能为空", trigger: "blur" }
  154. ],
  155. groupUrl: [
  156. { required: true, message: "群二维码不能为空", trigger: "change" }
  157. ],
  158. liveCodeId: [
  159. { required: true, message: "群活码不能为空", trigger: "change" }
  160. ]
  161. }
  162. };
  163. },
  164. created() {
  165. // 从路由参数中获取liveCodeId
  166. this.liveCodeId = this.$route.query.liveCodeId;
  167. // 如果从群活码页面跳转过来,自动设置筛选条件
  168. if (this.liveCodeId) {
  169. this.queryParams.liveCodeId = this.liveCodeId;
  170. }
  171. this.loadGroupLiveCodeList();
  172. this.getList();
  173. },
  174. methods: {
  175. /** 查询群实际码列表 */
  176. getList() {
  177. this.loading = true;
  178. const params = { ...this.queryParams };
  179. if (this.liveCodeId) {
  180. params.liveCodeId = this.liveCodeId;
  181. }
  182. listGroupActual(params).then(response => {
  183. this.groupActualList = response.data.records;
  184. this.total = response.data.total;
  185. this.loading = false;
  186. }).catch(() => {
  187. this.loading = false;
  188. });
  189. },
  190. /** 新增按钮 */
  191. handleAdd() {
  192. this.reset();
  193. // 如果是从群活码页面跳转过来的,新增时自动带入liveCodeId
  194. if (this.liveCodeId) {
  195. this.form.liveCodeId = parseInt(this.liveCodeId);
  196. }
  197. this.loadGroupLiveCodeList();
  198. this.open = true;
  199. this.title = "新增群实际码";
  200. },
  201. /** 加载群活码列表 */
  202. loadGroupLiveCodeList() {
  203. listGroupLiveCode({ pageNum: 1, pageSize: 1000 }).then(response => {
  204. this.groupLiveCodeList = response.data.records;
  205. }).catch(() => {
  206. this.groupLiveCodeList = [];
  207. });
  208. },
  209. // ... existing code ...
  210. handleUpdate(row) {
  211. this.reset();
  212. this.loadGroupLiveCodeList();
  213. this.open = true;
  214. this.title = "修改群实际码";
  215. getGroupActual(row.id).then(response => {
  216. this.form = response.data;
  217. });
  218. },
  219. /** 启用/停用 */
  220. handleStatusChange(row) {
  221. const status = row.status === 1 ? 0 : 1;
  222. const statusText = status === 1 ? "启用" : "停用";
  223. this.$confirm(`确认要${statusText}该群实际码吗?`, "警告", {
  224. confirmButtonText: "确定",
  225. cancelButtonText: "取消",
  226. type: "warning"
  227. }).then(() => {
  228. const data = {
  229. id: row.id,
  230. status: status
  231. };
  232. addOrUpdateGroupActual(data).then(response => {
  233. this.msgSuccess(`${statusText}成功`);
  234. this.getList();
  235. });
  236. }).catch(() => {});
  237. },
  238. /** 表单提交 */
  239. submitForm() {
  240. this.$refs.form.validate(valid => {
  241. if (valid) {
  242. const data = { ...this.form };
  243. // 有效期处理:剆除时間秘,添加默认时間秘 00:00:00
  244. if (data.efficientTime && typeof data.efficientTime === 'string') {
  245. data.efficientTime = data.efficientTime + 'T00:00:00';
  246. }
  247. addOrUpdateGroupActual(data).then(response => {
  248. this.msgSuccess(this.form.id ? "修改成功" : "新增成功");
  249. this.open = false;
  250. this.getList();
  251. });
  252. }
  253. });
  254. },
  255. /** 取消 */
  256. cancel() {
  257. this.open = false;
  258. this.reset();
  259. },
  260. /** 表单重置 */
  261. reset() {
  262. this.form = {
  263. id: null,
  264. liveCodeId: null,
  265. groupName: null,
  266. groupUrl: null,
  267. efficientTime: null,
  268. assignNum: 0,
  269. status: 1
  270. };
  271. this.resetForm("form");
  272. },
  273. /** 搜索 */
  274. handleQuery() {
  275. this.queryParams.pageNum = 1;
  276. this.getList();
  277. },
  278. /** 重置 */
  279. resetQuery() {
  280. this.resetForm("queryForm");
  281. // 重置时,如果是从群活码页面跳转过来的,保留liveCodeId筛选
  282. if (this.liveCodeId) {
  283. this.queryParams.liveCodeId = this.liveCodeId;
  284. }
  285. this.handleQuery();
  286. }
  287. }
  288. };
  289. </script>