equipmentManagement.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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.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="openModal = true">添加设备</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 { getAreaCgj } 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. provinceSn: undefined
  92. },
  93. addrProvinceList: [],
  94. openModal: false,
  95. itemId: '',
  96. columns: [
  97. { title: '序号', dataIndex: 'no', width: 80, align: 'center', fixed: 'left' },
  98. { title: '设备编码', dataIndex: 'deviceCode', align: 'center', customRender: function (text) { return text || '--' } },
  99. { title: '设备名称', dataIndex: 'deviceName', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  100. { title: '地区', scopedSlots: { customRender: 'addressInfo' }, align: 'center' },
  101. { title: '经销商', dataIndex: 'dealer.dealerName', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  102. { title: '是否启用', scopedSlots: { customRender: 'isEnabled' }, align: 'center' },
  103. { title: '添加时间', dataIndex: 'createDate', align: 'center', customRender: function (text) { return text || '--' } },
  104. { title: '操作', scopedSlots: { customRender: 'action' }, align: 'center' }
  105. ],
  106. // 加载数据方法 必须为 Promise 对象
  107. loadData: parameter => {
  108. this.disabled = true
  109. return handDeviceList(Object.assign(parameter, this.queryParam)).then(res => {
  110. const data = res.data
  111. const no = (data.pageNo - 1) * data.pageSize
  112. for (var i = 0; i < data.list.length; i++) {
  113. data.list[i].no = no + i + 1
  114. data.list[i].isChecked = data.list[i].enabledFlag == 1
  115. }
  116. this.disabled = false
  117. return data
  118. })
  119. }
  120. }
  121. },
  122. mounted () {
  123. this.getCityList()
  124. },
  125. methods: {
  126. // 获取所属省份
  127. getCityList () {
  128. getAreaCgj({ type: '2' }).then(res => {
  129. if (res.status == 200) {
  130. this.addrProvinceList = res.data || []
  131. } else {
  132. this.addrProvinceList = []
  133. }
  134. })
  135. },
  136. // 修改启用状态
  137. handleChecked (row) {
  138. const _this = this
  139. handDeviceEdit({
  140. id: row.id,
  141. enabledFlag: row.isChecked ? '0' : '1',
  142. dealerSn: row.dealerSn,
  143. deviceCode: row.deviceCode,
  144. deviceName: row.deviceName
  145. }).then(res => {
  146. if (res.status == 200) {
  147. _this.$message.success(res.message)
  148. _this.resetSearchForm()
  149. }
  150. })
  151. },
  152. // 选择客户
  153. custChange (val) {
  154. this.queryParam.dealerSn = val.key
  155. },
  156. handleEdit (row) {
  157. this.itemId = row.id
  158. this.$nextTick(() => {
  159. this.openModal = true
  160. this.$refs.equipmentBox.pageInit()
  161. })
  162. },
  163. handleDel (row) {
  164. const _this = this
  165. this.$warning({
  166. title: '提示',
  167. content: '删除该设备后,所有绑定数据将被清除,并且不能继续操作。',
  168. okText: '删除',
  169. onOk () {
  170. handDeviceDel({ id: row.id }).then(res => {
  171. if (res.status == 200) {
  172. _this.$message.success(res.message)
  173. _this.resetSearchForm()
  174. }
  175. })
  176. },
  177. onCancel () {}
  178. })
  179. },
  180. // 时间 change
  181. dateChange (date) {
  182. this.queryParam.beginDate = date[0]
  183. this.queryParam.endDate = date[1]
  184. },
  185. // 重置
  186. resetSearchForm () {
  187. this.queryParam.dealerSn = undefined
  188. this.queryParam.deviceCode = ''
  189. this.queryParam.deviceName = ''
  190. this.queryParam.enabledFlag = undefined
  191. this.queryParam.provinceSn = undefined
  192. this.$refs.storeList.resetForm()
  193. this.$refs.table.refresh(true)
  194. }
  195. }
  196. }
  197. </script>
  198. <style lang="less">
  199. .equipmentManagement{
  200. .sTable{
  201. margin-top: 10px;
  202. }
  203. }
  204. </style>