123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: () => {
- const { reactive, onMounted } = Vue
- const index = {
- setup() {
- const state = reactive({
- data: [],
- })
- function getData() {
- Fast.api.ajax({
- url: 'shopro/commission/level',
- type: 'GET',
- }, function (ret, res) {
- state.data = res.data
- return false
- }, function (ret, res) { })
- }
- function onAdd() {
- Fast.api.open(`shopro/commission/level/add?type=add`, "添加", {
- callback() {
- getData()
- }
- })
- }
- function onEdit(id) {
- Fast.api.open(`shopro/commission/level/edit?type=edit&id=${id}`, "编辑", {
- callback() {
- getData()
- }
- })
- }
- function onDelete(id) {
- Fast.api.ajax({
- url: `shopro/commission/level/delete/id/${id}`,
- type: 'POST',
- }, function (ret, res) {
- getData();
- }, function (ret, res) { })
- }
- onMounted(() => {
- getData()
- })
- return {
- state,
- getData,
- onAdd,
- onEdit,
- onDelete,
- }
- }
- }
- createApp('index', index);
- },
- add: () => {
- Controller.form();
- },
- edit: () => {
- Controller.form();
- },
- form: () => {
- const { reactive, onMounted, getCurrentInstance } = Vue
- const addEdit = {
- setup() {
- const { proxy } = getCurrentInstance();
- const state = reactive({
- type: new URLSearchParams(location.search).get('type'),
- id: new URLSearchParams(location.search).get('id')
- })
- const form = reactive({
- model: {
- level: null,
- name: '',
- image: '',
- commission_rules: {
- commission_1: '0.00',
- commission_2: '0.00',
- commission_3: '0.00',
- },
- upgrade_type: 0,
- upgrade_rules: {},
- },
- rules: {
- level: [{ required: true, message: '请选择等级权重', trigger: 'blur' }],
- name: [{ required: true, message: '请输入等级名称', trigger: 'blur' }],
- commission_rules: {
- commission: [{ required: true, message: '佣金比例', trigger: 'blur' }],
- },
- upgrade_rules: [
- {
- validator: (rule, value, callback) => {
- if (isEmpty(value)) {
- callback(new Error('请填写升级条件'));
- } else {
- callback();
- }
- },
- trigger: 'blur',
- },
- ],
- upgrade_rules_inner: {
- rules: [{ required: true, message: '请输入', trigger: 'blur' }],
- level: [{ required: true, message: '请选择分销商等级', trigger: 'blur' }],
- },
- },
- })
- function getDetail() {
- Fast.api.ajax({
- url: `shopro/commission/level/detail/id/${state.id}`,
- type: 'GET',
- }, function (ret, res) {
- form.model = res.data;
- if (!isObject(form.model.upgrade_rules)) form.model.upgrade_rules = {};
- // level=1时 等级权重不可修改
- if (form.model.level == 1) {
- level.data = [
- {
- name: '一级',
- level: 1,
- },
- ];
- level.existLevel = [];
- level.data.forEach((e) => {
- level.existLevel.push(e.level);
- });
- } else {
- level.data = JSON.parse(JSON.stringify(defaultLevel));
- }
- let index = level.existLevel.findIndex((l) => l == form.model.level);
- level.existLevel.splice(index, 1);
- return false
- }, function (ret, res) { })
- }
- const defaultLevel = [
- {
- name: '一级',
- level: 1,
- },
- {
- name: '二级',
- level: 2,
- },
- {
- name: '三级',
- level: 3,
- },
- {
- name: '四级',
- level: 4,
- },
- {
- name: '五级',
- level: 5,
- },
- {
- name: '六级',
- level: 6,
- },
- {
- name: '七级',
- level: 7,
- },
- {
- name: '八级',
- level: 8,
- },
- {
- name: '九级',
- level: 9,
- },
- {
- name: '十级',
- level: 10,
- },
- ];
- function onSelectLevel(l) {
- if (!level.existLevel.includes(l)) {
- form.model.level = l;
- // 清空规则
- form.model.upgrade_rules = {};
- }
- }
- const level = reactive({
- data: [],
- select: [],
- existLevel: [],
- });
- function getLevelSelect() {
- Fast.api.ajax({
- url: `shopro/commission/level/select`,
- type: 'GET',
- }, function (ret, res) {
- level.select = res.data;
- level.select.forEach((e) => {
- level.existLevel.push(e.level);
- });
- return false
- }, function (ret, res) { })
- }
- const upgradeCondition = {
- user: {
- total_consume: {
- name: '用户消费金额',
- },
- child_user_count_1: {
- name: '一级用户人数',
- },
- child_user_count_2: {
- name: '二级用户人数',
- },
- child_user_count_all: {
- name: '团队用户人数',
- },
- },
- order_money: {
- child_order_money_0: {
- name: '自购分销订单总金额',
- },
- child_order_money_1: {
- name: '一级分销订单金额',
- },
- child_order_money_2: {
- name: '二级分销订单金额',
- },
- child_order_money_all: {
- name: '团队分销订单金额',
- },
- },
- order_count: {
- child_order_count_0: {
- name: '自购分销订单数量',
- },
- child_order_count_1: {
- name: '一级分销订单数量',
- },
- child_order_count_2: {
- name: '二级分销订单数量',
- },
- child_order_count_all: {
- name: '团队分销订单数量',
- },
- },
- agent_count: {
- child_agent_count_1: {
- name: '一级分销商人数',
- },
- child_agent_count_2: {
- name: '二级分销商人数',
- },
- child_agent_count_all: {
- name: '团队分销商人数',
- },
- },
- agent_level: {
- child_agent_level_all: {
- name: '团队分销商等级统计',
- },
- child_agent_level_1: {
- name: '一级分销商等级统计',
- },
- },
- };
- function onSelectUpgradeCondition(key) {
- form.model.upgrade_rules[key] = '';
- if (key == 'child_agent_level_all' || key == 'child_agent_level_1') {
- form.model.upgrade_rules[key] = [
- {
- level: '',
- count: '',
- },
- ];
- }
- }
- function onAddUpgradeRules(key) {
- form.model.upgrade_rules[key].push({
- level: '',
- count: '',
- });
- }
- function onDeleteRules(key, index) {
- if (key == 'child_agent_level_all' || key == 'child_agent_level_1') {
- form.model.upgrade_rules[key].splice(index, 1);
- if (form.model.upgrade_rules[key].length == 0) delete form.model.upgrade_rules[key];
- } else {
- delete form.model.upgrade_rules[key];
- }
- }
- function initUnit(key) {
- if (key.includes('child_user_count') || key.includes('child_agent_count')) {
- return '人';
- }
- if (key.includes('total_consume') || key.includes('child_order_money')) {
- return '元';
- }
- if (key.includes('child_order_count')) {
- return '单';
- }
- }
- function onConfirm() {
- proxy.$refs['formRef'].validate((valid) => {
- if (valid) {
- Fast.api.ajax({
- url: state.type == 'add' ? 'shopro/commission/level/add' : `shopro/commission/level/edit/id/${state.id}`,
- type: 'POST',
- data: JSON.parse(JSON.stringify(form.model))
- }, function (ret, res) {
- Fast.api.close()
- }, function (ret, res) { })
- }
- });
- }
- onMounted(() => {
- getLevelSelect()
- if (state.type == 'add') {
- level.data = JSON.parse(JSON.stringify(defaultLevel));
- } else if (state.type == 'edit') {
- getDetail()
- }
- })
- return {
- state,
- form,
- onSelectLevel,
- defaultLevel,
- level,
- getLevelSelect,
- upgradeCondition,
- onSelectUpgradeCondition,
- onAddUpgradeRules,
- onDeleteRules,
- initUnit,
- onConfirm
- }
- }
- }
- createApp('addEdit', addEdit);
- },
- select: () => {
- const { reactive, onMounted } = Vue
- const select = {
- setup() {
- const state = reactive({
- level: new URLSearchParams(location.search).get('level'),
- data: [],
- })
- function getData() {
- Fast.api.ajax({
- url: 'shopro/commission/level/select',
- type: 'GET',
- }, function (ret, res) {
- state.data = res.data
- return false
- }, function (ret, res) { })
- }
- function onSelect(level) {
- state.level = level;
- }
- function onConfirm() {
- Fast.api.close(state.level)
- }
- onMounted(() => {
- getData()
- })
- return {
- state,
- getData,
- onSelect,
- onConfirm,
- }
- }
- }
- createApp('select', select);
- },
- };
- return Controller;
- });
|