addProductModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. <a-select
  46. placeholder="请选择产品品牌"
  47. id="chooseProducts-productBrandSn"
  48. allowClear
  49. v-model="queryParam.productBrandSn"
  50. :showSearch="true"
  51. option-filter-prop="children"
  52. :filter-option="filterOption">
  53. <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn">{{ item.brandName }}</a-select-option>
  54. </a-select>
  55. </a-form-model-item>
  56. </a-col>
  57. <a-col :md="6" :sm="24">
  58. <a-form-model-item label="产品分类">
  59. <a-cascader
  60. @change="changeProductType"
  61. change-on-select
  62. v-model="queryParam.productType"
  63. expand-trigger="hover"
  64. :options="productTypeList"
  65. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  66. id="chooseProducts-productType"
  67. placeholder="请选择产品分类"
  68. allowClear />
  69. </a-form-model-item>
  70. </a-col>
  71. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  72. <a-button type="primary" @click="handleSearch" :disabled="disabled" id="chooseProducts-refresh">查询</a-button>
  73. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="chooseProducts-reset">重置</a-button>
  74. </a-col>
  75. </a-row>
  76. </a-form-model></a-form>
  77. </div>
  78. <!-- 列表 -->
  79. <s-table
  80. class="sTable"
  81. ref="table"
  82. size="small"
  83. :rowKey="(record) => record.productSn"
  84. rowKeyName="productSn"
  85. :row-selection="{ columnWidth: 40, getCheckboxProps:record =>({props: { disabled: this.chooseData && this.chooseData.indexOf(record.productSn) > -1 }}) }"
  86. @rowSelection="rowSelectionFun"
  87. :columns="columns"
  88. :data="loadData"
  89. :defaultLoadData="false"
  90. bordered>
  91. </s-table>
  92. </div>
  93. <!-- 按钮 -->
  94. <div class="btn-con">
  95. <a-button
  96. type="primary"
  97. id="chooseProducts-save"
  98. size="large"
  99. class="button-primary"
  100. @click="handleSave"
  101. style="padding: 0 60px;">保存</a-button>
  102. <a-button
  103. id="chooseProducts-cancel"
  104. size="large"
  105. class="button-cancel"
  106. @click="isShow=false"
  107. style="padding: 0 60px;margin-left: 15px;">取消</a-button>
  108. </div>
  109. </div>
  110. </a-spin>
  111. </a-modal>
  112. </template>
  113. <script>
  114. import { STable } from '@/components'
  115. import { productBrandQuery } from '@/api/productBrand'
  116. import { productTypeQuery, productTypeQueryAll } from '@/api/productType'
  117. import supplier from '@/views/common/supplier.js'
  118. import { addProduct, supplierProductSnList } from '@/api/supplier'
  119. import { productPricingList } from '@/api/product'
  120. export default {
  121. name: 'ChooseProductsModal',
  122. components: { STable, supplier },
  123. props: {
  124. openModal: { // 弹框显示状态
  125. type: Boolean,
  126. default: false
  127. },
  128. type: { // 类型,经销权设置dealership, 供应商添加产品supplier
  129. type: String,
  130. default: 'supplier'
  131. },
  132. dealerSn: {
  133. type: String || Number,
  134. default: ''
  135. }
  136. },
  137. data () {
  138. return {
  139. spinning: false,
  140. isShow: this.openModal, // 是否打开弹框
  141. formItemLayout: {
  142. labelCol: { span: 4 },
  143. wrapperCol: { span: 20 }
  144. },
  145. supplierSn: undefined, // 供应商sn
  146. queryParam: { // 查询条件
  147. code: '', // 产品编码
  148. productBrandSn: undefined, // 产品品牌
  149. productType: [],
  150. productTypeSn1: '', // 产品一级分类
  151. productTypeSn2: '', // 产品二级分类
  152. productTypeSn3: '' // 产品三级分类
  153. },
  154. rules: {
  155. productBrandSn: [ { required: true, message: '请选择产品品牌', trigger: 'change' } ],
  156. productType: [ { required: true, message: '请选择产品分类', trigger: 'change' } ]
  157. },
  158. chooseData: [], // 已选产品
  159. disabled: false, // 查询、重置按钮是否可操作
  160. loading: false, // 表格加载中
  161. columns: [
  162. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  163. { title: '产品编码', dataIndex: 'code', align: 'center' },
  164. { title: '产品名称', dataIndex: 'name', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } }
  165. ],
  166. // 加载数据方法 必须为 Promise 对象
  167. loadData: parameter => {
  168. this.disabled = true
  169. this.spinning = true
  170. const params = Object.assign(parameter, this.queryParam)
  171. return productPricingList(params).then(res => {
  172. let data
  173. if (res.status == 200) {
  174. data = res.data
  175. const no = (data.pageNo - 1) * data.pageSize
  176. for (var i = 0; i < data.list.length; i++) {
  177. data.list[i].no = no + i + 1
  178. }
  179. this.disabled = false
  180. }
  181. this.spinning = false
  182. return data
  183. })
  184. },
  185. productBrandList: [], // 品牌下拉数据
  186. productTypeList: [], // 分类下拉数据
  187. rowSelectionInfo: null
  188. }
  189. },
  190. methods: {
  191. // 表格选中项
  192. rowSelectionFun (obj) {
  193. this.rowSelectionInfo = obj || null
  194. },
  195. // 查询所有已选sn
  196. getChoosed () {
  197. this.spinning = true
  198. supplierProductSnList({ sn: this.supplierSn }).then(res => {
  199. if (res.status == 200) {
  200. this.$refs.table.clearTable()
  201. this.chooseData = res.data // 包含先前所选产品
  202. this.handleSearch()
  203. }
  204. this.spinning = false
  205. })
  206. },
  207. // 查询
  208. handleSearch () {
  209. const _this = this
  210. _this.$refs.ruleForm.validate(valid => {
  211. if (valid) {
  212. if (_this.supplierSn) {
  213. _this.$refs.table.refresh(true)
  214. } else {
  215. _this.$message.warning('请先选择供应商!')
  216. }
  217. } else {
  218. return false
  219. }
  220. })
  221. },
  222. // 重置数据
  223. resetData () {
  224. this.queryParam.code = ''
  225. this.queryParam.productBrandSn = undefined
  226. this.queryParam.productTypeSn1 = ''
  227. this.queryParam.productTypeSn2 = ''
  228. this.queryParam.productTypeSn3 = ''
  229. this.queryParam.productType = []
  230. // this.supplierSn = undefined //供应商sn
  231. },
  232. // 重置
  233. resetSearchForm () {
  234. this.resetData()
  235. // this.$refs.table.clearTable()
  236. this.$refs.table.refresh(true)
  237. },
  238. // 保存
  239. handleSave () {
  240. const _this = this
  241. if (!this.supplierSn) {
  242. this.$message.warning('请先选择供应商!')
  243. return
  244. }
  245. if (!this.rowSelectionInfo || (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  246. this.$message.warning('请选择产品!')
  247. return
  248. }
  249. const arr = []
  250. this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.map(item => {
  251. if (_this.chooseData.indexOf(item) == -1) {
  252. arr.push(item)
  253. }
  254. })
  255. if (arr.length) {
  256. this.addProduct(arr)
  257. } else {
  258. this.$message.warning('请选择产品!')
  259. }
  260. },
  261. // 添加产品 数据处理
  262. addProduct (arr) {
  263. this.spinning = true
  264. addProduct({
  265. supplierSn: this.supplierSn,
  266. productSnList: arr
  267. }).then(res => {
  268. if (res.status == 200) {
  269. this.$emit('ok')
  270. this.isShow = false
  271. }
  272. this.spinning = false
  273. })
  274. },
  275. // 产品分类 change
  276. changeProductType (val, opt) {
  277. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  278. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  279. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  280. },
  281. filterOption (input, option) {
  282. return (
  283. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  284. )
  285. },
  286. // 产品品牌 列表
  287. getProductBrand () {
  288. productBrandQuery({}).then(res => {
  289. if (res.status == 200) {
  290. this.productBrandList = res.data
  291. } else {
  292. this.productBrandList = []
  293. }
  294. })
  295. },
  296. // 产品分类 列表
  297. getProductType () {
  298. productTypeQuery({}).then(res => {
  299. if (res.status == 200) {
  300. this.productTypeList = res.data
  301. } else {
  302. this.productTypeList = []
  303. }
  304. })
  305. }
  306. },
  307. watch: {
  308. // 父页面传过来的弹框状态
  309. openModal (newValue, oldValue) {
  310. this.isShow = newValue
  311. },
  312. // 重定义的弹框状态
  313. isShow (newValue, oldValue) {
  314. if (!newValue) {
  315. this.$emit('close')
  316. this.$refs.table.clearTable()
  317. this.chooseData = []
  318. this.supplierSn = undefined
  319. this.resetData()
  320. } else {
  321. if (this.productBrandList.length == 0) {
  322. this.getProductBrand()
  323. }
  324. if (this.productTypeList.length == 0) {
  325. this.getProductType()
  326. }
  327. }
  328. }
  329. }
  330. }
  331. </script>
  332. <style lang="less" scoped>
  333. .chooseProducts-modal{
  334. .products-con{
  335. .btn-con{
  336. text-align: center;
  337. margin: 30px 0 20px;
  338. .button-cancel{
  339. font-size: 12px;
  340. }
  341. }
  342. }
  343. }
  344. </style>