chooseProductsModal.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. bordered>
  71. <!-- 产品分类 -->
  72. <template slot="productType" slot-scope="text, record">
  73. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  74. <span v-else>--</span>
  75. </template>
  76. </s-table>
  77. </div>
  78. </div>
  79. </a-spin>
  80. </a-modal>
  81. </template>
  82. <script>
  83. import { STable } from '@/components'
  84. import tablePagination from '@/views/common/tablePagination.vue'
  85. import ProductBrand from '@/views/common/productBrand.js'
  86. import productTypeAll from '@/views/common/productTypeAll.js'
  87. import { productList } from '@/api/product'
  88. export default {
  89. name: 'ChooseProductsModal',
  90. components: { STable, tablePagination, ProductBrand, productTypeAll },
  91. props: {
  92. openModal: { // 弹框显示状态
  93. type: Boolean,
  94. default: false
  95. },
  96. chooseData: {
  97. type: Array,
  98. default: () => {
  99. return []
  100. }
  101. }
  102. },
  103. data () {
  104. return {
  105. spinning: false,
  106. isShow: this.openModal, // 是否打开弹框
  107. formItemLayout: {
  108. labelCol: { span: 4 },
  109. wrapperCol: { span: 20 }
  110. },
  111. queryParam: { // 查询条件
  112. name: '', // 产品名称
  113. code: '', // 产品编码
  114. productBrandSn: undefined, // 产品品牌
  115. productType: [],
  116. productTypeSn1: '', // 产品一级分类
  117. productTypeSn2: '', // 产品二级分类
  118. productTypeSn3: '' // 产品三级分类
  119. },
  120. chooseDataList: [],
  121. disabled: false, // 查询、重置按钮是否可操作
  122. loading: false, // 表格加载中
  123. columns: [
  124. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  125. { title: '产品编码', dataIndex: 'code', align: 'center' },
  126. { title: '产品名称', dataIndex: 'name', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  127. { title: '原厂编码', dataIndex: 'origCode', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  128. { title: '品牌', dataIndex: 'productBrandName', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  129. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: '10%', align: 'center' },
  130. { title: '包装数', dataIndex: 'packQtyV', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  131. { title: '单位', dataIndex: 'unit', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } }
  132. ],
  133. // 加载数据方法 必须为 Promise 对象
  134. loadData: parameter => {
  135. this.disabled = true
  136. this.spinning = true
  137. const params = Object.assign(parameter, this.queryParam)
  138. return productList(params).then(res => {
  139. let data
  140. if (res.status == 200) {
  141. data = res.data
  142. const no = (data.pageNo - 1) * data.pageSize
  143. for (var i = 0; i < data.list.length; i++) {
  144. data.list[i].no = no + i + 1
  145. }
  146. this.disabled = false
  147. }
  148. this.spinning = false
  149. return data
  150. })
  151. },
  152. rowSelectionInfo: null
  153. }
  154. },
  155. computed: {
  156. selectCount () {
  157. return this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length
  158. }
  159. },
  160. methods: {
  161. // 表格选中项
  162. rowSelectionFun (obj) {
  163. this.rowSelectionInfo = obj || null
  164. },
  165. // 重置数据
  166. resetData () {
  167. this.queryParam.code = ''
  168. this.queryParam.name = ''
  169. this.queryParam.productBrandSn = undefined
  170. this.queryParam.productTypeSn1 = ''
  171. this.queryParam.productTypeSn2 = ''
  172. this.queryParam.productTypeSn3 = ''
  173. this.queryParam.productType = []
  174. },
  175. // 重置
  176. resetSearchForm () {
  177. this.resetData()
  178. this.$refs.table.refresh()
  179. this.$refs.table.clearTable()
  180. },
  181. // 保存
  182. handleSave () {
  183. if (!this.rowSelectionInfo || (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  184. this.$message.warning('请在列表勾选后再进行操作!')
  185. return
  186. }
  187. this.$emit('ok', this.rowSelectionInfo && this.rowSelectionInfo.selectedRows)
  188. this.isShow = false
  189. },
  190. // 产品分类 change
  191. changeProductType (val, opt) {
  192. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  193. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  194. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  195. },
  196. handleDisabled (list) {
  197. this.chooseDataList = list
  198. }
  199. },
  200. watch: {
  201. // 父页面传过来的弹框状态
  202. openModal (newValue, oldValue) {
  203. this.isShow = newValue
  204. },
  205. // 重定义的弹框状态
  206. isShow (newValue, oldValue) {
  207. if (!newValue) {
  208. this.$emit('close')
  209. } else {
  210. const _this = this
  211. _this.resetSearchForm()
  212. const selectedRows = []
  213. const selectedRowKeys = []
  214. selectedRows = this.chooseData
  215. this.chooseData.map(item => {
  216. selectedRowKeys.push(item.goodsSn)
  217. })
  218. this.$nextTick(() => { // 页面渲染完成后的回调
  219. _this.$refs.table.setTableSelected(selectedRowKeys, selectedRows) // 设置表格选中项
  220. })
  221. }
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="less" scoped>
  227. .chooseProducts-modal{
  228. .products-con{
  229. .btn-con{
  230. text-align: center;
  231. margin: 30px 0 20px;
  232. .button-cancel{
  233. font-size: 12px;
  234. }
  235. }
  236. }
  237. }
  238. </style>