list.vue 11 KB

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