chooseProductsModal.vue 11 KB

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