index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <span>供应商名称:</span>
  5. <el-input v-model="listQuery.shopName" placeholder="供应商名称" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
  6. <span>供应商类型:</span>
  7. <el-select v-model="listQuery.shopType" placeholder="供应商类型" clearable style="width: 200px" class="filter-item" @change="getList()">
  8. <el-option label="所有类型" value="" />
  9. <el-option label="代理商" :value="2" />
  10. <el-option label="品牌方" :value="1" />
  11. </el-select>
  12. <span>所属品牌:</span>
  13. <el-select v-model="listQuery.brandId" placeholder="所属品牌" clearable class="filter-item" style="width: 200px" filterable @change="getList()">
  14. <el-option label="所有品牌" value="" />
  15. <el-option
  16. v-for="item in brandList"
  17. :key="item.id"
  18. :label="item.name"
  19. :value="item.id"
  20. />
  21. </el-select>
  22. <span>手机号:</span>
  23. <el-input v-model="listQuery.mobile" placeholder="手机号" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
  24. <span>联系人:</span>
  25. <el-input v-model="listQuery.linkMan" placeholder="联系人" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
  26. <el-button type="primary" icon="el-icon-search" @click="getList(listQuery)">查询</el-button>
  27. <el-button type="primary" icon="el-icon-edit" @click="$_navigationTo('add')">添加供应商</el-button>
  28. </div>
  29. <!-- 表格区域 -->
  30. <el-table
  31. :key="tableKey"
  32. v-loading="listLoading"
  33. :data="list"
  34. border
  35. fit
  36. highlight-current-row
  37. style="width: 100%;"
  38. header-row-class-name="tableHeader"
  39. >
  40. <el-table-column label="序号" type="index" sortable="custom" align="center" width="80" />
  41. <el-table-column label="供应商名称" align="center" prop="name" />
  42. <el-table-column label="供应商类型" width="150px" align="center">
  43. <template v-slot="{row}">
  44. <span v-if="row.shopType === 1">品牌方</span>
  45. <span v-if="row.shopType === 2">代理商</span>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="手机号" width="120px" align="center" prop="mobile" />
  49. <el-table-column label="联系人" width="100px" align="center" prop="linkMan" />
  50. <el-table-column label="供应商状态" align="center" width="140px">
  51. <template v-slot="{row}">
  52. <el-switch v-model="row.shopStatus" @change="handleChangeStatus(row)" />
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="创建时间" class-name="status-col" width="200px">
  56. <template slot-scope="{row}">
  57. <span>{{ row.createTime | formatTime }}</span>
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="创建人" class-name="status-col" width="100px" prop="createBy" />
  61. <el-table-column label="操作" align="center" width="360" class-name="small-padding fixed-width">
  62. <template slot-scope="{row}">
  63. <el-button size="mini" type="primary" @click="$_navigationTo(`edit?id=${row.authUserId}`)">
  64. 编辑
  65. </el-button>
  66. <el-button size="mini" type="primary" @click="handleProxy(row)">
  67. 代他操作
  68. </el-button>
  69. <el-button size="mini" type="primary" @click="$_navigationTo(`/auth/list?id=${row.authUserId}`)">
  70. 授权信息
  71. </el-button>
  72. <el-button size="mini" type="primary" @click="handleResetPwd(row)">
  73. 重置密码
  74. </el-button>
  75. </template>
  76. </el-table-column>
  77. </el-table>
  78. <!-- 页码 -->
  79. <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="getList(listQuery)" />
  80. </div>
  81. </template>
  82. <script>
  83. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  84. import { fetchSupplierList, supplierStatusChange } from '@/api/supplier'
  85. import { resetPassword } from '@/api/user'
  86. import { fetchBrandList } from '@/api/brand'
  87. import { formatDate } from '@/utils'
  88. // import scrollTo from '@/mixin/scrollTo'
  89. export default {
  90. name: 'ComplexTable',
  91. components: { Pagination },
  92. filters: {
  93. formatTime(time) {
  94. if (!time) {
  95. return ''
  96. }
  97. return formatDate(time, 'yyyy-MM-DD HH:mm:ss')
  98. }
  99. },
  100. // mixins: [scrollTo],
  101. data() {
  102. return {
  103. slider: 1,
  104. listLoading: true,
  105. tableKey: '',
  106. total: 0, // 条数统计
  107. listQuery: {
  108. brandId: '', // 品牌id
  109. linkMan: '', // 联系人
  110. mobile: '', // 手机号
  111. pageNum: 0, // 页码
  112. pageSize: 20, // 分页大小
  113. shopName: '', // 供应商名称
  114. shopType: ''// 供应商类型
  115. },
  116. list: [],
  117. brandList: [], // 品牌列表
  118. prevData: ''
  119. }
  120. },
  121. created() {
  122. this.getList()
  123. this.getBrandList()
  124. },
  125. methods: {
  126. // 获取列表数据
  127. getList() {
  128. this.listLoading = true
  129. fetchSupplierList(this.listQuery).then(res => {
  130. if (res.code !== 0) {
  131. return this.$message.error('获取数据失败~')
  132. }
  133. const { total, list } = res.data
  134. this.total = total
  135. this.formatList(list)
  136. this.list = list
  137. console.log(this.list)
  138. }).catch(err => { console.log(err) }).finally(() => {
  139. this.listLoading = false
  140. })
  141. },
  142. // 格式化数组
  143. formatList(list = []) {
  144. list.forEach(i => {
  145. i.shopStatus = i.shopStatus === 1
  146. })
  147. },
  148. // 获取品牌列表
  149. getBrandList() {
  150. // 获取品牌列表
  151. fetchBrandList().then(res => {
  152. if (res.code === 0) {
  153. this.brandList = res.data
  154. }
  155. }).catch(err => console.log(err))
  156. },
  157. // 供应商状态改变
  158. handleChangeStatus(item) {
  159. const params = {
  160. status: item.shopStatus ? 1 : 0,
  161. authUserId: item.authUserId
  162. }
  163. supplierStatusChange(params)
  164. .then(res => {
  165. if (res.code === 0) {
  166. this.getList()
  167. this.$message({
  168. message: '操作成功',
  169. duration: 500,
  170. type: 'success'
  171. })
  172. }
  173. }).catch(() => {
  174. this.getList()
  175. this.$message({
  176. message: '操作失败',
  177. duration: 500,
  178. type: 'danger'
  179. })
  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. // 要执行的操作
  214. console.log(item)
  215. this.$store.commit('user/SET_PROXY_INFO', item)
  216. this.$router.push(`/auth/list?type=${item.shopType}`)
  217. },
  218. // 过滤列表
  219. handleFilter() {
  220. this.listQuery.page = 1
  221. this.getList()
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .filter-container{
  228. span{
  229. display: inline-block;
  230. margin-bottom: 10px;
  231. vertical-align: middle;
  232. font-size: 14px;
  233. }
  234. .el-button{
  235. display: inline-block;
  236. margin-bottom: 10px;
  237. vertical-align: middle;
  238. }
  239. .el-input,.el-select{
  240. margin-right: 10px;
  241. margin-left: 10px;
  242. }
  243. }
  244. </style>