index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <span>机构名称:</span>
  5. <el-input v-model="listQuery.authParty" placeholder="机构名称" style="width: 280px;" class="filter-item" @keyup.enter.native="handleFilter" />
  6. <el-button icon="el-icon-search" type="primary" @click="getList">查询</el-button>
  7. </div>
  8. <!-- 表格区域 -->
  9. <el-table
  10. :key="tableKey"
  11. v-loading="listLoading"
  12. :data="list"
  13. border
  14. fit
  15. highlight-current-row
  16. style="width: 100%;"
  17. header-row-class-name="tableHeader"
  18. >
  19. <el-table-column label="序号" align="center" width="80" type="index" />
  20. <el-table-column label="机构名称" align="center" prop="authParty" />
  21. <el-table-column label="创建时间" class-name="status-col" width="360px">
  22. <template slot-scope="{row}">
  23. <span>{{ row.createTime | formatTime }}</span>
  24. </template>
  25. </el-table-column>
  26. <!-- <el-table-column label="创建人" class-name="status-col" width="160px" prop="createBy" /> -->
  27. <el-table-column label="操作" align="center" width="300" class-name="small-padding fixed-width">
  28. <template slot-scope="{row}">
  29. <el-button type="primary" size="mini" @click="$_navigationTo(`/club/user-list?id=${row.authId}&authParty=${row.authParty}`)">
  30. 用户列表
  31. </el-button>
  32. </template>
  33. </el-table-column>
  34. </el-table>
  35. <!-- 页码 -->
  36. <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="getList" />
  37. <!-- 对话框区域 -->
  38. <el-dialog
  39. :title="dialogTitle"
  40. :visible.sync="showAddAuthDialog"
  41. width="30%"
  42. @close="dialogClosed"
  43. >
  44. <el-form ref="addAuthForm" :rules="addAuthFormRules" :model="addAuthFormData" label-width="100px">
  45. <el-form-item label="授权机构:" prop="authParty">
  46. <el-input v-model="addAuthFormData.authParty" placeholder="请输入授权机构名称" />
  47. </el-form-item>
  48. <!-- <el-form-item label="上线状态:">
  49. <el-select v-model="addAuthFormData.status">
  50. <el-option label="上线" :value="1" />
  51. <el-option label="下线" :value="0" />
  52. </el-select>
  53. </el-form-item> -->
  54. </el-form>
  55. <span slot="footer" class="dialog-footer">
  56. <el-button @click="showAddAuthDialog = false">取 消</el-button>
  57. <el-button type="primary" :disabled="disabled" @click="handleUpdateBrandAuth">确 定</el-button>
  58. </span>
  59. </el-dialog>
  60. </div>
  61. </template>
  62. <script>
  63. import { fecthAuthList, saveBrandAuth, changeAuthStatus, removeAuth } from '@/api/auth'
  64. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  65. import { mapGetters } from 'vuex'
  66. import { formatDate } from '@/utils'
  67. export default {
  68. name: 'ComplexTable',
  69. components: { Pagination },
  70. filters: {
  71. formatTime(time) {
  72. if (!time) {
  73. return ''
  74. }
  75. return formatDate(time, 'yyyy-MM-DD HH:mm:ss')
  76. }
  77. },
  78. data() {
  79. return {
  80. noticeTitle: '添加',
  81. dialogFlag: true, // 对话框状态
  82. tableKey: 0,
  83. list: null,
  84. total: 0,
  85. listLoading: true,
  86. // 查询参数
  87. listQuery: {
  88. authParty: '', // 授权机构
  89. authUserId: '', // 供应商用户id
  90. pageNum: 1, // 页码
  91. pageSize: 10, // 分页
  92. status: ''
  93. },
  94. // 添加品牌授权
  95. showAddAuthDialog: false, // 显示添加供应商对话框
  96. dialogTitle: '',
  97. addAuthFormData: {
  98. authId: '', // 授权id
  99. authUserId: '', // 供应商用户id
  100. authParty: '', // 授权机构
  101. createBy: '', // 创建人id
  102. status: 2 // 授权状态 0下线,1上线 2待审核
  103. },
  104. addAuthFormRules: {
  105. authParty: [
  106. { required: true, message: '请输入授权机构名称', trigger: 'blur' }
  107. ]
  108. },
  109. disabled: false,
  110. // 审核未通过
  111. auditFailedList: [],
  112. auditNoticeFlag: true
  113. }
  114. },
  115. computed: {
  116. ...mapGetters(['authUserId', 'userIdentity', 'proxyInfo'])
  117. },
  118. created() {
  119. this.listQuery.authUserId = this.$route.query.id || this.proxyInfo?.authUserId || this.authUserId
  120. const type = this.$route.query.type
  121. // 如果是通过路由参数传递的type,则需要同步到store
  122. if (type) {
  123. this.$store.commit('user/SET_SHOP_TYPE', parseInt(type))
  124. }
  125. this.getList()
  126. },
  127. destroyed() {
  128. // 页面关闭时清空代理数据
  129. // this.$store.commit('user/SET_PROXY_INFO', null)
  130. },
  131. methods: {
  132. // 获取授权列表
  133. getList() {
  134. this.listLoading = true
  135. fecthAuthList(this.listQuery).then(response => {
  136. if (response.code !== 0) {
  137. return this.$message.error('授权列表信息获取失败')
  138. }
  139. const { list, total } = response.data
  140. // this.formatList(list)
  141. this.list = list
  142. this.total = total
  143. // 获取审核未通过的列表
  144. this.checkAuditFailedList(list)
  145. }).catch(err => {
  146. console.log(err)
  147. return this.$message.error('授权列表信息获取失败')
  148. }).finally(() => {
  149. this.listLoading = false
  150. })
  151. },
  152. // 获取审核未通过条数
  153. // Audit failed 审核未通过
  154. checkAuditFailedList(data) {
  155. this.auditFailedList = data.filter(item => item.auditStatus === 0)
  156. if (this.auditFailedList.length > 0 && this.auditNoticeFlag && (this.userIdentity !== 1 || this.proxyInfo !== null)) {
  157. this.$notify.info({
  158. title: '消息通知',
  159. dangerouslyUseHTMLString: true,
  160. message: `共有<b style="color:red">${this.auditFailedList.length}</b>个授权机构未能通过审核,请查看原因并及时修改!`,
  161. duration: 3000
  162. })
  163. this.auditNoticeFlag = false
  164. }
  165. },
  166. // 检查机构名是否存在 true:存在 false:不存在
  167. handleCheckAuthName(name) {
  168. const flag = this.list.some(item => item.authParty === name)
  169. console.log(flag)
  170. return flag
  171. },
  172. // 添加授权
  173. handleUpdateBrandAuth() {
  174. if (this.handleCheckAuthName(this.addAuthFormData.authParty) && this.dialogFlag) {
  175. this.$message({
  176. message: '该授权机构已存在',
  177. duration: 1000,
  178. type: 'warning'
  179. })
  180. return
  181. }
  182. this.$refs.addAuthForm.validate(valide => {
  183. if (valide) {
  184. this.disabled = true
  185. this.listLoading = true
  186. // authUserId先判断是否为代理操作,是就从代理数据中获取,否则直接获取当前登录用户的信息
  187. this.addAuthFormData.authUserId = this.$route.query.id || this.proxyInfo?.authUserId || this.authUserId
  188. this.addAuthFormData.createBy = this.addAuthFormData.authUserId
  189. saveBrandAuth(this.addAuthFormData).then(res => {
  190. if (res.code !== 0) {
  191. return
  192. }
  193. this.getList()
  194. const h = this.$createElement
  195. this.$notify.success({
  196. title: `${this.noticeTitle}授权机构`,
  197. message: h('i', { style: 'color: #333' }, `已${this.noticeTitle}授权机构:"${this.addAuthFormData.authParty}"`),
  198. duration: 3000
  199. })
  200. this.$refs.addAuthForm.resetFields()
  201. }).catch(err => {
  202. console.log(err)
  203. this.$message.danger('操作失败')
  204. }).finally(() => {
  205. this.showAddAuthDialog = false
  206. this.listLoading = false
  207. this.disabled = false
  208. })
  209. }
  210. })
  211. },
  212. // 删除品牌授权
  213. async handleRemoveAuth(item) {
  214. const text = await this.$confirm('确认删除该数据吗?删除后,对应的商品数据也将全部删除', '提示', {
  215. confirmButtonText: '确定',
  216. cancelButtonText: '取消',
  217. type: 'warning'
  218. }).catch(() => {
  219. this.$message.info('已取消操作')
  220. })
  221. if (text !== 'confirm') return
  222. // 要执行的操作
  223. this.listLoading = true
  224. removeAuth({ authId: item.authId }).then(res => {
  225. if (res.code !== 0) return
  226. const h = this.$createElement
  227. this.$notify.success({
  228. title: '移除授权机构',
  229. message: h('i', { style: 'color: #333' }, `移除授权机构:"${item.authParty}"`),
  230. duration: 3000
  231. })
  232. }).catch(err => {
  233. console.log(err)
  234. }).finally(() => {
  235. this.listLoading = false
  236. this.getList()
  237. })
  238. },
  239. // 格式化列表数据
  240. formatList(list = []) {
  241. list.forEach(i => {
  242. i.status = i.status === 1
  243. })
  244. },
  245. // 供应商状态改变
  246. handleChangeStatus(item) {
  247. if (this.userIdentity !== 2 && this.proxyInfo === null) return
  248. this.listLoading = true
  249. // const params = {
  250. // authId: item.authId,
  251. // status: item.status ? 1 : 0
  252. // }
  253. const params = {
  254. authId: item.authId,
  255. status: item.status === 1 ? 0 : 1
  256. }
  257. changeAuthStatus(params).then(res => {
  258. // this.$message.success(res.data)
  259. this.$message({
  260. message: res.data,
  261. duration: 500,
  262. type: 'success'
  263. })
  264. this.getList()
  265. }).catch(err => {
  266. console.log(err)
  267. }).finally(() => {
  268. this.listLoading = false
  269. })
  270. },
  271. // 过滤列表
  272. handleFilter() {
  273. this.listQuery.page = 1
  274. this.getList()
  275. },
  276. // 添加供应商
  277. handleAddAuth() {
  278. console.log('添加供应商')
  279. },
  280. // 对话框关闭事件
  281. dialogClosed() {
  282. console.log('dialog is closed')
  283. this.addAuthFormData.authParty = ''
  284. this.addAuthFormData.authId = ''
  285. this.addAuthFormData.status = 1
  286. this.noticeTitle = '添加'
  287. this.$refs.addAuthForm.resetFields()
  288. },
  289. handleShowEditDialog(title, data) {
  290. this.dialogTitle = title
  291. if (data) {
  292. this.addAuthFormData.authId = data.authId
  293. this.addAuthFormData.authUserId = data.authUserId
  294. this.addAuthFormData.authParty = data.authParty
  295. this.addAuthFormData.createBy = data.createBy
  296. this.status = data.status
  297. this.noticeTitle = '修改'
  298. this.dialogFlag = false
  299. } else {
  300. this.dialogFlag = true
  301. }
  302. this.showAddAuthDialog = true
  303. }
  304. }
  305. }
  306. </script>
  307. <style lang="scss" scoped>
  308. .filter-container{
  309. span{
  310. display: inline-block;
  311. margin-bottom: 10px;
  312. vertical-align: middle;
  313. font-size: 14px;
  314. }
  315. .el-button{
  316. display: inline-block;
  317. margin-bottom: 10px;
  318. vertical-align: middle;
  319. }
  320. .el-input,.el-select{
  321. margin-right: 10px;
  322. margin-left: 10px;
  323. }
  324. }
  325. </style>