electronicScale.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <a-card class="electronicScale-container" :bordered="false">
  3. <!-- 搜索框 -->
  4. <div class="electronicScale-container-searchForm">
  5. <a-form-model :model="searchForm" layout="inline" ref="searchForm" @keyup.enter.native="$refs.table.refresh(true)">
  6. <a-row :gutter="24">
  7. <a-col :xs="24" :sm="12" :md="8" :lg="6">
  8. <a-form-model-item label="设备MAC地址" :label-col="{ span: 7 }" :wrapper-col="{ span: 17 }">
  9. <a-input v-model="searchForm.macAddress" placeholder="请输入设备MAC地址" :maxLength="12" allowClear id="electronicScale-macAddress"/>
  10. </a-form-model-item>
  11. </a-col>
  12. <a-col :xs="24" :sm="12" :md="8" :lg="6">
  13. <a-button class="handle-btn serach-btn" type="primary" @click="$refs.table.refresh(true)" id="electronicScale-refresh">查询</a-button>
  14. <a-button class="handle-btn" type="" @click="handleReset" id="electronicScale-handleReset">重置</a-button>
  15. </a-col>
  16. </a-row>
  17. </a-form-model>
  18. </div>
  19. <!-- 新增 -->
  20. <div class="electronicScale-container-add"><a-button type="primary" icon="plus" @click="openModal" id="electronicScale-openModal" v-hasPermission="'B_electronicScale_add'">新增</a-button></div>
  21. <!-- 合计 -->
  22. <a-alert type="info" showIcon style="margin-bottom:15px">
  23. <div class="ftext" slot="message">
  24. 总计
  25. <span>{{ totalNum }} 个</span>
  26. </div>
  27. </a-alert>
  28. <!-- 列表 -->
  29. <s-table ref="table" :rowKey="record => record.id" :columns="columns" :data="loadData" bordered>
  30. <span slot="action" slot-scope="text, record">
  31. <a-icon type="qrcode" title="二维码" class="actionBtn icon-green" @click="getQrCode(record)" />
  32. <a-icon type="edit" title="编辑" class="actionBtn icon-blues" @click="handleEdit(record)" v-hasPermission="'B_electronicScale_edit'"/>
  33. <a-icon type="delete" title="删除" class="actionBtn icon-red" @click="delect(record)" v-hasPermission="'B_electronicScale_del'"/>
  34. <!-- <a-icon type="edit" title="编辑" class="actionBtn icon-blues" @click="handleEdit(record)"/>
  35. <a-icon type="delete" title="删除" class="actionBtn icon-red" @click="delect(record)"/> -->
  36. </span>
  37. <span v-if="!($hasPermissions('B_electronicScale_edit') && $hasPermissions('B_electronicScale_del'))">--</span>
  38. </s-table>
  39. <!-- 新增/编辑弹窗 -->
  40. <addElectronicScale :visible="isOpenModal" :id="itemId" :deviceCode="itemDeviceCode" @refresh="refreshTable" @close="isOpenModal = false"></addElectronicScale>
  41. <!-- 查看小程序码 -->
  42. <a-modal
  43. class="qrCodeModal"
  44. title="查看MAC地址二维码"
  45. :width="400"
  46. :footer="null"
  47. :shName="shName"
  48. :destroyOnClose="true"
  49. @cancel="isQrCodeModal = false"
  50. v-model="isQrCodeModal">
  51. <img :src="qrCode" width="300" height="300" class="qrCode" />
  52. <a-button type="primary" class="downQrCode" @click="downloadCode">下载二维码</a-button>
  53. </a-modal>
  54. </a-card>
  55. </template>
  56. <script>
  57. import { STable } from '@/components'
  58. import addElectronicScale from './addElectronicScale.vue'
  59. import { getDeviceList, delectDevice } from '@/api/electronicScale.js'
  60. import QRCode from 'qrcode'
  61. export default {
  62. components: { STable, addElectronicScale },
  63. data () {
  64. return {
  65. searchForm: {
  66. macAddress: '' // 设备MAC地址
  67. },
  68. isOpenModal: false, // 默认弹窗关闭
  69. itemDeviceCode: '', // 编辑行设备编号
  70. itemId: '', // 编辑行id
  71. totalNum: '', // 总计条数
  72. isQrCodeModal: false,
  73. shName: '',
  74. qrCode: '',
  75. // 列表表头
  76. columns: [
  77. { title: '序号', dataIndex: 'no', width: 60, align: 'center' },
  78. { title: '创建时间', dataIndex: 'createDate', width: 100, align: 'center' },
  79. { title: '设备MAC地址', dataIndex: 'macAddress', width: 100, align: 'center' },
  80. { title: '设备名称', dataIndex: 'deviceName', width: 100, align: 'center', ellipsis: true, customRender: text => { return text || '--' } },
  81. { title: '设备编号', dataIndex: 'deviceCode', width: 100, align: 'center', ellipsis: true, customRender: text => { return text || '--' } },
  82. { title: '设备型号', dataIndex: 'deviceModel', width: 100, align: 'center', ellipsis: true, customRender: text => { return text || '--' } },
  83. { title: '生产厂家', dataIndex: 'manufacturer', width: 100, align: 'center', ellipsis: true, customRender: text => { return text || '--' } },
  84. { title: '操作', dataIndex: 'action', width: 100, align: 'center', scopedSlots: { customRender: 'action' } }
  85. ],
  86. // 加载数据方法 必须为 Promise 对象
  87. loadData: parameter => {
  88. return getDeviceList(Object.assign(parameter, this.searchForm, { deviceType: 'STEELYARD' })).then(res => {
  89. if (res.status == 200) {
  90. const no = (res.data.pageNo - 1) * res.data.pageSize
  91. for (let i = 0; i < res.data.list.length; i++) {
  92. const _item = res.data.list[i]
  93. _item.no = no + i + 1
  94. }
  95. this.totalNum = res.data.count
  96. return res.data
  97. } else {
  98. this.totalNum = 0
  99. }
  100. })
  101. }
  102. }
  103. },
  104. methods: {
  105. // 下载二维码
  106. downloadCode (item) {
  107. const link = document.createElement('a')
  108. link.href = this.qrCode
  109. if (this.shName) {
  110. link.download = this.shName + '.png'
  111. } else {
  112. link.download = 'MAC地址二维码' + '.png'
  113. }
  114. link.click()
  115. },
  116. // 查看二维码
  117. getQrCode (item) {
  118. const _this = this
  119. const opts = {
  120. errorCorrectionLevel: 'H',
  121. type: 'image/jpeg',
  122. quality: 0.3,
  123. margin: 1.5,
  124. width: 240,
  125. color: {
  126. dark: '#000000',
  127. light: '#ffffff'
  128. }
  129. }
  130. const url = item.macAddress
  131. _this.shName = item.deviceName
  132. if (url) {
  133. QRCode.toDataURL(url, opts, function (err, url) {
  134. _this.qrCode = url
  135. _this.isQrCodeModal = true
  136. })
  137. }
  138. },
  139. // 重置
  140. handleReset () {
  141. this.searchForm = {
  142. macAddress: ''
  143. }
  144. this.$refs.table.refresh(true)
  145. },
  146. // 新增
  147. openModal () {
  148. this.itemId = ''
  149. this.itemDeviceCode = ''
  150. this.isOpenModal = true
  151. },
  152. // 编辑
  153. handleEdit (record) {
  154. this.itemId = record.id
  155. this.itemDeviceCode = record.srcDeviceCode
  156. this.isOpenModal = true
  157. },
  158. // 删除
  159. delect (record) {
  160. const _this = this
  161. _this.$confirm({
  162. title: '警告',
  163. centered: true,
  164. content: '删除后无法恢复,确认删除?',
  165. okText: '确定',
  166. cancelText: '取消',
  167. onOk () {
  168. delectDevice({
  169. id: record.id
  170. }).then(res => {
  171. if (res.status == 200) {
  172. _this.$message.success(res.message)
  173. _this.$refs.table.refresh()
  174. }
  175. })
  176. }
  177. })
  178. },
  179. // 保存或编辑后刷新列表
  180. refreshTable () {
  181. // 编辑
  182. if (this.itemId) {
  183. this.$refs.table.refresh()
  184. } else {
  185. // 保存
  186. this.$refs.table.refresh(true)
  187. }
  188. }
  189. }
  190. }
  191. </script>
  192. <style lang="less" scoped>
  193. .electronicScale-container {
  194. .electronicScale-container-searchForm {
  195. .ant-form-inline .ant-form-item {
  196. width: 100%;
  197. }
  198. }
  199. // 查询按钮
  200. .handle-btn {
  201. margin-top: 4px;
  202. }
  203. .serach-btn {
  204. margin-right: 10px;
  205. }
  206. .electronicScale-container-add {
  207. margin: 15px 0;
  208. }
  209. }
  210. // 查看小程序码 弹框
  211. .qrCodeModal {
  212. .qrCode {
  213. display: block;
  214. max-width: 100%;
  215. margin: 0 auto;
  216. }
  217. .downQrCode {
  218. display: block;
  219. margin: 30px auto;
  220. }
  221. }
  222. </style>