list.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <a-card size="small" :bordered="false" class="shoppingCar-wrap">
  3. <!-- 搜索条件 -->
  4. <div ref="tableSearch" class="table-page-search-wrapper">
  5. <a-form layout="inline" @keyup.enter.native="searchForm()">
  6. <a-row type="flex" :gutter="12" justify="start">
  7. <a-col flex="auto">
  8. <a-form-item label="产品编码">
  9. <a-input id="shoppingCar-code" v-model.trim="queryParam.code" allowClear placeholder="请输入产品编码"/>
  10. </a-form-item>
  11. </a-col>
  12. <a-col flex="auto">
  13. <a-form-item label="产品名称">
  14. <a-input id="shoppingCar-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称"/>
  15. </a-form-item>
  16. </a-col>
  17. <a-col flex="250px">
  18. <a-form-item label="产品分类">
  19. <ProductType id="shoppingCar-productType" placeholder="请选择产品分类" :isDealer="true" @change="changeProductType" v-model="productType"></ProductType>
  20. </a-form-item>
  21. </a-col>
  22. <a-col flex="250px">
  23. <a-form-item label="产品品牌">
  24. <ProductBrand id="shoppingCar-productBrandSn" placeholder="请选择产品品牌" v-model="queryParam.productBrandSn"></ProductBrand>
  25. </a-select>
  26. </a-form-item>
  27. </a-col>
  28. <a-col flex="250px" v-if="modes=='pages'">
  29. <a-form-item label="产品状态">
  30. <v-select
  31. code="ONLINE_FLAG2"
  32. id="productPricingList-onlineFalg"
  33. v-model="queryParam.onlineFalg"
  34. allowClear
  35. placeholder="请选择产品状态"
  36. ></v-select>
  37. </a-form-item>
  38. </a-col>
  39. <a-col flex="auto" style="margin-bottom:10px;">
  40. <a-button type="primary" @click="searchForm()" :disabled="disabled" id="shoppingCar-refresh">查询</a-button>
  41. <a-button style="margin-left: 5px" @click="resetSearchForm()" :disabled="disabled" id="shoppingCar-reset">重置</a-button>
  42. </a-col>
  43. </a-row>
  44. </a-form>
  45. <!-- 操作按钮 -->
  46. <div class="table-operator">
  47. <a-row :gutter="16">
  48. <a-col class="gutter-row" :span="24">
  49. <a-button type="primary" :loading="loading" ghost v-if="modes=='pages'" @click="deleteMore">
  50. 批量删除
  51. </a-button>
  52. <a-button type="primary" :loading="loading" ghost v-if="modes=='modals'" @click="addMore">
  53. 批量添加
  54. </a-button>
  55. <span style="font-weight: bold;margin-left:15px;" v-if="rowSelectionInfo&&rowSelectionInfo.selectedRowKeys.length">已选 {{ rowSelectionInfo.selectedRowKeys.length }} 项</span>
  56. </a-col>
  57. </a-row>
  58. </div>
  59. </div>
  60. <!-- 列表 -->
  61. <s-table
  62. class="sTable"
  63. ref="table"
  64. :style="modes=='pages'?{ height: tableHeight+84.5+'px' }:{}"
  65. size="small"
  66. :row-selection="modes=='pages'?{ columnWidth: 40 }:{ columnWidth: 40, getCheckboxProps: record => ({ props:{disabled: (purchaseType&&purchaseType=='SUPPLIER_SYS'&&record.productEntity.onlineFalg == 0) || record.dealerScopeFlag == 0 }}) }"
  67. @rowSelection="rowSelectionFun"
  68. rowKeyName="productSn"
  69. :rowKey="(record) => record.productSn"
  70. :columns="columns"
  71. :data="loadData"
  72. :scroll="modes=='pages'?{ y: tableHeight }:{ x:tableWidth, y: tableHeight }"
  73. :defaultLoadData="false"
  74. :pageSize="30"
  75. bordered>
  76. <!-- 采购数量 -->
  77. <template slot="purchaseQty" slot-scope="text, record">
  78. <a-input-number
  79. size="small"
  80. v-model="record.qty"
  81. :precision="0"
  82. :min="1"
  83. :max="999999"
  84. @blur="updateQty(record)"
  85. style="width: 100%;"
  86. placeholder="请输入采购数量" />
  87. </template>
  88. <!-- 包装数 -->
  89. <template slot="baozh" slot-scope="text, record">
  90. {{ record.productEntity.packQty||'--' }}{{ record.productEntity.packQty ? record.productEntity.unit : '' }}/{{ record.productEntity.packQtyUnit||'--' }}
  91. </template>
  92. <!-- 产品编码 -->
  93. <template slot="productCode" slot-scope="text, record">
  94. <div v-if="modes=='pages'">
  95. <span style="padding-right: 15px;">{{ text }}</span>
  96. <a-tag v-if="record.productEntity.onlineFalg == 0">下架</a-tag>
  97. </div>
  98. <div v-else>
  99. <span style="padding-right: 15px;">{{ text }}</span>
  100. <!-- <a-tag v-if="record.productEntity.onlineFalg == 0">下架</a-tag> -->
  101. <a-tag color="red" v-if="record.dealerScopeFlag == 0">无权限</a-tag>
  102. </div>
  103. </template>
  104. </s-table>
  105. </a-card>
  106. </template>
  107. <script>
  108. import { commonMixin } from '@/utils/mixin'
  109. import { mapActions } from 'vuex'
  110. import { purchaseCartList, purchaseDeleteBatch, purchaseUpdateQty } from '@/api/purchaseCart'
  111. import { purchaseDetailCancelSave } from '@/api/purchaseDetail'
  112. import ProductType from '../../common/productType.js'
  113. import ProductBrand from '../../common/productBrand.js'
  114. import { STable, VSelect } from '@/components'
  115. export default {
  116. name: 'ShoppingCarList',
  117. components: { STable, VSelect, ProductType, ProductBrand },
  118. mixins: [commonMixin],
  119. props: {
  120. modes: {
  121. type: String,
  122. default: 'pages'
  123. },
  124. purchaseType: {
  125. type: String,
  126. default: null
  127. }
  128. },
  129. data () {
  130. return {
  131. loading: false,
  132. tableHeight: 0,
  133. tableWidth: 960,
  134. productType: [],
  135. queryParam: { // 查询条件
  136. code: '', // 产品编码
  137. name: '', // 产品名称
  138. productBrandSn: undefined, // 产品品牌
  139. productTypeSn1: '', // 产品一级分类
  140. productTypeSn2: '', // 产品二级分类
  141. productTypeSn3: '', // 产品三级分类
  142. onlineFalg: undefined
  143. },
  144. paramsData: null,
  145. openEditPriceModal: false, // 自定义报价弹窗
  146. disabled: false, // 查询、重置按钮是否可操作
  147. columns: [],
  148. // 加载数据方法 必须为 Promise 对象
  149. loadData: parameter => {
  150. this.disabled = true
  151. this.spinning = true
  152. return purchaseCartList(Object.assign(parameter, { productEntity: this.queryParam }, this.paramsData)).then(res => {
  153. let data
  154. if (res.status == 200) {
  155. data = res.data
  156. const no = (data.pageNo - 1) * data.pageSize
  157. for (var i = 0; i < data.list.length; i++) {
  158. data.list[i].no = no + i + 1
  159. data.list[i].qtyBack = data.list[i].qty
  160. }
  161. this.disabled = false
  162. }
  163. this.spinning = false
  164. return data
  165. })
  166. },
  167. rowSelectionInfo: null
  168. }
  169. },
  170. methods: {
  171. ...mapActions(['getCartList']),
  172. // 查询
  173. searchForm (flag) {
  174. this.$refs.table.refresh(true)
  175. if (flag) {
  176. this.$refs.table.clearSelected()
  177. this.rowSelectionInfo = null
  178. }
  179. },
  180. // 重置
  181. resetSearchForm (flag) {
  182. this.queryParam.code = ''
  183. this.queryParam.name = ''
  184. this.queryParam.productBrandSn = undefined
  185. this.queryParam.productTypeSn1 = ''
  186. this.queryParam.productTypeSn2 = ''
  187. this.queryParam.productTypeSn3 = ''
  188. this.queryParam.onlineFalg = undefined
  189. this.productType = []
  190. this.$refs.table.refresh(true)
  191. if (flag) {
  192. this.$refs.table.clearSelected()
  193. this.rowSelectionInfo = null
  194. }
  195. },
  196. // 设置表头
  197. getColumns () {
  198. const _this = this
  199. if (this.modes == 'pages') {
  200. this.columns = [
  201. { title: '产品编码', dataIndex: 'productEntity.code', scopedSlots: { customRender: 'productCode' }, width: '20%', align: 'center' },
  202. { title: '产品名称', dataIndex: 'productEntity.name', width: '30%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  203. { title: '可用库存数量', dataIndex: 'currentStockQty', width: '14%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  204. { title: '成本价', dataIndex: 'productEntity.productPrice', width: '8%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  205. { title: '单位', dataIndex: 'productEntity.unit', width: '8%', align: 'center', customRender: function (text) { return (!text || text == ' ') ? '--' : text } },
  206. { title: '包装数', scopedSlots: { customRender: 'baozh' }, dataIndex: 'productEntity.packQty', width: '8%', align: 'center' },
  207. { title: '采购数量', scopedSlots: { customRender: 'purchaseQty' }, width: '12%', align: 'center' }
  208. ]
  209. } else {
  210. this.columns = [
  211. { title: '产品编码', dataIndex: 'productEntity.code', scopedSlots: { customRender: 'productCode' }, width: '200px', align: 'center', fixed: 'left' },
  212. { title: '产品名称', dataIndex: 'productEntity.name', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  213. { title: '可用库存数量', dataIndex: 'currentStockQty', width: '140px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  214. { title: '成本价', dataIndex: 'productEntity.productPrice', width: '80px', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  215. { title: '单位', dataIndex: 'productEntity.unit', width: '80px', align: 'center', customRender: function (text) { return (!text || text == ' ') ? '--' : text } },
  216. { title: '包装数', scopedSlots: { customRender: 'baozh' }, dataIndex: 'productEntity.packQty', width: '80px', align: 'center' },
  217. { title: '采购数量', scopedSlots: { customRender: 'purchaseQty' }, width: '120px', align: 'center', fixed: 'right' }
  218. ]
  219. }
  220. },
  221. // 产品分类 change
  222. changeProductType (val, opt) {
  223. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  224. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  225. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  226. },
  227. // 表格选中项
  228. rowSelectionFun (obj) {
  229. this.rowSelectionInfo = obj || null
  230. },
  231. // 修改数量
  232. updateQty (row) {
  233. if (row.qty != row.qtyBack && row.qty) {
  234. purchaseUpdateQty({ qty: row.qty, purchaseCartSn: row.purchaseCartSn }).then(res => {
  235. if (res.status == 200) {
  236. this.$message.info(res.message)
  237. row.qtyBack = row.qty
  238. } else {
  239. row.qty = row.qtyBack
  240. }
  241. })
  242. } else {
  243. row.qty = row.qtyBack
  244. }
  245. },
  246. // 批量删除
  247. deleteMore () {
  248. const rows = this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys || []
  249. if (!this.rowSelectionInfo || (rows.length <= 0)) {
  250. this.$message.warning('请在列表勾选后再进行批量操作!')
  251. return
  252. }
  253. this.$confirm({
  254. title: '提示',
  255. content: '您已经选择' + rows.length + '个产品,确认要将已选产品从购物车中移除吗?',
  256. centered: true,
  257. onOk: () => {
  258. this.loading = true
  259. purchaseDeleteBatch({
  260. productSnList: rows
  261. }).then(res => {
  262. if (res.status == 200) {
  263. this.$message.info(res.message)
  264. this.getCartList()
  265. this.searchForm(true)
  266. }
  267. this.loading = false
  268. })
  269. }
  270. })
  271. },
  272. // 保存
  273. addMore () {
  274. const _this = this
  275. const rows = this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys || []
  276. if (!this.rowSelectionInfo || (rows.length <= 0)) {
  277. this.$message.warning('请在列表勾选后再进行批量操作!')
  278. return
  279. }
  280. const rowsList = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows || []
  281. const list = []
  282. rowsList.map(item => {
  283. list.push({
  284. cancelQty: item.qty,
  285. qty: item.qty,
  286. productSn: item.productSn,
  287. price: item.productEntity.purchasePrice
  288. })
  289. })
  290. const params = {
  291. confirm: false,
  292. purchaseBillSn: this.paramsData.purchaseBillSn,
  293. purchaseBillNo: this.paramsData.purchaseBillNo,
  294. purchaseBillDetailEntityList: list,
  295. purchaseCartFlag: true
  296. }
  297. purchaseDetailCancelSave(params).then(res => {
  298. if (res.status == 200 && res.data) {
  299. let content = ''
  300. if ((res.data.productSizeRepeat != res.data.productSize) && (res.data.productSizeRepeat != 0)) {
  301. content = `您已经选择 ${res.data.productSize} 个产品,其中 ${res.data.productSizeRepeat} 个产品已经存在于采购单中,本次只会加入不重复的产品。确认加入本次采购吗?`
  302. this.confirmFun(content, params)
  303. } else if (res.data.productSizeRepeat == res.data.productSize) {
  304. content = `抱歉,您选择的 ${res.data.productSize} 个产品,采购单中已经全部存在,无需加入!`
  305. this.$info({
  306. title: '提示',
  307. content: content,
  308. okText: '好的',
  309. centered: true,
  310. zIndex: 1100,
  311. onOk () {
  312. _this.$refs.table.clearSelected() // 清空表格选中项
  313. }
  314. })
  315. } else {
  316. content = `您已经选择 ${res.data.productSize} 个产品,确认要将已选产品加入本次采购吗?`
  317. this.confirmFun(content, params)
  318. }
  319. }
  320. })
  321. },
  322. confirmFun (content, params) {
  323. const _this = this
  324. this.$confirm({
  325. title: '提示',
  326. content: content,
  327. okText: '确认加入',
  328. cancelText: '重新选择',
  329. centered: true,
  330. closable: true,
  331. zIndex: 1100,
  332. onOk () {
  333. _this.loading = true
  334. params.confirm = true
  335. purchaseDetailCancelSave(params).then(res => {
  336. if (res.status == 200) {
  337. _this.$emit('ok')
  338. _this.getCartList()
  339. _this.searchForm(true)
  340. _this.loading = false
  341. } else {
  342. _this.loading = false
  343. }
  344. })
  345. },
  346. onCancel () {
  347. _this.$refs.table.clearSelected() // 清空表格选中项
  348. }
  349. })
  350. },
  351. pageInit (paramsData) {
  352. this.paramsData = paramsData || {}
  353. this.getColumns()
  354. this.setTableH()
  355. this.resetSearchForm()
  356. },
  357. setTableH () {
  358. this.$nextTick(() => { // 页面渲染完成后的回调
  359. const tableSearchH = this.$refs.tableSearch.offsetHeight
  360. this.tableHeight = window.innerHeight - tableSearchH - (this.modes == 'pages' ? 200 : 290)
  361. })
  362. }
  363. },
  364. watch: {
  365. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  366. this.setTableH()
  367. }
  368. },
  369. mounted () {
  370. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  371. this.pageInit()
  372. }
  373. },
  374. activated () {
  375. // 如果是新页签打开,则重置当前页面
  376. if (this.$store.state.app.isNewTab) {
  377. this.pageInit()
  378. }
  379. },
  380. beforeRouteEnter (to, from, next) {
  381. next(vm => {})
  382. }
  383. }
  384. </script>
  385. <style lang="less" scoped>
  386. .setTableList{
  387. text-align: right;
  388. position: relative;
  389. span{
  390. margin-right: 10px;
  391. color:#56a2fb;
  392. }
  393. .setTableList-box{
  394. padding:10px 12px;
  395. border:1px solid #d5d5d5;
  396. border-radius: 5px;
  397. background:#fff;
  398. text-align: left;
  399. position: absolute;
  400. top:22px;
  401. right:0;
  402. z-index: 99999;
  403. div{
  404. margin-bottom: 10px;
  405. &:last-child{
  406. margin-bottom: 0px;
  407. }
  408. }
  409. }
  410. }
  411. </style>