equipmentManagement.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <a-card :bordered="false">
  3. <div class="equipmentManagement">
  4. <!-- 搜索框 -->
  5. <div class="table-page-search-wrapper">
  6. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  7. <a-row :gutter="15">
  8. <a-col :md="5" :sm="24">
  9. <a-form-item label="设备编码">
  10. <a-input allowClear v-model.trim="queryParam.deviceCode" placeholder="请输入设备编码" />
  11. </a-form-item>
  12. </a-col>
  13. <a-col :md="5" :sm="24">
  14. <a-form-item label="经销商">
  15. <storeList ref="storeList" @change="custChange"></storeList>
  16. </a-form-item>
  17. </a-col>
  18. <a-col :md="5" :sm="24">
  19. <a-form-item label="所属省份">
  20. <a-select id="equipmentManagement-addrProvince" allowClear v-model="queryParam.dealer.provinceSn" placeholder="请选择省">
  21. <a-select-option v-for="item in addrProvinceList" :value="item.areaSn" :key="item.areaSn + 'a'">{{ item.name }}</a-select-option>
  22. </a-select>
  23. </a-form-item>
  24. </a-col>
  25. <a-col :md="5" :sm="24">
  26. <a-form-item label="启用状态">
  27. <v-select
  28. v-model="queryParam.enabledFlag"
  29. ref="auditStatus"
  30. code="ENABLE_FLAG"
  31. placeholder="请选择启用状态"
  32. allowClear></v-select>
  33. </a-form-item>
  34. </a-col>
  35. <a-col :md="4" :sm="24">
  36. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="equipmentManagement-refresh">查询</a-button>
  37. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="equipmentManagement-reset">重置</a-button>
  38. </a-col>
  39. </a-row>
  40. </a-form>
  41. </div>
  42. <div class="table-operator">
  43. <a-button type="primary" class="button-error" @click="addEquipment">添加设备</a-button>
  44. </div>
  45. <!-- 列表 -->
  46. <s-table
  47. class="sTable"
  48. ref="table"
  49. size="default"
  50. rowKey="id"
  51. :columns="columns"
  52. :data="loadData"
  53. bordered>
  54. <!-- 地区 -->
  55. <template slot="addressInfo" slot-scope="text, record">
  56. <span v-if="record.dealer">{{ record.dealer.provinceName }}{{ record.dealer.cityName }}</span>
  57. </template>
  58. <!--是否启用 -->
  59. <template slot="isEnabled" slot-scope="text, record">
  60. <a-switch checked-children="是" un-checked-children="否" :checked="record.isChecked" @change="handleChecked(record)" />
  61. </template>
  62. <!-- 操作 -->
  63. <template slot="action" slot-scope="text, record">
  64. <a-button size="small" type="link" class="button-primary" @click="handleEdit(record)">编辑</a-button>
  65. <a-button size="small" type="link" class="button-primary" @click="handleDel(record)">删除</a-button>
  66. </template>
  67. </s-table>
  68. </div>
  69. <!-- 添加设备 -->
  70. <addEquipmentModal ref="equipmentBox" :openModal="openModal" :itemId="itemId" @confirm="$refs.table.refresh(true)" @close="openModal=false" />
  71. </a-card>
  72. </template>
  73. <script>
  74. import storeList from '@/views/common/storeList.vue'
  75. import { STable, VSelect } from '@/components'
  76. import addEquipmentModal from './addEquipmentModal'
  77. import { handDeviceList, handDeviceDel, handDeviceEdit } from '@/api/handDevice.js'
  78. import { getArea } from '@/api/data'
  79. export default {
  80. name: 'EquipmentManagement',
  81. components: { STable, VSelect, storeList, addEquipmentModal },
  82. data () {
  83. return {
  84. advanced: false, // 高级搜索 展开/关闭
  85. disabled: false, // 查询、重置按钮是否可操作
  86. queryParam: {
  87. dealerSn: undefined,
  88. deviceCode: '',
  89. deviceName: '',
  90. enabledFlag: undefined,
  91. dealer: {
  92. provinceSn: undefined
  93. }
  94. },
  95. addrProvinceList: [],
  96. openModal: false,
  97. itemId: '',
  98. columns: [
  99. { title: '序号', dataIndex: 'no', width: 80, align: 'center', fixed: 'left' },
  100. { title: '设备编码', dataIndex: 'deviceCode', align: 'center', customRender: function (text) { return text || '--' } },
  101. { title: '设备名称', dataIndex: 'deviceName', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  102. { title: '地区', scopedSlots: { customRender: 'addressInfo' }, align: 'center' },
  103. { title: '经销商', dataIndex: 'dealer.dealerName', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  104. { title: '是否启用', scopedSlots: { customRender: 'isEnabled' }, align: 'center' },
  105. { title: '添加时间', dataIndex: 'createDate', align: 'center', customRender: function (text) { return text || '--' } },
  106. { title: '操作', scopedSlots: { customRender: 'action' }, align: 'center' }
  107. ],
  108. // 加载数据方法 必须为 Promise 对象
  109. loadData: parameter => {
  110. this.disabled = true
  111. return handDeviceList(Object.assign(parameter, this.queryParam)).then(res => {
  112. const data = res.data
  113. const no = (data.pageNo - 1) * data.pageSize
  114. for (var i = 0; i < data.list.length; i++) {
  115. data.list[i].no = no + i + 1
  116. data.list[i].isChecked = data.list[i].enabledFlag == 1
  117. }
  118. this.disabled = false
  119. return data
  120. })
  121. }
  122. }
  123. },
  124. mounted () {
  125. this.getCityList()
  126. },
  127. methods: {
  128. // 新增设备
  129. addEquipment () {
  130. this.itemId = ''
  131. this.openModal = true
  132. },
  133. // 获取所属省份
  134. getCityList () {
  135. getArea({ type: '2' }).then(res => {
  136. if (res.status == 200) {
  137. this.addrProvinceList = res.data || []
  138. } else {
  139. this.addrProvinceList = []
  140. }
  141. })
  142. },
  143. // 修改启用状态
  144. handleChecked (row) {
  145. const _this = this
  146. handDeviceEdit({
  147. id: row.id,
  148. enabledFlag: row.isChecked ? '0' : '1',
  149. dealerSn: row.dealerSn,
  150. deviceCode: row.deviceCode,
  151. deviceName: row.deviceName
  152. }).then(res => {
  153. if (res.status == 200) {
  154. _this.$message.success(res.message)
  155. _this.resetSearchForm()
  156. }
  157. })
  158. },
  159. // 选择客户
  160. custChange (val) {
  161. this.queryParam.dealerSn = val.key
  162. },
  163. handleEdit (row) {
  164. this.itemId = row.id
  165. this.$nextTick(() => {
  166. this.openModal = true
  167. this.$refs.equipmentBox.pageInit()
  168. })
  169. },
  170. handleDel (row) {
  171. const _this = this
  172. this.$confirm({
  173. title: '提示',
  174. content: '删除该设备后,所有绑定数据将被清除,并且不能继续操作。',
  175. okText: '删除',
  176. cancelText: '取消',
  177. onOk () {
  178. handDeviceDel({ id: row.id }).then(res => {
  179. if (res.status == 200) {
  180. _this.$message.success(res.message)
  181. _this.resetSearchForm()
  182. }
  183. })
  184. },
  185. onCancel () {
  186. console.log('取消删除')
  187. }
  188. })
  189. },
  190. // 时间 change
  191. dateChange (date) {
  192. this.queryParam.beginDate = date[0]
  193. this.queryParam.endDate = date[1]
  194. },
  195. // 重置
  196. resetSearchForm () {
  197. this.queryParam.dealerSn = undefined
  198. this.queryParam.deviceCode = ''
  199. this.queryParam.deviceName = ''
  200. this.queryParam.enabledFlag = undefined
  201. this.queryParam.dealer.provinceSn = undefined
  202. this.$refs.storeList.resetForm()
  203. this.$refs.table.refresh(true)
  204. }
  205. }
  206. }
  207. </script>
  208. <style lang="less">
  209. .equipmentManagement{
  210. .sTable{
  211. margin-top: 10px;
  212. }
  213. }
  214. </style>