list.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <div>
  3. <a-card size="small" :bordered="false" class="associatedProductList-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="associatedProductList-productName" v-model.trim="queryParam.supplierName" 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="associatedProductList-productName" v-model.trim="queryParam.product.name" allowClear placeholder="请输入产品名称"/>
  16. </a-form-item>
  17. </a-col>
  18. <a-col :md="6" :sm="24">
  19. <a-form-item label="产品编码/原厂编码">
  20. <a-input id="associatedProductList-productCode" v-model.trim="queryParam.product.queryWord" allowClear placeholder="请输入产品编码"/>
  21. </a-form-item>
  22. </a-col>
  23. <template v-if="advanced">
  24. <a-col :md="6" :sm="24">
  25. <a-form-item label="产品分类">
  26. <ProductType id="associatedProduct-productType" v-model="productType" @change="changeProductType"></ProductType>
  27. </a-form-item>
  28. </a-col>
  29. <a-col :md="6" :sm="24">
  30. <a-form-item label="品牌">
  31. <ProductBrand id="associatedProduct-productBrandSn" v-model="queryParam.product.productBrandSn"></ProductBrand>
  32. </a-form-item>
  33. </a-col>
  34. </template>
  35. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  36. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="associatedProductList-refresh">查询</a-button>
  37. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="associatedProductList-reset">重置</a-button>
  38. <a @click="advanced=!advanced" style="margin-left: 5px">
  39. {{ advanced ? '收起' : '展开' }}
  40. <a-icon :type="advanced ? 'up' : 'down'"/>
  41. </a>
  42. </a-col>
  43. </a-row>
  44. </a-form>
  45. </div>
  46. </a-card>
  47. <!-- 列表 -->
  48. <a-card size="small" :bordered="false">
  49. <a-spin :spinning="spinning" tip="Loading...">
  50. <s-table
  51. class="sTable fixPagination"
  52. ref="table"
  53. :style="{ height: tableHeight+84.5+'px' }"
  54. size="small"
  55. :rowKey="(record) => record.id"
  56. :columns="columns"
  57. :data="loadData"
  58. :scroll="{ y: tableHeight }"
  59. :defaultLoadData="false"
  60. bordered>
  61. <!-- 产品分类 -->
  62. <template slot="productType" slot-scope="text, record">
  63. <span v-if="record.product&&(record.product.productTypeName2 || record.product.productTypeName3)">{{ record.product.productTypeName2 }} {{ record.product.productTypeName3 ? '>' : '' }} {{ record.product.productTypeName3 }}</span>
  64. <span v-else>--</span>
  65. </template>
  66. </s-table>
  67. </a-spin>
  68. </a-card>
  69. </div>
  70. </template>
  71. <script>
  72. import { commonMixin } from '@/utils/mixin'
  73. import { STable, VSelect } from '@/components'
  74. import ProductType from '@/views/common/productType.js'
  75. import ProductBrand from '@/views/common/productBrand.js'
  76. import { supplierProductList } from '@/api/supplier'
  77. export default {
  78. name: 'AssociatedProductDetailsList',
  79. mixins: [commonMixin],
  80. components: { STable, VSelect, ProductBrand, ProductType },
  81. data () {
  82. return {
  83. spinning: false,
  84. advanced: true, // 高级搜索 展开/关闭
  85. tableHeight: 0,
  86. queryParam: { // 查询条件
  87. supplierName: '',
  88. product: {
  89. name: '', // 产品名称
  90. queryWord: '', // 产品编码/原厂编码
  91. productBrandSn: undefined, // 产品品牌
  92. productTypeSn1: '', // 产品一级分类
  93. productTypeSn2: '', // 产品二级分类
  94. productTypeSn3: '' // 产品三级分类
  95. }
  96. },
  97. disabled: false, // 查询、重置按钮是否可操作
  98. productType: [],
  99. // 加载数据方法 必须为 Promise 对象
  100. loadData: parameter => {
  101. this.disabled = true
  102. this.spinning = true
  103. return supplierProductList(Object.assign(parameter, this.queryParam)).then(res => {
  104. let data
  105. if (res.status == 200) {
  106. data = res.data
  107. const no = (data.pageNo - 1) * data.pageSize
  108. for (var i = 0; i < data.list.length; i++) {
  109. data.list[i].no = no + i + 1
  110. }
  111. this.disabled = false
  112. }
  113. this.spinning = false
  114. return data
  115. })
  116. }
  117. }
  118. },
  119. computed: {
  120. columns () {
  121. const _this = this
  122. const arr = [
  123. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  124. { title: '供应商名称', dataIndex: 'supplierName', width: '20%', align: 'center', customRender: function (text) { return text || '--' } },
  125. { title: '品牌', dataIndex: 'product.productBrandName', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  126. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: '18%', align: 'center' },
  127. { title: '产品名称', dataIndex: 'product.name', width: '20%', align: 'center', customRender: function (text) { return text || '--' } },
  128. { title: '产品编码', dataIndex: 'product.code', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  129. { title: '成本价', dataIndex: 'cost', width: '6%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  130. { title: '原厂编码', dataIndex: 'product.origCode', width: '8%', align: 'center', customRender: function (text) { return text || '--' } }
  131. ]
  132. return arr
  133. }
  134. },
  135. methods: {
  136. // 重置
  137. resetSearchForm () {
  138. this.queryParam.supplierName = ''
  139. this.queryParam.product.name = ''
  140. this.queryParam.product.queryWord = ''
  141. this.queryParam.product.productBrandSn = undefined
  142. this.queryParam.product.productTypeSn1 = ''
  143. this.queryParam.product.productTypeSn2 = ''
  144. this.queryParam.product.productTypeSn3 = ''
  145. this.productType = []
  146. this.$refs.table.refresh(true)
  147. },
  148. // 产品分类 change
  149. changeProductType (val, opt) {
  150. this.queryParam.product.productTypeSn1 = val[0] ? val[0] : ''
  151. this.queryParam.product.productTypeSn2 = val[1] ? val[1] : ''
  152. this.queryParam.product.productTypeSn3 = val[2] ? val[2] : ''
  153. },
  154. pageInit () {
  155. const _this = this
  156. this.$nextTick(() => { // 页面渲染完成后的回调
  157. _this.setTableH()
  158. })
  159. },
  160. setTableH () {
  161. const tableSearchH = this.$refs.tableSearch.offsetHeight
  162. this.tableHeight = window.innerHeight - tableSearchH - 215
  163. }
  164. },
  165. watch: {
  166. advanced (newValue, oldValue) {
  167. const _this = this
  168. this.$nextTick(() => { // 页面渲染完成后的回调
  169. _this.setTableH()
  170. })
  171. },
  172. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  173. this.setTableH()
  174. }
  175. },
  176. mounted () {
  177. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  178. this.pageInit()
  179. this.resetSearchForm()
  180. }
  181. },
  182. activated () {
  183. // 如果是新页签打开,则重置当前页面
  184. if (this.$store.state.app.isNewTab) {
  185. this.pageInit()
  186. this.resetSearchForm()
  187. }
  188. // 仅刷新列表,不重置页面
  189. if (this.$store.state.app.updateList) {
  190. this.pageInit()
  191. this.$refs.table.refresh()
  192. }
  193. },
  194. beforeRouteEnter (to, from, next) {
  195. next(vm => {})
  196. }
  197. }
  198. </script>