list.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <a-card size="small" :bordered="false" class="productLevelList-wrap">
  3. <!-- 搜索条件 -->
  4. <div ref="tableSearch" class="table-page-search-wrapper">
  5. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  6. <a-row :gutter="15">
  7. <a-col :md="6" :sm="24">
  8. <a-form-item label="产品名称">
  9. <a-input id="productLevelList-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称"/>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :md="6" :sm="24">
  13. <a-form-item label="产品编码/原厂编码">
  14. <a-input id="productLevelList-queryWord" v-model.trim="queryParam.queryWord" allowClear placeholder="请输入产品编码"/>
  15. </a-form-item>
  16. </a-col>
  17. <a-col :md="6" :sm="24">
  18. <a-form-model-item label="产品分类">
  19. <ProductType id="productLevelList-productType" placeholder="请选择产品分类" @change="changeProductType" v-model="productType"></ProductType>
  20. </a-form-model-item>
  21. </a-col>
  22. <template v-if="advanced">
  23. <a-col :md="6" :sm="24">
  24. <a-form-item label="品牌">
  25. <ProductBrand id="productLevelList-productBrandSn" v-model="queryParam.productBrandSn"></ProductBrand>
  26. </a-form-item>
  27. </a-col>
  28. <a-col :md="6" :sm="24">
  29. <a-form-item label="产品级别">
  30. <v-select code="PRODUCT_LEVEL" id="productLevelList-level" v-model="queryParam.level" allowClear placeholder="请选择产品级别"></v-select>
  31. </a-form-item>
  32. </a-col>
  33. </template>
  34. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  35. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="productLevelList-refresh">查询</a-button>
  36. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="productLevelList-reset">重置</a-button>
  37. <a @click="advanced=!advanced" style="margin-left: 5px">
  38. {{ advanced ? '收起' : '展开' }}
  39. <a-icon :type="advanced ? 'up' : 'down'"/>
  40. </a>
  41. </a-col>
  42. </a-row>
  43. </a-form>
  44. </div>
  45. <!-- 操作按钮 -->
  46. <!-- <div class="table-operator" style="margin-bottom: 10px;">
  47. <a-button id="productLevelList-import" type="primary" @click="handleImport">导入</a-button>
  48. <a-button style="margin-left: 5px" id="productLevelList-export" type="danger" @click="handleExport" :loading="exportLoading">导出</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.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.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_productLevel_edit')"
  73. class="button-info"
  74. @click="handleEdit(record)"
  75. id="productLevelList-edit-btn">编辑</a-button>
  76. <span v-else>--</span>
  77. </template>
  78. </s-table>
  79. <!-- 编辑价格 -->
  80. <product-level-edit-modal
  81. v-drag
  82. :openModal="openModal"
  83. :itemId="itemId"
  84. :nowData="nowData"
  85. @close="closeModal"
  86. @ok="$refs.table.refresh()" />
  87. </a-card>
  88. </template>
  89. <script>
  90. import { commonMixin } from '@/utils/mixin'
  91. import moment from 'moment'
  92. import { STable, VSelect } from '@/components'
  93. import productLevelEditModal from './editModal.vue'
  94. import ProductBrand from '@/views/common/productBrand.js'
  95. import ProductType from '@/views/common/productType.js'
  96. import { productLevelList } from '@/api/product'
  97. export default {
  98. name: 'ProductLevelList',
  99. mixins: [commonMixin],
  100. components: { STable, VSelect, productLevelEditModal, ProductBrand, ProductType },
  101. data () {
  102. return {
  103. advanced: true, // 高级搜索 展开/关闭
  104. tableHeight: 0,
  105. queryParam: { // 查询条件
  106. name: '', // 产品名称
  107. queryWord: '', // 产品编码/原厂编码
  108. productBrandSn: undefined, // 产品品牌
  109. productTypeSn1: '', // 产品一级分类
  110. productTypeSn2: '', // 产品二级分类
  111. productTypeSn3: '', // 产品三级分类
  112. level: undefined
  113. },
  114. productType: [],
  115. disabled: false, // 查询、重置按钮是否可操作
  116. exportLoading: false, // 导出loading
  117. columns: [
  118. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  119. { title: '产品名称', dataIndex: 'name', align: 'center', width: '25%', ellipsis: true, customRender: function (text) { return text || '--' } },
  120. { title: '产品编码', dataIndex: 'code', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  121. { title: '原厂编码', dataIndex: 'origCode', width: '19%', align: 'center', customRender: function (text) { return text || '--' } },
  122. { title: '品牌', dataIndex: 'productBrandName', width: '5%', align: 'center', customRender: function (text) { return text || '--' } },
  123. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: '16%', align: 'center' },
  124. { title: '包装数', dataIndex: 'packQtyV', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  125. { title: '单位', dataIndex: 'unit', width: '5%', align: 'center', customRender: function (text) { return text || '--' } },
  126. { title: '产品级别', dataIndex: 'level', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  127. { title: '操作', scopedSlots: { customRender: 'action' }, width: '6%', align: 'center' }
  128. ],
  129. // 加载数据方法 必须为 Promise 对象
  130. loadData: parameter => {
  131. this.disabled = true
  132. this.spinning = true
  133. return productLevelList(Object.assign(parameter, this.queryParam)).then(res => {
  134. let data
  135. if (res.status == 200) {
  136. data = res.data
  137. const no = (data.pageNo - 1) * data.pageSize
  138. for (var i = 0; i < data.list.length; i++) {
  139. data.list[i].no = no + i + 1
  140. const packQty = (data.list[i].packQty || data.list[i].packQty == 0) ? data.list[i].packQty : '--'
  141. const unit = data.list[i].unit || '--'
  142. const packQtyUnit = data.list[i].packQtyUnit || '--'
  143. data.list[i].packQtyV = packQty + unit + '/' + packQtyUnit
  144. }
  145. this.disabled = false
  146. }
  147. this.spinning = false
  148. return data
  149. })
  150. },
  151. openModal: false, // 编辑 弹框
  152. itemId: '', // 当前产品id
  153. productBrandList: [], // 品牌下拉数据
  154. productTypeList: [], // 分类下拉数据
  155. nowData: null
  156. }
  157. },
  158. methods: {
  159. // 重置
  160. resetSearchForm () {
  161. this.queryParam.name = ''
  162. this.queryParam.queryWord = ''
  163. this.queryParam.productBrandSn = undefined
  164. this.queryParam.productTypeSn1 = ''
  165. this.queryParam.productTypeSn2 = ''
  166. this.queryParam.productTypeSn3 = ''
  167. this.queryParam.level = undefined
  168. this.productType = []
  169. this.$refs.table.refresh(true)
  170. },
  171. // 编辑
  172. handleEdit (row) {
  173. this.nowData = row
  174. this.itemId = row.id
  175. this.openModal = true
  176. },
  177. // 关闭弹框
  178. closeModal () {
  179. this.itemId = ''
  180. this.nowData = null
  181. this.openModal = false
  182. },
  183. // 产品分类 change
  184. changeProductType (val, opt) {
  185. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  186. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  187. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  188. },
  189. // 导入
  190. handleImport () {},
  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 - 195
  221. }
  222. },
  223. watch: {
  224. advanced (newValue, oldValue) {
  225. const _this = this
  226. this.$nextTick(() => { // 页面渲染完成后的回调
  227. _this.setTableH()
  228. })
  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>