index.vue 15 KB

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