chooseProductsModal.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <a-modal
  3. centered
  4. class="chooseProducts-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="选择产品"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. :width="900">
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <div class="products-con">
  13. <div>
  14. <!-- 搜索条件 -->
  15. <div class="table-page-search-wrapper">
  16. <a-form-model
  17. ref="ruleForm"
  18. class="form-model-con"
  19. layout="inline"
  20. :model="queryParam"
  21. @keyup.enter.native="handleSearch"
  22. :label-col="formItemLayout.labelCol"
  23. :wrapper-col="formItemLayout.wrapperCol">
  24. <a-row :gutter="15">
  25. <a-col :md="6" :sm="24">
  26. <a-form-model-item label="产品编码">
  27. <a-input id="chooseProducts-code" v-model.trim="queryParam.code" allowClear placeholder="请输入产品编码"/>
  28. </a-form-model-item>
  29. </a-col>
  30. <a-col :md="6" :sm="24">
  31. <a-form-model-item label="产品名称">
  32. <a-input id="chooseProducts-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称"/>
  33. </a-form-model-item>
  34. </a-col>
  35. <a-col :md="6" :sm="24">
  36. <a-form-model-item label="产品分类">
  37. <productTypeAll placeholder="请选择产品分类" @change="changeProductType" v-model="queryParam.productType" id="chooseProducts-productType"></productTypeAll>
  38. </a-form-model-item>
  39. </a-col>
  40. <a-col :md="6" :sm="24">
  41. <a-form-model-item label="产品品牌">
  42. <ProductBrand id="chooseProducts-productBrandSn" v-model="queryParam.productBrandSn"></ProductBrand>
  43. </a-form-model-item>
  44. </a-col>
  45. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  46. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="chooseProducts-refresh">查询</a-button>
  47. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="chooseProducts-reset">重置</a-button>
  48. </a-col>
  49. </a-row>
  50. </a-form-model>
  51. </div>
  52. <div style="margin-bottom: 10px">
  53. <a-button type="primary" ghost :loading="loading" @click="handleSave">批量添加</a-button>
  54. <span style="margin-left: 5px">
  55. <template v-if="selectCount"> {{ `已选 ${selectCount} 项` }} </template>
  56. </span>
  57. </div>
  58. <!-- 列表 -->
  59. <s-table
  60. class="sTable"
  61. ref="table"
  62. size="small"
  63. :rowKey="(record) => record.productSn"
  64. rowKeyName="productSn"
  65. :row-selection="{ columnWidth: 40, getCheckboxProps:record =>({props: { disabled: this.chooseDataList && this.chooseDataList.indexOf(record.productSn) > -1 }}) }"
  66. @rowSelection="rowSelectionFun"
  67. :columns="columns"
  68. :data="loadData"
  69. :defaultLoadData="false"
  70. style="max-height:580px;"
  71. :scroll="{ y: 520 }"
  72. bordered>
  73. <!-- 产品分类 -->
  74. <template slot="productType" slot-scope="text, record">
  75. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  76. <span v-else>--</span>
  77. </template>
  78. </s-table>
  79. </div>
  80. </div>
  81. </a-spin>
  82. </a-modal>
  83. </template>
  84. <script>
  85. import { STable } from '@/components'
  86. import tablePagination from '@/views/common/tablePagination.vue'
  87. import ProductBrand from '@/views/common/productBrand.js'
  88. import productTypeAll from '@/views/common/productTypeAll.js'
  89. import { productList } from '@/api/product'
  90. export default {
  91. name: 'ChooseProductsModal',
  92. components: { STable, tablePagination, ProductBrand, productTypeAll },
  93. props: {
  94. openModal: { // 弹框显示状态
  95. type: Boolean,
  96. default: false
  97. },
  98. chooseData: {
  99. type: Array,
  100. default: () => {
  101. return []
  102. }
  103. }
  104. },
  105. data () {
  106. return {
  107. spinning: false,
  108. isShow: this.openModal, // 是否打开弹框
  109. formItemLayout: {
  110. labelCol: { span: 4 },
  111. wrapperCol: { span: 20 }
  112. },
  113. queryParam: { // 查询条件
  114. name: '', // 产品名称
  115. code: '', // 产品编码
  116. productBrandSn: undefined, // 产品品牌
  117. productType: [],
  118. productTypeSn1: '', // 产品一级分类
  119. productTypeSn2: '', // 产品二级分类
  120. productTypeSn3: '' // 产品三级分类
  121. },
  122. chooseDataList: [],
  123. disabled: false, // 查询、重置按钮是否可操作
  124. loading: false, // 表格加载中
  125. columns: [
  126. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  127. { title: '产品编码', dataIndex: 'code', align: 'center' },
  128. { title: '产品名称', dataIndex: 'name', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  129. { title: '原厂编码', dataIndex: 'origCode', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  130. { title: '品牌', dataIndex: 'productBrandName', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  131. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: '10%', align: 'center' },
  132. { title: '包装数', dataIndex: 'packQtyV', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  133. { title: '单位', dataIndex: 'unit', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } }
  134. ],
  135. // 加载数据方法 必须为 Promise 对象
  136. loadData: parameter => {
  137. this.disabled = true
  138. this.spinning = true
  139. const params = Object.assign(parameter, this.queryParam)
  140. return productList(params).then(res => {
  141. let data
  142. if (res.status == 200) {
  143. 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. }
  148. this.disabled = false
  149. }
  150. this.spinning = false
  151. return data
  152. })
  153. },
  154. rowSelectionInfo: null
  155. }
  156. },
  157. computed: {
  158. selectCount () {
  159. return this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length
  160. }
  161. },
  162. methods: {
  163. // 表格选中项
  164. rowSelectionFun (obj) {
  165. this.rowSelectionInfo = obj || null
  166. },
  167. // 重置数据
  168. resetData () {
  169. this.queryParam.code = ''
  170. this.queryParam.name = ''
  171. this.queryParam.productBrandSn = undefined
  172. this.queryParam.productTypeSn1 = ''
  173. this.queryParam.productTypeSn2 = ''
  174. this.queryParam.productTypeSn3 = ''
  175. this.queryParam.productType = []
  176. },
  177. // 重置
  178. resetSearchForm () {
  179. this.resetData()
  180. this.$nextTick(() => {
  181. this.$refs.table.refresh()
  182. this.$refs.table.clearTable()
  183. })
  184. },
  185. // 保存
  186. handleSave () {
  187. if (!this.rowSelectionInfo || (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  188. this.$message.warning('请在列表勾选后再进行操作!')
  189. return
  190. }
  191. this.$emit('ok', this.rowSelectionInfo && this.rowSelectionInfo.selectedRows)
  192. this.isShow = 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. handleDisabled (list) {
  201. this.chooseDataList = list
  202. }
  203. },
  204. watch: {
  205. // 父页面传过来的弹框状态
  206. openModal (newValue, oldValue) {
  207. this.isShow = newValue
  208. },
  209. // 重定义的弹框状态
  210. isShow (newValue, oldValue) {
  211. if (!newValue) {
  212. this.$emit('close')
  213. } else {
  214. const _this = this
  215. _this.resetSearchForm()
  216. let selectedRows = []
  217. const selectedRowKeys = []
  218. selectedRows = _this.chooseData
  219. _this.chooseData.map(item => {
  220. selectedRowKeys.push(item.goodsSn)
  221. })
  222. this.$nextTick(() => { // 页面渲染完成后的回调
  223. _this.$refs.table.setTableSelected(selectedRowKeys, selectedRows) // 设置表格选中项
  224. })
  225. }
  226. }
  227. }
  228. }
  229. </script>
  230. <style lang="less" scoped>
  231. .chooseProducts-modal{
  232. .products-con{
  233. .btn-con{
  234. text-align: center;
  235. margin: 30px 0 20px;
  236. .button-cancel{
  237. font-size: 12px;
  238. }
  239. }
  240. }
  241. }
  242. </style>