index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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" @click="getList(listQuery)">查询</el-button>
  27. <el-button type="primary" @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. export default {
  89. name: 'ComplexTable',
  90. components: { Pagination },
  91. filters: {
  92. formatTime(time) {
  93. if (!time) {
  94. return ''
  95. }
  96. return formatDate(time, 'yyyy-MM-DD HH:mm:ss')
  97. }
  98. },
  99. data() {
  100. return {
  101. slider: 1,
  102. listLoading: true,
  103. tableKey: '',
  104. total: 0, // 条数统计
  105. listQuery: {
  106. brandId: '', // 品牌id
  107. linkMan: '', // 联系人
  108. mobile: '', // 手机号
  109. pageNum: 0, // 页码
  110. pageSize: 20, // 分页大小
  111. shopName: '', // 供应商名称
  112. shopType: ''// 供应商类型
  113. },
  114. list: [],
  115. brandList: [], // 品牌列表
  116. prevData: ''
  117. }
  118. },
  119. created() {
  120. // console.log(1)
  121. // this.prevData = JSON.parse(window.localStorage.getItem('prevData')) || null
  122. // if (this.prevData !== null) {
  123. // this.listQuery.pageNum = this.prevData.prevData
  124. // this.listQuery.pageSize = this.prevData.pageSize
  125. // }
  126. this.getList()
  127. this.getBrandList()
  128. },
  129. // mounted() {
  130. // if (this.prevData !== null) {
  131. // window.scrollTo(0, this.prevData.scroll)
  132. // }
  133. // this.addEventListenerScroll()
  134. // },
  135. methods: {
  136. // addEventListenerScroll() {
  137. // let timer = null
  138. // const that = this
  139. // window.addEventListener('scroll', function() {
  140. // clearTimeout(timer)
  141. // timer = setTimeout(() => {
  142. // // console.log(this.scrollY)
  143. // const data = JSON.stringify({
  144. // scroll: this.scrollY,
  145. // pageNum: that.listQuery.pageNum,
  146. // pageSize: that.listQuery.pageSize
  147. // })
  148. // window.localStorage.setItem('prevData', data)
  149. // }, 200)
  150. // })
  151. // },
  152. // 获取列表数据
  153. getList() {
  154. this.listLoading = true
  155. fetchSupplierList(this.listQuery).then(res => {
  156. if (res.code !== 0) {
  157. return this.$message.error('获取数据失败~')
  158. }
  159. const { total, list } = res.data
  160. this.total = total
  161. this.formatList(list)
  162. this.list = list
  163. console.log(this.list)
  164. }).catch(err => { console.log(err) }).finally(() => {
  165. this.listLoading = false
  166. })
  167. },
  168. // 格式化数组
  169. formatList(list = []) {
  170. list.forEach(i => {
  171. i.shopStatus = i.shopStatus === 1
  172. })
  173. },
  174. // 获取品牌列表
  175. getBrandList() {
  176. // 获取品牌列表
  177. fetchBrandList().then(res => {
  178. if (res.code === 0) {
  179. this.brandList = res.data
  180. }
  181. }).catch(err => console.log(err))
  182. },
  183. // 供应商状态改变
  184. handleChangeStatus(item) {
  185. const params = {
  186. status: item.shopStatus ? 1 : 0,
  187. authUserId: item.authUserId
  188. }
  189. supplierStatusChange(params)
  190. .then(res => {
  191. if (res.code === 0) {
  192. this.getList()
  193. this.$message({
  194. message: '操作成功',
  195. duration: 500,
  196. type: 'success'
  197. })
  198. }
  199. }).catch(() => {
  200. this.getList()
  201. this.$message({
  202. message: '操作失败',
  203. duration: 500,
  204. type: 'danger'
  205. })
  206. })
  207. },
  208. // 重置密码
  209. async handleResetPwd(item) {
  210. const text = await this.$confirm('此操作将重置该供应商的密码, 是否继续?', '提示', {
  211. confirmButtonText: '确定',
  212. cancelButtonText: '取消',
  213. type: 'warning'
  214. }).catch(() => {
  215. this.$message.info('已取消操作')
  216. })
  217. if (text !== 'confirm') return
  218. // 要执行的操作
  219. resetPassword({ authUserId: item.authUserId }).then(res => {
  220. if (res.code !== 0) return
  221. const h = this.$createElement
  222. this.$notify.success({
  223. title: '重置密码',
  224. message: h('i', { style: 'color: #333' }, `已重置供应商"${item.name}"的面膜`),
  225. duration: 2000
  226. })
  227. })
  228. },
  229. // 代他操作
  230. async handleProxy(item) {
  231. const text = await this.$confirm('此操作将临时登录该供应商账号, 是否继续?', '提示', {
  232. confirmButtonText: '确定',
  233. cancelButtonText: '取消',
  234. type: 'warning'
  235. }).catch(() => {
  236. this.$message.info('已取消操作')
  237. })
  238. if (text !== 'confirm') return
  239. // 要执行的操作
  240. console.log(item)
  241. this.$store.commit('user/SET_PROXY_INFO', item)
  242. this.$router.push(`/auth/list?type=${item.shopType}`)
  243. },
  244. // 过滤列表
  245. handleFilter() {
  246. this.listQuery.page = 1
  247. this.getList()
  248. }
  249. }
  250. }
  251. </script>
  252. <style lang="scss" scoped>
  253. .filter-container{
  254. span{
  255. display: inline-block;
  256. margin-bottom: 10px;
  257. vertical-align: middle;
  258. font-size: 14px;
  259. }
  260. .el-button{
  261. display: inline-block;
  262. margin-bottom: 10px;
  263. vertical-align: middle;
  264. }
  265. .el-input,.el-select{
  266. margin-right: 10px;
  267. margin-left: 10px;
  268. }
  269. }
  270. </style>