list.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <div>
  3. <a-card size="small" :bordered="false" class="productInfoList-wrap searchBoxNormal">
  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-item label="产品编码">
  10. <a-input id="productInfoList-code" v-model.trim="queryParam.code" allowClear placeholder="请输入产品编码"/>
  11. </a-form-item>
  12. </a-col>
  13. <a-col :md="6" :sm="24">
  14. <a-form-item label="产品名称">
  15. <a-input id="productInfoList-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称"/>
  16. </a-form-item>
  17. </a-col>
  18. <a-col :md="6" :sm="24">
  19. <a-form-model-item :label="($route.params.onlineFalg=='1'?'上':'下')+'线时间'">
  20. <rangeDate ref="rangeDate" :value="time" @change="dateChange" />
  21. </a-form-model-item>
  22. </a-col>
  23. <template v-if="advanced">
  24. <a-col :md="6" :sm="24">
  25. <a-form-item label="产品品牌">
  26. <ProductBrand id="productInfoList-productBrandSn" v-model="queryParam.productBrandSn"></ProductBrand>
  27. </a-form-item>
  28. </a-col>
  29. <a-col :md="6" :sm="24">
  30. <a-form-item label="产品分类">
  31. <productTypeAll placeholder="请选择产品分类" @change="changeProductType" v-model="productType" id="productInfoList-productType"></productTypeAll>
  32. </a-form-item>
  33. </a-col>
  34. <a-col :md="6" :sm="24">
  35. <a-form-item label="原厂编码">
  36. <a-input id="productInfoList-origCode" v-model.trim="queryParam.origCode" allowClear placeholder="请输入原厂编码"/>
  37. </a-form-item>
  38. </a-col>
  39. </template>
  40. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  41. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="productInfoList-refresh">查询</a-button>
  42. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="productInfoList-reset">重置</a-button>
  43. <a @click="advanced=!advanced" style="margin-left: 5px">
  44. {{ advanced ? '收起' : '展开' }}
  45. <a-icon :type="advanced ? 'up' : 'down'"/>
  46. </a>
  47. </a-col>
  48. </a-row>
  49. </a-form>
  50. </div>
  51. </a-card>
  52. <!-- 列表 -->
  53. <a-card size="small" :bordered="false">
  54. <a-spin :spinning="spinning" tip="Loading...">
  55. <s-table
  56. class="sTable fixPagination"
  57. ref="table"
  58. :style="{ height: tableHeight+70+'px' }"
  59. size="small"
  60. :rowKey="(record) => record.id"
  61. :columns="columns"
  62. :data="loadData"
  63. :defaultLoadData="false"
  64. :scroll="{ y: tableHeight }"
  65. bordered>
  66. <!-- 上/下线时间 表头 -->
  67. <template slot="auditTimeTit">
  68. {{ $route.params.onlineFalg=='1'?'上':'下' }}线时间
  69. </template>
  70. <!-- 产品分类 -->
  71. <template slot="productType" slot-scope="text, record">
  72. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  73. <span v-else>--</span>
  74. </template>
  75. <!-- 操作 -->
  76. <template slot="action" slot-scope="text, record">
  77. <a-button
  78. size="small"
  79. type="link"
  80. class="button-success"
  81. @click="handleDetail(record)"
  82. id="productInfoList-detail-btn">详情</a-button>
  83. </template>
  84. </s-table>
  85. </a-spin>
  86. </a-card>
  87. </div>
  88. </template>
  89. <script>
  90. import { commonMixin } from '@/utils/mixin'
  91. import { queryNewProductPage, queryOnlinePageList } from '@/api/product'
  92. import { STable, VSelect } from '@/components'
  93. import ProductBrand from '@/views/common/productBrand.js'
  94. import productTypeAll from '@/views/common/productTypeAll.js'
  95. import rangeDate from '@/views/common/rangeDate.vue'
  96. import moment from 'moment'
  97. import getDate from '@/libs/getDate.js'
  98. export default {
  99. name: 'NewProductList',
  100. mixins: [commonMixin],
  101. components: { STable, VSelect, rangeDate, ProductBrand, productTypeAll },
  102. data () {
  103. return {
  104. spinning: false,
  105. advanced: true, // 高级搜索 展开/关闭
  106. tableHeight: 0,
  107. productType: [],
  108. queryParam: { // 查询条件
  109. beginDate: '',
  110. endDate: '',
  111. code: '', // 产品编码
  112. name: '', // 产品名称
  113. origCode: '', // 原厂编码
  114. sysFlag: '0',
  115. productBrandSn: undefined, // 产品品牌
  116. productTypeSn1: '', // 产品一级分类
  117. productTypeSn2: '', // 产品二级分类
  118. productTypeSn3: '', // 产品三级分类
  119. enabledFlag: undefined // 状态
  120. },
  121. disabled: false, // 查询、重置按钮是否可操作
  122. exportLoading: false, // 导出loading
  123. time: [
  124. moment(getDate.getCurrMonthDays().starttime, 'YYYY-MM-DD'),
  125. moment(getDate.getCurrMonthDays().endtime, 'YYYY-MM-DD')
  126. ],
  127. columns: [
  128. { title: '序号', dataIndex: 'no', width: 50, align: 'center' },
  129. { slots: { title: 'auditTimeTit' }, dataIndex: 'auditTime', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
  130. { title: '产品品牌', dataIndex: 'productBrandName', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  131. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: 350, align: 'left' },
  132. { title: '产品名称', dataIndex: 'name', align: 'left', ellipsis: true, customRender: function (text) { return text || '--' } },
  133. { title: '产品编码', dataIndex: 'code', width: 180, align: 'left', customRender: function (text) { return text || '--' } },
  134. { title: '单位', dataIndex: 'unit', width: 60, align: 'center', customRender: function (text) { return text || '--' } },
  135. { title: '原厂编码', dataIndex: 'origCode', width: 140, align: 'left', 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. const ajaxName = this.$route.params.type == 'onlineInfo' ? queryOnlinePageList : queryNewProductPage
  143. if (this.$route.params.type == 'onlineInfo') {
  144. if (this.queryParam.beginDate || this.queryParam.endDate) {
  145. this.queryParam.onlineFalg = 1
  146. this.queryParam.newProductDateScope = 9999
  147. } else {
  148. this.queryParam.onlineFalg = undefined
  149. this.queryParam.newProductDateScope = undefined
  150. }
  151. } else {
  152. this.queryParam.onlineFalg = this.$route.params.onlineFalg
  153. }
  154. return ajaxName(Object.assign(parameter, this.queryParam)).then(res => {
  155. let data
  156. if (res.status == 200) {
  157. data = res.data
  158. const no = (data.pageNo - 1) * data.pageSize
  159. for (var i = 0; i < data.list.length; i++) {
  160. data.list[i].no = no + i + 1
  161. }
  162. this.disabled = false
  163. }
  164. this.spinning = false
  165. return data
  166. })
  167. },
  168. openModal: false, // 查看详情 弹框
  169. itemId: '' // 当前产品productSn
  170. }
  171. },
  172. methods: {
  173. // 创建时间 change
  174. dateChange (date) {
  175. this.queryParam.beginDate = date[0] || ''
  176. this.queryParam.endDate = date[1] || ''
  177. },
  178. // 重置
  179. resetSearchForm () {
  180. this.$refs.rangeDate.resetDate()
  181. this.queryParam.code = ''
  182. this.queryParam.name = ''
  183. this.queryParam.origCode = ''
  184. this.queryParam.productBrandSn = undefined
  185. this.queryParam.productTypeSn1 = ''
  186. this.queryParam.productTypeSn2 = ''
  187. this.queryParam.productTypeSn3 = ''
  188. this.queryParam.enabledFlag = undefined
  189. this.productType = []
  190. if (this.$route.params.type == 'onlineInfo') {
  191. this.$refs.rangeDate.resetDate(this.time)
  192. this.queryParam.beginDate = getDate.getCurrMonthDays().starttime
  193. this.queryParam.endDate = getDate.getCurrMonthDays().endtime
  194. } else {
  195. this.queryParam.beginDate = ''
  196. this.queryParam.endDate = ''
  197. this.time = []
  198. this.$refs.rangeDate.resetDate([])
  199. }
  200. this.$refs.table.refresh(true)
  201. },
  202. // 详情
  203. handleDetail (row) {
  204. this.itemId = row.productSn
  205. this.$router.push({ name: 'viewProduct', params: { sn: row.productSn } })
  206. },
  207. // 产品分类 change
  208. changeProductType (val, opt) {
  209. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  210. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  211. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  212. },
  213. pageInit () {
  214. const _this = this
  215. this.$nextTick(() => { // 页面渲染完成后的回调
  216. _this.setTableH()
  217. })
  218. },
  219. setTableH () {
  220. const tableSearchH = this.$refs.tableSearch.offsetHeight
  221. this.tableHeight = window.innerHeight - tableSearchH - 200
  222. }
  223. },
  224. watch: {
  225. advanced (newValue, oldValue) {
  226. const _this = this
  227. this.$nextTick(() => { // 页面渲染完成后的回调
  228. _this.setTableH()
  229. })
  230. },
  231. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  232. this.setTableH()
  233. }
  234. },
  235. mounted () {
  236. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  237. this.pageInit()
  238. this.resetSearchForm()
  239. }
  240. },
  241. activated () {
  242. // 如果是新页签打开,则重置当前页面
  243. if (this.$store.state.app.isNewTab) {
  244. this.pageInit()
  245. this.resetSearchForm()
  246. }
  247. // 仅刷新列表,不重置页面
  248. if (this.$store.state.app.updateList) {
  249. this.pageInit()
  250. this.$refs.table.refresh()
  251. }
  252. },
  253. beforeRouteEnter (to, from, next) {
  254. next(vm => {})
  255. }
  256. }
  257. </script>