list.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <a-card size="small" :bordered="false" class="productUniversalList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  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="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">
  36. <a-button style="margin-bottom: 18px;" type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="productUniversalList-refresh">查询</a-button>
  37. <a-button style="margin: 0 0 18px 8px" @click="resetSearchForm" :disabled="disabled" id="productUniversalList-reset">重置</a-button>
  38. <a @click="advanced=!advanced" style="margin-left: 8px">
  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"
  53. ref="table"
  54. size="small"
  55. :rowKey="(record) => record.id"
  56. :columns="columns"
  57. :data="loadData"
  58. :scroll="{ x: 1580, y: tableHeight }"
  59. bordered>
  60. <!-- 产品分类 -->
  61. <template slot="productType" slot-scope="text, record">
  62. <span v-if="record.productCommont.productTypeName2 || record.productCommont.productTypeName3">{{ record.productCommont.productTypeName2 }} {{ record.productCommont.productTypeName3 ? '>' : '' }} {{ record.productCommont.productTypeName3 }}</span>
  63. <span v-else>--</span>
  64. </template>
  65. <!-- 操作 -->
  66. <template slot="action" slot-scope="text, record">
  67. <a-button
  68. size="small"
  69. type="link"
  70. v-if="$hasPermissions('B_productUniversal_edit')"
  71. class="button-info"
  72. @click="handleEdit(record)"
  73. id="productUniversalList-edit-btn">编辑</a-button>
  74. <a-button
  75. size="small"
  76. type="link"
  77. v-if="$hasPermissions('B_productUniversal_del')"
  78. class="button-error"
  79. @click="handleDel(record)"
  80. id="productUniversalList-del-btn">删除</a-button>
  81. <span v-if="!$hasPermissions('B_productUniversal_edit') && !$hasPermissions('B_productUniversal_del')">--</span>
  82. </template>
  83. </s-table>
  84. </a-spin>
  85. <!-- 新增/编辑 -->
  86. <product-universal-edit-modal :openModal="openModal" :itemId="itemId" @close="closeModal" @ok="$refs.table.refresh()" />
  87. </a-card>
  88. </template>
  89. <script>
  90. import moment from 'moment'
  91. import { STable, VSelect } from '@/components'
  92. import productUniversalEditModal from './editModal.vue'
  93. import { productUniversalCodeList, productUniversalCodeDel } from '@/api/productUniversalCode'
  94. export default {
  95. components: { STable, VSelect, productUniversalEditModal },
  96. data () {
  97. return {
  98. spinning: false,
  99. advanced: false, // 高级搜索 展开/关闭
  100. queryParam: { // 查询条件
  101. productCode: '',
  102. productName: '',
  103. productState: undefined,
  104. productCommonName: '',
  105. productCommonCode: ''
  106. },
  107. productType: [],
  108. disabled: false, // 查询、重置按钮是否可操作
  109. exportLoading: false, // 导出loading
  110. columns: [
  111. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  112. { title: '产品编码', dataIndex: 'productCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  113. { title: '产品名称', dataIndex: 'product.name', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  114. { title: '产品状态', dataIndex: 'product.stateDictValue', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
  115. { title: '通用产品编码', dataIndex: 'productCommonCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  116. { title: '通用产品名称', dataIndex: 'productCommont.name', width: 200, align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  117. { title: '通用产品分类', scopedSlots: { customRender: 'productType' }, width: 200, align: 'center' },
  118. { title: '通用产品状态', dataIndex: 'productCommont.stateDictValue', width: 150, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  119. { title: '操作', scopedSlots: { customRender: 'action' }, width: 150, align: 'center', fixed: 'right' }
  120. ],
  121. // 加载数据方法 必须为 Promise 对象
  122. loadData: parameter => {
  123. this.disabled = true
  124. return productUniversalCodeList(Object.assign(parameter, this.queryParam)).then(res => {
  125. const data = res.data
  126. const no = (data.pageNo - 1) * data.pageSize
  127. for (var i = 0; i < data.list.length; i++) {
  128. data.list[i].no = no + i + 1
  129. }
  130. this.disabled = false
  131. return data
  132. })
  133. },
  134. openModal: false, // 编辑 弹框
  135. itemId: '' // 当前id
  136. }
  137. },
  138. computed: {
  139. tableHeight () {
  140. return window.innerHeight - (this.advanced ? 425 : 370)
  141. }
  142. },
  143. methods: {
  144. // 重置
  145. resetSearchForm () {
  146. this.queryParam.productCode = ''
  147. this.queryParam.productName = ''
  148. this.queryParam.productState = undefined
  149. this.queryParam.productCommonName = ''
  150. this.queryParam.productCommonCode = ''
  151. this.$refs.table.refresh(true)
  152. },
  153. // 编辑
  154. handleEdit (row) {
  155. if (row) {
  156. this.itemId = row.id
  157. } else {
  158. this.itemId = null
  159. }
  160. this.openModal = true
  161. },
  162. // 关闭弹框
  163. closeModal () {
  164. this.itemId = ''
  165. this.openModal = false
  166. },
  167. // 删除
  168. handleDel (row) {
  169. const _this = this
  170. this.$confirm({
  171. title: '提示',
  172. content: '确认要删除吗?',
  173. centered: true,
  174. onOk () {
  175. _this.spinning = true
  176. productUniversalCodeDel({ id: row.id }).then(res => {
  177. if (res.status == 200) {
  178. _this.$message.success(res.message)
  179. _this.$refs.table.refresh()
  180. _this.spinning = false
  181. } else {
  182. _this.spinning = false
  183. }
  184. })
  185. }
  186. })
  187. },
  188. // 导出
  189. handleExport () {
  190. const params = this.queryParam
  191. this.exportLoading = true
  192. // customerBundleExportDelay(params).then(res => {
  193. // this.exportLoading = false
  194. // this.download(res)
  195. // })
  196. },
  197. download (data) {
  198. if (!data) { return }
  199. const url = window.URL.createObjectURL(new Blob([data]))
  200. const link = document.createElement('a')
  201. link.style.display = 'none'
  202. link.href = url
  203. const a = moment().format('YYYYMMDDHHmmss')
  204. const fname = '通用产品_' + a
  205. link.setAttribute('download', fname + '.xlsx')
  206. document.body.appendChild(link)
  207. link.click()
  208. }
  209. },
  210. beforeRouteEnter (to, from, next) {
  211. next(vm => {})
  212. }
  213. }
  214. </script>