index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <span>授权机构:</span>
  5. <el-input v-model="listQuery.title" 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. <el-button type="primary" @click="handleFilter">查询</el-button>
  9. <el-button v-if="userIdentity === 2 || proxyInfo !== null" type="primary" @click="$_navigationTo(`add?id=${listQuery.authId}`)">添加商品</el-button>
  10. </div>
  11. <!-- 表格区域 -->
  12. <el-table
  13. :key="tableKey"
  14. v-loading="listLoading"
  15. :data="list"
  16. border
  17. fit
  18. highlight-current-row
  19. style="width: 100%;"
  20. header-row-class-name="tableHeader"
  21. >
  22. <el-table-column label="序号" type="index" align="center" width="80" />
  23. <el-table-column label="商品名称" align="center" prop="productName" />
  24. <el-table-column label="商品SN码" align="center" prop="snCode" />
  25. <el-table-column v-if="userIdentity===2 || proxyInfo !== null" label="上线状态" width="140px" align="center">
  26. <template slot-scope="{row}">
  27. <template v-if="row.status === 0">
  28. <span style="margin-right:10px;" class="status danger">已下线</span>
  29. <el-button type="primary" size="mini" @click="handleChangeStatus(row)">上线</el-button>
  30. </template>
  31. <template v-else>
  32. <span style="margin-right:10px;" class="status success ">已上线</span>
  33. <el-button type="info" size="mini" plain @click="handleChangeStatus(row)">下线</el-button>
  34. </template>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="创建时间" class-name="status-col" width="300px" align="center">
  38. <template slot-scope="{row}">
  39. <span>{{ row.createTime | formatTime }}</span>
  40. </template>
  41. </el-table-column>
  42. <el-table-column label="创建人" width="180px" align="center" prop="createBy" />
  43. <el-table-column label="操作" align="center" width="240px" class-name="small-padding fixed-width">
  44. <template slot-scope="{row}">
  45. <template v-if="userIdentity === 2|| proxyInfo !== null">
  46. <el-button type="default" size="mini" @click="$_navigationTo(`edit?id=${row.productId}`)">
  47. 编辑
  48. </el-button>
  49. <el-button type="danger" size="mini" @click="handleRemoveProduct(row)">
  50. 删除
  51. </el-button>
  52. </template>
  53. <el-button type="primary" size="mini" @click="handleShowQRcode(row)">
  54. 二维码
  55. </el-button>
  56. </template>
  57. </el-table-column>
  58. </el-table>
  59. <!-- 页码 -->
  60. <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="getList" />
  61. <!-- 二维码 -->
  62. <qrcode v-if="showQRcode" :is-visible="showQRcode" :product-info="productInfo" @close="showQRcode = false" />
  63. </div>
  64. </template>
  65. <script>
  66. import { getProdList, setProductStatus, removeProduct } from '@/api/product'
  67. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  68. import Qrcode from '@/components/qrcode'
  69. import { formatDate } from '@/utils'
  70. import { mapGetters } from 'vuex'
  71. export default {
  72. name: 'ComplexTable',
  73. components: { Pagination, Qrcode },
  74. filters: {
  75. formatTime(time) {
  76. if (!time) {
  77. return ''
  78. }
  79. return formatDate(time, 'yyyy-MM-DD HH:mm:ss')
  80. }
  81. },
  82. data() {
  83. return {
  84. tableKey: 0,
  85. list: null,
  86. total: 0,
  87. listLoading: true,
  88. listQuery: {
  89. authId: '',
  90. productName: '',
  91. snCode: '',
  92. pageNum: 1,
  93. pageSize: 10
  94. },
  95. showQRcode: false,
  96. productInfo: {}
  97. }
  98. },
  99. computed: {
  100. ...mapGetters(['userIdentity', 'proxyInfo'])
  101. },
  102. created() {
  103. this.listQuery.authId = this.$route.query.id
  104. this.getList()
  105. },
  106. methods: {
  107. // 添加
  108. handleAddPro() {
  109. this.$router.push('add')
  110. },
  111. // 修改
  112. handleEditPro() {
  113. this.$router.push('edit')
  114. },
  115. // 获取列表信息
  116. getList() {
  117. getProdList(this.listQuery).then(res => {
  118. this.total = res.data.total
  119. this.list = res.data.list
  120. }).finally(() => {
  121. this.listLoading = false
  122. })
  123. },
  124. // 过滤列表
  125. handleFilter() {
  126. this.listQuery.page = 1
  127. this.getList()
  128. },
  129. // 改变启用状态
  130. handleChangeStatus(item) {
  131. if (this.userIdentity === 2 || this.proxyInfo !== null) {
  132. this.listLoading = true
  133. const { status, productId } = item
  134. const newStatus = status === 0 ? 1 : 0
  135. setProductStatus({ status: newStatus, productId }).then(res => {
  136. // this.$message.success(res.data)
  137. this.$message({
  138. message: '操作成功',
  139. duration: 500,
  140. type: 'success'
  141. })
  142. this.listLoading = false
  143. }).finally(() => {
  144. this.getList()
  145. })
  146. }
  147. },
  148. // 删除商品
  149. async handleRemoveProduct(item) {
  150. const text = await this.$confirm('此操作将删除该商品, 是否继续?', '提示', {
  151. confirmButtonText: '确定',
  152. cancelButtonText: '取消',
  153. type: 'warning'
  154. }).catch(() => {
  155. this.$message.info('已取消操作')
  156. })
  157. if (text !== 'confirm') return
  158. removeProduct({ productId: item.productId }).then(res => {
  159. const h = this.$createElement
  160. this.$notify.success({
  161. title: '删除商品',
  162. message: h('i', { style: 'color: #333' }, `已删除商品:"${item.productName}"`),
  163. duration: 2000
  164. })
  165. }).finally(() => {
  166. this.getList()
  167. })
  168. },
  169. // 显示二维码
  170. handleShowQRcode(item) {
  171. this.productInfo = item
  172. this.showQRcode = true
  173. }
  174. }
  175. }
  176. </script>
  177. <style lang="scss" scoped>
  178. .filter-container{
  179. span{
  180. display: inline-block;
  181. margin-bottom: 10px;
  182. vertical-align: middle;
  183. font-size: 14px;
  184. }
  185. .el-button{
  186. display: inline-block;
  187. margin-bottom: 10px;
  188. vertical-align: middle;
  189. }
  190. .el-input,.el-select{
  191. margin-right: 10px;
  192. margin-left: 10px;
  193. }
  194. }
  195. </style>