cloudroam
2025-03-28 cef2bb0eeeb91a22860cf5d23c7348af1ba921dc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<template>
  <el-bus-crud ref="crud" v-bind="tableConfig" />
</template>
 
<script>
import { getPartnerListConfig } from '@/utils/form-item-config'
export default {
  data() {
    return {
      tableConfig: {
        url: 'flower/api/customer/page',
        hasNew: false,
        hasEdit: false,
        hasDelete: false,
        operationAttrs: {
          width: 150,
          fixed: 'right',
        },
        beforeOpen: (data, isNew) => {
          if (!isNew) {
            data.area = this.getDistrict(data)
          }
        },
        columns: [
          { label: '商户名称', prop: 'name', minWidth: 150, fixed: 'left' },
          { label: '商户昵称', prop: 'nickName', minWidth: 150 },
          { label: '所属合伙人', prop: 'partnerName', minWidth: 150 },
          { label: '下单次数', prop: 'orderNum', minWidth: 150 },
          {
            label: '地址',
            formatter: (row) => this.getDistrict(row),
            minWidth: 250,
          },
          { label: '联系方式', prop: 'tel', minWidth: 150 },
          { label: '注册时间', prop: 'createTime', minWidth: 180 },
          {
            label: '启用/禁用',
            formatter: (row) => (
              <el-switch
                value={row.isEnabled}
                onChange={this.onEnabledChange.bind(this, row)}
              ></el-switch>
            ),
            minWidth: 120,
            fixed: 'right',
          },
        ],
        searchForm: [
          {
            type: 'row',
            items: [
              { label: '商户名称', id: 'name', type: 'input' },
              {
                ...getPartnerListConfig(),
                label: '合伙人',
              },
              {
                label: '所属地区',
                id: 'area',
                component: 'el-bus-select-area',
                commonFormat: true,
                commonFormatProps: ['province', 'city', 'region'],
                customClass: 'in-bus-form',
              },
              { label: '手机号', id: 'tel', type: 'input' },
              {
                label: '启用/禁用',
                id: 'isEnabled',
                type: 'bus-select-dict',
                default: '1',
                el: {
                  code: 'USER_ENABLED_OR_DISABLED',
                  clearable: true,
                  style: 'width:100%',
                },
              },
            ],
          },
        ],
        form: [
          { label: '商户名称:', id: 'name', type: 'input' },
          { label: '商户昵称:', id: 'nickName', type: 'input' },
          { label: '所属合伙人:', id: 'partnerName', type: 'input' },
          { label: '地址:', id: 'area', type: 'input' },
          { label: '联系方式:', id: 'tel', type: 'input' },
        ],
        extraDialogs: [
          {
            title: '变更合伙人',
            hiddenReverseItems: [],
            form: [
              {
                ...getPartnerListConfig(),
                label: '所属合伙人:',
              },
            ],
            atConfirm: async (val) => {
              const { code } = await this.$elBusHttp.request(
                'flower/api/customer/change/partner',
                {
                  method: 'post',
                  data: val,
                }
              )
              if (code === 0) {
                this.$message.success('变更合伙人成功')
              }
            },
          },
        ],
        extraButtons: [
          {
            text: '变更合伙人',
            atClick: (row) => {
              this.$refs.crud.$refs.extraDialog[0].show(row)
              return false
            },
          },
        ],
      },
    }
  },
  head() {
    return {
      title: '商户列表',
    }
  },
  methods: {
    getDistrict(row) {
      return `${row.province || ''}${row.city || ''}${row.region || ''}${
        row.address || ''
      }`
    },
    onEnabledChange(row, e) {
      const url = 'flower/api/customer/page/isEnable'
      const text = e ? '启用' : '禁用'
      this.$elBusUtil
        .confirm(`确定要${text}这个商户吗?`)
        .then(async () => {
          const { code } = await this.$elBusHttp.request(url, {
            params: {
              id: row.id,
            },
          })
          if (code === 0) {
            this.$message.success(`${text}成功`)
            this.$refs.crud.getList()
          }
        })
        .catch(() => {})
    },
  },
}
</script>