chooseProductsModal.vue 9.8 KB

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