list.vue 11 KB

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