index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <div class="filter-control">
  5. <span>供应商名称:</span>
  6. <el-input v-model="listQuery.shopName" placeholder="供应商名称" @keyup.enter.native="handleFilter" />
  7. </div>
  8. <div class="filter-control">
  9. <span>供应商类型:</span>
  10. <el-select
  11. v-model="listQuery.shopType"
  12. placeholder="供应商类型"
  13. clearable
  14. style="width: 200px"
  15. class="filter-item"
  16. @change="getList()"
  17. >
  18. <el-option label="所有类型" value="" />
  19. <el-option label="代理商" :value="2" />
  20. <el-option label="品牌方" :value="1" />
  21. </el-select>
  22. </div>
  23. <div class="filter-control">
  24. <span>登录账号:</span>
  25. <el-input v-model="listQuery.loginAccount" placeholder="登录账号" @keyup.enter.native="handleFilter" />
  26. </div>
  27. <div class="filter-control">
  28. <span>手机号:</span>
  29. <el-input
  30. v-model="listQuery.mobile"
  31. placeholder="手机号"
  32. style="width: 200px"
  33. class="filter-item"
  34. @keyup.enter.native="handleFilter"
  35. />
  36. </div>
  37. <div class="filter-control">
  38. <span>联系人:</span>
  39. <el-input
  40. v-model="listQuery.linkMan"
  41. placeholder="联系人"
  42. style="width: 200px"
  43. class="filter-item"
  44. @keyup.enter.native="handleFilter"
  45. />
  46. </div>
  47. <div class="filter-control">
  48. <el-button type="primary" @click="getList(listQuery)">查询</el-button>
  49. <el-button type="primary" @click="navigationTo('supplier-add')">添加供应商</el-button>
  50. </div>
  51. </div>
  52. <!-- 表格区域 -->
  53. <el-table
  54. :key="tableKey"
  55. v-loading="listLoading"
  56. :data="list"
  57. border
  58. fit
  59. highlight-current-row
  60. style="width: 100%"
  61. header-row-class-name="tableHeader"
  62. >
  63. <el-table-column label="序号" :index="indexMethod" type="index" sortable="custom" align="center" width="80" />
  64. <el-table-column label="供应商名称" align="center" prop="name" />
  65. <el-table-column label="供应商类型" width="100px" align="center">
  66. <template v-slot="{ row }">
  67. <span v-if="row.shopType === 1">品牌方</span>
  68. <span v-if="row.shopType === 2">代理商</span>
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="登录账号" width="120px" align="center">
  72. <template slot-scope="{ row }">
  73. <span v-if="row.loginAccount">{{ row.loginAccount }}</span>
  74. <span v-else>未绑定</span>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="手机号" width="120px" align="center" prop="mobile" />
  78. <el-table-column label="联系人" width="100px" align="center" prop="linkMan" />
  79. <el-table-column label="供应商状态" align="center" width="100px">
  80. <template v-slot="{ row }">
  81. <el-switch v-model="row.shopStatus" @change="handleChangeStatus(row)" />
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="创建时间" class-name="status-col" width="160px">
  85. <template slot-scope="{ row }">
  86. <span>{{ row.createTime | formatTime }}</span>
  87. </template>
  88. </el-table-column>
  89. <el-table-column label="创建人" width="120px" align="center" prop="createBy" />
  90. <!-- <el-table-column label="创建人" class-name="status-col" width="100px" prop="createBy" /> -->
  91. <el-table-column label="操作" align="center" width="360" class-name="small-padding fixed-width">
  92. <template slot-scope="{ row }">
  93. <el-button size="mini" type="primary" @click="onGetLink(row, $event)"> 首页链接 </el-button>
  94. <el-button size="mini" type="primary" @click="navigationTo(`supplier-edit?id=${row.authUserId}&type=edit`)">
  95. 编辑
  96. </el-button>
  97. <el-button size="mini" type="primary" @click="handleResetPwd(row)"> 重置密码 </el-button>
  98. <el-button size="mini" type="primary" @click="handleProxy(row)"> 代他操作 </el-button>
  99. <!-- <el-button size="mini" type="primary" @click="navigationTo(`club-list?id=${row.authUserId}`)">
  100. 查看机构认证
  101. </el-button> -->
  102. </template>
  103. </el-table-column>
  104. </el-table>
  105. <!-- 页码 -->
  106. <pagination
  107. :total="total"
  108. :page.sync="listQuery.pageNum"
  109. :limit.sync="listQuery.pageSize"
  110. @pagination="getList(listQuery)"
  111. />
  112. </div>
  113. </template>
  114. <script>
  115. import { fetchSupplierList, supplierStatusChange } from '@/api/supplier'
  116. import { generateProxyToken, resetPassword } from '@/api/user'
  117. import handleClipboard from '@/utils/clipboard'
  118. export default {
  119. name: 'ComplexTable',
  120. // mixins: [scrollTo],
  121. data() {
  122. return {
  123. slider: 1,
  124. listLoading: true,
  125. tableKey: '',
  126. total: 0, // 条数统计
  127. listQuery: {
  128. infoId: '', // 品牌id
  129. linkMan: '', // 联系人
  130. mobile: '', // 手机号
  131. pageNum: 0, // 页码
  132. pageSize: 10, // 分页大小
  133. shopName: '', // 供应商名称
  134. shopType: '', // 供应商类型
  135. loginAccount: '' // 登录账号
  136. },
  137. list: [],
  138. prevData: ''
  139. }
  140. },
  141. created() {
  142. this.getList()
  143. },
  144. methods: {
  145. // 获取列表数据
  146. async getList() {
  147. this.listLoading = true
  148. try {
  149. const res = await fetchSupplierList(this.listQuery)
  150. const { total, list } = res.data
  151. this.total = total
  152. this.list = this.formatList(list)
  153. } catch (error) {
  154. console.log(error)
  155. } finally {
  156. this.listLoading = false
  157. }
  158. },
  159. // 格式化数组
  160. formatList(list = []) {
  161. return list.map((item) => {
  162. item.shopStatus = item.shopStatus === 1
  163. return item
  164. })
  165. },
  166. // 供应商状态改变
  167. async handleChangeStatus(item) {
  168. console.log(item.shopStatus)
  169. const oldStatus = !item.shopStatus // 保存旧状态
  170. try {
  171. await supplierStatusChange({
  172. status: item.shopStatus ? 1 : 0,
  173. authUserId: item.authUserId
  174. })
  175. this.$message.success('操作成功')
  176. } catch (error) {
  177. // eslint-disable-next-line require-atomic-updates
  178. item.shopStatus = oldStatus
  179. console.log(error)
  180. }
  181. },
  182. // 重置密码
  183. async handleResetPwd(item) {
  184. const text = await this.$confirm('此操作将重置该供应商的密码, 是否继续?', '提示', {
  185. confirmButtonText: '确定',
  186. cancelButtonText: '取消',
  187. type: 'warning'
  188. }).catch(() => {
  189. this.$message.info('已取消操作')
  190. })
  191. if (text !== 'confirm') return
  192. // 要执行的操作
  193. resetPassword({ authUserId: item.authUserId }).then((res) => {
  194. if (res.code !== 0) return
  195. const h = this.$createElement
  196. this.$notify.success({
  197. title: '重置密码',
  198. message: h('i', { style: 'color: #333' }, `已重置供应商"${item.name}"的密码`),
  199. duration: 2000
  200. })
  201. })
  202. },
  203. // 代他操作
  204. async handleProxy(item) {
  205. const text = await this.$confirm('此操作将临时登录该供应商账号, 是否继续?', '提示', {
  206. confirmButtonText: '确定',
  207. cancelButtonText: '取消',
  208. type: 'warning'
  209. }).catch(() => {
  210. this.$message.info('已取消操作')
  211. })
  212. if (text !== 'confirm') return
  213. if (!item.shopStatus) {
  214. this.$message.warning('当前供应商未启用')
  215. return
  216. }
  217. try {
  218. const res = await generateProxyToken({ authUserId: item.authUserId })
  219. const userInfo = { ...item, token: res.data }
  220. // 要执行的操作
  221. this.$store.commit('proxy/OPEN_PROXY', userInfo)
  222. this.$store.dispatch('user/proxyLogin')
  223. this.$router.push('/proxy')
  224. } catch (error) {
  225. console.log(error)
  226. }
  227. },
  228. // 过滤列表
  229. handleFilter() {
  230. this.listQuery.page = 1
  231. this.getList()
  232. },
  233. indexMethod(index) {
  234. return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
  235. },
  236. // 获取供应商链接
  237. onGetLink(row, $event) {
  238. const link = process.env.VUE_APP_WWW_HOST + '/' + row.authUserId + '/' + (row.prefix || 'app')
  239. handleClipboard(link, '已复制到剪切板', $event)
  240. }
  241. }
  242. }
  243. </script>
  244. <style lang="scss" scoped></style>