chooseProductsModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. :rules="rules"
  22. @keyup.enter.native="handleSearch"
  23. :label-col="formItemLayout.labelCol"
  24. :wrapper-col="formItemLayout.wrapperCol">
  25. <a-row :gutter="15">
  26. <a-col :md="6" :sm="24">
  27. <a-form-model-item label="产品编码" prop="code">
  28. <a-input id="chooseProducts-code" v-model.trim="queryParam.code" allowClear placeholder="请输入产品编码"/>
  29. </a-form-model-item>
  30. </a-col>
  31. <a-col :md="6" :sm="24">
  32. <a-form-item label="产品品牌" :prop="type=='dealership'?'productBrandSn':''">
  33. <ProductBrand id="chooseProducts-productBrandSn" v-model="queryParam.productBrandSn"></ProductBrand>
  34. </a-form-item>
  35. </a-col>
  36. <a-col :md="6" :sm="24">
  37. <a-form-item label="产品分类" :prop="type=='dealership'?'productType':''">
  38. <productTypeAll :isAll="type!='default'" placeholder="请选择产品分类" @change="changeProductType" v-model="queryParam.productType" id="chooseProducts-productType"></productTypeAll>
  39. </a-form-item>
  40. </a-col>
  41. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  42. <a-button type="primary" @click="handleSearch" :disabled="disabled" id="chooseProducts-refresh">查询</a-button>
  43. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="chooseProducts-reset">重置</a-button>
  44. </a-col>
  45. </a-row>
  46. </a-form-model>
  47. </div>
  48. <p style="font-weight: bold;">当前已选:{{ rowSelectionInfo&&rowSelectionInfo.selectedRowKeys.length }}个</p>
  49. <!-- 列表 -->
  50. <s-table
  51. class="sTable"
  52. ref="table"
  53. size="small"
  54. :rowKey="(record) => record.productSn"
  55. rowKeyName="productSn"
  56. :row-selection="{ columnWidth: 40, getCheckboxProps:record =>({props: { disabled: (this.type == 'supplier') && (this.chooseData && this.chooseData.indexOf(record.productSn) > -1) }}) }"
  57. @rowSelection="rowSelectionFun"
  58. :columns="columns"
  59. :data="loadData"
  60. :defaultLoadData="false"
  61. bordered>
  62. </s-table>
  63. </div>
  64. <!-- 按钮 -->
  65. <div class="btn-con">
  66. <a-button
  67. type="primary"
  68. id="chooseProducts-save"
  69. size="large"
  70. class="button-primary"
  71. @click="handleSave"
  72. style="padding: 0 60px;">保存</a-button>
  73. <a-button
  74. id="chooseProducts-cancel"
  75. size="large"
  76. class="button-cancel"
  77. @click="isShow=false"
  78. style="padding: 0 60px;margin-left: 15px;">取消</a-button>
  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 { dealerScopeValidProduct } from '@/api/dealerScope'
  90. import { productPricedList, productPricingList } from '@/api/product'
  91. export default {
  92. name: 'ChooseProductsModal',
  93. components: { STable, tablePagination, ProductBrand, productTypeAll },
  94. props: {
  95. openModal: { // 弹框显示状态
  96. type: Boolean,
  97. default: false
  98. },
  99. chooseData: {
  100. type: Array,
  101. default: () => {
  102. return []
  103. }
  104. },
  105. type: { // 类型,经销权设置dealership, 供应商添加产品supplier
  106. type: String,
  107. default: 'default'
  108. },
  109. dealerSn: {
  110. type: String || Number,
  111. default: ''
  112. }
  113. },
  114. data () {
  115. return {
  116. spinning: false,
  117. isShow: this.openModal, // 是否打开弹框
  118. formItemLayout: {
  119. labelCol: { span: 4 },
  120. wrapperCol: { span: 20 }
  121. },
  122. queryParam: { // 查询条件
  123. code: '', // 产品编码
  124. productBrandSn: undefined, // 产品品牌
  125. productType: [],
  126. productTypeSn1: '', // 产品一级分类
  127. productTypeSn2: '', // 产品二级分类
  128. productTypeSn3: '' // 产品三级分类
  129. },
  130. rules: {
  131. productBrandSn: [ { required: true, message: '请选择产品品牌', trigger: 'change' } ],
  132. productType: [ { required: true, message: '请选择产品分类', trigger: 'change' } ]
  133. },
  134. disabled: false, // 查询、重置按钮是否可操作
  135. loading: false, // 表格加载中
  136. columns: [
  137. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  138. { title: '产品编码', dataIndex: 'code', align: 'center' },
  139. { title: '产品名称', dataIndex: 'name', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } }
  140. ],
  141. // 加载数据方法 必须为 Promise 对象
  142. loadData: parameter => {
  143. this.disabled = true
  144. this.spinning = true
  145. let url = productPricedList // 获取定过价的产品
  146. if (this.type == 'supplier') { // 供应商增加产品
  147. url = productPricingList // 获取定价产品
  148. }
  149. const params = Object.assign(parameter, this.queryParam)
  150. if (this.type != 'supplier' && this.type != 'dealership') { // 促销
  151. params.onlineFalg = 1
  152. }
  153. return url(params).then(res => {
  154. let data
  155. if (res.status == 200) {
  156. data = res.data
  157. const no = (data.pageNo - 1) * data.pageSize
  158. for (var i = 0; i < data.list.length; i++) {
  159. data.list[i].no = no + i + 1
  160. }
  161. this.disabled = false
  162. }
  163. this.spinning = false
  164. return data
  165. })
  166. },
  167. rowSelectionInfo: null
  168. }
  169. },
  170. methods: {
  171. // 表格选中项
  172. rowSelectionFun (obj) {
  173. this.rowSelectionInfo = obj || null
  174. },
  175. // 查询
  176. handleSearch () {
  177. const _this = this
  178. _this.$refs.ruleForm.validate(valid => {
  179. if (valid) {
  180. if (_this.type == 'dealership') { // 设置经销权时选择产品
  181. // 校验产品是否被包含在品牌分类中
  182. const params = []
  183. if (_this.queryParam.productBrandSn) {
  184. params.push({
  185. dealerSn: _this.dealerSn,
  186. goodsType: 'BRAND',
  187. goodsSn: _this.queryParam.productBrandSn
  188. })
  189. }
  190. if (_this.queryParam.productTypeSn1) {
  191. params.push({
  192. dealerSn: _this.dealerSn,
  193. goodsType: 'CATEGORY',
  194. goodsSn: _this.queryParam.productTypeSn1
  195. })
  196. }
  197. if (_this.queryParam.productTypeSn2) {
  198. params.push({
  199. dealerSn: _this.dealerSn,
  200. goodsType: 'CATEGORY',
  201. goodsSn: _this.queryParam.productTypeSn2
  202. })
  203. }
  204. if (_this.queryParam.productTypeSn3) {
  205. params.push({
  206. dealerSn: _this.dealerSn,
  207. goodsType: 'CATEGORY',
  208. goodsSn: _this.queryParam.productTypeSn3
  209. })
  210. }
  211. dealerScopeValidProduct(params).then(res => {
  212. if (res.status == 200) {
  213. _this.$refs.table.refresh(true)
  214. }
  215. })
  216. } else {
  217. _this.$refs.table.refresh(true)
  218. }
  219. } else {
  220. return false
  221. }
  222. })
  223. },
  224. // 重置数据
  225. resetData () {
  226. this.queryParam.code = ''
  227. this.queryParam.productBrandSn = undefined
  228. this.queryParam.productTypeSn1 = ''
  229. this.queryParam.productTypeSn2 = ''
  230. this.queryParam.productTypeSn3 = ''
  231. this.queryParam.productType = []
  232. },
  233. // 重置
  234. resetSearchForm () {
  235. this.resetData()
  236. // this.$refs.table.clearTable()
  237. this.$refs.table.refresh(true)
  238. },
  239. // 保存
  240. handleSave () {
  241. const _this = this
  242. if (!this.rowSelectionInfo || (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  243. this.$message.warning('请在列表勾选后再进行操作!')
  244. return
  245. }
  246. if (this.type == 'supplier') { // 供应商增加产品
  247. const arr = []
  248. this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.map(item => {
  249. if (_this.chooseData.indexOf(item) == -1) {
  250. arr.push(item)
  251. }
  252. })
  253. this.$emit('ok', arr)
  254. } else {
  255. this.$emit('ok', this.rowSelectionInfo && this.rowSelectionInfo.selectedRows)
  256. }
  257. this.isShow = false
  258. },
  259. // 产品分类 change
  260. changeProductType (val, opt) {
  261. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  262. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  263. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  264. }
  265. },
  266. watch: {
  267. // 父页面传过来的弹框状态
  268. openModal (newValue, oldValue) {
  269. this.isShow = newValue
  270. },
  271. // 重定义的弹框状态
  272. isShow (newValue, oldValue) {
  273. if (!newValue) {
  274. this.$emit('close')
  275. this.$refs.table.clearTable()
  276. this.resetData()
  277. } else {
  278. const _this = this
  279. let selectedRows = []
  280. let selectedRowKeys = []
  281. if (this.type == 'supplier') { // 供应商增加产品
  282. selectedRows = []
  283. selectedRowKeys = this.chooseData
  284. } else {
  285. selectedRows = this.chooseData
  286. selectedRowKeys = []
  287. this.chooseData.map(item => {
  288. selectedRowKeys.push(item.goodsSn)
  289. })
  290. }
  291. this.$nextTick(() => { // 页面渲染完成后的回调
  292. _this.$refs.table.setTableSelected(selectedRowKeys, selectedRows) // 设置表格选中项
  293. })
  294. }
  295. }
  296. }
  297. }
  298. </script>
  299. <style lang="less" scoped>
  300. .chooseProducts-modal{
  301. .products-con{
  302. .btn-con{
  303. text-align: center;
  304. margin: 30px 0 20px;
  305. .button-cancel{
  306. font-size: 12px;
  307. }
  308. }
  309. }
  310. }
  311. </style>