list.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <div>
  3. <a-card size="small" :bordered="false" class="productLevelList-wrap searchBoxNormal">
  4. <!-- 搜索条件 -->
  5. <div ref="tableSearch" class="table-page-search-wrapper">
  6. <a-form layout="inline" id="productLevelList-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="productLevelList-queryWord" v-model.trim="queryParam.queryWord" 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="productLevelList-name" v-model.trim="queryParam.name" 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_LEVEL" id="productLevelList-level" v-model="queryParam.level" 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. <ProductBrand id="productLevelList-productBrandSn" v-model="queryParam.productBrandSn"></ProductBrand>
  27. </a-form-item>
  28. </a-col>
  29. <a-col :md="6" :sm="24">
  30. <a-form-item label="产品分类">
  31. <ProductType id="productLevelList-productType" placeholder="请选择产品分类" @change="changeProductType" v-model="productType"></ProductType>
  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="productLevelList-refresh">查询</a-button>
  37. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="productLevelList-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. </a-card>
  47. <!-- 列表 -->
  48. <a-card size="small" :bordered="false">
  49. <s-table
  50. class="sTable fixPagination"
  51. ref="table"
  52. :style="{ height: tableHeight+70+'px' }"
  53. size="small"
  54. :rowKey="(record) => record.id"
  55. :columns="columns"
  56. :data="loadData"
  57. :pageSize="30"
  58. :scroll="{ y: tableHeight }"
  59. :defaultLoadData="false"
  60. bordered>
  61. <!-- 产品分类 -->
  62. <template slot="productType" slot-scope="text, record">
  63. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  64. <span v-else>--</span>
  65. </template>
  66. <!-- 操作 -->
  67. <template slot="action" slot-scope="text, record">
  68. <a-button
  69. size="small"
  70. type="link"
  71. v-if="$hasPermissions('B_productLevel_edit')"
  72. class="button-info"
  73. @click="handleEdit(record)"
  74. :id="'productLevelList-edit-btn'+record.id">编辑</a-button>
  75. <span v-else>--</span>
  76. </template>
  77. </s-table>
  78. <!-- 编辑价格 -->
  79. <product-level-edit-modal
  80. v-drag
  81. :openModal="openModal"
  82. :itemId="itemId"
  83. :nowData="nowData"
  84. @close="closeModal"
  85. @ok="$refs.table.refresh()" />
  86. </a-card>
  87. </div>
  88. </template>
  89. <script>
  90. import { commonMixin } from '@/utils/mixin'
  91. import moment from 'moment'
  92. // 组件
  93. import { STable, VSelect } from '@/components'
  94. import productLevelEditModal from './editModal.vue'
  95. import ProductBrand from '@/views/common/productBrand.js'
  96. import ProductType from '@/views/common/productType.js'
  97. // 接口
  98. import { productLevelList } from '@/api/product'
  99. export default {
  100. name: 'ProductLevelList',
  101. mixins: [commonMixin],
  102. components: { STable, VSelect, productLevelEditModal, ProductBrand, ProductType },
  103. data () {
  104. return {
  105. advanced: true, // 高级搜索 展开/关闭
  106. tableHeight: 0, // 表格高度
  107. disabled: false, // 查询、重置按钮是否可操作
  108. exportLoading: false, // 导出loading
  109. // 查询条件
  110. queryParam: {
  111. name: '', // 产品名称
  112. queryWord: '', // 产品编码/原厂编码
  113. productBrandSn: undefined, // 产品品牌
  114. productTypeSn1: '', // 产品一级分类
  115. productTypeSn2: '', // 产品二级分类
  116. productTypeSn3: '', // 产品三级分类
  117. level: undefined // 产品级别
  118. },
  119. productType: [], // 产品分类
  120. columns: [
  121. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  122. { title: '产品名称', dataIndex: 'name', align: 'left', width: '25%', ellipsis: true, customRender: function (text) { return text || '--' } },
  123. { title: '产品编码', dataIndex: 'code', width: '6%', align: 'left', customRender: function (text) { return text || '--' } },
  124. { title: '原厂编码', dataIndex: 'origCode', width: '19%', align: 'left', customRender: function (text) { return text || '--' } },
  125. { title: '品牌', dataIndex: 'productBrandName', width: '5%', align: 'center', customRender: function (text) { return text || '--' } },
  126. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: '16%', align: 'left' },
  127. { title: '包装数', dataIndex: 'packQtyV', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  128. { title: '单位', dataIndex: 'unit', width: '5%', align: 'center', customRender: function (text) { return text || '--' } },
  129. { title: '产品级别', dataIndex: 'level', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  130. { title: '操作', scopedSlots: { customRender: 'action' }, width: '6%', align: 'center' }
  131. ],
  132. // 加载数据方法 必须为 Promise 对象
  133. loadData: parameter => {
  134. this.disabled = true
  135. this.spinning = true
  136. return productLevelList(Object.assign(parameter, this.queryParam)).then(res => {
  137. let data
  138. if (res.status == 200) {
  139. data = res.data
  140. const no = (data.pageNo - 1) * data.pageSize
  141. for (var i = 0; i < data.list.length; i++) {
  142. data.list[i].no = no + i + 1
  143. const packQty = (data.list[i].packQty || data.list[i].packQty == 0) ? data.list[i].packQty : '--'
  144. const unit = data.list[i].unit || '--'
  145. const packQtyUnit = data.list[i].packQtyUnit || '--'
  146. data.list[i].packQtyV = packQty + unit + '/' + packQtyUnit
  147. }
  148. this.disabled = false
  149. }
  150. this.spinning = false
  151. return data
  152. })
  153. },
  154. openModal: false, // 编辑 弹框
  155. itemId: '', // 当前产品id
  156. productBrandList: [], // 品牌下拉数据
  157. productTypeList: [], // 分类下拉数据
  158. nowData: null // 当前行数据
  159. }
  160. },
  161. methods: {
  162. // 重置
  163. resetSearchForm () {
  164. this.queryParam.name = ''
  165. this.queryParam.queryWord = ''
  166. this.queryParam.productBrandSn = undefined
  167. this.queryParam.productTypeSn1 = ''
  168. this.queryParam.productTypeSn2 = ''
  169. this.queryParam.productTypeSn3 = ''
  170. this.queryParam.level = undefined
  171. this.productType = []
  172. this.$refs.table.refresh(true)
  173. },
  174. // 编辑
  175. handleEdit (row) {
  176. this.nowData = row
  177. this.itemId = row.id
  178. this.openModal = true
  179. },
  180. // 关闭弹框
  181. closeModal () {
  182. this.itemId = ''
  183. this.nowData = null
  184. this.openModal = false
  185. },
  186. // 产品分类 change
  187. changeProductType (val, opt) {
  188. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  189. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  190. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  191. },
  192. // 导出配置
  193. download (data) {
  194. if (!data) { return }
  195. const url = window.URL.createObjectURL(new Blob([data]))
  196. const link = document.createElement('a')
  197. link.style.display = 'none'
  198. link.href = url
  199. const a = moment().format('YYYYMMDDHHmmss')
  200. const fname = '产品级别' + a
  201. link.setAttribute('download', fname + '.xlsx')
  202. document.body.appendChild(link)
  203. link.click()
  204. },
  205. // 初始化
  206. pageInit () {
  207. const _this = this
  208. this.$nextTick(() => { // 页面渲染完成后的回调
  209. _this.setTableH()
  210. })
  211. },
  212. // 计算表格高度
  213. setTableH () {
  214. const tableSearchH = this.$refs.tableSearch.offsetHeight
  215. this.tableHeight = window.innerHeight - tableSearchH - 200
  216. }
  217. },
  218. watch: {
  219. // 展开关闭 监听表格高度变化
  220. advanced (newValue, oldValue) {
  221. const _this = this
  222. this.$nextTick(() => { // 页面渲染完成后的回调
  223. _this.setTableH()
  224. })
  225. },
  226. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  227. this.setTableH()
  228. }
  229. },
  230. mounted () {
  231. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  232. this.pageInit()
  233. this.resetSearchForm()
  234. }
  235. },
  236. activated () {
  237. // 如果是新页签打开,则重置当前页面
  238. if (this.$store.state.app.isNewTab) {
  239. this.pageInit()
  240. this.resetSearchForm()
  241. }
  242. // 仅刷新列表,不重置页面
  243. if (this.$store.state.app.updateList) {
  244. this.pageInit()
  245. this.$refs.table.refresh()
  246. }
  247. },
  248. beforeRouteEnter (to, from, next) {
  249. next(vm => {})
  250. }
  251. }
  252. </script>