list.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <a-card size="small" :bordered="false" class="productUniversalList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div ref="tableSearch" 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="6" :sm="24">
  9. <a-form-item label="产品编码">
  10. <a-input id="productUniversalList-productCode" v-model.trim="queryParam.productCode" allowClear placeholder="请输入产品编码"/>
  11. </a-form-item>
  12. </a-col>
  13. <a-col :md="6" :sm="24">
  14. <a-form-item label="产品名称">
  15. <a-input id="productUniversalList-productName" v-model.trim="queryParam.productName" allowClear placeholder="请输入产品名称"/>
  16. </a-form-item>
  17. </a-col>
  18. <a-col :md="6" :sm="24">
  19. <a-form-item label="产品状态">
  20. <v-select code="PRODUCT_STATUS" id="productUniversalList-productState" v-model="queryParam.productState" allowClear placeholder="请选择产品状态"></v-select>
  21. </a-form-item>
  22. </a-col>
  23. <template v-if="advanced">
  24. <a-col :md="6" :sm="24">
  25. <a-form-item label="通用产品编码">
  26. <a-input id="productUniversalList-productCommonCode" v-model.trim="queryParam.productCommonCode" allowClear placeholder="请输入通用产品编码"/>
  27. </a-form-item>
  28. </a-col>
  29. <a-col :md="6" :sm="24">
  30. <a-form-item label="通用产品名称">
  31. <a-input id="productUniversalList-productCommonName" v-model.trim="queryParam.productCommonName" allowClear placeholder="请输入通用产品名称"/>
  32. </a-form-item>
  33. </a-col>
  34. </template>
  35. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  36. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="productUniversalList-refresh">查询</a-button>
  37. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="productUniversalList-reset">重置</a-button>
  38. <a @click="advanced=!advanced" style="margin-left: 5px">
  39. {{ advanced ? '收起' : '展开' }}
  40. <a-icon :type="advanced ? 'up' : 'down'"/>
  41. </a>
  42. </a-col>
  43. </a-row>
  44. </a-form>
  45. </div>
  46. <!-- 操作按钮 -->
  47. <div class="table-operator">
  48. <a-button id="productUniversalList-add" type="primary" v-if="$hasPermissions('B_productUniversal_add')" class="button-error" @click="handleEdit()">新增</a-button>
  49. </div>
  50. <!-- 列表 -->
  51. <s-table
  52. class="sTable fixPagination"
  53. ref="table"
  54. :style="{ height: tableHeight+84.5+'px' }"
  55. size="small"
  56. :rowKey="(record) => record.id"
  57. :columns="columns"
  58. :data="loadData"
  59. :scroll="{ y: tableHeight }"
  60. :defaultLoadData="false"
  61. bordered>
  62. <!-- 产品分类 -->
  63. <template slot="productType" slot-scope="text, record">
  64. <span v-if="record.productCommont.productTypeName2 || record.productCommont.productTypeName3">{{ record.productCommont.productTypeName2 }} {{ record.productCommont.productTypeName3 ? '>' : '' }} {{ record.productCommont.productTypeName3 }}</span>
  65. <span v-else>--</span>
  66. </template>
  67. <!-- 操作 -->
  68. <template slot="action" slot-scope="text, record">
  69. <a-button
  70. size="small"
  71. type="link"
  72. v-if="$hasPermissions('B_productUniversal_edit')"
  73. class="button-info"
  74. @click="handleEdit(record)"
  75. id="productUniversalList-edit-btn">编辑</a-button>
  76. <a-button
  77. size="small"
  78. type="link"
  79. v-if="$hasPermissions('B_productUniversal_del')"
  80. class="button-error"
  81. @click="handleDel(record)"
  82. id="productUniversalList-del-btn">删除</a-button>
  83. <span v-if="!$hasPermissions('B_productUniversal_edit') && !$hasPermissions('B_productUniversal_del')">--</span>
  84. </template>
  85. </s-table>
  86. </a-spin>
  87. <!-- 新增/编辑 -->
  88. <product-universal-edit-modal :openModal="openModal" :itemId="itemId" @close="closeModal" @ok="$refs.table.refresh()" />
  89. </a-card>
  90. </template>
  91. <script>
  92. import moment from 'moment'
  93. import { STable, VSelect } from '@/components'
  94. import productUniversalEditModal from './editModal.vue'
  95. import { productUniversalCodeList, productUniversalCodeDel } from '@/api/productUniversalCode'
  96. export default {
  97. components: { STable, VSelect, productUniversalEditModal },
  98. data () {
  99. return {
  100. spinning: false,
  101. advanced: true, // 高级搜索 展开/关闭
  102. tableHeight: 0,
  103. queryParam: { // 查询条件
  104. productCode: '',
  105. productName: '',
  106. productState: undefined,
  107. productCommonName: '',
  108. productCommonCode: ''
  109. },
  110. productType: [],
  111. disabled: false, // 查询、重置按钮是否可操作
  112. exportLoading: false, // 导出loading
  113. columns: [
  114. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  115. { title: '产品编码', dataIndex: 'productCode', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  116. { title: '产品名称', dataIndex: 'product.name', align: 'center', width: '24%', customRender: function (text) { return text || '--' }, ellipsis: true },
  117. { title: '产品状态', dataIndex: 'product.stateDictValue', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  118. { title: '通用产品编码', dataIndex: 'productCommonCode', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  119. { title: '通用产品名称', dataIndex: 'productCommont.name', width: '16%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  120. { title: '通用产品分类', scopedSlots: { customRender: 'productType' }, width: '12%', align: 'center' },
  121. { title: '通用产品状态', dataIndex: 'productCommont.stateDictValue', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  122. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  123. ],
  124. // 加载数据方法 必须为 Promise 对象
  125. loadData: parameter => {
  126. this.disabled = true
  127. this.spinning = true
  128. return productUniversalCodeList(Object.assign(parameter, this.queryParam)).then(res => {
  129. let data
  130. if (res.status == 200) {
  131. data = res.data
  132. const no = (data.pageNo - 1) * data.pageSize
  133. for (var i = 0; i < data.list.length; i++) {
  134. data.list[i].no = no + i + 1
  135. }
  136. this.disabled = false
  137. }
  138. this.spinning = false
  139. return data
  140. })
  141. },
  142. openModal: false, // 编辑 弹框
  143. itemId: '' // 当前id
  144. }
  145. },
  146. methods: {
  147. // 重置
  148. resetSearchForm () {
  149. this.queryParam.productCode = ''
  150. this.queryParam.productName = ''
  151. this.queryParam.productState = undefined
  152. this.queryParam.productCommonName = ''
  153. this.queryParam.productCommonCode = ''
  154. this.$refs.table.refresh(true)
  155. },
  156. // 编辑
  157. handleEdit (row) {
  158. if (row) {
  159. this.itemId = row.id
  160. } else {
  161. this.itemId = null
  162. }
  163. this.openModal = true
  164. },
  165. // 关闭弹框
  166. closeModal () {
  167. this.itemId = ''
  168. this.openModal = false
  169. },
  170. // 删除
  171. handleDel (row) {
  172. const _this = this
  173. this.$confirm({
  174. title: '提示',
  175. content: '确认要删除吗?',
  176. centered: true,
  177. onOk () {
  178. _this.spinning = true
  179. productUniversalCodeDel({ id: row.id }).then(res => {
  180. if (res.status == 200) {
  181. _this.$message.success(res.message)
  182. _this.$refs.table.refresh()
  183. _this.spinning = false
  184. } else {
  185. _this.spinning = false
  186. }
  187. })
  188. }
  189. })
  190. },
  191. // 导出
  192. handleExport () {
  193. const params = this.queryParam
  194. this.exportLoading = true
  195. // customerBundleExportDelay(params).then(res => {
  196. // this.exportLoading = false
  197. // this.download(res)
  198. // })
  199. },
  200. download (data) {
  201. if (!data) { return }
  202. const url = window.URL.createObjectURL(new Blob([data]))
  203. const link = document.createElement('a')
  204. link.style.display = 'none'
  205. link.href = url
  206. const a = moment().format('YYYYMMDDHHmmss')
  207. const fname = '通用产品_' + a
  208. link.setAttribute('download', fname + '.xlsx')
  209. document.body.appendChild(link)
  210. link.click()
  211. },
  212. pageInit () {
  213. const _this = this
  214. this.$nextTick(() => { // 页面渲染完成后的回调
  215. _this.setTableH()
  216. })
  217. },
  218. setTableH () {
  219. const tableSearchH = this.$refs.tableSearch.offsetHeight
  220. this.tableHeight = window.innerHeight - tableSearchH - 235
  221. }
  222. },
  223. watch: {
  224. advanced (newValue, oldValue) {
  225. const _this = this
  226. setTimeout(() => {
  227. _this.setTableH()
  228. }, 400)
  229. },
  230. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  231. this.setTableH()
  232. }
  233. },
  234. mounted () {
  235. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  236. this.pageInit()
  237. this.resetSearchForm()
  238. }
  239. },
  240. activated () {
  241. // 如果是新页签打开,则重置当前页面
  242. if (this.$store.state.app.isNewTab) {
  243. this.pageInit()
  244. this.resetSearchForm()
  245. }
  246. // 仅刷新列表,不重置页面
  247. if (this.$store.state.app.updateList) {
  248. this.pageInit()
  249. this.$refs.table.refresh()
  250. }
  251. },
  252. beforeRouteEnter (to, from, next) {
  253. next(vm => {})
  254. }
  255. }
  256. </script>