list.vue 15 KB

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