list.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <a-card size="small" :bordered="false" class="productInfoList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div ref="tableSearch" class="table-page-search-wrapper">
  6. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  7. <a-row :gutter="15">
  8. <a-col :md="6" :sm="24">
  9. <a-form-model-item label="上线日期" prop="time">
  10. <rangeDate ref="rangeDate" v-model.trim="time" @change="dateChange" />
  11. </a-form-model-item>
  12. </a-col>
  13. <a-col :md="6" :sm="24">
  14. <a-form-item label="产品品牌">
  15. <a-select
  16. placeholder="请选择产品品牌"
  17. id="productInfoList-productBrandSn"
  18. allowClear
  19. v-model="queryParam.productBrandSn"
  20. :showSearch="true"
  21. option-filter-prop="children"
  22. :filter-option="filterOption">
  23. <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn">{{ item.brandName }}</a-select-option>
  24. </a-select>
  25. </a-form-item>
  26. </a-col>
  27. <a-col :md="6" :sm="24">
  28. <a-form-item label="产品分类">
  29. <a-cascader
  30. @change="changeProductType"
  31. change-on-select
  32. v-model="productType"
  33. expand-trigger="hover"
  34. :options="productTypeList"
  35. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  36. id="productInfoList-productType"
  37. placeholder="请选择产品分类"
  38. allowClear />
  39. </a-form-item>
  40. </a-col>
  41. <a-col :md="6" :sm="24">
  42. <a-form-item label="产品名称">
  43. <a-input id="productInfoList-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称"/>
  44. </a-form-item>
  45. </a-col>
  46. <template v-if="advanced">
  47. <a-col :md="6" :sm="24">
  48. <a-form-item label="产品编码">
  49. <a-input id="productInfoList-code" v-model.trim="queryParam.code" allowClear placeholder="请输入产品编码"/>
  50. </a-form-item>
  51. </a-col>
  52. <a-col :md="6" :sm="24">
  53. <a-form-item label="原厂编码">
  54. <a-input id="productInfoList-origCode" v-model.trim="queryParam.origCode" allowClear placeholder="请输入原厂编码"/>
  55. </a-form-item>
  56. </a-col>
  57. </template>
  58. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  59. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="productInfoList-refresh">查询</a-button>
  60. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="productInfoList-reset">重置</a-button>
  61. <a-button
  62. style="margin: 0 0 18px 8px"
  63. type="danger"
  64. @click="handleExport"
  65. :disabled="disabled"
  66. :loading="exportLoading"
  67. id="newProduct-export">导出</a-button>
  68. <a @click="advanced=!advanced" style="margin-left: 5px">
  69. {{ advanced ? '收起' : '展开' }}
  70. <a-icon :type="advanced ? 'up' : 'down'"/>
  71. </a>
  72. </a-col>
  73. </a-row>
  74. </a-form>
  75. </div>
  76. <!-- 列表 -->
  77. <s-table
  78. class="sTable fixPagination"
  79. ref="table"
  80. :style="{ height: tableHeight+84.5+'px' }"
  81. size="small"
  82. :rowKey="(record) => record.id"
  83. :columns="columns"
  84. :data="loadData"
  85. :scroll="{ x: 1300, y: tableHeight }"
  86. bordered>
  87. <!-- 产品分类 -->
  88. <template slot="productType" slot-scope="text, record">
  89. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  90. <span v-else>--</span>
  91. </template>
  92. <!-- 操作 -->
  93. <template slot="action" slot-scope="text, record">
  94. <a-button
  95. size="small"
  96. type="link"
  97. class="button-success"
  98. @click="handleDetail(record)"
  99. id="productInfoList-detail-btn">详情</a-button>
  100. </template>
  101. </s-table>
  102. </a-spin>
  103. </a-card>
  104. </template>
  105. <script>
  106. import moment from 'moment'
  107. import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
  108. import { dealerProductTypeList } from '@/api/dealerProductType'
  109. // import { dealerProductList, dealerProductExport } from '@/api/dealerProduct'
  110. import { queryNewProductPage } from '@/api/product'
  111. import { STable, VSelect } from '@/components'
  112. import rangeDate from '@/views/common/rangeDate.vue'
  113. export default {
  114. components: { STable, VSelect, rangeDate },
  115. data () {
  116. return {
  117. spinning: false,
  118. advanced: true, // 高级搜索 展开/关闭
  119. tableHeight: 0,
  120. productType: [],
  121. time: [],
  122. queryParam: { // 查询条件
  123. beginDate: '',
  124. endDate: '',
  125. code: '', // 产品编码
  126. name: '', // 产品名称
  127. origCode: '', // 原厂编码
  128. sysFlag: '0',
  129. productBrandSn: undefined, // 产品品牌
  130. productTypeSn1: '', // 产品一级分类
  131. productTypeSn2: '', // 产品二级分类
  132. productTypeSn3: '', // 产品三级分类
  133. enabledFlag: undefined // 状态
  134. },
  135. disabled: false, // 查询、重置按钮是否可操作
  136. exportLoading: false, // 导出loading
  137. columns: [
  138. { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
  139. { title: '上线日期', dataIndex: 'createDate', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
  140. { title: '产品品牌', dataIndex: 'productBrandName', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  141. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: 200, align: 'center' },
  142. { title: '产品名称', dataIndex: 'name', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  143. { title: '产品编码', dataIndex: 'code', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  144. { title: '单位', dataIndex: 'unit', width: 80, align: 'center', customRender: function (text) { return text || '--' } },
  145. { title: '原厂编码', dataIndex: 'origCode', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  146. { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center', fixed: 'right' }
  147. ],
  148. // 加载数据方法 必须为 Promise 对象
  149. loadData: parameter => {
  150. this.disabled = true
  151. this.spinning = true
  152. return queryNewProductPage(Object.assign(parameter, this.queryParam)).then(res => {
  153. const data = res.data
  154. const no = (data.pageNo - 1) * data.pageSize
  155. for (var i = 0; i < data.list.length; i++) {
  156. data.list[i].no = no + i + 1
  157. const productTypeName1 = data.list[i].productTypeName1 ? data.list[i].productTypeName1 : ''
  158. const productTypeName2 = data.list[i].productTypeName2 ? ' > ' + data.list[i].productTypeName2 : ''
  159. const productTypeName3 = data.list[i].productTypeName3 ? ' > ' + data.list[i].productTypeName3 : ''
  160. data.list[i].productTypeName = productTypeName1 + productTypeName2 + productTypeName3
  161. }
  162. this.disabled = false
  163. this.spinning = false
  164. return data
  165. })
  166. },
  167. openModal: false, // 查看客户详情 弹框
  168. itemId: '', // 当前产品productSn
  169. productBrandList: [], // 品牌下拉数据
  170. productTypeList: [] // 分类下拉数据
  171. }
  172. },
  173. methods: {
  174. // 创建时间 change
  175. dateChange (date) {
  176. this.queryParam.time = date
  177. this.queryParam.beginDate = date[0] || ''
  178. this.queryParam.endDate = date[1] || ''
  179. },
  180. // 重置
  181. resetSearchForm () {
  182. this.queryParam.code = ''
  183. this.queryParam.name = ''
  184. this.queryParam.origCode = ''
  185. this.queryParam.productBrandSn = undefined
  186. this.queryParam.productTypeSn1 = ''
  187. this.queryParam.productTypeSn2 = ''
  188. this.queryParam.productTypeSn3 = ''
  189. this.queryParam.enabledFlag = undefined
  190. this.productType = []
  191. this.$refs.table.refresh(true)
  192. },
  193. filterOption (input, option) {
  194. return (
  195. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  196. )
  197. },
  198. // 详情
  199. handleDetail (row) {
  200. this.itemId = row.productSn
  201. this.$router.push({ name: 'viewProduct', params: { sn: row.productSn } })
  202. },
  203. // 产品分类 change
  204. changeProductType (val, opt) {
  205. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  206. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  207. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  208. },
  209. // 导出
  210. handleExport () {
  211. this.exportLoading = true
  212. this.spinning = true
  213. dealerProductExport(this.queryParam).then(res => {
  214. this.exportLoading = false
  215. this.download(res)
  216. this.spinning = false
  217. })
  218. },
  219. download (data) {
  220. if (!data) { return }
  221. const url = window.URL.createObjectURL(new Blob([data]))
  222. const link = document.createElement('a')
  223. link.style.display = 'none'
  224. link.href = url
  225. const a = moment().format('YYYYMMDDHHmmss')
  226. const fname = '自建产品列表' + a
  227. link.setAttribute('download', fname + '.xlsx')
  228. document.body.appendChild(link)
  229. link.click()
  230. },
  231. // 产品品牌 列表
  232. getProductBrand () {
  233. dealerProductBrandQuery({}).then(res => {
  234. if (res.status == 200) {
  235. this.productBrandList = res.data
  236. } else {
  237. this.productBrandList = []
  238. }
  239. })
  240. },
  241. // 产品分类 列表
  242. getProductType () {
  243. dealerProductTypeList({}).then(res => {
  244. if (res.status == 200) {
  245. this.productTypeList = res.data
  246. } else {
  247. this.productTypeList = []
  248. }
  249. })
  250. },
  251. setTableH () {
  252. const tableSearchH = this.$refs.tableSearch.offsetHeight
  253. this.tableHeight = window.innerHeight - tableSearchH - 235
  254. }
  255. },
  256. mounted () {
  257. const _this = this
  258. this.$nextTick(() => { // 页面渲染完成后的回调
  259. _this.setTableH()
  260. })
  261. },
  262. watch: {
  263. advanced (newValue, oldValue) {
  264. const _this = this
  265. setTimeout(() => {
  266. _this.setTableH()
  267. }, 400)
  268. }
  269. },
  270. beforeRouteEnter (to, from, next) {
  271. next(vm => {
  272. vm.getProductBrand()
  273. vm.getProductType()
  274. })
  275. }
  276. }
  277. </script>