From 9d710c38af14a66d992a2d56dfbc32181b345f78 Mon Sep 17 00:00:00 2001 From: 729234283 <729234283@qq.com> Date: Tue, 24 Nov 2020 12:01:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/product-select/script.js | 5 +- src/views/ads/list/form/index.vue | 75 +------ src/views/ads/list/form/script.js | 72 ++++++ src/views/ads/list/index.vue | 194 +--------------- src/views/ads/list/script.js | 191 ++++++++++++++++ src/views/articles/form/index.vue | 76 +------ src/views/articles/form/script.js | 73 ++++++ src/views/articles/list/index.vue | 204 +---------------- src/views/articles/list/script.js | 201 +++++++++++++++++ src/views/brands/list/form/index.vue | 75 +------ src/views/brands/list/form/script.js | 72 ++++++ src/views/brands/list/index.vue | 191 ---------------- src/views/brands/list/script.js | 191 ++++++++++++++++ src/views/categories/list/index.vue | 287 ------------------------ src/views/categories/list/script.js | 287 ++++++++++++++++++++++++ src/views/comments/list/index.vue | 141 +----------- src/views/comments/list/script.js | 138 ++++++++++++ src/views/commissions/list/index.vue | 146 +----------- src/views/commissions/list/script.js | 143 ++++++++++++ src/views/coupons/list/form/index.vue | 75 +------ src/views/coupons/list/form/script.js | 72 ++++++ src/views/coupons/list/index.vue | 171 +------------- src/views/coupons/list/script.js | 168 ++++++++++++++ src/views/login/index.vue | 42 +--- src/views/login/script.js | 39 ++++ src/views/merchants/list/form/index.vue | 73 +----- src/views/merchants/list/form/script.js | 70 ++++++ src/views/merchants/list/index.vue | 125 +---------- src/views/merchants/list/script.js | 122 ++++++++++ src/views/orders/list/index.vue | 234 +------------------ src/views/orders/list/script.js | 231 +++++++++++++++++++ src/views/points/list/form/index.vue | 79 +------ src/views/points/list/form/script.js | 76 +++++++ src/views/points/list/index.vue | 131 +---------- src/views/points/list/script.js | 128 +++++++++++ src/views/products/form/index.vue | 100 +-------- src/views/products/form/script.js | 97 ++++++++ src/views/products/list/index.vue | 219 +----------------- src/views/products/list/script.js | 216 ++++++++++++++++++ src/views/withdraws/list/index.vue | 171 +------------- src/views/withdraws/list/script.js | 168 ++++++++++++++ src/views/wx-users/list/index.vue | 139 +----------- src/views/wx-users/list/script.js | 136 +++++++++++ 43 files changed, 2913 insertions(+), 2931 deletions(-) create mode 100644 src/views/ads/list/form/script.js create mode 100644 src/views/ads/list/script.js create mode 100644 src/views/articles/form/script.js create mode 100644 src/views/articles/list/script.js create mode 100644 src/views/brands/list/form/script.js create mode 100644 src/views/brands/list/script.js create mode 100644 src/views/categories/list/script.js create mode 100644 src/views/comments/list/script.js create mode 100644 src/views/commissions/list/script.js create mode 100644 src/views/coupons/list/form/script.js create mode 100644 src/views/coupons/list/script.js create mode 100644 src/views/login/script.js create mode 100644 src/views/merchants/list/form/script.js create mode 100644 src/views/merchants/list/script.js create mode 100644 src/views/orders/list/script.js create mode 100644 src/views/points/list/form/script.js create mode 100644 src/views/points/list/script.js create mode 100644 src/views/products/form/script.js create mode 100644 src/views/products/list/script.js create mode 100644 src/views/withdraws/list/script.js create mode 100644 src/views/wx-users/list/script.js diff --git a/src/components/product-select/script.js b/src/components/product-select/script.js index a40b8162..f094466a 100644 --- a/src/components/product-select/script.js +++ b/src/components/product-select/script.js @@ -1,4 +1,4 @@ -import { Component, Prop, Vue } from "vue-property-decorator"; +import { Component, Emit, Prop, Vue } from "vue-property-decorator"; import Model from "@/models/admin/products"; @Component @@ -30,7 +30,8 @@ export default class ProductSelect extends Vue { this.items = items; } + @Emit() change(value) { - this.$emit("change", value); + return value; } } diff --git a/src/views/ads/list/form/index.vue b/src/views/ads/list/form/index.vue index 2939541f..06376827 100644 --- a/src/views/ads/list/form/index.vue +++ b/src/views/ads/list/form/index.vue @@ -60,77 +60,4 @@ - + diff --git a/src/views/ads/list/form/script.js b/src/views/ads/list/form/script.js new file mode 100644 index 00000000..24b19185 --- /dev/null +++ b/src/views/ads/list/form/script.js @@ -0,0 +1,72 @@ +import { Component, Vue } from "vue-property-decorator"; +import FormMixin from "view-ui-admin/src/mixins/form"; + +const module = "ads"; + +@Component({ + mixins: [FormMixin] +}) +export default class ListForm extends Vue { + data() { + return { + cForm: { + id: 0, + modal: false, + loading: true, + model: this.getFormInitModel(), + rules: { + title: [ + { + required: true, + message: "标题不能为空" + } + ], + pictureId: [ + { + required: true, + message: "图片不能为空" + } + ] + } + } + }; + } + + getFormInitModel() { + return { + status: 1 + }; + } + + show(detail) { + this.cForm.modal = true; + + if (detail && detail.id) { + this.cForm.id = detail.id; + this.initFormFields(detail); + } else { + this.cForm.id = 0; + } + } + + submit() { + this.$refs.form.validate(async valid => { + if (valid) { + const { id, model } = this.cForm; + const { data } = await this.$store.dispatch( + `${module}/${id ? "put" : "post"}`, + { + id, + body: model + } + ); + + this.cForm.modal = false; + this.$Message.success(`${id ? "编辑" : "新增"}成功`); + this.$emit("get-list", data); + } + + this.fixFormButtonLoading(); + }); + } +} diff --git a/src/views/ads/list/index.vue b/src/views/ads/list/index.vue index 4b4e9683..3beb2431 100644 --- a/src/views/ads/list/index.vue +++ b/src/views/ads/list/index.vue @@ -62,196 +62,4 @@ - + diff --git a/src/views/ads/list/script.js b/src/views/ads/list/script.js new file mode 100644 index 00000000..e6cc1eb2 --- /dev/null +++ b/src/views/ads/list/script.js @@ -0,0 +1,191 @@ +import { Component, Vue } from "vue-property-decorator"; +import { mapState } from "vuex"; +import ListForm from "./form"; +import RouteParamsMixin from "view-ui-admin/src/mixins/route-params"; +import ListMixin from "view-ui-admin/src/mixins/list"; + +const module = "ads"; +const initWhere = { + status: { + $eq: "" + }, + title: { + $like: "" + } +}; + +@Component({ + mixins: [RouteParamsMixin, ListMixin], + components: { + "c-list-form": ListForm + }, + computed: mapState({ + list: state => state[module].list + }) +}) +export default class extends Vue { + data() { + const { ListColumnWidth, OrderAction } = this.$consts; + + return { + cList: { + columns: [ + { + type: "selection", + width: 60 + }, + { + title: "图片", + width: 118, + render: (h, { row }) => { + return h("c-list-image", { + props: { + src: this.$helpers.getImageUrl({ + id: row.pictureId, + width: 80, + height: 80 + }) + } + }); + } + }, + { + title: "标题", + key: "title", + minWidth: ListColumnWidth.Title + }, + { + title: "链接", + key: "link", + width: 300 + }, + { + title: "状态", + width: 80, + render: (h, { row }) => + h( + "span", + null, + this.$helpers.getItem( + this.dicts.PublishStatus, + "value", + row.status + )["label"] + ) + }, + { + title: "操作", + key: "action", + width: 340, + render: (h, { row }) => + h("div", [ + h( + "Button", + { + on: { + click: () => { + this.$refs.form.show(row); + } + } + }, + "编辑" + ), + h("c-dropdown", { + props: { + width: 90, + title: "修改状态", + options: this.dicts.PublishStatus + }, + on: { + click: action => { + this.changeStatus(row.id, action); + } + } + }), + h("c-dropdown", { + attrs: { + title: "排序", + options: OrderAction + }, + on: { + click: action => { + this.order(row.id, action); + } + } + }), + h("c-confirm-button", { + props: { + buttonText: "删除", + confirmText: "确认删除?" + }, + on: { + ok: () => { + this.confirmDelete(row.id); + } + } + }) + ]) + } + ], + cSearch: { + where: this.$helpers.deepCopy(initWhere) + } + } + }; + } + + async beforeRouteUpdate(to, from, next) { + this.initListSearchWhere(initWhere); + this.getList(); + next(); + } + + async created() { + this.initListSearchWhere(initWhere); + this.getList(); + } + + getList() { + return this.$store.dispatch(`${module}/getList`, { + query: { + offset: (this.listPageCurrent - 1) * this.$consts.PageSize, + limit: this.$consts.PageSize, + where: this.listSearchWhere || initWhere, + order: [["order", "DESC"]] + } + }); + } + + async confirmDelete(ids) { + await this.$store.dispatch(`${module}/delete`, { id: ids }); + this.$Message.success("删除成功"); + + const { items } = await this.getList(); + !items.length && this.goListPrevPage(); + } + + async changeStatus(id, action) { + await this.$store.dispatch(`${module}/put`, { + id, + body: { + status: action + } + }); + this.$Message.success("修改状态成功"); + this.getList(); + } + + async order(id, action) { + await this.$store.dispatch(`${module}/postAction`, { + id, + action: "order", + query: { + where: this.listSearchWhere || initWhere + }, + body: { action } + }); + + this.$Message.success("排序成功"); + this.getList(); + } +} diff --git a/src/views/articles/form/index.vue b/src/views/articles/form/index.vue index b06dba82..90b1228f 100644 --- a/src/views/articles/form/index.vue +++ b/src/views/articles/form/index.vue @@ -77,78 +77,4 @@ - + diff --git a/src/views/articles/form/script.js b/src/views/articles/form/script.js new file mode 100644 index 00000000..96ddd56f --- /dev/null +++ b/src/views/articles/form/script.js @@ -0,0 +1,73 @@ +import { Component, Vue } from "vue-property-decorator"; +import RouteParamsMixin from "view-ui-admin/src/mixins/route-params"; +import FormMixin from "view-ui-admin/src/mixins/form"; +import { mapState } from "vuex"; + +const module = "articles"; + +@Component({ + mixins: [RouteParamsMixin, FormMixin], + computed: mapState({ + detail: state => state[module].detail + }) +}) +export default class extends Vue { + data() { + return { + cForm: { + model: this.getFormInitModel(), + rules: { + title: [ + { + required: true, + message: "标题不能为空" + } + ], + content: [ + { + required: true, + message: "内容不能为空" + } + ] + } + } + }; + } + + created() { + this.id && this.getDetail(module, this.id); + } + + getFormInitModel() { + return { + originalPrice: 0, + price: 0, + stock: 0, + status: 1, + content: "" + }; + } + + submit() { + this.$refs.form.validate(async valid => { + if (valid) { + const { + model: { id, ...restModel } + } = this.cForm; + const { data } = await this.$store.dispatch( + `${module}/${id ? "put" : "post"}`, + { + id, + body: restModel + } + ); + + this.cForm.modal = false; + this.$Message.success(`${id ? "编辑" : "新增"}成功`); + this.$emit("get-list", data); + } + + this.fixFormButtonLoading(); + }); + } +} diff --git a/src/views/articles/list/index.vue b/src/views/articles/list/index.vue index a04853b4..3606f5f5 100644 --- a/src/views/articles/list/index.vue +++ b/src/views/articles/list/index.vue @@ -74,206 +74,4 @@ - + diff --git a/src/views/articles/list/script.js b/src/views/articles/list/script.js new file mode 100644 index 00000000..39d7b6f0 --- /dev/null +++ b/src/views/articles/list/script.js @@ -0,0 +1,201 @@ +import { Component, Vue } from "vue-property-decorator"; +import { mapState } from "vuex"; +import RouteParamsMixin from "view-ui-admin/src/mixins/route-params"; +import ListMixin from "view-ui-admin/src/mixins/list"; +import AllCategoriesListMixin from "view-ui-admin/src/mixins/all-categories-list"; + +const module = "articles"; + +const initWhere = { + title: { + $like: "" + }, + categoryId: { + $eq: "" + }, + status: { + $eq: "" + } +}; + +@Component({ + mixins: [RouteParamsMixin, ListMixin, AllCategoriesListMixin], + computed: mapState({ + list: state => state[module].list + }) +}) +export default class extends Vue { + data() { + const { ListColumnWidth, OrderAction } = this.$consts; + + return { + cList: { + columns: [ + { + type: "selection", + width: 60 + }, + { + title: "标题", + key: "title", + minWidth: ListColumnWidth.Title + }, + { + title: "分类", + width: ListColumnWidth.Category, + render: (h, { row }) => + h("span", this.getCategoryNameById(row.categoryId, false)) + }, + { + title: "发布时间", + width: ListColumnWidth.CreatedAt, + render: (h, { row }) => h("span", this.$time.getTime(row.createdAt)) + }, + { + title: "标签", + width: 100, + render: (h, { row }) => { + let tags = []; + + if (row.hot) { + tags.push("热门"); + } + + if (row.top) { + tags.push("置顶"); + } + + return h("span", tags.join("; ")); + } + }, + { + title: "状态", + width: 80, + render: (h, { row }) => + h( + "span", + null, + this.$helpers.getItem( + this.dicts.PublishStatus, + "value", + row.status + )["label"] + ) + }, + { + title: "操作", + key: "action", + width: 340, + render: (h, { row }) => + h("div", [ + h( + "Button", + { + props: { + to: `/${this.alias}/articles/list/form/${row.id}` + } + }, + "编辑" + ), + h("c-dropdown", { + props: { + width: 90, + title: "修改状态", + options: this.dicts.PublishStatus + }, + on: { + click: action => { + this.changeStatus(row.id, action); + } + } + }), + h("c-dropdown", { + props: { + title: "排序", + options: OrderAction + }, + on: { + click: action => { + this.order(row.id, action); + } + } + }), + h("c-confirm-button", { + props: { + buttonText: "删除", + confirmText: "确认删除?" + }, + on: { + ok: () => { + this.confirmDelete(row.id); + } + } + }) + ]) + } + ], + cSearch: { + where: this.$helpers.deepCopy(initWhere) + } + } + }; + } + + async beforeRouteUpdate(to, from, next) { + this.initListSearchWhere(initWhere); + this.getList(); + next(); + } + + async created() { + this.initListSearchWhere(initWhere); + this.getList(); + } + + getList() { + return this.$store.dispatch(`${module}/getList`, { + query: { + offset: (this.listPageCurrent - 1) * this.$consts.PageSize, + limit: this.$consts.PageSize, + where: this.listSearchWhere || initWhere, + order: [ + ["top", "DESC"], + ["order", "DESC"] + ] + } + }); + } + + async confirmDelete(ids) { + await this.$store.dispatch(`${module}/delete`, { id: ids }); + this.$Message.success("删除成功"); + + const { items } = await this.getList(); + !items.length && this.goListPrevPage(); + } + + async changeStatus(id, action) { + await this.$store.dispatch(`${module}/put`, { + id, + body: { + status: action + } + }); + this.$Message.success("修改状态成功"); + this.getList(); + } + + async order(id, action) { + await this.$store.dispatch(`${module}/postAction`, { + id, + action: "order", + query: { + where: this.listSearchWhere || initWhere + }, + body: { action } + }); + + this.$Message.success("排序成功"); + this.getList(); + } +} diff --git a/src/views/brands/list/form/index.vue b/src/views/brands/list/form/index.vue index 34a22235..57d4b16b 100644 --- a/src/views/brands/list/form/index.vue +++ b/src/views/brands/list/form/index.vue @@ -59,77 +59,4 @@ - + diff --git a/src/views/brands/list/form/script.js b/src/views/brands/list/form/script.js new file mode 100644 index 00000000..2a2dd876 --- /dev/null +++ b/src/views/brands/list/form/script.js @@ -0,0 +1,72 @@ +import { Component, Vue } from "vue-property-decorator"; +import FormMixin from "view-ui-admin/src/mixins/form"; + +const module = "brands"; + +@Component({ + mixins: [FormMixin] +}) +export default class BrandsListForm extends Vue { + data() { + return { + cForm: { + id: 0, + modal: false, + loading: true, + model: this.getFormInitModel(), + rules: { + name: [ + { + required: true, + message: "名称不能为空" + } + ], + logoId: [ + { + required: true, + message: "Logo 不能为空" + } + ] + } + } + }; + } + + getFormInitModel() { + return { + status: 1 + }; + } + + show(detail) { + this.cForm.modal = true; + + if (detail && detail.id) { + this.cForm.id = detail.id; + this.initFormFields(detail); + } else { + this.cForm.id = 0; + } + } + + submit() { + this.$refs.form.validate(async valid => { + if (valid) { + const { id, model } = this.cForm; + const { data } = await this.$store.dispatch( + `${module}/${id ? "put" : "post"}`, + { + id, + body: model + } + ); + + this.cForm.modal = false; + this.$Message.success(`${id ? "编辑" : "新增"}成功`); + this.$emit("get-list", data); + } + + this.fixFormButtonLoading(); + }); + } +} diff --git a/src/views/brands/list/index.vue b/src/views/brands/list/index.vue index de2939b4..1adb197a 100644 --- a/src/views/brands/list/index.vue +++ b/src/views/brands/list/index.vue @@ -57,195 +57,4 @@ diff --git a/src/views/brands/list/script.js b/src/views/brands/list/script.js new file mode 100644 index 00000000..965d96da --- /dev/null +++ b/src/views/brands/list/script.js @@ -0,0 +1,191 @@ +import { Component, Vue } from "vue-property-decorator"; +import { mapState } from "vuex"; +import BrandsListForm from "./form"; +import RouteParamsMixin from "view-ui-admin/src/mixins/route-params"; +import ListMixin from "view-ui-admin/src/mixins/list"; + +const module = "brands"; +const initWhere = { + status: { + $eq: "" + }, + name: { + $like: "" + } +}; + +@Component({ + mixins: [RouteParamsMixin, ListMixin], + components: { + "c-brands-list-form": BrandsListForm + }, + computed: mapState({ + list: state => state[module].list + }) +}) +export default class extends Vue { + data() { + const { ListColumnWidth, OrderAction } = this.$consts; + + return { + cList: { + columns: [ + { + type: "selection", + width: 60 + }, + { + title: "Logo", + width: 118, + render: (h, { row }) => { + return h("c-list-image", { + props: { + src: this.$helpers.getImageUrl({ + id: row.logoId, + width: 80, + height: 80 + }) + } + }); + } + }, + { + title: "名称", + key: "name", + minWidth: ListColumnWidth.Title + }, + { + title: "链接", + key: "link", + width: 300 + }, + { + title: "状态", + width: 80, + render: (h, { row }) => + h( + "span", + null, + this.$helpers.getItem( + this.dicts.PublishStatus, + "value", + row.status + )["label"] + ) + }, + { + title: "操作", + key: "action", + width: 340, + render: (h, { row }) => + h("div", [ + h( + "Button", + { + on: { + click: () => { + this.$refs.form.show(row); + } + } + }, + "编辑" + ), + h("c-dropdown", { + props: { + width: 90, + title: "修改状态", + options: this.dicts.PublishStatus + }, + on: { + click: action => { + this.changeStatus(row.id, action); + } + } + }), + h("c-dropdown", { + attrs: { + title: "排序", + options: OrderAction + }, + on: { + click: action => { + this.order(row.id, action); + } + } + }), + h("c-confirm-button", { + props: { + buttonText: "删除", + confirmText: "确认删除?" + }, + on: { + ok: () => { + this.confirmDelete(row.id); + } + } + }) + ]) + } + ], + cSearch: { + where: this.$helpers.deepCopy(initWhere) + } + } + }; + } + + async beforeRouteUpdate(to, from, next) { + this.initListSearchWhere(initWhere); + this.getList(); + next(); + } + + async created() { + this.initListSearchWhere(initWhere); + this.getList(); + } + + getList() { + return this.$store.dispatch(`${module}/getList`, { + query: { + offset: (this.listPageCurrent - 1) * this.$consts.PageSize, + limit: this.$consts.PageSize, + where: this.listSearchWhere || initWhere, + order: [["order", "DESC"]] + } + }); + } + + async confirmDelete(ids) { + await this.$store.dispatch(`${module}/delete`, { id: ids }); + this.$Message.success("删除成功"); + + const { items } = await this.getList(); + !items.length && this.goListPrevPage(); + } + + async changeStatus(id, action) { + await this.$store.dispatch(`${module}/put`, { + id, + body: { + status: action + } + }); + this.$Message.success("修改状态成功"); + this.getList(); + } + + async order(id, action) { + await this.$store.dispatch(`${module}/postAction`, { + id, + action: "order", + query: { + where: this.listSearchWhere || initWhere + }, + body: { action } + }); + + this.$Message.success("排序成功"); + this.getList(); + } +} diff --git a/src/views/categories/list/index.vue b/src/views/categories/list/index.vue index f0fea6d6..df9d955d 100644 --- a/src/views/categories/list/index.vue +++ b/src/views/categories/list/index.vue @@ -108,291 +108,4 @@ diff --git a/src/views/categories/list/script.js b/src/views/categories/list/script.js new file mode 100644 index 00000000..fceda3d4 --- /dev/null +++ b/src/views/categories/list/script.js @@ -0,0 +1,287 @@ +import { Component, Vue } from "vue-property-decorator"; +import { mapState } from "vuex"; +import RouteParamsMixin from "view-ui-admin/src/mixins/route-params"; +import ListMixin from "view-ui-admin/src/mixins/list"; +import FormMixin from "view-ui-admin/src/mixins/form"; + +const module = "categories"; +const initWhere = { + parentIds: [0], + name: { + $like: "" + } +}; + +@Component({ + mixins: [RouteParamsMixin, ListMixin, FormMixin], + computed: { + ...mapState({ + list: state => state[module].list, + parentDetail: state => state[module].detail + }), + levels() { + return this.$consts.CategoryLevel[this.$route.params.alias]; + }, + isParent() { + const listSearchWhere = this.listSearchWhere; + + return ( + listSearchWhere && + listSearchWhere.parentIds && + listSearchWhere.parentIds[listSearchWhere.parentIds.length - 1] !== 0 + ); + } + } +}) +export default class extends Vue { + data() { + const { ListColumnWidth, OrderAction, CategoryLevel } = this.$consts; + + const getLevels = () => { + return CategoryLevel[this.$route.params.alias]; + }; + + return { + parents: [], + cList: { + columns: [ + { + type: "selection", + width: 60 + }, + { + title: "图标", + width: 118, + render: (h, { row }) => { + return row.iconId + ? h("c-list-image", { + props: { + src: this.$helpers.getImageUrl({ + id: row.iconId, + width: 80, + height: 80 + }) + } + }) + : h("span", "无"); + } + }, + { + title: "名称", + key: "name", + minWidth: ListColumnWidth.Title + }, + { + title: "操作", + key: "action", + width: getLevels() === 1 ? 245 : 340, + render: (h, { row }) => + h("div", [ + h( + "Button", + { + on: { + click: () => { + this.showForm(row); + } + } + }, + "编辑" + ), + this.levels === 2 + ? h( + "Button", + { + on: { + click: () => { + this.manageChild(row.id); + } + } + }, + "管理子分类" + ) + : null, + h("c-dropdown", { + props: { + title: "排序", + options: OrderAction + }, + on: { + click: action => { + this.order(row.id, action); + } + } + }), + h("c-confirm-button", { + props: { + buttonText: "删除", + confirmText: "确认删除?" + }, + on: { + ok: () => { + this.confirmDelete(row.id); + } + } + }) + ]) + } + ], + cSearch: { + where: this.$helpers.deepCopy(initWhere) + } + }, + cForm: { + id: 0, + modal: false, + model: {}, + loading: true, + rules: { + name: [ + { + required: true, + message: "名称不能为空" + } + ] + } + } + }; + } + + async beforeRouteUpdate(to, from, next) { + this.initListSearchWhere(initWhere); + this.getList(); + this.getParentDetail(); + next(); + } + + async created() { + this.$store.dispatch(`${module}/resetList`); + this.initListSearchWhere(initWhere); + this.getList(); + this.getParentDetail(); + } + + getParentDetail() { + if (this.listSearchWhere && this.listSearchWhere.parentIds) { + const id = this.listSearchWhere.parentIds[ + this.listSearchWhere.parentIds.length - 1 + ]; + id && this.$store.dispatch(`${module}/getDetail`, { id }); + } + } + + getList() { + const { name, parentIds = [0] } = this.listSearchWhere || initWhere; + + return this.$store.dispatch(`${module}/getList`, { + query: { + offset: (this.listPageCurrent - 1) * this.$consts.PageSize, + limit: this.$consts.PageSize, + where: { + parentId: { $eq: parentIds[parentIds.length - 1] || null }, + name, + alias: this.alias + }, + order: [["order", "DESC"]] + } + }); + } + + async manageChild(id) { + const parentIds = + this.listSearchWhere && this.listSearchWhere.parentIds + ? this.$helpers.deepCopy(this.listSearchWhere.parentIds) + : [0]; + + if (parentIds[parentIds.length - 1] !== id) { + parentIds.push(id); + this.$router.push({ + query: { + listSearchWhere: JSON.stringify({ + ...initWhere, + parentIds: parentIds + }) + } + }); + } + } + + gotoParent() { + const parentIds = this.$helpers.deepCopy(this.listSearchWhere.parentIds); + + parentIds.pop(); + + this.$router.push({ + query: { + listSearchWhere: JSON.stringify({ ...initWhere, parentIds }) + } + }); + } + + showForm(detail) { + this.cForm.modal = true; + + if (detail.id) { + this.cForm.id = detail.id; + this.initFormFields(detail); + } else { + this.cForm.id = 0; + } + } + + async confirmDelete(id) { + await this.$store.dispatch(`${module}/delete`, { id }); + this.$Message.success("删除成功!"); + + const { items } = await this.getList(); + !items.length && this.goListPrevPage(); + } + + async order(id, action) { + const { name } = this.listSearchWhere || initWhere; + + await this.$store.dispatch(`${module}/postAction`, { + id, + action: "order", + query: { + where: { + parentId: this.isParent ? this.parentDetail.id : 0, + name, + alias: this.alias + } + }, + body: { action } + }); + + this.$Message.success("排序成功"); + this.getList(); + } + + submit() { + this.$refs.form.validate(async valid => { + if (valid) { + const { id, model } = this.cForm; + + await this.$store.dispatch(`${module}/${id ? "put" : "post"}`, { + id, + body: { + ...model, + alias: this.alias, + parentId: this.isParent ? this.parentDetail.id : undefined + } + }); + + this.cForm.modal = false; + this.$Message.success(`${id ? "编辑" : "新增"}成功`); + !id && + this.resetListSearch({ + ...initWhere, + parentIds: this.isParent ? this.listSearchWhere.parentIds : [0] + }); + this.getList(); + } + + this.fixFormButtonLoading(); + }); + } +} diff --git a/src/views/comments/list/index.vue b/src/views/comments/list/index.vue index a4aaf22f..e38db8ac 100644 --- a/src/views/comments/list/index.vue +++ b/src/views/comments/list/index.vue @@ -65,143 +65,4 @@ - + diff --git a/src/views/comments/list/script.js b/src/views/comments/list/script.js new file mode 100644 index 00000000..a84378e8 --- /dev/null +++ b/src/views/comments/list/script.js @@ -0,0 +1,138 @@ +import { Component, Vue } from "vue-property-decorator"; +import { mapState } from "vuex"; +import RouteParamsMixin from "view-ui-admin/src/mixins/route-params"; +import ListMixin from "view-ui-admin/src/mixins/list"; + +const module = "comments"; +const initWhere = { + dateRange: { + $eq: [] + }, + status: { + $eq: "" + } +}; + +@Component({ + mixins: [RouteParamsMixin, ListMixin], + computed: mapState({ + list: state => state[module].list + }) +}) +export default class extends Vue { + data() { + const { ListColumnWidth } = this.$consts; + + return { + cList: { + columns: [ + { + type: "selection", + width: 60 + }, + { + title: "评价用户", + width: ListColumnWidth.User, + render: (h, { row }) => h("span", row.wxUser.nickName) + }, + { + title: "评价内容", + key: "content" + }, + { + title: "审核状态", + width: 100, + render: (h, { row }) => + h( + "span", + null, + this.$helpers.getItem( + this.dicts.CheckStatus, + "value", + row.status + )["label"] + ) + }, + { + title: "操作", + key: "action", + width: 180, + render: (h, { row }) => + h("div", [ + h("c-dropdown", { + props: { + width: 66, + title: "审核", + options: this.dicts.CheckStatus + }, + on: { + click: action => { + this.changeStatus(row.id, action); + } + } + }), + h("c-confirm-button", { + props: { + buttonText: "删除", + confirmText: "确认删除?" + }, + on: { + ok: () => { + this.confirmDelete(row.id); + } + } + }) + ]) + } + ], + cSearch: { + where: this.$helpers.deepCopy(initWhere) + } + } + }; + } + + async beforeRouteUpdate(to, from, next) { + this.initListSearchWhere(initWhere); + this.getList(); + next(); + } + + async created() { + this.initListSearchWhere(initWhere); + this.getList(); + } + + getList() { + return this.$store.dispatch(`${module}/getList`, { + query: { + offset: (this.listPageCurrent - 1) * this.$consts.PageSize, + limit: this.$consts.PageSize, + where: { + ...(this.listSearchWhere || initWhere), + productId: this.$route.params.productId + }, + include: [{ model: "WxUser", as: "wxUser" }] + } + }); + } + + async confirmDelete(ids) { + await this.$store.dispatch(`${module}/delete`, { id: ids }); + this.$Message.success("删除成功"); + + const { items } = await this.getList(); + !items.length && this.goListPrevPage(); + } + + async changeStatus(id, action) { + await this.$store.dispatch(`${module}/put`, { + id, + body: { + status: action + } + }); + this.$Message.success("修改状态成功"); + this.getList(); + } +} diff --git a/src/views/commissions/list/index.vue b/src/views/commissions/list/index.vue index c6e68fd1..e5488b9a 100644 --- a/src/views/commissions/list/index.vue +++ b/src/views/commissions/list/index.vue @@ -54,148 +54,4 @@ - + diff --git a/src/views/commissions/list/script.js b/src/views/commissions/list/script.js new file mode 100644 index 00000000..b5ff4642 --- /dev/null +++ b/src/views/commissions/list/script.js @@ -0,0 +1,143 @@ +import { Component, Vue } from "vue-property-decorator"; +import { mapState } from "vuex"; +import RouteParamsMixin from "view-ui-admin/src/mixins/route-params"; +import ListMixin from "view-ui-admin/src/mixins/list"; + +const module = "commissions"; +const initWhere = { + dateRange: { + $eq: [] + }, + wxUserId: { + $eq: "" + } +}; + +@Component({ + mixins: [RouteParamsMixin, ListMixin], + computed: mapState({ + list: state => state[module].list + }) +}) +export default class extends Vue { + data() { + const { ListColumnWidth } = this.$consts; + + return { + cList: { + columns: [ + { + type: "selection", + width: 60 + }, + { + title: "微信用户", + width: 150, + render: (h, { row }) => h("span", row.wxUser.nickName) + }, + { + title: "下线", + width: 150, + render: (h, { row }) => + h("span", row.lowerWxUser ? row.lowerWxUser.nickName : "--") + }, + { + title: "消费金额", + render: (h, { row }) => + h("span", `${row.order ? row.order.amount : 0}元`) + }, + { + title: "佣金", + render: (h, { row }) => h("span", `${row.value}元`) + }, + { + title: "时间", + width: ListColumnWidth.CreatedAt, + render: (h, { row }) => h("span", this.$time.getTime(row.createdAt)) + }, + { + title: "操作", + key: "action", + width: 104, + render: (h, { row }) => + h("div", [ + h("c-confirm-button", { + props: { + buttonText: "删除", + confirmText: "确认删除?" + }, + on: { + ok: () => { + this.confirmDelete(row.id); + } + } + }) + ]) + } + ], + cSearch: { + where: this.$helpers.deepCopy(initWhere) + }, + total: 0 + } + }; + } + + async beforeRouteUpdate(to, from, next) { + this.initListSearchWhere(initWhere); + await this.getListAndTotal(); + next(); + } + + async created() { + this.initListSearchWhere(initWhere); + await this.getListAndTotal(); + } + + async getListAndTotal() { + this.getList(); + this.cList.total = await this.getTotal(); + } + + getList() { + return this.$store.dispatch(`${module}/getList`, { + query: { + offset: (this.listPageCurrent - 1) * this.$consts.PageSize, + limit: this.$consts.PageSize, + where: this.listSearchWhere || initWhere, + include: [ + { + model: "WxUser", + as: "wxUser" + }, + { + model: "WxUser", + as: "lowerWxUser" + }, + { + model: "Order", + as: "order" + } + ] + } + }); + } + + async getTotal() { + const { data } = await this.$store.dispatch(`${module}/postAction`, { + action: "getTotal", + query: { + where: this.listSearchWhere || initWhere + } + }); + return data; + } + + async confirmDelete(ids) { + await this.$store.dispatch(`${module}/delete`, { id: ids }); + this.$Message.success("删除成功"); + + const { items } = await this.getList(); + !items.length && this.goListPrevPage(); + } +} diff --git a/src/views/coupons/list/form/index.vue b/src/views/coupons/list/form/index.vue index b0d2db2c..d03bb4d4 100644 --- a/src/views/coupons/list/form/index.vue +++ b/src/views/coupons/list/form/index.vue @@ -111,77 +111,4 @@ - + diff --git a/src/views/coupons/list/form/script.js b/src/views/coupons/list/form/script.js new file mode 100644 index 00000000..f6aad022 --- /dev/null +++ b/src/views/coupons/list/form/script.js @@ -0,0 +1,72 @@ +import { Component, Vue } from "vue-property-decorator"; +import FormMixin from "view-ui-admin/src/mixins/form"; + +const module = "coupons"; + +@Component({ + mixins: [FormMixin] +}) +export default class CouponsListForm extends Vue { + data() { + return { + cForm: { + id: 0, + modal: false, + loading: true, + model: this.getFormInitModel(), + rules: { + name: [ + { + required: true, + message: "名称不能为空" + } + ] + } + } + }; + } + + getFormInitModel() { + return { + type: "FullReduction", + objectType: "All", + categoryIds: [], + productIds: [], + deductAmount: 0, + minConsumeAmount: 0, + period: 30 + }; + } + + show(detail) { + this.cForm.modal = true; + + if (detail && detail.id) { + this.cForm.id = detail.id; + this.initFormFields(detail); + } else { + this.cForm.id = 0; + } + } + + submit() { + this.$refs.form.validate(async valid => { + if (valid) { + const { id, model } = this.cForm; + const { data } = await this.$store.dispatch( + `${module}/${id ? "put" : "post"}`, + { + id, + body: model + } + ); + + this.cForm.modal = false; + this.$Message.success(`${id ? "编辑" : "新增"}成功`); + this.$emit("get-list", data); + } + + this.fixFormButtonLoading(); + }); + } +} diff --git a/src/views/coupons/list/index.vue b/src/views/coupons/list/index.vue index 51532b34..cb280ebc 100644 --- a/src/views/coupons/list/index.vue +++ b/src/views/coupons/list/index.vue @@ -62,173 +62,4 @@ - + diff --git a/src/views/coupons/list/script.js b/src/views/coupons/list/script.js new file mode 100644 index 00000000..3fc122a3 --- /dev/null +++ b/src/views/coupons/list/script.js @@ -0,0 +1,168 @@ +import { Component, Vue } from "vue-property-decorator"; +import { mapState } from "vuex"; +import CouponsListForm from "./form"; +import RouteParamsMixin from "view-ui-admin/src/mixins/route-params"; +import ListMixin from "view-ui-admin/src/mixins/list"; + +const module = "coupons"; +const initWhere = { + status: { + $eq: "" + }, + name: { + $like: "" + } +}; + +@Component({ + mixins: [RouteParamsMixin, ListMixin], + components: { + "c-coupons-list-form": CouponsListForm + }, + computed: mapState({ + list: state => state[module].list + }) +}) +export default class extends Vue { + data() { + return { + cList: { + columns: [ + { + type: "selection", + width: 60 + }, + { + title: "名称", + key: "name" + }, + { + title: "类型", + width: 90, + render: (h, { row }) => + h( + "span", + this.$helpers.getItem(this.dicts.CouponType, "value", row.type)[ + "label" + ] + ) + }, + { + title: "抵扣金额", + width: 100, + render: (h, { row }) => h("span", `${row.deductAmount}元`) + }, + { + title: "最低消费", + width: 100, + render: (h, { row }) => h("span", `${row.minConsumeAmount}元`) + }, + { + title: "有效期", + width: 100, + render: (h, params) => h("span", null, `${params.row.period}天`) + }, + { + title: "状态", + width: 80, + render: (h, { row }) => + h( + "span", + null, + this.$helpers.getItem( + this.dicts.PublishStatus, + "value", + row.status + )["label"] + ) + }, + { + title: "操作", + key: "action", + width: 266, + render: (h, { row }) => + h("div", [ + h( + "Button", + { + on: { + click: () => { + this.$refs.form.show(row); + } + } + }, + "编辑" + ), + h("c-dropdown", { + props: { + width: 90, + title: "修改状态", + options: this.dicts.PublishStatus + }, + on: { + click: action => { + this.changeStatus(row.id, action); + } + } + }), + h("c-confirm-button", { + props: { + buttonText: "删除", + confirmText: "确认删除?" + }, + on: { + ok: () => { + this.confirmDelete(row.id); + } + } + }) + ]) + } + ], + cSearch: { + where: this.$helpers.deepCopy(initWhere) + } + } + }; + } + + async beforeRouteUpdate(to, from, next) { + this.initListSearchWhere(initWhere); + this.getList(); + next(); + } + + async created() { + this.initListSearchWhere(initWhere); + this.getList(); + } + + getList() { + return this.$store.dispatch(`${module}/getList`, { + query: { + offset: (this.listPageCurrent - 1) * this.$consts.PageSize, + limit: this.$consts.PageSize, + where: this.listSearchWhere || initWhere + } + }); + } + + async confirmDelete(ids) { + await this.$store.dispatch(`${module}/delete`, { id: ids }); + this.$Message.success("删除成功"); + + const { items } = await this.getList(); + !items.length && this.goListPrevPage(); + } + + async changeStatus(id, action) { + await this.$store.dispatch(`${module}/put`, { + id, + body: { + status: action + } + }); + this.$Message.success("修改状态成功"); + this.getList(); + } +} diff --git a/src/views/login/index.vue b/src/views/login/index.vue index aab17e1d..65187c61 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -37,46 +37,6 @@ - + diff --git a/src/views/login/script.js b/src/views/login/script.js new file mode 100644 index 00000000..d95cd81c --- /dev/null +++ b/src/views/login/script.js @@ -0,0 +1,39 @@ +import { Component, Vue } from "vue-property-decorator"; + +@Component +export default class extends Vue { + cForm = { + model: {}, + rules: { + username: [ + { + required: true, + message: "账号不能为空" + } + ], + password: [ + { + required: true, + message: "密码不能为空" + } + ] + } + }; + + login() { + this.$refs.form.validate(async valid => { + if (valid) { + const { + data: { manager, token } + } = await this.$store.dispatch("public/managers/postAction", { + action: "login", + body: this.cForm.model + }); + + this.$auth.login({ user: manager, token }); + this.$Message.success("登录成功"); + this.$router.push(this.$route.query.redirect || "/"); + } + }); + } +} diff --git a/src/views/merchants/list/form/index.vue b/src/views/merchants/list/form/index.vue index 4480b4e0..9f097ccc 100644 --- a/src/views/merchants/list/form/index.vue +++ b/src/views/merchants/list/form/index.vue @@ -58,75 +58,4 @@ - + diff --git a/src/views/merchants/list/form/script.js b/src/views/merchants/list/form/script.js new file mode 100644 index 00000000..55d62563 --- /dev/null +++ b/src/views/merchants/list/form/script.js @@ -0,0 +1,70 @@ +import { Component, Vue } from "vue-property-decorator"; +import FormMixin from "view-ui-admin/src/mixins/form"; + +const module = "merchants"; + +@Component({ + mixins: [FormMixin] +}) +export default class MerchantsListForm extends Vue { + data() { + return { + cForm: { + id: 0, + modal: false, + loading: true, + model: this.getFormInitModel(), + rules: { + name: [ + { + required: true, + message: "名称不能为空" + } + ], + pictureId: [ + { + required: true, + message: "图片不能为空" + } + ] + } + } + }; + } + + getFormInitModel() { + return {}; + } + + show(detail) { + this.cForm.modal = true; + + if (detail && detail.id) { + this.cForm.id = detail.id; + this.initFormFields(detail); + } else { + this.cForm.id = 0; + } + } + + submit() { + this.$refs.form.validate(async valid => { + if (valid) { + const { id, model } = this.cForm; + const { data } = await this.$store.dispatch( + `${module}/${id ? "put" : "post"}`, + { + id, + body: model + } + ); + + this.cForm.modal = false; + this.$Message.success(`${id ? "编辑" : "新增"}成功`); + this.$emit("get-list", data); + } + + this.fixFormButtonLoading(); + }); + } +} diff --git a/src/views/merchants/list/index.vue b/src/views/merchants/list/index.vue index 5874f6db..8b01436c 100644 --- a/src/views/merchants/list/index.vue +++ b/src/views/merchants/list/index.vue @@ -44,127 +44,4 @@ - + diff --git a/src/views/merchants/list/script.js b/src/views/merchants/list/script.js new file mode 100644 index 00000000..fe119ebb --- /dev/null +++ b/src/views/merchants/list/script.js @@ -0,0 +1,122 @@ +import { Component, Vue } from "vue-property-decorator"; +import { mapState } from "vuex"; +import MerchantsListForm from "./form"; +import RouteParamsMixin from "view-ui-admin/src/mixins/route-params"; +import ListMixin from "view-ui-admin/src/mixins/list"; + +const module = "merchants"; +const initWhere = { + name: { + $like: "" + } +}; + +@Component({ + mixins: [RouteParamsMixin, ListMixin], + components: { + "c-merchants-list-form": MerchantsListForm + }, + computed: mapState({ + list: state => state[module].list + }) +}) +export default class extends Vue { + data() { + const { ListColumnWidth } = this.$consts; + + return { + cList: { + columns: [ + { + type: "selection", + width: 60 + }, + { + title: "名称", + key: "name", + minWidth: ListColumnWidth.Title + }, + { + title: "关联的微信用户", + width: 130, + render: (h, { row }) => + h("span", row.wxUser ? row.wxUser.nickName : "") + }, + { + title: "联系人", + key: "contactName", + width: 100 + }, + { + title: "手机号", + key: "phoneNumber", + width: 120 + }, + { + title: "操作", + key: "action", + width: 170, + render: (h, { row }) => + h("div", [ + h( + "Button", + { + on: { + click: () => { + this.$refs.form.show(row); + } + } + }, + "编辑" + ), + h("c-confirm-button", { + props: { + buttonText: "删除", + confirmText: "确认删除?" + }, + on: { + ok: () => { + this.confirmDelete(row.id); + } + } + }) + ]) + } + ], + cSearch: { + where: this.$helpers.deepCopy(initWhere) + } + } + }; + } + + async beforeRouteUpdate(to, from, next) { + this.initListSearchWhere(initWhere); + this.getList(); + next(); + } + + async created() { + this.initListSearchWhere(initWhere); + this.getList(); + } + + getList() { + return this.$store.dispatch(`${module}/getList`, { + query: { + offset: (this.listPageCurrent - 1) * this.$consts.PageSize, + limit: this.$consts.PageSize, + where: this.listSearchWhere || initWhere, + include: [{ model: "WxUser", as: "wxUser" }] + } + }); + } + + async confirmDelete(ids) { + await this.$store.dispatch(`${module}/delete`, { id: ids }); + this.$Message.success("删除成功"); + + const { items } = await this.getList(); + !items.length && this.goListPrevPage(); + } +} diff --git a/src/views/orders/list/index.vue b/src/views/orders/list/index.vue index ec894167..40886661 100644 --- a/src/views/orders/list/index.vue +++ b/src/views/orders/list/index.vue @@ -100,236 +100,4 @@ - + diff --git a/src/views/orders/list/script.js b/src/views/orders/list/script.js new file mode 100644 index 00000000..94b30f5f --- /dev/null +++ b/src/views/orders/list/script.js @@ -0,0 +1,231 @@ +import { Component, Vue } from "vue-property-decorator"; +import { mapState } from "vuex"; +import RouteParamsMixin from "view-ui-admin/src/mixins/route-params"; +import ListMixin from "view-ui-admin/src/mixins/list"; +import xlsx from "view-ui-admin/src/utils/xlsx"; +import Model from "@/models/admin/orders"; + +const module = "orders"; +const initWhere = { + dateRange: { + $eq: [] + }, + payment: { + $eq: "" + }, + status: { + $eq: "" + }, + wxUserId: { + $eq: "" + } +}; + +@Component({ + mixins: [RouteParamsMixin, ListMixin], + computed: mapState({ + list: state => state[module].list + }) +}) +export default class extends Vue { + data() { + return { + cList: { + columns: [ + { + type: "selection", + width: 60 + }, + { + title: "订单号", + key: "no", + width: 150 + }, + { + title: "微信用户", + key: "wxUser", + width: 150, + render: (h, { row }) => h("span", row.wxUser.nickName) + }, + { + title: "购买商品", + key: "products", + render: (h, { row }) => h("span", row.products[0].name) + }, + { + title: "支付方式", + key: "payment", + width: 90, + render: (h, { row }) => + h( + "span", + this.$helpers.getItem( + this.dicts.OrderPayment, + "value", + row.payment + )["label"] + ) + }, + { + title: "支付金额", + key: "amount", + width: 90, + render: (h, { row }) => h("span", row.amount + " 元") + }, + { + title: "下单时间", + key: "createdAt", + width: 140, + render: (h, { row }) => h("span", this.$time.getTime(row.createdAt)) + }, + { + title: "状态", + key: "status", + width: 80, + render: (h, { row }) => + h( + "span", + this.$helpers.getItem( + this.dicts.OrderStatus, + "value", + row.status + )["label"] + ) + }, + { + title: "操作", + key: "action", + width: 192, + render: (h, { row }) => + h("div", [ + h( + "Button", + { + props: { + disabled: !row.formData + }, + on: { + click: () => { + this.cList.cFormData.data = row.formData; + this.cList.cFormData.fields = + row.products[0].formFields; + this.cList.cFormData.modal = true; + } + } + }, + "表单信息" + ), + h("c-confirm-button", { + props: { + buttonText: "删除", + confirmText: "确认删除?" + }, + on: { + ok: () => { + this.confirmDelete(row.id); + } + } + }) + ]) + } + ], + cSearch: { + where: this.$helpers.deepCopy(initWhere) + }, + cFormData: { + fields: {}, + data: {}, + modal: false + } + } + }; + } + + async beforeRouteUpdate(to, from, next) { + this.initListSearchWhere(initWhere); + this.getList(); + next(); + } + + async created() { + this.initListSearchWhere(initWhere); + this.getList(); + } + + getList() { + return this.$store.dispatch(`${module}/getList`, { + query: { + offset: (this.listPageCurrent - 1) * this.$consts.PageSize, + limit: this.$consts.PageSize, + where: this.listSearchWhere || initWhere, + include: [{ model: "WxUser", as: "wxUser" }] + } + }); + } + + async confirmDelete(ids) { + await this.$store.dispatch(`${module}/delete`, { id: ids }); + this.$Message.success("删除成功"); + + const { items } = await this.getList(); + !items.length && this.goListPrevPage(); + } + + deliver() {} + + getFormData(data, fields) { + return Object.keys(data).map(field => ({ + key: field, + label: this.$helpers.getItem(fields, "key", field)["label"], + value: data[field] + })); + } + + async getExportListItems() { + this.search(); + + const { + data: { items } + } = await new Model().GET({ + query: { + where: this.listSearchWhere, + include: [{ model: "WxUser", as: "wxUser" }] + } + }); + + return items; + } + + async exportXLSX() { + const items = await this.getExportListItems(); + + xlsx.download({ + fileName: `订单(${this.$time.getDate()})`, + data: (() => { + return items.map(item => { + let ret = {}; + + console.log(item, "-"); + + ret["订单号"] = item.no; + ret["微信用户"] = item.wxUser.nickName; + ret["购买商品"] = item.products[0].name; + ret["支付方式"] = this.$helpers.getItem( + this.dicts.OrderPayment, + "value", + item.payment + )["label"]; + ret["支付金额"] = `${item.amount}元`; + ret["下单时间"] = this.$time.getTime(item.createdAt); + ret["状态"] = this.$helpers.getItem( + this.dicts.OrderStatus, + "value", + item.status + )["label"]; + + return ret; + }); + })() + }); + } +} diff --git a/src/views/points/list/form/index.vue b/src/views/points/list/form/index.vue index ba1db5cb..fce73fca 100644 --- a/src/views/points/list/form/index.vue +++ b/src/views/points/list/form/index.vue @@ -33,81 +33,4 @@ - + diff --git a/src/views/points/list/form/script.js b/src/views/points/list/form/script.js new file mode 100644 index 00000000..bbf9d7a8 --- /dev/null +++ b/src/views/points/list/form/script.js @@ -0,0 +1,76 @@ +import { Component, Vue } from "vue-property-decorator"; +import FormMixin from "view-ui-admin/src/mixins/form"; + +const module = "points"; + +@Component({ + mixins: [FormMixin] +}) +export default class ListForm extends Vue { + data() { + return { + cForm: { + id: 0, + modal: false, + loading: true, + model: this.getFormInitModel(), + rules: { + schoolId: [ + { + required: true, + message: "校区不能为空" + } + ], + wxUserId: [ + { + required: true, + message: "微信用户不能为空" + } + ], + value: [ + { + asyncValidator: (rule, value) => { + return new Promise((resolve, reject) => { + if (!value) { + reject("佣金不能为 0 或为空"); + } else { + resolve(); + } + }); + } + } + ] + } + } + }; + } + + getFormInitModel() { + return { + value: 0 + }; + } + + async show() { + this.cForm.modal = true; + } + + submit() { + this.$refs.form.validate(async valid => { + if (valid) { + const { model } = this.cForm; + + await this.$store.dispatch(`${module}/postAction`, { + action: "increaseOrDecrease", + body: model + }); + + this.cForm.modal = false; + this.$Message.success("操作成功"); + this.$emit("get-list"); + } + + this.fixFormButtonLoading(); + }); + } +} diff --git a/src/views/points/list/index.vue b/src/views/points/list/index.vue index 4f0838d6..7341cfe1 100644 --- a/src/views/points/list/index.vue +++ b/src/views/points/list/index.vue @@ -62,133 +62,4 @@ - + diff --git a/src/views/points/list/script.js b/src/views/points/list/script.js new file mode 100644 index 00000000..4a164c0d --- /dev/null +++ b/src/views/points/list/script.js @@ -0,0 +1,128 @@ +import { Component, Vue } from "vue-property-decorator"; +import { mapState } from "vuex"; +import RouteParamsMixin from "view-ui-admin/src/mixins/route-params"; +import ListMixin from "view-ui-admin/src/mixins/list"; +import ListForm from "./form"; + +const module = "points"; +const initWhere = { + dateRange: { + $eq: [] + }, + wxUserId: { + $eq: "" + } +}; + +@Component({ + components: { + "c-list-form": ListForm + }, + mixins: [RouteParamsMixin, ListMixin], + computed: mapState({ + list: state => state[module].list + }) +}) +export default class extends Vue { + data() { + const { ListColumnWidth } = this.$consts; + + return { + cList: { + columns: [ + { + type: "selection", + width: 60 + }, + { + title: "微信用户", + render: (h, { row }) => h("span", row.wxUser.nickName) + }, + { + title: "积分", + key: "value", + width: 100 + }, + { + title: "时间", + width: ListColumnWidth.CreatedAt, + render: (h, { row }) => h("span", this.$time.getTime(row.createdAt)) + }, + { + title: "操作", + key: "action", + width: 104, + render: (h, { row }) => + h("div", [ + h("c-confirm-button", { + props: { + buttonText: "删除", + confirmText: "确认删除?" + }, + on: { + ok: () => { + this.confirmDelete(row.id); + } + } + }) + ]) + } + ], + cSearch: { + where: this.$helpers.deepCopy(initWhere) + }, + total: 0 + } + }; + } + + async beforeRouteUpdate(to, from, next) { + this.initListSearchWhere(initWhere); + await this.getListAndTotal(); + next(); + } + + async created() { + this.initListSearchWhere(initWhere); + await this.getListAndTotal(); + } + + async getListAndTotal() { + this.getList(); + this.cList.total = await this.getTotal(); + } + + getList() { + return this.$store.dispatch(`${module}/getList`, { + query: { + offset: (this.listPageCurrent - 1) * this.$consts.PageSize, + limit: this.$consts.PageSize, + where: this.listSearchWhere, + include: [ + { + model: "WxUser", + as: "wxUser" + } + ] + } + }); + } + + async getTotal() { + const { data } = await this.$store.dispatch(`${module}/postAction`, { + action: "getTotal", + query: { + where: this.listSearchWhere + } + }); + return data; + } + + async confirmDelete(ids) { + await this.$store.dispatch(`${module}/delete`, { id: ids }); + this.$Message.success("删除成功"); + + const { items } = await this.getList(); + !items.length && this.goListPrevPage(); + } +} diff --git a/src/views/products/form/index.vue b/src/views/products/form/index.vue index 2aa7d0d2..fcfcb41f 100644 --- a/src/views/products/form/index.vue +++ b/src/views/products/form/index.vue @@ -118,102 +118,4 @@ - + diff --git a/src/views/products/form/script.js b/src/views/products/form/script.js new file mode 100644 index 00000000..8f07d443 --- /dev/null +++ b/src/views/products/form/script.js @@ -0,0 +1,97 @@ +import { Component, Vue } from "vue-property-decorator"; +import RouteParamsMixin from "view-ui-admin/src/mixins/route-params"; +import FormMixin from "view-ui-admin/src/mixins/form"; +import { mapState } from "vuex"; + +const module = "products"; + +@Component({ + mixins: [RouteParamsMixin, FormMixin], + computed: mapState({ + detail: state => state[module].detail + }) +}) +export default class extends Vue { + data() { + return { + cForm: { + model: this.getFormInitModel(), + rules: { + name: [ + { + required: true, + message: "名称不能为空" + } + ], + categoryId: [ + { + required: true, + message: "分类不能为空" + } + ], + type: [ + { + required: true, + message: "类型不能为空" + } + ], + pictureIds: [ + { + required: true, + message: "图片不能为空" + } + ], + content: [ + { + required: true, + message: "详情不能为空" + } + ] + } + }, + formField: { + key: 0, + label: "" + } + }; + } + + async created() { + this.id && this.getDetail(module, this.id); + } + + getFormInitModel() { + return { + originalPrice: 0, + price: 0, + commissionRate: 0, + stock: 0, + sales: 0, + status: 1 + }; + } + + submit() { + this.$refs.form.validate(async valid => { + if (valid) { + const { + model: { id, ...restModel } + } = this.cForm; + + const { data } = await this.$store.dispatch( + `${module}/${id ? "put" : "post"}`, + { + id, + body: restModel + } + ); + + this.cForm.modal = false; + this.$Message.success(`${id ? "编辑" : "新增"}成功`); + this.$emit("get-list", data); + } + + this.fixFormButtonLoading(); + }); + } +} diff --git a/src/views/products/list/index.vue b/src/views/products/list/index.vue index a96dff36..1d294c6b 100644 --- a/src/views/products/list/index.vue +++ b/src/views/products/list/index.vue @@ -73,221 +73,4 @@ - + diff --git a/src/views/products/list/script.js b/src/views/products/list/script.js new file mode 100644 index 00000000..21829fd7 --- /dev/null +++ b/src/views/products/list/script.js @@ -0,0 +1,216 @@ +import { Component, Vue } from "vue-property-decorator"; +import { mapState } from "vuex"; +import RouteParamsMixin from "view-ui-admin/src/mixins/route-params"; +import ListMixin from "view-ui-admin/src/mixins/list"; +import AllCategoriesListMixin from "view-ui-admin/src/mixins/all-categories-list"; + +const module = "products"; + +const initWhere = { + status: { + $eq: "" + }, + categoryId: { + $eq: "" + }, + name: { + $like: "" + } +}; + +@Component({ + mixins: [RouteParamsMixin, ListMixin, AllCategoriesListMixin], + computed: mapState({ + list: state => state[module].list + }) +}) +export default class extends Vue { + data() { + const { ListColumnWidth, OrderAction } = this.$consts; + + return { + cList: { + columns: [ + { + type: "selection", + width: 60 + }, + { + title: "图片", + width: 118, + render: (h, { row }) => { + return h("c-list-image", { + props: { + src: this.$helpers.getImageUrl({ + id: row.pictureIds[0], + width: 80, + height: 80 + }) + } + }); + } + }, + { + title: "名称", + key: "name", + minWidth: ListColumnWidth.Title + }, + { + title: "分类", + width: 100, + render: (h, { row }) => + h("span", this.getCategoryNameById(row.categoryId, true)) + }, + { + title: "原价", + width: 80, + render: (h, { row }) => h("span", row.originalPrice + "元") + }, + { + title: "会员价", + width: 80, + render: (h, { row }) => h("span", row.price + "元") + }, + { + title: "佣金比例", + width: 90, + render: (h, { row }) => h("span", row.commissionRate + "%") + }, + { + title: "库存", + key: "stock", + width: 80 + }, + { + title: "销量", + key: "sales", + width: 80 + }, + { + title: "状态", + width: 80, + render: (h, { row }) => + h( + "span", + null, + this.$helpers.getItem( + this.dicts.PublishStatus, + "value", + row.status + )["label"] + ) + }, + { + title: "操作", + key: "action", + width: 340, + render: (h, { row }) => + h("div", [ + h( + "Button", + { + props: { + to: `/${this.alias}/products/list/form/${row.id}` + } + }, + "编辑" + ), + h("c-dropdown", { + props: { + width: 90, + title: "修改状态", + options: this.dicts.PublishStatus + }, + on: { + click: action => { + this.changeStatus(row.id, action); + } + } + }), + h("c-dropdown", { + props: { + title: "排序", + options: OrderAction + }, + on: { + click: action => { + this.order(row.id, action); + } + } + }), + h("c-confirm-button", { + props: { + buttonText: "删除", + confirmText: "确认删除?" + }, + on: { + ok: () => { + this.confirmDelete(row.id); + } + } + }) + ]) + } + ], + cSearch: { + where: this.$helpers.deepCopy(initWhere) + } + } + }; + } + + async beforeRouteUpdate(to, from, next) { + this.initListSearchWhere(initWhere); + this.getList(); + next(); + } + + async created() { + this.initListSearchWhere(initWhere); + this.getList(); + } + + getList() { + return this.$store.dispatch(`${module}/getList`, { + query: { + offset: (this.listPageCurrent - 1) * this.$consts.PageSize, + limit: this.$consts.PageSize, + where: this.listSearchWhere || initWhere, + order: [["order", "DESC"]] + } + }); + } + + async confirmDelete(ids) { + await this.$store.dispatch(`${module}/delete`, { id: ids }); + this.$Message.success("删除成功"); + + const { items } = await this.getList(); + !items.length && this.goListPrevPage(); + } + + async changeStatus(id, action) { + await this.$store.dispatch(`${module}/put`, { + id, + body: { + status: action + } + }); + this.$Message.success("修改状态成功"); + this.getList(); + } + + async order(id, action) { + await this.$store.dispatch(`${module}/postAction`, { + id, + action: "order", + query: { + where: this.listSearchWhere || initWhere + }, + body: { action } + }); + + this.$Message.success("排序成功"); + this.getList(); + } +} diff --git a/src/views/withdraws/list/index.vue b/src/views/withdraws/list/index.vue index 74162cc7..fec8246d 100644 --- a/src/views/withdraws/list/index.vue +++ b/src/views/withdraws/list/index.vue @@ -70,173 +70,4 @@ - + diff --git a/src/views/withdraws/list/script.js b/src/views/withdraws/list/script.js new file mode 100644 index 00000000..0be1c758 --- /dev/null +++ b/src/views/withdraws/list/script.js @@ -0,0 +1,168 @@ +import { Component, Vue } from "vue-property-decorator"; +import { mapState } from "vuex"; +import RouteParamsMixin from "view-ui-admin/src/mixins/route-params"; +import ListMixin from "view-ui-admin/src/mixins/list"; + +const module = "withdraws"; +const initWhere = { + dateRange: { + $eq: [] + }, + status: { + $eq: "" + }, + wxUserId: { + $eq: "" + } +}; + +@Component({ + mixins: [RouteParamsMixin, ListMixin], + computed: mapState({ + list: state => state[module].list + }) +}) +export default class extends Vue { + data() { + const { ListColumnWidth } = this.$consts; + + return { + cList: { + columns: [ + { + type: "selection", + width: 60 + }, + { + title: "微信用户", + width: 150, + render: (h, { row }) => h("span", row.wxUser.nickName) + }, + { + title: "提现金额", + render: (h, { row }) => h("span", `${row.value}元`) + }, + { + title: "申请时间", + width: ListColumnWidth.CreatedAt, + render: (h, { row }) => h("span", this.$time.getTime(row.createdAt)) + }, + { + title: "状态", + width: 80, + render: (h, { row }) => + h( + "span", + null, + this.$helpers.getItem( + this.dicts.WithdrawStatus, + "value", + row.status + )["label"] + ) + }, + { + title: "操作", + key: "action", + width: 180, + render: (h, { row }) => + h("div", [ + h("c-dropdown", { + props: { + width: 66, + title: "审核", + options: this.dicts.CheckAction, + disabled: !this.isPlatform() || row.status === "Paid" + }, + on: { + click: action => { + this.$Modal.confirm({ + title: "请确认", + content: `确认${ + this.$helpers.getItem( + this.dicts.CheckStatus, + "value", + action + )["label"] + }?`, + onOk: () => { + this.changeStatus(row.id, action); + } + }); + } + } + }), + h( + "c-confirm-button", + { + props: { + disabled: !this.isPlatform() + }, + on: { + ok: () => { + this.confirmDelete(row.id); + } + } + }, + "删除" + ) + ]) + } + ], + cSearch: { + where: this.$helpers.deepCopy(initWhere) + } + } + }; + } + + async beforeRouteUpdate(to, from, next) { + this.initListSearchWhere(initWhere); + this.getList(); + next(); + } + + async created() { + this.initListSearchWhere(initWhere); + this.getList(); + } + + getList() { + return this.$store.dispatch(`${module}/getList`, { + query: { + offset: (this.listPageCurrent - 1) * this.$consts.PageSize, + limit: this.$consts.PageSize, + where: this.listSearchWhere || initWhere, + include: [ + { + model: "WxUser", + as: "wxUser" + } + ] + } + }); + } + + async confirmDelete(ids) { + await this.$store.dispatch(`${module}/delete`, { id: ids }); + this.$Message.success("删除成功"); + + const { items } = await this.getList(); + !items.length && this.goListPrevPage(); + } + + async changeStatus(id, action) { + await this.$store.dispatch(`${module}/put`, { + id, + body: { + status: this.$helpers.actionToStatus(this.dicts.WithdrawStatus, action) + } + }); + this.$Message.success( + `${ + this.$helpers.getItem(this.dicts.CheckStatus, "value", action)["label"] + }成功` + ); + this.getList(); + } +} diff --git a/src/views/wx-users/list/index.vue b/src/views/wx-users/list/index.vue index 5c1264ac..3abcd3e8 100644 --- a/src/views/wx-users/list/index.vue +++ b/src/views/wx-users/list/index.vue @@ -48,141 +48,4 @@ - + diff --git a/src/views/wx-users/list/script.js b/src/views/wx-users/list/script.js new file mode 100644 index 00000000..028b9fe2 --- /dev/null +++ b/src/views/wx-users/list/script.js @@ -0,0 +1,136 @@ +import { Component, Vue } from "vue-property-decorator"; +import { mapState } from "vuex"; +import RouteParamsMixin from "view-ui-admin/src/mixins/route-params"; +import ListMixin from "view-ui-admin/src/mixins/list"; + +const module = "wxUsers"; +const initWhere = { + nickName: { + $like: "" + }, + name: { + $like: "" + } +}; + +@Component({ + mixins: [RouteParamsMixin, ListMixin], + computed: mapState({ + list: state => state[module].list + }) +}) +export default class extends Vue { + data() { + const { ListColumnWidth } = this.$consts; + + return { + cList: { + columns: [ + { + type: "selection", + width: 60 + }, + { + title: "图片", + width: 118, + render: (h, { row }) => { + return h("c-list-image", { + props: { + src: row.avatarUrl + } + }); + } + }, + { + title: "昵称", + key: "nickName", + minWidth: ListColumnWidth.User + }, + { + title: "姓名", + key: "name", + minWidth: ListColumnWidth.User + }, + { + title: "手机号", + key: "phoneNumber", + width: 150 + }, + { + title: "性别", + key: "gender", + width: 65, + render: (h, { row }) => + h( + "span", + this.$helpers.getItem(this.dicts.Gender, "value", row.gender)[ + "label" + ] + ) + }, + { + title: "省份", + key: "province", + width: 100 + }, + { + title: "城市", + key: "city", + width: 100 + }, + { + title: "操作", + key: "action", + width: 90, + render: (h, { row }) => + h("div", [ + h("c-confirm-button", { + props: { + buttonText: "删除", + confirmText: "确认删除?" + }, + on: { + ok: () => { + this.confirmDelete(row.id); + } + } + }) + ]) + } + ], + cSearch: { + where: this.$helpers.deepCopy(initWhere) + } + } + }; + } + + async beforeRouteUpdate(to, from, next) { + this.initListSearchWhere(initWhere); + this.getList(); + next(); + } + + async created() { + this.initListSearchWhere(initWhere); + this.getList(); + } + + getList() { + return this.$store.dispatch(`${module}/getList`, { + query: { + offset: (this.listPageCurrent - 1) * this.$consts.PageSize, + limit: this.$consts.PageSize, + where: this.listSearchWhere || initWhere + } + }); + } + + async confirmDelete(ids) { + await this.$store.dispatch(`${module}/delete`, { id: ids }); + this.$Message.success("删除成功"); + + const { items } = await this.getList(); + !items.length && this.goListPrevPage(); + } +}