indexhdt.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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="companyId" >-->
  5. <!-- <el-select v-model="queryParams.companyId" placeholder="请选择所属公司" filterable clearable size="small">-->
  6. <!-- <el-option v-for="(option, index) in companyList" :key="index" :value="option.dictValue" :label="option.dictLabel"></el-option>-->
  7. <!-- </el-select>-->
  8. <!-- </el-form-item>-->
  9. <el-form-item label="项目" prop="project">
  10. <el-select v-model="queryParams.project" placeholder="请选择项目" filterable clearable size="small">
  11. <el-option
  12. v-for="dict in projectOptions"
  13. :key="dict.dictValue"
  14. :label="dict.dictLabel"
  15. :value="dict.dictValue"
  16. />
  17. </el-select>
  18. </el-form-item>
  19. <!-- <el-form-item label="课程" prop="courseId">-->
  20. <!-- <el-select filterable v-model="queryParams.courseId" placeholder="请选择课程" clearable size="small" @change="courseChange(queryParams.courseId)">-->
  21. <!-- <el-option-->
  22. <!-- v-for="dict in courseLists"-->
  23. <!-- :key="dict.dictValue"-->
  24. <!-- :label="dict.dictLabel"-->
  25. <!-- :value="dict.dictValue"-->
  26. <!-- />-->
  27. <!-- </el-select>-->
  28. <!-- </el-form-item>-->
  29. <el-form-item label="年月" prop="time">
  30. <el-date-picker
  31. v-model="time"
  32. type="daterange"
  33. placeholder="选择年月"
  34. :picker-options="pickerOptions"
  35. :value-format="'yyyy-MM-dd'"
  36. @change="handleDateData"
  37. ></el-date-picker>
  38. </el-form-item>
  39. <el-form-item>
  40. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  41. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  42. </el-form-item>
  43. </el-form>
  44. <el-row :gutter="10" class="mb8">
  45. <el-col :span="1.5">
  46. <el-button
  47. type="warning"
  48. plain
  49. icon="el-icon-download"
  50. size="mini"
  51. :loading="exportLoading"
  52. @click="handleExport"
  53. v-hasPermi="['course:courseTrafficLog:export']"
  54. >导出</el-button>
  55. </el-col>
  56. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  57. </el-row>
  58. <el-table border v-loading="loading" :data="courseTrafficLogList" @selection-change="handleSelectionChange" show-summary :summary-method="getSummaries">
  59. <el-table-column type="selection" width="55" align="center" />
  60. <el-table-column label="项目" align="center" prop="projectName" />
  61. <el-table-column label="日期" align="center" prop="month" />
  62. <el-table-column label="使用流量" align="center" prop="totalInternetTraffic">
  63. <template slot-scope="scope">
  64. <span>{{ formatTrafficData(scope.row.totalInternetTraffic) }}</span>
  65. </template>
  66. </el-table-column>
  67. <!-- <el-table-column label="费用" align="center">-->
  68. <!-- <template slot-scope="scope">-->
  69. <!-- <span>{{ formatTrafficMoney(scope.row.totalInternetTraffic) }}</span>-->
  70. <!-- </template>-->
  71. <!-- </el-table-column>-->
  72. </el-table>
  73. <pagination
  74. v-show="total>0"
  75. :total="total"
  76. :page.sync="queryParams.pageNum"
  77. :limit.sync="queryParams.pageSize"
  78. @pagination="getList"
  79. />
  80. </div>
  81. </template>
  82. <script>
  83. import { listCourseTrafficLog, getCourseTrafficLog, delCourseTrafficLog, addCourseTrafficLog, updateCourseTrafficLog, exportCourseTrafficLog } from "@/api/course/courseTrafficLog";
  84. import {courseList} from "@/api/course/courseRedPacketLog";
  85. import {allList}from "@/api/company/company";
  86. export default {
  87. name: "CourseTrafficLog",
  88. data() {
  89. return {
  90. pickerOptions: {
  91. shortcuts: [{
  92. text: '最近一周',
  93. onClick(picker) {
  94. const end = new Date();
  95. const start = new Date();
  96. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  97. picker.$emit('pick', [start, end]);
  98. }
  99. }]
  100. },
  101. companyList:[],
  102. // 遮罩层
  103. loading: false,
  104. // 导出遮罩层
  105. exportLoading: false,
  106. // 选中数组
  107. ids: [],
  108. // 非单个禁用
  109. single: true,
  110. // 非多个禁用
  111. multiple: true,
  112. // 显示搜索条件
  113. showSearch: true,
  114. // 总条数
  115. total: 0,
  116. // 短链课程流量记录表格数据
  117. courseTrafficLogList: [],
  118. projectOptions:[],
  119. courseLists:[],
  120. // 弹出层标题
  121. title: "",
  122. // 是否显示弹出层
  123. open: false,
  124. time: null,
  125. // 查询参数
  126. queryParams: {
  127. startDate: null,
  128. endDate: null,
  129. pageNum: 1,
  130. pageSize: 10,
  131. userId: null,
  132. videoId: null,
  133. qwExternalContactId: null,
  134. internetTraffic: null,
  135. qwUserId: null,
  136. companyUserId: null,
  137. companyId: null,
  138. courseId: null,
  139. tabType: 'project',
  140. typeFlag:0
  141. },
  142. // 表单参数
  143. form: {},
  144. // 表单校验
  145. rules: {
  146. }
  147. };
  148. },
  149. created() {
  150. courseList().then(response => {
  151. this.courseLists = response.list;
  152. });
  153. this.getDicts("sys_course_project").then(response => {
  154. this.projectOptions = response.data;
  155. });
  156. this.getAllCompany();
  157. },
  158. methods: {
  159. getSummaries(param) {
  160. const { columns, data } = param;
  161. const sums = [];
  162. columns.forEach((column, index) => {
  163. if (index === 0) {
  164. sums[index] = '合计';
  165. return;
  166. }
  167. if (column.property === 'totalInternetTraffic') {
  168. const values = data.map(item => Number(item.totalInternetTraffic));
  169. const total = values.reduce((acc, curr) => acc + curr, 0);
  170. sums[index] = this.formatTrafficData(total);
  171. } else {
  172. sums[index] = '';
  173. }
  174. });
  175. return sums;
  176. },
  177. handleDateData(){
  178. if (this.time) {
  179. this.queryParams.startDate = this.time[0];
  180. this.queryParams.endDate = this.time[1];
  181. } else {
  182. this.queryParams.startDate = null;
  183. this.queryParams.endDate = null;
  184. }
  185. },
  186. getAllCompany() {
  187. allList().then(response => {
  188. this.companyList = response.rows;
  189. });
  190. },
  191. formatTrafficData(traffic) {
  192. if (traffic < 1024) { // Less than 1 KB
  193. return traffic + ' B';
  194. } else if (traffic < 1024 * 1024) { // Less than 1 MB
  195. return (traffic / 1024).toFixed(2) + ' KB';
  196. } else if (traffic < 1024 * 1024 * 1024) { // Less than 1 GB
  197. return (traffic / (1024 * 1024)).toFixed(2) + ' MB';
  198. } else { // More than 1 GB
  199. return (traffic / (1024 * 1024 * 1024)).toFixed(2) + ' GB';
  200. }
  201. },
  202. formatTrafficMoney(traffic){
  203. return (traffic / (1024 * 1024 * 1024) * 0.095).toFixed(2) + ' 元'
  204. },
  205. handleShortcut() {
  206. this.queryParams.time = new Date().toISOString().slice(0, 7);
  207. },
  208. /** 查询短链课程流量记录列表 */
  209. getList() {
  210. this.loading = true;
  211. listCourseTrafficLog(this.queryParams).then(response => {
  212. this.courseTrafficLogList = response.rows;
  213. this.total = response.total;
  214. this.loading = false;
  215. }).finally(()=>{
  216. this.loading = false;
  217. })
  218. },
  219. // 取消按钮
  220. cancel() {
  221. this.open = false;
  222. this.reset();
  223. },
  224. // 表单重置
  225. reset() {
  226. this.form = {
  227. logId: null,
  228. userId: null,
  229. videoId: null,
  230. createTime: null,
  231. qwExternalContactId: null,
  232. internetTraffic: null,
  233. qwUserId: null,
  234. companyUserId: null,
  235. companyId: null,
  236. courseId: null
  237. };
  238. this.resetForm("form");
  239. },
  240. /** 搜索按钮操作 */
  241. handleQuery() {
  242. this.queryParams.pageNum = 1;
  243. this.getList();
  244. },
  245. /** 重置按钮操作 */
  246. resetQuery() {
  247. this.resetForm("queryForm");
  248. this.handleQuery();
  249. },
  250. // 多选框选中数据
  251. handleSelectionChange(selection) {
  252. this.ids = selection.map(item => item.logId)
  253. this.single = selection.length!==1
  254. this.multiple = !selection.length
  255. },
  256. /** 新增按钮操作 */
  257. handleAdd() {
  258. this.reset();
  259. this.open = true;
  260. this.title = "添加短链课程流量记录";
  261. },
  262. /** 修改按钮操作 */
  263. handleUpdate(row) {
  264. this.reset();
  265. const logId = row.logId || this.ids
  266. getCourseTrafficLog(logId).then(response => {
  267. this.form = response.data;
  268. this.open = true;
  269. this.title = "修改短链课程流量记录";
  270. });
  271. },
  272. /** 提交按钮 */
  273. submitForm() {
  274. this.$refs["form"].validate(valid => {
  275. if (valid) {
  276. if (this.form.logId != null) {
  277. updateCourseTrafficLog(this.form).then(response => {
  278. this.msgSuccess("修改成功");
  279. this.open = false;
  280. this.getList();
  281. });
  282. } else {
  283. addCourseTrafficLog(this.form).then(response => {
  284. this.msgSuccess("新增成功");
  285. this.open = false;
  286. this.getList();
  287. });
  288. }
  289. }
  290. });
  291. },
  292. /** 删除按钮操作 */
  293. handleDelete(row) {
  294. const logIds = row.logId || this.ids;
  295. this.$confirm('是否确认删除短链课程流量记录编号为"' + logIds + '"的数据项?', "警告", {
  296. confirmButtonText: "确定",
  297. cancelButtonText: "取消",
  298. type: "warning"
  299. }).then(function() {
  300. return delCourseTrafficLog(logIds);
  301. }).then(() => {
  302. this.getList();
  303. this.msgSuccess("删除成功");
  304. }).catch(() => {});
  305. },
  306. /** 导出按钮操作 */
  307. handleExport() {
  308. const queryParams = this.queryParams;
  309. this.$confirm('是否确认导出所有短链课程流量记录数据项?', "警告", {
  310. confirmButtonText: "确定",
  311. cancelButtonText: "取消",
  312. type: "warning"
  313. }).then(() => {
  314. this.exportLoading = true;
  315. return exportCourseTrafficLog(queryParams);
  316. }).then(response => {
  317. this.download(response.msg);
  318. this.exportLoading = false;
  319. }).catch(() => {});
  320. }
  321. }
  322. };
  323. </script>