chooseProductsModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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="产品编码">
  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-model-item label="产品品牌">
  33. <ProductBrand id="chooseProducts-productBrandSn" v-model="queryParam.productBrandSn"></ProductBrand>
  34. </a-form-model-item>
  35. </a-col>
  36. <a-col :md="6" :sm="24">
  37. <a-form-model-item label="产品分类">
  38. <productTypeAll :isAll="type!='default'" placeholder="请选择产品分类" @change="changeProductType" v-model="queryParam.productType" id="chooseProducts-productType"></productTypeAll>
  39. </a-form-model-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. id="chooseProducts-cancel"
  68. class="button-cancel"
  69. @click="isShow=false"
  70. style="padding: 0 30px;">取消</a-button>
  71. <a-button
  72. type="primary"
  73. id="chooseProducts-save"
  74. @click="handleSave"
  75. style="padding: 0 30px;margin-left: 15px;">保存</a-button>
  76. </div>
  77. </div>
  78. </a-spin>
  79. </a-modal>
  80. </template>
  81. <script>
  82. import { STable } from '@/components'
  83. import tablePagination from '@/views/common/tablePagination.vue'
  84. import ProductBrand from '@/views/common/productBrand.js'
  85. import productTypeAll from '@/views/common/productTypeAll.js'
  86. import { dealerScopeValidProduct } from '@/api/dealerScope'
  87. import { productPricedList, productPricingList } 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. type: { // 类型,经销权设置dealership, 供应商添加产品supplier
  103. type: String,
  104. default: 'default'
  105. },
  106. dealerSn: {
  107. type: String || Number,
  108. default: ''
  109. }
  110. },
  111. data () {
  112. return {
  113. spinning: false,
  114. isShow: this.openModal, // 是否打开弹框
  115. formItemLayout: {
  116. labelCol: { span: 4 },
  117. wrapperCol: { span: 20 }
  118. },
  119. queryParam: { // 查询条件
  120. code: '', // 产品编码
  121. productBrandSn: undefined, // 产品品牌
  122. productType: [],
  123. productTypeSn1: '', // 产品一级分类
  124. productTypeSn2: '', // 产品二级分类
  125. productTypeSn3: '' // 产品三级分类
  126. },
  127. rules: {
  128. productBrandSn: [ { required: true, message: '请选择产品品牌', trigger: 'change' } ],
  129. productType: [ { required: true, message: '请选择产品分类', trigger: 'change' } ]
  130. },
  131. disabled: false, // 查询、重置按钮是否可操作
  132. loading: false, // 表格加载中
  133. columns: [
  134. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  135. { title: '产品编码', dataIndex: 'code', align: 'left',width: 200 },
  136. { title: '产品名称', dataIndex: 'name', align: 'left', ellipsis: true, customRender: function (text) { return text || '--' } }
  137. ],
  138. // 加载数据方法 必须为 Promise 对象
  139. loadData: parameter => {
  140. this.disabled = true
  141. this.spinning = true
  142. let url = productPricedList // 获取定过价的产品
  143. if (this.type == 'supplier') { // 供应商增加产品
  144. url = productPricingList // 获取定价产品
  145. }
  146. const params = Object.assign(parameter, this.queryParam)
  147. if (this.type != 'supplier' && this.type != 'dealership') { // 促销
  148. params.onlineFalg = 1
  149. }
  150. return url(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. methods: {
  168. // 表格选中项
  169. rowSelectionFun (obj) {
  170. this.rowSelectionInfo = obj || null
  171. },
  172. // 查询
  173. handleSearch () {
  174. const _this = this
  175. _this.$refs.ruleForm.validate(valid => {
  176. if (valid) {
  177. if (_this.type == 'dealership') { // 设置经销权时选择产品
  178. if (!_this.queryParam.productBrandSn && !_this.queryParam.productTypeSn1) {
  179. _this.$message.info('请选择产品品牌或产品分类')
  180. return
  181. }
  182. // 校验产品是否被包含在品牌分类中
  183. const params = []
  184. if (_this.queryParam.productBrandSn) {
  185. params.push({
  186. dealerSn: _this.dealerSn,
  187. goodsType: 'BRAND',
  188. goodsSn: _this.queryParam.productBrandSn
  189. })
  190. }
  191. if (_this.queryParam.productTypeSn1) {
  192. params.push({
  193. dealerSn: _this.dealerSn,
  194. goodsType: 'CATEGORY',
  195. goodsSn: _this.queryParam.productTypeSn1
  196. })
  197. }
  198. if (_this.queryParam.productTypeSn2) {
  199. params.push({
  200. dealerSn: _this.dealerSn,
  201. goodsType: 'CATEGORY',
  202. goodsSn: _this.queryParam.productTypeSn2
  203. })
  204. }
  205. if (_this.queryParam.productTypeSn3) {
  206. params.push({
  207. dealerSn: _this.dealerSn,
  208. goodsType: 'CATEGORY',
  209. goodsSn: _this.queryParam.productTypeSn3
  210. })
  211. }
  212. dealerScopeValidProduct(params).then(res => {
  213. if (res.status == 200) {
  214. _this.$refs.table.refresh(true)
  215. }
  216. })
  217. } else {
  218. _this.$refs.table.refresh(true)
  219. }
  220. } else {
  221. return false
  222. }
  223. })
  224. },
  225. // 重置数据
  226. resetData () {
  227. this.queryParam.code = ''
  228. this.queryParam.productBrandSn = undefined
  229. this.queryParam.productTypeSn1 = ''
  230. this.queryParam.productTypeSn2 = ''
  231. this.queryParam.productTypeSn3 = ''
  232. this.queryParam.productType = []
  233. },
  234. // 重置
  235. resetSearchForm () {
  236. this.resetData()
  237. this.$refs.table.clearTable()
  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>