index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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="280" class-name="small-padding fixed-width">
  92. <template slot-scope="{ row }">
  93. <el-button size="mini" type="primary" @click="navigationTo(`supplier-edit?id=${row.authUserId}&type=edit`)">
  94. 编辑
  95. </el-button>
  96. <el-button size="mini" type="primary" @click="handleResetPwd(row)"> 重置密码 </el-button>
  97. <el-button size="mini" type="primary" @click="handleProxy(row)"> 代他操作 </el-button>
  98. <!-- <el-button size="mini" type="primary" @click="navigationTo(`club-list?id=${row.authUserId}`)">
  99. 查看机构认证
  100. </el-button> -->
  101. </template>
  102. </el-table-column>
  103. </el-table>
  104. <!-- 页码 -->
  105. <pagination
  106. :total="total"
  107. :page.sync="listQuery.pageNum"
  108. :limit.sync="listQuery.pageSize"
  109. @pagination="getList(listQuery)"
  110. />
  111. </div>
  112. </template>
  113. <script>
  114. import { fetchSupplierList, supplierStatusChange } from '@/api/supplier'
  115. import { resetPassword } from '@/api/user'
  116. export default {
  117. name: 'ComplexTable',
  118. // mixins: [scrollTo],
  119. data() {
  120. return {
  121. slider: 1,
  122. listLoading: true,
  123. tableKey: '',
  124. total: 0, // 条数统计
  125. listQuery: {
  126. brandId: '', // 品牌id
  127. linkMan: '', // 联系人
  128. mobile: '', // 手机号
  129. pageNum: 0, // 页码
  130. pageSize: 10, // 分页大小
  131. shopName: '', // 供应商名称
  132. shopType: '', // 供应商类型
  133. loginAccount: '' // 登录账号
  134. },
  135. list: [],
  136. prevData: ''
  137. }
  138. },
  139. created() {
  140. this.getList()
  141. },
  142. methods: {
  143. // 获取列表数据
  144. async getList() {
  145. this.listLoading = true
  146. try {
  147. const res = await fetchSupplierList(this.listQuery)
  148. const { total, list } = res.data
  149. this.total = total
  150. this.list = this.formatList(list)
  151. } catch (error) {
  152. console.log(error)
  153. } finally {
  154. this.listLoading = false
  155. }
  156. },
  157. // 格式化数组
  158. formatList(list = []) {
  159. return list.map((item) => {
  160. item.shopStatus = item.shopStatus === 1
  161. return item
  162. })
  163. },
  164. // 供应商状态改变
  165. async handleChangeStatus(item) {
  166. console.log(item.shopStatus)
  167. const oldStatus = !item.shopStatus // 保存旧状态
  168. try {
  169. await supplierStatusChange({
  170. status: item.shopStatus ? 1 : 0,
  171. authUserId: item.authUserId
  172. })
  173. this.$message.success('操作成功')
  174. } catch (error) {
  175. // eslint-disable-next-line require-atomic-updates
  176. item.shopStatus = oldStatus
  177. console.log(error)
  178. }
  179. },
  180. // 重置密码
  181. async handleResetPwd(item) {
  182. const text = await this.$confirm('此操作将重置该供应商的密码, 是否继续?', '提示', {
  183. confirmButtonText: '确定',
  184. cancelButtonText: '取消',
  185. type: 'warning'
  186. }).catch(() => {
  187. this.$message.info('已取消操作')
  188. })
  189. if (text !== 'confirm') return
  190. // 要执行的操作
  191. resetPassword({ authUserId: item.authUserId }).then((res) => {
  192. if (res.code !== 0) return
  193. const h = this.$createElement
  194. this.$notify.success({
  195. title: '重置密码',
  196. message: h('i', { style: 'color: #333' }, `已重置供应商"${item.name}"的密码`),
  197. duration: 2000
  198. })
  199. })
  200. },
  201. // 代他操作
  202. async handleProxy(item) {
  203. const text = await this.$confirm('此操作将临时登录该供应商账号, 是否继续?', '提示', {
  204. confirmButtonText: '确定',
  205. cancelButtonText: '取消',
  206. type: 'warning'
  207. }).catch(() => {
  208. this.$message.info('已取消操作')
  209. })
  210. if (text !== 'confirm') return
  211. if (!item.shopStatus) {
  212. this.$message.warning('当前供应商未启用')
  213. return
  214. }
  215. console.log(item)
  216. // 要执行的操作
  217. this.$store.commit('proxy/OPEN_PROXY', item)
  218. this.$store.dispatch('user/proxyLogin')
  219. this.$router.push('/proxy')
  220. },
  221. // 过滤列表
  222. handleFilter() {
  223. this.listQuery.page = 1
  224. this.getList()
  225. },
  226. indexMethod(index) {
  227. return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
  228. }
  229. }
  230. }
  231. </script>
  232. <style lang="scss" scoped></style>