index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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="companyName">
  5. <el-input
  6. v-model="queryParams.companyName"
  7. placeholder="请输入公司名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="显示状态" prop="liveShow">
  14. <el-select
  15. v-model="queryParams.liveShow"
  16. placeholder="请选择显示状态"
  17. clearable
  18. size="small"
  19. style="width: 150px"
  20. >
  21. <el-option label="展示" :value="1"></el-option>
  22. <el-option label="不展示" :value="0"></el-option>
  23. </el-select>
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  27. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  28. </el-form-item>
  29. </el-form>
  30. <el-row :gutter="10" class="mb8">
  31. <el-col :span="3">
  32. <el-select
  33. v-model="batchLiveShow"
  34. placeholder="批量操作"
  35. size="mini"
  36. style="width: 120px"
  37. :disabled="selectedCompanyIds.length === 0"
  38. @change="handleBatchUpdateLiveShow"
  39. >
  40. <el-option label="批量展示" :value="1"></el-option>
  41. <el-option label="批量不展示" :value="0"></el-option>
  42. </el-select>
  43. </el-col>
  44. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  45. </el-row>
  46. <el-table v-loading="loading" :data="companyList" @selection-change="handleSelectionChange">
  47. <el-table-column
  48. type="selection"
  49. width="55"
  50. align="center"
  51. />
  52. <el-table-column label="公司ID" align="center" prop="companyId" width="100" />
  53. <el-table-column label="公司名称" align="center" prop="companyName" />
  54. <el-table-column label="显示状态" align="center" prop="liveShow" width="120">
  55. <template slot-scope="scope">
  56. <el-tag v-if="scope.row.liveShow == 1" type="success">显示</el-tag>
  57. <el-tag v-else type="info">不显示</el-tag>
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
  61. <template slot-scope="scope">
  62. <el-button
  63. size="mini"
  64. type="text"
  65. icon="el-icon-edit"
  66. @click="handleEditLiveShow(scope.row)"
  67. >修改显示状态</el-button>
  68. </template>
  69. </el-table-column>
  70. </el-table>
  71. <pagination
  72. v-show="total>0"
  73. :total="total"
  74. :page.sync="queryParams.pageNum"
  75. :limit.sync="queryParams.pageSize"
  76. @pagination="getList"
  77. />
  78. <!-- 修改显示状态对话框 -->
  79. <el-dialog title="修改显示状态" :visible.sync="editLiveShowDialog" width="500px" append-to-body>
  80. <el-form :model="editLiveShowForm" label-width="100px">
  81. <el-form-item label="公司名称">
  82. <el-input v-model="editLiveShowForm.companyName" :disabled="true" />
  83. </el-form-item>
  84. <el-form-item label="显示状态" prop="liveShow">
  85. <el-select v-model="editLiveShowForm.liveShow" placeholder="请选择显示状态" style="width: 100%">
  86. <el-option label="不展示" :value="0"></el-option>
  87. <el-option label="展示" :value="1"></el-option>
  88. </el-select>
  89. </el-form-item>
  90. </el-form>
  91. <div slot="footer" class="dialog-footer">
  92. <el-button type="primary" @click="submitEditLiveShow">确 定</el-button>
  93. <el-button @click="cancelEditLiveShow">取 消</el-button>
  94. </div>
  95. </el-dialog>
  96. </div>
  97. </template>
  98. <script>
  99. import { liveShowList, batchUpdateCompanyLiveShow } from "@/api/company/company";
  100. export default {
  101. name: "LiveMiniLives",
  102. data() {
  103. return {
  104. // 遮罩层
  105. loading: true,
  106. // 公司列表加载(对话框)
  107. companyLoading: false,
  108. // 选中数组
  109. ids: [],
  110. // 非多个禁用
  111. multiple: true,
  112. // 显示搜索条件
  113. showSearch: true,
  114. // 总条数
  115. total: 0,
  116. // 公司列表总条数(对话框)
  117. companyTotal: 0,
  118. // 公司列表
  119. companyList: [],
  120. // 对话框中的公司列表
  121. dialogCompanyList: [],
  122. // 选中的公司
  123. selectedCompanies: [],
  124. // 是否显示弹出层
  125. open: false,
  126. // 是否显示修改显示状态对话框
  127. editLiveShowDialog: false,
  128. // 修改显示状态表单
  129. editLiveShowForm: {
  130. companyId: null,
  131. companyName: '',
  132. liveShow: 0
  133. },
  134. // 查询参数
  135. queryParams: {
  136. pageNum: 1,
  137. pageSize: 10,
  138. companyName: null,
  139. liveShow: null
  140. },
  141. // 公司查询参数(对话框)
  142. queryCompanyParams: {
  143. pageNum: 1,
  144. pageSize: 10,
  145. companyName: null
  146. },
  147. // 批量操作选中的公司
  148. selectedCompanyIds: [],
  149. // 批量操作显示状态
  150. batchLiveShow: null
  151. };
  152. },
  153. created() {
  154. this.getList();
  155. },
  156. methods: {
  157. /** 查询公司列表 */
  158. getList() {
  159. this.loading = true;
  160. liveShowList(this.queryParams).then(response => {
  161. if (response.code === 200) {
  162. this.companyList = response.rows || [];
  163. this.total = response.total || 0;
  164. } else {
  165. this.companyList = [];
  166. this.total = 0;
  167. }
  168. this.loading = false;
  169. }).catch(() => {
  170. this.companyList = [];
  171. this.total = 0;
  172. this.loading = false;
  173. });
  174. },
  175. /** 查询公司列表(对话框) */
  176. getCompanyList() {
  177. this.companyLoading = true;
  178. liveShowList(this.queryCompanyParams).then(response => {
  179. if (response.code === 200) {
  180. this.dialogCompanyList = response.rows || [];
  181. this.companyTotal = response.total || 0;
  182. } else {
  183. this.dialogCompanyList = [];
  184. this.companyTotal = 0;
  185. }
  186. this.companyLoading = false;
  187. }).catch(() => {
  188. this.dialogCompanyList = [];
  189. this.companyTotal = 0;
  190. this.companyLoading = false;
  191. });
  192. },
  193. /** 搜索按钮操作 */
  194. handleQuery() {
  195. this.queryParams.pageNum = 1;
  196. this.getList();
  197. },
  198. /** 重置按钮操作 */
  199. resetQuery() {
  200. this.resetForm("queryForm");
  201. this.queryParams.companyName = null;
  202. this.queryParams.liveShow = null;
  203. this.handleQuery();
  204. },
  205. /** 公司搜索按钮操作 */
  206. handleCompanyQuery() {
  207. this.queryCompanyParams.pageNum = 1;
  208. this.getCompanyList();
  209. },
  210. // 多选框选中数据
  211. handleSelectionChange(selection) {
  212. // 记录所有选中的公司ID(用于批量操作)
  213. this.selectedCompanyIds = selection.map(item => item.companyId);
  214. // 只记录已绑定(liveShow == 1)的公司ID(用于批量删除)
  215. this.ids = selection.filter(item => item.liveShow == 1).map(item => item.companyId);
  216. // 只有选中了已绑定的公司才能批量删除
  217. this.multiple = this.ids.length === 0;
  218. },
  219. /** 绑定公司按钮操作 */
  220. handleAdd() {
  221. this.open = true;
  222. this.selectedCompanies = [];
  223. this.queryCompanyParams = {
  224. pageNum: 1,
  225. pageSize: 10,
  226. companyName: null
  227. };
  228. this.getCompanyList();
  229. },
  230. /** 取消按钮 */
  231. cancel() {
  232. this.open = false;
  233. this.selectedCompanies = [];
  234. },
  235. /** 检查公司是否已绑定 */
  236. isCompanyBound(company) {
  237. return company.liveShow == 1;
  238. },
  239. /** 检查行是否可选(对话框表格) */
  240. checkSelectable(row) {
  241. // 已绑定的公司(liveShow == 1)不可选
  242. return row.liveShow != 1;
  243. },
  244. /** 打开修改显示状态对话框 */
  245. handleEditLiveShow(row) {
  246. this.editLiveShowForm = {
  247. companyId: row.companyId,
  248. companyName: row.companyName,
  249. liveShow: row.liveShow || 0
  250. };
  251. this.editLiveShowDialog = true;
  252. },
  253. /** 取消修改显示状态 */
  254. cancelEditLiveShow() {
  255. this.editLiveShowDialog = false;
  256. this.editLiveShowForm = {
  257. companyId: null,
  258. companyName: '',
  259. liveShow: 0
  260. };
  261. },
  262. /** 提交修改显示状态 */
  263. submitEditLiveShow() {
  264. if (this.editLiveShowForm.liveShow === null || this.editLiveShowForm.liveShow === undefined) {
  265. this.msgWarning("请选择显示状态");
  266. return;
  267. }
  268. const selectIds=[]
  269. selectIds.push(this.editLiveShowForm.companyId)
  270. const data = {
  271. ids: selectIds,
  272. liveShow: this.editLiveShowForm.liveShow
  273. };
  274. batchUpdateCompanyLiveShow(data).then(response => {
  275. if (response.code === 200) {
  276. this.msgSuccess("修改成功");
  277. this.editLiveShowDialog = false;
  278. this.getList();
  279. } else {
  280. this.msgError(response.msg || "修改失败");
  281. }
  282. }).catch(() => {
  283. this.msgError("修改失败");
  284. });
  285. },
  286. /** 批量修改显示状态 */
  287. handleBatchUpdateLiveShow(value) {
  288. if (value === null || value === undefined) {
  289. return;
  290. }
  291. if (!this.selectedCompanyIds || this.selectedCompanyIds.length === 0) {
  292. this.msgWarning("请先选择要操作的公司");
  293. this.batchLiveShow = null;
  294. return;
  295. }
  296. const statusText = value == 1 ? "展示" : "不展示";
  297. this.$confirm('是否确认将所选' + this.selectedCompanyIds.length + '个公司设置为"' + statusText + '"?', "提示", {
  298. confirmButtonText: "确定",
  299. cancelButtonText: "取消",
  300. type: "warning"
  301. }).then(() => {
  302. const data = {
  303. ids: this.selectedCompanyIds,
  304. liveShow: value
  305. };
  306. batchUpdateCompanyLiveShow(data).then(response => {
  307. if (response.code === 200) {
  308. this.msgSuccess("批量修改成功");
  309. this.batchLiveShow = null;
  310. this.getList();
  311. } else {
  312. this.msgError(response.msg || "批量修改失败");
  313. this.batchLiveShow = null;
  314. }
  315. }).catch(() => {
  316. this.msgError("批量修改失败");
  317. this.batchLiveShow = null;
  318. });
  319. }).catch(() => {
  320. this.batchLiveShow = null;
  321. });
  322. },
  323. }
  324. };
  325. </script>
  326. <style scoped>
  327. ::v-deep .bound-row {
  328. background-color: #f0f9ff;
  329. color: #909399;
  330. }
  331. </style>