index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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.productName" placeholder="设备名称" @keyup.enter.native="handleFilter" />
  7. </div>
  8. <div class="filter-control">
  9. <span>设备SN码:</span>
  10. <el-input v-model="listQuery.snCode" placeholder="设备SN码" @keyup.enter.native="handleFilter" />
  11. </div>
  12. <div class="filter-control">
  13. <span>审核状态:</span>
  14. <el-select v-model="listQuery.auditStatus" placeholder="审核状态" clearable @change="getList">
  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. </div>
  21. <div class="filter-control">
  22. <span>上线状态:</span>
  23. <el-select v-model="listQuery.status" placeholder="上线状态" clearable @change="getList">
  24. <el-option label="全部" value="" />
  25. <el-option label="已上线" :value="1" />
  26. <el-option label="待上线" :value="2" />
  27. <el-option label="未上线" :value="0" />
  28. </el-select>
  29. </div>
  30. <div class="filter-control">
  31. <permission-button type="primary" @click="handleFilter">查询</permission-button>
  32. <permission-button
  33. type="primary"
  34. @click="navigationTo(`device-add?type=add`)"
  35. >添加新设备认证</permission-button>
  36. <permission-button type="primary" @click="navigationTo(`device-bind`)">关联已认证设备</permission-button>
  37. </div>
  38. </div>
  39. <!-- 表格区域 -->
  40. <el-table
  41. :key="tableKey"
  42. :data="list"
  43. border
  44. fit
  45. highlight-current-row
  46. style="width: 100%"
  47. header-row-class-name="tableHeader"
  48. >
  49. <el-table-column label="序号" :index="indexMethod" type="index" align="center" width="80" />
  50. <el-table-column label="设备名称" align="center" prop="productName" />
  51. <el-table-column label="设备SN码" align="center" prop="snCode" />
  52. <el-table-column label="审核状态" width="120px" align="center">
  53. <template slot-scope="{ row }">
  54. <audit-status :status="row.auditStatus" :reason="row.invalidReason" />
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="上线状态" width="160px" align="center">
  58. <template slot-scope="{ row }">
  59. <!-- 只有审核通过了才能操作上下线 auditStatus :审核状态 -->
  60. <template v-if="row.auditStatus === 1">
  61. <template v-if="row.status === 0">
  62. <span style="margin-right: 10px" class="status danger">已下线</span>
  63. <permission-button type="primary" size="mini" @click="handleChangeStatus(row)">上架</permission-button>
  64. </template>
  65. <template v-else>
  66. <span style="margin-right: 10px" class="status success">已上线</span>
  67. <permission-button type="info" size="mini" @click="handleChangeStatus(row)">下架</permission-button>
  68. </template>
  69. </template>
  70. <template v-else>
  71. <!-- <el-tag type="warning">待上线</el-tag> -->
  72. <span style="margin-right: 10px" class="status warning">待上线</span>
  73. </template>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="访问次数" align="center" prop="scanCount" width="80" />
  77. <el-table-column label="创建时间" class-name="status-col" width="160px" align="center">
  78. <template slot-scope="{ row }">
  79. <span>{{ row.createTime | formatTime }}</span>
  80. </template>
  81. </el-table-column>
  82. <!-- <el-table-column v-if="false" label="创建人" width="180px" align="center" prop="createBy" /> -->
  83. <el-table-column label="操作" align="center" width="340px" class-name="small-padding fixed-width">
  84. <template slot-scope="{ row }">
  85. <permission-button
  86. type="primary"
  87. size="mini"
  88. @click="navigationTo(`device-edit?type=edit&id=${row.productId}&relationId=${row.relationId}`)"
  89. >
  90. 编辑
  91. </permission-button>
  92. <permission-button v-if="row.auditStatus === 1" type="primary" size="mini" @click="handleShowQRcode(row)">
  93. 二维码
  94. </permission-button>
  95. <permission-button v-else type="info" size="mini" disabled> 二维码 </permission-button>
  96. <permission-button type="primary" size="mini" @click="fetchDeviceAssClubList(row)">
  97. 其他关联机构
  98. </permission-button>
  99. <permission-button type="danger" size="mini" @click="handleRemoveProduct(row)"> 删除 </permission-button>
  100. </template>
  101. </el-table-column>
  102. </el-table>
  103. <!-- 页码 -->
  104. <pagination :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="getList" />
  105. <!-- 二维码 -->
  106. <transition name="fade">
  107. <qrcode-device v-if="showQRcode" :product-info="productInfo" @close="showQRcode = false" />
  108. </transition>
  109. <!-- 关联机构 -->
  110. <el-dialog title="其他关联机构" :visible.sync="dialogClubVisible" width="30%">
  111. <associated-club-list
  112. class="associated-club-list"
  113. :selection="false"
  114. :control="true"
  115. :show-filter="false"
  116. height="300"
  117. :list="assClubList"
  118. >
  119. <template #control="{ row }">
  120. <el-button size="mini" type="primary" @click="onToClubDetail(row)">查看</el-button>
  121. </template>
  122. </associated-club-list>
  123. </el-dialog>
  124. </div>
  125. </template>
  126. <script>
  127. import { getProdList, setProductStatus, removeProduct, fetchDeviceAssClubList } from '@/api/product'
  128. import { AssociatedClubList } from '@/views/components/index'
  129. import QrcodeDevice from '@/components/QrcodeDevice'
  130. import { mapGetters } from 'vuex'
  131. import { setStorage } from '@/utils/storage'
  132. export default {
  133. name: 'ComplexTable',
  134. components: { QrcodeDevice, AssociatedClubList },
  135. data() {
  136. return {
  137. authParty: '',
  138. tableKey: 0,
  139. list: null,
  140. total: 0,
  141. listQuery: {
  142. status: '',
  143. auditStatus: '',
  144. authId: '',
  145. productName: '',
  146. snCode: '',
  147. pageNum: 1,
  148. pageSize: 10
  149. },
  150. showQRcode: false,
  151. productInfo: {},
  152. // 审核未通过
  153. auditFailedList: [],
  154. auditNoticeFlag: true,
  155. dialogClubVisible: false,
  156. assClubList: []
  157. }
  158. },
  159. computed: {
  160. ...mapGetters(['userIdentity'])
  161. },
  162. created() {
  163. this.initPage()
  164. },
  165. activated() {
  166. this.initPage()
  167. },
  168. methods: {
  169. initPage() {
  170. this.listQuery.authId = this.$route.query.id
  171. this.authParty = this.$route.query.authParty
  172. // 保存机构id,用于设备管理
  173. setStorage('device-setting-authId', this.listQuery.authId)
  174. this.getList()
  175. },
  176. // 机构详情
  177. onToClubDetail(row) {
  178. this.dialogClubVisible = false
  179. const fullPath = `/club/device-list?id=${row.authId}`
  180. this.$router.replace({
  181. path: '/redirect' + fullPath
  182. })
  183. },
  184. // 获取设备关联机构列表
  185. async fetchDeviceAssClubList(row) {
  186. try {
  187. const res = await fetchDeviceAssClubList({ snCode: row.snCode })
  188. this.assClubList = res.data
  189. this.dialogClubVisible = true
  190. } catch (error) {
  191. console.log(error)
  192. }
  193. },
  194. // 获取列表信息
  195. getList() {
  196. getProdList(this.listQuery)
  197. .then((res) => {
  198. const { total, list } = res.data
  199. this.total = total
  200. this.list = list
  201. // this.checkAuditFailedList(list)
  202. })
  203. .catch((error) => {
  204. console.log(error)
  205. })
  206. },
  207. // 过滤列表
  208. handleFilter() {
  209. this.listQuery.page = 1
  210. this.getList()
  211. },
  212. // 改变启用状态
  213. handleChangeStatus(item) {
  214. if (this.userIdentity === 2 || this.proxyInfo !== null) {
  215. const { status, productId } = item
  216. const newStatus = status === 0 ? 1 : 0
  217. setProductStatus({ status: newStatus, productId })
  218. .then((res) => {
  219. // this.$message.success(res.data)
  220. this.$message({
  221. message: '操作成功',
  222. duration: 500,
  223. type: 'success'
  224. })
  225. })
  226. .catch((error) => {
  227. console.log(error)
  228. })
  229. .finally(() => {
  230. this.getList()
  231. })
  232. }
  233. },
  234. // 删除商品
  235. async handleRemoveProduct(item) {
  236. const text = await this.$confirm(
  237. '确定删除该设备认证吗?删除后,其他机构已关联此设备认证的也将一并删除,请慎重操作。',
  238. '提示',
  239. {
  240. confirmButtonText: '确定',
  241. cancelButtonText: '取消',
  242. type: 'warning'
  243. }
  244. ).catch(() => {
  245. this.$message.info('已取消操作')
  246. })
  247. if (text !== 'confirm') return
  248. removeProduct({ productId: item.productId })
  249. .then((res) => {
  250. const h = this.$createElement
  251. this.$notify.success({
  252. title: '删除商品',
  253. message: h('i', { style: 'color: #333' }, `已删除商品:"${item.productName}"`),
  254. duration: 2000
  255. })
  256. })
  257. .catch((error) => {
  258. console.log(error)
  259. })
  260. .finally(() => {
  261. this.getList()
  262. })
  263. },
  264. // 显示二维码
  265. handleShowQRcode(item) {
  266. this.productInfo = item
  267. this.productInfo.authParty = this.authParty
  268. this.showQRcode = true
  269. },
  270. // 获取审核未通过条数
  271. // Audit failed 审核未通过
  272. checkAuditFailedList(data) {
  273. this.auditFailedList = data.filter((item) => item.auditStatus === 0)
  274. if (this.auditFailedList.length > 0 && this.auditNoticeFlag) {
  275. this.$notify.info({
  276. title: '消息通知',
  277. dangerouslyUseHTMLString: true,
  278. message: `共有<b style="color:red">${this.auditFailedList.length}</b>件商品未能通过审核,请查看原因并及时修改!`,
  279. duration: 3000
  280. })
  281. this.auditNoticeFlag = false
  282. }
  283. },
  284. indexMethod(index) {
  285. return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
  286. }
  287. }
  288. }
  289. </script>
  290. <style lang="scss" scoped></style>