index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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.name" placeholder="设备名称" @keyup.enter.native="handleFilter" />
  7. </div>
  8. <div class="filter-control">
  9. <span>审核状态:</span>
  10. <el-select v-model="listQuery.auditStatus" placeholder="审核状态" clearable @change="getList">
  11. <el-option label="全部" value="" />
  12. <el-option label="待审核" :value="2" />
  13. <el-option label="审核通过" :value="1" />
  14. <el-option label="审核未通过" :value="0" />
  15. </el-select>
  16. </div>
  17. <div class="filter-control">
  18. <span>上线状态:</span>
  19. <el-select v-model="listQuery.status" placeholder="上线状态" clearable @change="getList">
  20. <el-option label="全部" value="" />
  21. <el-option label="已上线" :value="1" />
  22. <el-option label="待上线" :value="2" />
  23. <el-option label="未上线" :value="0" />
  24. </el-select>
  25. </div>
  26. <div class="filter-control">
  27. <permission-button type="primary" @click="handleFilter">查询</permission-button>
  28. <permission-button type="primary" @click="handleAdd">添加</permission-button>
  29. </div>
  30. </div>
  31. <!-- 表格区域 -->
  32. <el-table
  33. :key="tableKey"
  34. :data="list"
  35. border
  36. fit
  37. highlight-current-row
  38. style="width: 100%"
  39. header-row-class-name="tableHeader"
  40. >
  41. <el-table-column label="序号" :index="indexMethod" type="index" align="center" width="80" />
  42. <el-table-column label="设备名称" align="center" prop="name" />
  43. <el-table-column label="审核状态" width="220px" align="center">
  44. <template slot-scope="{ row }">
  45. <audit-status :status="row.auditStatus" :reason="row.invalidReason" />
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="上线状态" width="140px" align="center">
  49. <template slot-scope="{ row }">
  50. <!-- 只有审核通过了才能操作上下线 auditStatus :审核状态 -->
  51. <template v-if="row.auditStatus === 1">
  52. <template v-if="row.status === 0">
  53. <span style="margin-right: 10px" class="status danger">已下线</span>
  54. <permission-button type="primary" size="mini" @click="handleChangeStatus(row)">上线</permission-button>
  55. </template>
  56. <template v-else>
  57. <span style="margin-right: 10px" class="status success">已上线</span>
  58. <permission-button type="info" size="mini" @click="handleChangeStatus(row)">下线</permission-button>
  59. </template>
  60. </template>
  61. <template v-else>
  62. <!-- <el-tag type="warning">待上线</el-tag> -->
  63. <span style="margin-right: 10px" class="status warning">待上线</span>
  64. </template>
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="创建时间" class-name="status-col" width="160px" align="center">
  68. <template slot-scope="{ row }">
  69. <span>{{ row.createTime | formatTime }}</span>
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="创建人" align="center" prop="createBy" width="160" />
  73. <!-- <el-table-column v-if="false" label="创建人" width="180px" align="center" prop="createBy" /> -->
  74. <el-table-column label="操作" align="center" width="240px" class-name="small-padding fixed-width">
  75. <template slot-scope="{ row }">
  76. <permission-button type="primary" size="mini" @click="handleQrcode(row)"> 设备二维码 </permission-button>
  77. <permission-button type="primary" size="mini" @click="handleEdit(row)"> 编辑 </permission-button>
  78. <permission-button type="danger" size="mini" @click="handleRemove(row)"> 删除 </permission-button>
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. <!-- 页码 -->
  83. <pagination :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="getList" />
  84. </div>
  85. </template>
  86. <script>
  87. import { mapGetters } from 'vuex'
  88. import { fetchProductCateList, removeProductCate, updateProductCateStatus } from '@/api/product'
  89. const resetFormData = () => ({
  90. productTypeId: '',
  91. authUserId: '',
  92. name: '',
  93. image: '',
  94. createBy: ''
  95. })
  96. export default {
  97. name: 'ComplexTable',
  98. data() {
  99. return {
  100. tableKey: 0,
  101. list: null,
  102. total: 0,
  103. listQuery: {
  104. authUserId: '',
  105. auditStatus: '',
  106. listType: 1,
  107. name: '',
  108. pageNum: 1,
  109. pageSize: 10,
  110. status: ''
  111. },
  112. productInfo: {},
  113. // 添加分类表单
  114. formData: resetFormData(),
  115. rules: {
  116. name: [{ required: true, message: '请输入设备名称', trigger: ['blur'] }],
  117. image: [{ required: true, message: '请上传设备图片', trigger: ['change'] }]
  118. },
  119. productImageList: []
  120. }
  121. },
  122. computed: {
  123. ...mapGetters(['authUserId'])
  124. },
  125. created() {
  126. this.getList()
  127. },
  128. activated() {
  129. this.getList()
  130. },
  131. methods: {
  132. // 获取列表信息
  133. getList() {
  134. this.fetchProductList()
  135. },
  136. // 过滤列表
  137. handleFilter() {
  138. this.formData.pageNum = 1
  139. this.list = []
  140. this.fetchProductList()
  141. },
  142. // 改变启用状态
  143. async handleChangeStatus(row) {
  144. let status = Boolean(row.status)
  145. const tip = status ? '下架' : '上架'
  146. let confirmType = ''
  147. try {
  148. confirmType = await this.$confirm(`确定${tip}该设备管理吗?`, '提示', {
  149. confirmButtonText: '确定',
  150. cancelButtonText: '取消',
  151. type: 'warning'
  152. })
  153. status = !status
  154. } catch (error) {
  155. console.log(error)
  156. }
  157. if (confirmType !== 'confirm') {
  158. return
  159. }
  160. try {
  161. await updateProductCateStatus({
  162. productTypeId: row.productTypeId,
  163. status: Number(status)
  164. })
  165. this.$message.success('修改设备状态成功')
  166. this.fetchProductList()
  167. } catch (error) {
  168. console.log(error)
  169. }
  170. },
  171. // 获取设备分类列表
  172. async fetchProductList() {
  173. this.listQuery.authUserId = this.authUserId
  174. try {
  175. const res = await fetchProductCateList(this.listQuery)
  176. this.total = res.data.total
  177. this.list = res.data.list
  178. } catch (error) {
  179. console.log(error)
  180. }
  181. },
  182. // 添加分类
  183. handleAdd() {
  184. this.$router.push(`device-cate-edit?type=add`)
  185. },
  186. // 编辑分类
  187. handleEdit(row) {
  188. this.$router.push(`device-cate-edit?id=${row.productTypeId}&type=edit`)
  189. },
  190. // 设备二维码
  191. handleQrcode(row) {
  192. this.$router.push(`device-qrcode?id=${row.productTypeId}&name=${row.name}`)
  193. },
  194. // 删除
  195. async handleRemove(row) {
  196. let confirmType = ''
  197. try {
  198. confirmType = await this.$confirm('确认删除改商品分类吗?该操作不可逆!', '提示', {
  199. confirmButtonText: '确定',
  200. cancelButtonText: '取消',
  201. type: 'warning'
  202. })
  203. } catch (error) {
  204. console.log(error)
  205. }
  206. if (confirmType !== 'confirm') return
  207. try {
  208. await removeProductCate({
  209. productTypeId: row.productTypeId
  210. })
  211. this.$message.success('删除设备分类成功')
  212. this.fetchProductList()
  213. } catch (error) {
  214. console.log(error)
  215. }
  216. },
  217. // 表格索引
  218. indexMethod(index) {
  219. return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
  220. }
  221. }
  222. }
  223. </script>
  224. <style lang="scss" scoped>
  225. .app-container {
  226. ::v-deep {
  227. .el-dialog__body {
  228. padding-bottom: 0;
  229. }
  230. }
  231. .pd-10 {
  232. padding-top: 10px;
  233. }
  234. }
  235. </style>