chooseProductsModal.vue 10 KB

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