list.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <a-card size="small" :bordered="false" class="productLevelList-wrap">
  3. <!-- 搜索条件 -->
  4. <div 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: 'id', 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">
  53. <a-button style="margin-bottom: 18px;" type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="productLevelList-refresh">查询</a-button>
  54. <a-button style="margin: 0 0 18px 8px" @click="resetSearchForm" :disabled="disabled" id="productLevelList-reset">重置</a-button>
  55. <a @click="advanced=!advanced" style="margin-left: 8px">
  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">
  65. <a-button style="margin: 0 0 18px 0" id="productLevelList-import" type="primary" @click="handleImport">导入</a-button>
  66. <a-button style="margin: 0 0 18px 8px" id="productLevelList-export" type="danger" @click="handleExport" :loading="exportLoading">导出</a-button>
  67. </div>
  68. <!-- 列表 -->
  69. <s-table
  70. class="sTable"
  71. ref="table"
  72. size="default"
  73. :rowKey="(record) => record.id"
  74. :columns="columns"
  75. :data="loadData"
  76. :scroll="{ x: 1590 }"
  77. bordered>
  78. <!-- 产品分类 -->
  79. <template slot="productType" slot-scope="text, record">
  80. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  81. <span v-else>--</span>
  82. </template>
  83. <!-- 操作 -->
  84. <template slot="action" slot-scope="text, record">
  85. <a-button size="small" type="link" @click="handleEdit(record)" id="productLevelList-edit-btn">编辑</a-button>
  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 { productLevelList } from '@/api/product'
  99. export default {
  100. components: { STable, VSelect, productLevelEditModal },
  101. data () {
  102. return {
  103. advanced: false, // 高级搜索 展开/关闭
  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: 80, align: 'center' },
  119. { title: '产品名称', dataIndex: 'name', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  120. { title: '产品编码', dataIndex: 'code', width: 220, align: 'center' },
  121. { title: '原厂编码', dataIndex: 'origCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  122. { title: '品牌', dataIndex: 'productBrandName', width: 200, align: 'center', customRender: function (text) { return text || '--' } },
  123. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: 200, align: 'center' },
  124. { title: '包装数', dataIndex: 'packQtyV', width: 150, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  125. { title: '单位', dataIndex: 'unit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  126. { title: '产品级别', dataIndex: 'level', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  127. { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center', fixed: 'right' }
  128. ],
  129. // 加载数据方法 必须为 Promise 对象
  130. loadData: parameter => {
  131. this.disabled = true
  132. if (this.tableHeight == 0) {
  133. this.tableHeight = window.innerHeight - 380
  134. }
  135. return productLevelList(Object.assign(parameter, this.queryParam)).then(res => {
  136. const 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. 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. filterOption (input, option) {
  170. return (
  171. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  172. )
  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. handleImport () {},
  194. // 导出
  195. handleExport () {
  196. const params = this.queryParam
  197. this.exportLoading = true
  198. // customerBundleExportDelay(params).then(res => {
  199. // this.exportLoading = false
  200. // this.download(res)
  201. // })
  202. },
  203. download (data) {
  204. if (!data) { return }
  205. const url = window.URL.createObjectURL(new Blob([data]))
  206. const link = document.createElement('a')
  207. link.style.display = 'none'
  208. link.href = url
  209. const a = moment().format('YYYYMMDDHHmmss')
  210. const fname = '产品级别' + a
  211. link.setAttribute('download', fname + '.xlsx')
  212. document.body.appendChild(link)
  213. link.click()
  214. },
  215. // 产品品牌 列表
  216. getProductBrand () {
  217. productBrandQuery({}).then(res => {
  218. if (res.status == 200) {
  219. this.productBrandList = res.data
  220. } else {
  221. this.productBrandList = []
  222. }
  223. })
  224. },
  225. // 产品分类 列表
  226. getProductType () {
  227. productTypeQuery({}).then(res => {
  228. if (res.status == 200) {
  229. this.productTypeList = res.data
  230. } else {
  231. this.productTypeList = []
  232. }
  233. })
  234. }
  235. },
  236. beforeRouteEnter (to, from, next) {
  237. next(vm => {
  238. vm.getProductBrand()
  239. vm.getProductType()
  240. })
  241. }
  242. }
  243. </script>