addProductModal.vue 9.7 KB

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