index.vue 10 KB

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