list.vue 11 KB

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