index.vue 9.31 KB
<!-- 商品上架 -->
<template>
  <d2-container v-loading="loading.page" class="shelf-product-wrapper">
    <template #header>
      <div v-if="table.formSchema.length" class="header">
        <d2-search class="show-search"
                   label-width="100px"
                   :form-data="table.formSchema"
                   :search-form="table.searchForm">
        </d2-search>
        <div class="up-btns">
          <el-button size="small"
                     type="primary"
                     @click="handleSearch()">
            查询
          </el-button>
          <el-button size="small" @click="handleReset">
            重置
          </el-button>
        </div>
      </div>
    </template>
    <div v-if="table.tableParams.tableColumns.length" class="d2-container-content">
      <d2-table-header :left-span="24">
        <template #left>
          <div class="table-title-wrapper">
            <div class="title">
              任务列表
            </div>
            <div class="table-sum-wrapper">
              <el-tag type="info">
                <span>
                  总任务数
                </span>
                <span style="margin-left:4px">
                  {{ table.headerSummary.totalCount }}
                </span>
              </el-tag>
              <el-tag type="info">
                <span>
                  未完成
                </span>
                <span style="margin-left:4px">
                  {{ table.headerSummary.unfinishedCount }}
                </span>
              </el-tag>
              <el-tag type="info">
                <span>
                  已完成
                </span>
                <span style="margin-left:4px">
                  {{ table.headerSummary.finishedCount }}
                </span>
              </el-tag>
              <el-tag type="info">
                <span>
                  已逾期
                </span>
                <span style="margin-left:4px">
                  {{ table. headerSummary.overdueCount }}
                </span>
              </el-tag>
            </div>
            <div class="sort-wrapper">
              <el-dropdown @command="handleChangeSort">
                <span class="el-dropdown-link" style="cursor:pointer">
                  {{ table.searchForm.orderBy === "createdDate desc" ? "按创建时间" : "按截止时间" }}
                  <i class="el-icon-sort" />
                </span>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item command="createdDate desc" :class="table.searchForm.orderBy === 'createdDate desc' ? 'is-active' : '' ">
                      按创建时间
                    </el-dropdown-item>
                    <el-dropdown-item command="dueTime asc" :class="table.searchForm.orderBy === 'dueTime asc' ? 'is-active' : '' ">
                      按截止时间
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </div>
          </div>
        </template>

      </d2-table-header>
      <d2-table ref="tableRef" v-bind="table">
        <template #auth-button="{ scope }">
          <div style="padding:21px 0">
            <span style="margin-right: 10px">
              <auth-button :data="scope" :show-btn-ids="['9123001']" />
            </span>
          </div>
        </template>
      </d2-table>
      <!-- <RejectDialog v-model="dialog.reject.show"
                          :business-code="dialog.reject.businessCode"
                          @confirmSuccess="handleRefreshTable" /> -->
    </div>
  </d2-container>
</template>

<script>
import { get, isEmpty } from "lodash-es";
import { mapActions } from "vuex";
import { setAllOptions } from "@/libs/select.js";
import reportTrackFunMixin from "@/mixins/reportTrackFunMixin";
import { getTaskCenterCountApi, getTaskCenterListApi } from "@/views/residentManage/taskCenter/api/index.js";
import { getTableColumns, getTableFormSchema } from "@/views/residentManage/taskCenter/view/table/table.data";

export default {
	name: "TaskCenterTable",
	components: {
	},
	mixins: [reportTrackFunMixin],
	data() {
		return {
			loading: {
				page: false,
			},
			table: {
				pageSizes: [10, 50, 100],
				hasNum: false,
				formSchema: [],
				headerSummary: {
					finishedCount: 0,
					overdueCount: 0,
					totalCount: 0,
					unfinishedCount: 0,
				},
				getListApi: async (query) => {
					const res = await getTaskCenterListApi(query);
					const headerSummary = await getTaskCenterCountApi(query);
					Object.assign(this.table.headerSummary, headerSummary);
					return res;
				},
				searchForm: {
					orderBy: "createdDate desc",
					// 排序字段:创建时间升序:createdDate asc
					// 降序:createdDate desc
					// 更新时间升序:updatedDate asc
					// 降序:updatedDate desc
					// 截止时间升序:dueTime asc
					// 降序:dueTime desc
				},
				// 表格参数
				tableParams: {
					listName: "list",
					tableOption: { width: "140", fixed: false },
					tableColumns: [],
				},
			},
			dialog: {
				reject: {
					businessCode: "",
					show: false,
				},
			},

		};
	},
	async mounted() {
		this.loading.page = true;
		try {
			this.trackMenu();
			await this.getBaseData();
			await this.getHeaderSummary();
			this.table.formSchema = await getTableFormSchema();
			this.table.tableParams.tableColumns = await getTableColumns();
		} finally {
			this.loading.page = false;
		}
	},
	methods: {
		...mapActions({
			close: "d2admin/page/close",
		}),
		checkQuery() {
			const { searchForm, formSchema } = this.table;
			const hasFormValue = formSchema.some(({ name }) => {
				const value = get(searchForm, name);
				if (Array.isArray(value)) {
					return value.length > 0;
				}
				if (typeof value === "string") {
					return value.trim() !== "";
				}
				return !isEmpty(value);
			});
			if (hasFormValue) {
				return true;
			}
			return searchForm.orderBy !== "createdDate desc";
		},
		trackMenu() {
			this.setReportTrackData(0, "task_web_menu_entry", {});
		},
		handleSearch(clearQuery = true, resetPage = true) {
			const query = this.table.searchForm;
			if (this.checkQuery()) {
				console.log("埋点");
				this.setReportTrackData(0, "task_web_search_request", query);
			}
			this.$refs.tableRef.refreshTable(clearQuery, resetPage);
		},
		async getBaseData() {
			setAllOptions(this.table.formSchema);
		},

		async getHeaderSummary() {
			const headerSummary = await getTaskCenterCountApi();
			Object.assign(this.table.headerSummary, headerSummary);
		},

		handleReset() {
			this.table.searchForm = this.$options.data().table.searchForm;
			this.$refs.tableRef.refreshTable(false, true);
		},

		// 审核
		async handleApprove(row) {
			// this.$confirm("审核通过后,系统将自动完成上架商品及规则更新,且无法撤回。是否确认审核?", "提示", {
			// 	confirmButtonText: "确定",
			// 	cancelButtonText: "取消",
			// 	type: "warning",
			// 	beforeClose: async (action, instance, done) => {
			// 		if (action === "confirm") {
			// 			instance.confirmButtonLoading = true;
			// 			try {
			// 				await postShelfProductReviewApi({ businessCode: row.businessCode });
			// 				await this.handleRefreshTable();
			// 				this.$message.success("操作成功");
			// 			} finally {
			// 				instance.confirmButtonLoading = false;
			// 				done();
			// 			}
			// 		} else {
			// 			done();
			// 		}
			// 	},
			// });
		},
		handleRefreshTable() {
			// this.$refs.tableRef.refreshTable();
		},
		// 驳回
		handleReject(row) {
			// this.dialog.reject.businessCode = row.businessCode;
			// this.dialog.reject.show = true;
		},
		// 查看
		async handleDetail({ taskId, bizTypeName, bizType }) {
			try {
				this.setReportTrackData(0, "task_web_view_detail", { taskId, bizTypeName, bizType });
			} finally {
				this.$router.push({
					name: "residentManageTaskCenterDetail",
					query: {
						taskId,
					},
				});
			}
		},
		handleChangeSort(command) {
			if (this.table.searchForm.orderBy === command) {
				return;
			}
			this.table.searchForm.orderBy = command;
			this.handleSearch(false, true);
		},
		// 新增 或 修改
		handleModify({ operate, record }) {
			// console.log("record", record);
			// if (operate === "create") {
			// 	this.$router.push({
			// 		name: "goodsShelfCreate",
			// 	});
			// }

			// if (operate === "edit") {
			// 	this.$router.push({
			// 		name: "goodsShelfModify",
			// 		query: {
			// 			baseSceneCode: record.baseSceneCode,
			// 			businessCode: record.businessCode,
			// 			shelfType: record.shelfType,
			// 		},
			// 	});
			// }
		},
	},
};
</script>

<style lang="scss" scoped>
::v-deep .is-active {
	background-color: #eaeef7;
	color: #5579bd;
}
.d2-container-content {
	.table-title-wrapper {
		display: flex;
		align-items: center;
		margin-bottom: 8px;
		> .title {
			font-size: 16px;
			font-weight: bold;
			color: rgba(0, 0, 0, 0.88);
			flex-shrink: 0;
		}
		> .table-sum-wrapper {
			flex-shrink: 0;
			flex: 1;
			margin-left: 20px;
			.el-tag {
				margin-left: 16px;
				&:first-child {
					margin-left: 0;
				}
				color: #000;
				font-size: 13px;
				font-weight: bold;
				border: 0;
				background-color: #f5f5f5;
			}
		}
		> .sort-wrapper {
		}
	}
	::v-deep .d2-table {
		.el-table__body-wrapper {
			.cell {
				padding: 0 6px;
				.el-tag {
					width: auto !important;
				}
			}
		}
	}
}
</style>