index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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="time">
  10. <el-date-picker
  11. v-model="queryParams.time"
  12. type="month"
  13. placeholder="选择年月"
  14. :picker-options="pickerOptions"
  15. :value-format="'yyyy-MM'"
  16. @change="handleTimeChange"
  17. ></el-date-picker>
  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="warning"
  28. plain
  29. icon="el-icon-download"
  30. size="mini"
  31. :loading="exportLoading"
  32. @click="handleExport"
  33. v-hasPermi="['course:courseTrafficLog:export']"
  34. >导出</el-button>
  35. </el-col>
  36. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  37. </el-row>
  38. <el-table border v-loading="loading" :data="courseTrafficLogList" @selection-change="handleSelectionChange">
  39. <el-table-column type="selection" width="55" align="center" />
  40. <el-table-column label="公司名称" align="center" prop="companyName" />
  41. <el-table-column label="月份" align="center" prop="month" />
  42. <el-table-column label="使用流量" align="center">
  43. <template slot-scope="scope">
  44. <span>{{ formatTrafficData(scope.row.totalInternetTraffic) }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="费用" align="center">
  48. <template slot-scope="scope">
  49. <span>{{ formatTrafficMoney(scope.row.totalInternetTraffic) }}</span>
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. <pagination
  54. v-show="total>0"
  55. :total="total"
  56. :page.sync="queryParams.pageNum"
  57. :limit.sync="queryParams.pageSize"
  58. @pagination="getList"
  59. />
  60. </div>
  61. </template>
  62. <script>
  63. import { listCourseTrafficLog, getCourseTrafficLog, delCourseTrafficLog, addCourseTrafficLog, updateCourseTrafficLog, exportCourseTrafficLog } from "@/api/course/courseTrafficLog";
  64. import { allList } from '../../../api/company/company'
  65. export default {
  66. name: "CourseTrafficLog",
  67. data() {
  68. return {
  69. companyList:[],
  70. pickerOptions: {
  71. shortcuts: [{ text: '本月', onClick: () => this.handleShortcut() }],
  72. },
  73. // 遮罩层
  74. loading: true,
  75. // 导出遮罩层
  76. exportLoading: false,
  77. // 选中数组
  78. ids: [],
  79. // 非单个禁用
  80. single: true,
  81. // 非多个禁用
  82. multiple: true,
  83. // 显示搜索条件
  84. showSearch: true,
  85. // 总条数
  86. total: 0,
  87. // 短链课程流量记录表格数据
  88. courseTrafficLogList: [],
  89. // 弹出层标题
  90. title: "",
  91. // 是否显示弹出层
  92. open: false,
  93. // 查询参数
  94. queryParams: {
  95. pageNum: 1,
  96. pageSize: 10,
  97. userId: null,
  98. videoId: null,
  99. qwExternalContactId: null,
  100. internetTraffic: null,
  101. qwUserId: null,
  102. companyUserId: null,
  103. companyId: null,
  104. courseId: null,
  105. time:new Date().getFullYear()+'-'+(new Date().getMonth()+1).toString().padStart(2, '0'),
  106. //本月第一天
  107. startDate: new Date(new Date().getFullYear(), new Date().getMonth(), 1).toLocaleDateString().replaceAll('/','-'),
  108. //本月最后一天
  109. endDate: new Date(new Date().getFullYear(), new Date().getMonth()+1, 0).toLocaleDateString().replaceAll('/','-'),
  110. },
  111. // 表单参数
  112. form: {},
  113. // 表单校验
  114. rules: {
  115. }
  116. };
  117. },
  118. created() {
  119. this.getList();
  120. this.getAllCompany();
  121. },
  122. methods: {
  123. getAllCompany() {
  124. allList().then(response => {
  125. this.companyList = response.rows;
  126. });
  127. },
  128. formatTrafficData(traffic) {
  129. if (traffic < 1024) { // Less than 1 KB
  130. return traffic + ' B';
  131. } else if (traffic < 1024 * 1024) { // Less than 1 MB
  132. return (traffic / 1024).toFixed(2) + ' KB';
  133. } else if (traffic < 1024 * 1024 * 1024) { // Less than 1 GB
  134. return (traffic / (1024 * 1024)).toFixed(2) + ' MB';
  135. } else { // More than 1 GB
  136. return (traffic / (1024 * 1024 * 1024)).toFixed(2) + ' GB';
  137. }
  138. },
  139. formatTrafficMoney(traffic){
  140. return (traffic / (1024 * 1024 * 1024) * 0.095).toFixed(2) + ' 元'
  141. },
  142. handleShortcut() {
  143. const now = new Date();
  144. this.queryParams.time = now.getFullYear()+'-'+(now.getMonth() + 1).toString().padStart(2, '0');
  145. },
  146. handleTimeChange() {
  147. if(this.queryParams.time){
  148. const year = this.queryParams.time.slice(0, 4);
  149. const month = this.queryParams.time.slice(5, 7);
  150. this.queryParams.startDate = this.queryParams.time+'-01';
  151. const lastDay = new Date(year, month, 0).getDate();
  152. this.queryParams.endDate = this.queryParams.time+'-'+lastDay;
  153. }else{
  154. this.queryParams.startDate = null;
  155. this.queryParams.endDate = null;
  156. }
  157. },
  158. /** 查询短链课程流量记录列表 */
  159. getList() {
  160. this.loading = true;
  161. listCourseTrafficLog(this.queryParams).then(response => {
  162. this.courseTrafficLogList = response.rows;
  163. this.total = response.total;
  164. this.loading = false;
  165. });
  166. },
  167. // 取消按钮
  168. cancel() {
  169. this.open = false;
  170. this.reset();
  171. },
  172. // 表单重置
  173. reset() {
  174. this.form = {
  175. logId: null,
  176. userId: null,
  177. videoId: null,
  178. createTime: null,
  179. qwExternalContactId: null,
  180. internetTraffic: null,
  181. qwUserId: null,
  182. companyUserId: null,
  183. companyId: null,
  184. courseId: null
  185. };
  186. this.resetForm("form");
  187. },
  188. /** 搜索按钮操作 */
  189. handleQuery() {
  190. this.queryParams.pageNum = 1;
  191. this.getList();
  192. },
  193. /** 重置按钮操作 */
  194. resetQuery() {
  195. this.resetForm("queryForm");
  196. this.handleQuery();
  197. },
  198. // 多选框选中数据
  199. handleSelectionChange(selection) {
  200. this.ids = selection.map(item => item.logId)
  201. this.single = selection.length!==1
  202. this.multiple = !selection.length
  203. },
  204. /** 新增按钮操作 */
  205. handleAdd() {
  206. this.reset();
  207. this.open = true;
  208. this.title = "添加短链课程流量记录";
  209. },
  210. /** 修改按钮操作 */
  211. handleUpdate(row) {
  212. this.reset();
  213. const logId = row.logId || this.ids
  214. getCourseTrafficLog(logId).then(response => {
  215. this.form = response.data;
  216. this.open = true;
  217. this.title = "修改短链课程流量记录";
  218. });
  219. },
  220. /** 提交按钮 */
  221. submitForm() {
  222. this.$refs["form"].validate(valid => {
  223. if (valid) {
  224. if (this.form.logId != null) {
  225. updateCourseTrafficLog(this.form).then(response => {
  226. this.msgSuccess("修改成功");
  227. this.open = false;
  228. this.getList();
  229. });
  230. } else {
  231. addCourseTrafficLog(this.form).then(response => {
  232. this.msgSuccess("新增成功");
  233. this.open = false;
  234. this.getList();
  235. });
  236. }
  237. }
  238. });
  239. },
  240. /** 删除按钮操作 */
  241. handleDelete(row) {
  242. const logIds = row.logId || this.ids;
  243. this.$confirm('是否确认删除短链课程流量记录编号为"' + logIds + '"的数据项?', "警告", {
  244. confirmButtonText: "确定",
  245. cancelButtonText: "取消",
  246. type: "warning"
  247. }).then(function() {
  248. return delCourseTrafficLog(logIds);
  249. }).then(() => {
  250. this.getList();
  251. this.msgSuccess("删除成功");
  252. }).catch(() => {});
  253. },
  254. /** 导出按钮操作 */
  255. handleExport() {
  256. const queryParams = this.queryParams;
  257. this.$confirm('是否确认导出所有短链课程流量记录数据项?', "警告", {
  258. confirmButtonText: "确定",
  259. cancelButtonText: "取消",
  260. type: "warning"
  261. }).then(() => {
  262. this.exportLoading = true;
  263. return exportCourseTrafficLog(queryParams);
  264. }).then(response => {
  265. this.download(response.msg);
  266. this.exportLoading = false;
  267. }).catch(() => {});
  268. }
  269. }
  270. };
  271. </script>