123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 |
- 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: [],
- order: '',
- sort: '',
- filter: {
- drawer: false,
- data: {
- user: { field: 'id', value: '' },
- createtime: [],
- logintime: [],
- },
- tools: {
- user: {
- type: 'tinputprepend',
- label: '用户信息',
- placeholder: '请输入查询内容',
- value: {
- field: 'id',
- value: '',
- },
- options: {
- data: [{
- label: '用户ID',
- value: 'id',
- },
- {
- label: '用户名',
- value: 'username',
- },
- {
- label: '昵称',
- value: 'nickname',
- },
- {
- label: '手机号',
- value: 'mobile',
- },
- {
- label: '邮箱',
- value: 'email',
- }],
- }
- },
- createtime: {
- type: 'tdatetimerange',
- label: '注册时间',
- value: [],
- },
- logintime: {
- type: 'tdatetimerange',
- label: '上次登录',
- value: [],
- },
- },
- condition: {},
- }
- })
- function getData() {
- let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
- let search = composeFilter(tempSearch, {
- username: 'like',
- nickname: 'like',
- mobile: 'like',
- email: 'like',
- createtime: 'range',
- logintime: 'range',
- });
- Fast.api.ajax({
- url: 'shopro/user/user',
- type: 'GET',
- data: {
- page: pagination.page,
- list_rows: pagination.list_rows,
- order: state.order,
- sort: state.sort,
- ...search,
- },
- }, function (ret, res) {
- state.data = res.data.data
- pagination.total = res.data.total
- return false
- }, function (ret, res) { })
- }
- function onChangeSort({ prop, order }) {
- state.order = order == 'ascending' ? 'asc' : 'desc';
- state.sort = prop;
- getData();
- }
- function onOpenFilter() {
- state.filter.drawer = true
- }
- function onChangeFilter() {
- pagination.page = 1
- getData()
- state.filter.drawer && (state.filter.drawer = false)
- }
- const pagination = reactive({
- page: 1,
- list_rows: 10,
- total: 0,
- })
- function onDetail(id) {
- Fast.api.open(`shopro/user/user/detail?id=${id}`, "详情", {
- callback() {
- getData()
- }
- })
- }
- function onDelete(id) {
- Fast.api.ajax({
- url: `shopro/user/user/delete/id/${id}`,
- type: 'DELETE',
- }, function (ret, res) {
- getData()
- }, function (ret, res) { })
- }
- onMounted(() => {
- getData()
- })
- return {
- state,
- getData,
- onChangeSort,
- onOpenFilter,
- onChangeFilter,
- pagination,
- onDetail,
- onDelete
- }
- }
- }
- createApp('index', index);
- },
- detail: () => {
- const { reactive, onMounted } = Vue
- const detail = {
- setup() {
- const state = reactive({
- type: new URLSearchParams(location.search).get('type'),
- id: new URLSearchParams(location.search).get('id'),
- detail: {}
- })
- function getDetail() {
- Fast.api.ajax({
- url: `shopro/user/user/detail/id/${state.id}`,
- type: 'GET',
- }, function (ret, res) {
- state.detail = res.data;
- return false
- }, function (ret, res) { })
- }
- const platform = {
- wechat: {
- openPlatform: '微信开放平台',
- miniProgram: '微信小程序',
- officialAccount: '微信公众平台',
- },
- };
- function statusStyle(key) {
- let flag = state.detail.verification?.[key];
- return `<span style="color:${flag ? 'var(--el-color-success)' : 'var(--el-color-warning)'}">
- ${flag ? '已' : '未'}${key == 'username' || key == 'password' ? '设置' : '认证'}
- </span>`;
- }
- function onSelectAvatar() {
- Fast.api.open(`general/attachment/select`, "选择", {
- callback: function (data) {
- state.detail.avatar = data.url;
- }
- });
- }
- async function onSave() {
- Fast.api.ajax({
- url: `shopro/user/user/edit/id/${state.id}`,
- type: 'POST',
- data: state.detail,
- }, function (ret, res) {
- getDetail()
- }, function (ret, res) { })
- }
- function onChangeParentUser() {
- Fast.api.open(`shopro/commission/agent/select?id=${state.id}`, "更换上级分销商", {
- callback() {
- getDetail()
- }
- })
- }
- function onRecharge(type) {
- Fast.api.open(`shopro/user/user/recharge?type=${type}&id=${state.detail.id}`, "充值", {
- callback: function () {
- getDetail();
- getLog()
- }
- });
- }
- const log = reactive({
- tabActive: 'money',
- data: [],
- })
- function getLog() {
- let url
- let search = {}
- if (log.tabActive == 'money' || log.tabActive == 'score' || log.tabActive == 'commission') {
- url = `shopro/user/wallet_log/${log.tabActive}/id/${state.id}`
- }
- if (log.tabActive == 'order') {
- url = `shopro/order/order`
- search = {
- search: JSON.stringify({
- user_id: state.id
- })
- }
- }
- if (log.tabActive == 'share') {
- url = `shopro/share`
- search = {
- id: state.id
- }
- }
- if (log.tabActive == 'coupon') {
- url = `shopro/user/user/coupon/id/${state.id}`
- }
- Fast.api.ajax({
- url: url,
- type: 'GET',
- data: {
- page: pagination.page,
- list_rows: pagination.list_rows,
- ...search,
- },
- }, function (ret, res) {
- if (log.tabActive == 'order') {
- log.data = res.data.orders.data
- pagination.total = res.data.orders.total
- } else {
- log.data = res.data.data
- pagination.total = res.data.total
- }
- return false
- }, function (ret, res) { })
- }
- const pagination = reactive({
- page: 1,
- list_rows: 10,
- total: 0,
- })
- function onChangeTab() {
- log.data = []
- pagination.page = 1
- pagination.total = 0
- getLog()
- }
- onMounted(() => {
- getDetail()
- getLog()
- })
- return {
- state,
- getDetail,
- platform,
- statusStyle,
- onSelectAvatar,
- onSave,
- onChangeParentUser,
- onRecharge,
- log,
- getLog,
- pagination,
- onChangeTab,
- }
- }
- }
- createApp('detail', detail);
- },
- recharge: () => {
- const { reactive, getCurrentInstance } = Vue
- const recharge = {
- 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: {
- id: state.id,
- type: state.type,
- amount: '',
- memo: '',
- },
- rules: {
- amount: [{ required: true, message: '请输入', trigger: 'blur' }],
- },
- })
- function onConfirm() {
- proxy.$refs['formRef'].validate((valid) => {
- if (valid) {
- Fast.api.ajax({
- url: `shopro/user/user/recharge`,
- type: 'POST',
- data: form.model,
- }, function (ret, res) {
- Fast.api.close()
- }, function (ret, res) { })
- }
- });
- }
- return {
- state,
- form,
- onConfirm
- }
- }
- }
- createApp('recharge', recharge);
- },
- select: function () {
- const { reactive, onMounted } = Vue
- const select = {
- setup() {
- const state = reactive({
- id: new URLSearchParams(location.search).get('id') || false,
- filter: {
- drawer: false,
- data: {
- keyword: '',
- },
- tools: {},
- condition: {},
- },
- data: [],
- ids: [],
- isSelectAll: false,
- isIndeterminate: false,
- })
- function getData() {
- let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
- let search = composeFilter(tempSearch, {
- keyword: 'like',
- });
- Fast.api.ajax({
- url: 'shopro/user/user/select',
- type: 'GET',
- data: {
- page: pagination.page,
- list_rows: pagination.list_rows,
- ...search,
- },
- }, function (ret, res) {
- state.data = res.data.data
- pagination.total = res.data.total
- calculateSelect();
- return false
- }, function (ret, res) { })
- }
- const pagination = reactive({
- page: 1,
- list_rows: 10,
- total: 0,
- })
- function onChangeFilter() {
- pagination.page = 1
- getData()
- }
- function onSelect(type, row) {
- if (type) {
- state.ids.push(row.id);
- } else {
- let findIndex = state.ids.findIndex((id) => id == row.id);
- state.ids.splice(findIndex, 1);
- }
- calculateSelect();
- };
- function onSelectAll(type) {
- if (type) {
- state.data.forEach((item) => {
- state.ids.push(item.id);
- });
- state.ids = Array.from(new Set(state.ids));
- } else {
- state.data.forEach((item) => {
- if (state.ids.findIndex((id) => id == item.id) !== -1) {
- state.ids.splice(
- state.ids.findIndex((id) => id == item.id),
- 1,
- );
- }
- });
- }
- calculateSelect();
- }
- function calculateSelect() {
- state.isSelectAll = false;
- state.isIndeterminate = false;
- if (state.data.every((item) => state.ids.includes(item.id))) {
- state.isSelectAll = true;
- state.isIndeterminate = false;
- } else if (state.data.some((item) => state.ids.includes(item.id))) {
- state.isSelectAll = false;
- state.isIndeterminate = true;
- }
- if (state.data.length === 0) {
- state.isSelectAll = false;
- state.isIndeterminate = false;
- }
- }
- function onConfirm() {
- Fast.api.ajax({
- url: `shopro/coupon/send/id/${state.id}`,
- type: 'POST',
- data: {
- user_ids: state.ids
- },
- }, function (ret, res) {
- Fast.api.close()
- }, function (ret, res) { })
- }
- onMounted(() => {
- getData()
- })
- return {
- state,
- getData,
- pagination,
- onChangeFilter,
- onSelect,
- onSelectAll,
- onConfirm
- }
- }
- }
- createApp('select', select);
- },
- };
- return Controller;
- });
|