detailProductList.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <div class="productInfoList-wrap">
  3. <!-- alert -->
  4. <div style="margin-bottom: 10px;display: flex;align-items: center;" v-if="!showEmpty">
  5. <div style="display: flex;align-items: center;">
  6. <a-button type="danger" :disabled="newLoading" class="button-info" @click="delSalerDetailAll">批量删除</a-button>
  7. <span style="margin-left: 10px;" v-if="selectedRowKeys.length">已选 {{ selectedRowKeys.length }} 项</span>
  8. </div>
  9. <div style="padding-left: 20px;">
  10. <slot name="total"></slot>
  11. </div>
  12. </div>
  13. <a-spin :spinning="spinning" tip="Loading...">
  14. <ve-table
  15. border-y
  16. v-show="!showEmpty"
  17. :scroll-width="0"
  18. :max-height="tableHeight"
  19. :show-header="showTableHead"
  20. :row-style-option="{clickHighlight: true}"
  21. :cellSelectionOption="{enable: false}"
  22. :virtual-scroll-option="{enable: true}"
  23. :columns="columns"
  24. :table-data="dataSource"
  25. row-key-field-name="id"
  26. :cell-style-option="cellStyleOption"
  27. :cell-span-option="cellSpanOption"
  28. :column-width-resize-option="columnWidthResizeOption"
  29. :checkbox-option="checkboxOption"
  30. />
  31. <div v-show="showEmpty" class="empty-data"><a-empty description="暂无产品" :image="simpleImage"/></div>
  32. </a-spin>
  33. </div>
  34. </template>
  35. <script>
  36. import { commonMixin } from '@/utils/mixin'
  37. import { deleteBatch, waitDispatchDetailAllList, updateQty } from '@/api/waitDispatchDetail'
  38. import { Empty } from 'ant-design-vue';
  39. import { STable, VSelect } from '@/components'
  40. import chooseWarehouse from '@/views/common/chooseWarehouse'
  41. export default {
  42. name: 'DetailProductList',
  43. mixins: [commonMixin],
  44. components: { STable, VSelect, chooseWarehouse },
  45. props: {
  46. newLoading: {
  47. type: Boolean,
  48. default: false
  49. },
  50. maxHeight:{
  51. type: [String,Number],
  52. default: '300'
  53. },
  54. showHeader: {
  55. type: Boolean,
  56. default: true
  57. }
  58. },
  59. data () {
  60. return {
  61. productForm: {
  62. dispatchBillSn: ''
  63. },
  64. disabled: false, // 查询、重置按钮是否可操作
  65. spinning: false,
  66. simpleImage: Empty.PRESENTED_IMAGE_SIMPLE,
  67. dataSource: [],
  68. tableHeight: this.maxHeight,
  69. cellStyleOption: {
  70. bodyCellClass: ({ row, column, rowIndex }) => {
  71. if (row.id.indexOf('promo-')>=0 && column.field === "no") {
  72. return "table-body-cell-no";
  73. }
  74. },
  75. },
  76. columnWidthResizeOption: {
  77. // default false
  78. enable: true,
  79. // column resize min width
  80. minWidth: 50
  81. },
  82. cellSpanOption: {
  83. bodyCellSpan: this.bodyCellSpan,
  84. },
  85. showEmpty: false,
  86. showTableHead: true,
  87. disableSelectedRowKeys: [],
  88. selectedRowKeys: [],
  89. detailData: null,
  90. activeList: []
  91. }
  92. },
  93. computed: {
  94. checkboxOption () {
  95. return {
  96. disableSelectedRowKeys: this.disableSelectedRowKeys,
  97. selectedRowKeys: this.selectedRowKeys,
  98. // 行选择改变事件
  99. selectedRowChange: ({ row, isSelected, selectedRowKeys }) => {
  100. this.selectedRowChange({ row, isSelected, selectedRowKeys })
  101. },
  102. // 全选改变事件
  103. selectedAllChange: ({ isSelected, selectedRowKeys }) => {
  104. this.selectedAllChange({ isSelected, selectedRowKeys })
  105. },
  106. }
  107. },
  108. columns () {
  109. const _this = this
  110. const priceFormat = function(data){
  111. return _this.toThousands(data) || '--'
  112. }
  113. const numsFormat = function(data){
  114. return data || data == 0 ? data : '--'
  115. }
  116. const codeFormat = function(record,data,h){
  117. let ftext = ''
  118. let fcolor = ''
  119. if(record.promotionFlag == 'GIFT'){
  120. ftext = '促'
  121. fcolor = '#52c41a'
  122. }
  123. if(record.promotionFlag == 'DISCOUNT'){
  124. ftext = '特'
  125. fcolor = '#faad14'
  126. }
  127. return (
  128. <div>
  129. <span style="padding-right: 15px;">{data}</span>
  130. {ftext?(<a-badge count={ftext} number-style={{ backgroundColor: fcolor, zoom:'80%' }}></a-badge>):''}
  131. {Number(record.stockQty||0) < Number(record.unpushedQty||0)?(<a-badge count="缺" number-style={{ zoom:'80%' }}></a-badge>):''}
  132. </div>
  133. )
  134. }
  135. // 输入框
  136. const inputFormat = function(record,data,h) {
  137. if(record.surplusQty>0){
  138. return (
  139. <div>
  140. <a-input-number
  141. size="small"
  142. value={record.qty}
  143. onChange={e => record.qty = e}
  144. onBlur={e => _this.cancelNumsChange(e,record)}
  145. precision={0}
  146. min={1}
  147. max={record.surplusQty}
  148. style="width: 100%;"
  149. placeholder="请输入" />
  150. </div>
  151. )
  152. }
  153. return '--'
  154. }
  155. // 操作按钮
  156. const actionFormat = function(record,data,h) {
  157. if(record.surplusQty>0){
  158. return (
  159. <div>
  160. <a-button
  161. size="small"
  162. type="link"
  163. class="button-error"
  164. onClick={()=>_this.handleDel(record)}
  165. >删除</a-button>
  166. </div>
  167. )
  168. }
  169. return '--'
  170. }
  171. let arr= [
  172. { title: "", field: "", key: "acheck", type: "checkbox", align: "center" },
  173. { title: '序号', field: 'no',key: "a", width: 50, align: 'center', operationColumn: false },
  174. { title: '产品编码', field: 'productCode',key: "b", width: 150, align: 'center',operationColumn: false,renderBodyCell: ({ row, column, rowIndex }, h) => { return codeFormat(row,row[column.field],h)} },
  175. { title: '产品名称', field: 'productName',key: "c", width: 250, align: 'center',operationColumn: false , ellipsis: { showTitle: true },renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--'}},
  176. { title: '出库仓库', field: 'warehouseName',key: "e", width: 100, align: 'center',operationColumn: false,renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--'}},
  177. { title: '待下推数量', field: 'surplusQty', width: 80,key: "o", align: 'center',operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field])} },
  178. { title: '本次下推数', field: 'qty', width: 80,key: "r", align: 'center',operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return inputFormat(row,row[column.field],h)} },
  179. { title: '单位', field: 'productOrigUnit',key: "i", width: 80, align: 'center',operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--'}},
  180. { title: '操作', field: 'action', width: 80,key: "s", align: 'center',fixed: 'right',operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return actionFormat(row,row[column.field],h)} }
  181. ]
  182. return arr
  183. }
  184. },
  185. methods: {
  186. // 合并活动分类单元格
  187. bodyCellSpan({ row, column, rowIndex }) {
  188. if (row.id.indexOf('promo-')>=0) {
  189. if(column.field=='no'){
  190. return {
  191. rowspan: 1,
  192. colspan: 17,
  193. };
  194. }else{
  195. return {
  196. rowspan: 0,
  197. colspan: 0,
  198. }
  199. }
  200. }
  201. },
  202. // 选择单元格
  203. selectedRowChange({ row, isSelected, selectedRowKeys }){
  204. // console.log(row, isSelected, selectedRowKeys);
  205. this.selectedRowKeys = selectedRowKeys;
  206. },
  207. // 全选行
  208. selectedAllChange({ isSelected, selectedRowKeys }){
  209. // console.log(isSelected, selectedRowKeys);
  210. this.selectedRowKeys = selectedRowKeys;
  211. },
  212. async searchTable(){
  213. this.selectedRowKeys = []
  214. this.disableSelectedRowKeys = []
  215. this.dataSource = []
  216. this.disabled = true
  217. this.spinning = true
  218. const params = this.productForm
  219. // 带下推产品
  220. const listData = await waitDispatchDetailAllList(params).then(res => res.data)
  221. console.log(listData)
  222. this.dataSource = listData
  223. // 格式化数据
  224. let f = 0
  225. this.dataSource.map((item,i) => {
  226. if(item.id.indexOf('promo-')>=0){f = f - 1}
  227. item.no = i + 1 + f
  228. const productCode = (item.productEntity && item.productEntity.code) || (item.dealerProductEntity && item.dealerProductEntity.code)
  229. const productName = (item.productEntity && item.productEntity.name) || (item.dealerProductEntity && item.dealerProductEntity.name)
  230. const productOrigCode = (item.productEntity && item.productEntity.origCode) || (item.dealerProductEntity && item.dealerProductEntity.origCode)
  231. const productOrigUnit = (item.productEntity && item.productEntity.unit) || (item.dealerProductEntity && item.dealerProductEntity.unit)
  232. const warehouseName = item.dispatchBill && item.dispatchBill.warehouseName || ''
  233. item.productCode = productCode || '--'
  234. item.productName = productName || '--'
  235. item.productOrigCode = productOrigCode == ' ' ? '--' : productOrigCode
  236. item.productOrigUnit = productOrigUnit || '--'
  237. item.warehouseName = warehouseName || '--'
  238. item.qtyBackups = item.qty
  239. })
  240. this.showEmpty = this.dataSource.length <= 0
  241. this.tableHeight = (this.showEmpty ? 300 : this.maxHeight) + 'px'
  242. this.spinning = false
  243. this.disabled = false
  244. },
  245. // 重置
  246. resetSearchForm () {
  247. this.dataSource = []
  248. this.clearSelectTable()
  249. this.searchTable()
  250. },
  251. pageInit (productForm, detailData, activeList) {
  252. this.productForm = Object.assign(this.productForm,productForm)
  253. this.detailData = detailData
  254. this.activeList = activeList
  255. // 获取活动列表
  256. this.resetSearchForm()
  257. },
  258. // 清空选项
  259. clearSelectTable () {
  260. this.selectedRowKeys = []
  261. },
  262. // 已选产品 blur
  263. cancelNumsChange (e, record) {
  264. const _this = this
  265. const val = e.target.value
  266. if (val && val != record.qtyBackups && val<=record.surplusQty) {
  267. _this.spinning = true
  268. updateQty({
  269. dispatchBillDetailSn: record.dispatchBillDetailSn,
  270. qty: record.qty,
  271. salesBillSn: _this.detailData.salesBillSn,
  272. dispatchBillSn: _this.productForm.dispatchBillSn
  273. }).then(res => {
  274. if (res.status == 200) {
  275. _this.$message.success(res.message)
  276. _this.spinning = false
  277. _this.$emit('refashTable')
  278. } else {
  279. record.qty = record.qtyBackups
  280. _this.spinning = false
  281. }
  282. })
  283. } else {
  284. record.qty = record.qtyBackups
  285. }
  286. },
  287. // 删除产品
  288. handleDel (row) {
  289. const _this = this
  290. this.$confirm({
  291. title: '提示',
  292. content: '确认要删除吗?',
  293. centered: true,
  294. closable: true,
  295. onOk () {
  296. _this.deleteFun(row, 0)
  297. }
  298. })
  299. },
  300. // 移除操作
  301. deleteFun (row, type) {
  302. const _this = this
  303. _this.spinning = true
  304. deleteBatch({
  305. dispatchBillSn: this.productForm.dispatchBillSn,
  306. dispatchBillDetailList : type == 0 ? [row.dispatchBillDetailSn] : row
  307. }).then(res => {
  308. if (res.status == 200) {
  309. _this.$emit('refashTable')
  310. _this.$message.success(res.message)
  311. _this.spinning = false
  312. } else {
  313. _this.spinning = false
  314. }
  315. })
  316. },
  317. // 批量删除
  318. delSalerDetailAll () {
  319. const _this = this
  320. const chooseList = this.selectedRowKeys
  321. if (chooseList.length == 0) {
  322. _this.$message.warning('请选择待下推产品!')
  323. return
  324. }
  325. const chooseRow = this.dataSource.filter(item => chooseList.includes(item.id) && item.id.indexOf('promo-')<0)
  326. const obj = []
  327. chooseRow && chooseRow.map(item => {
  328. obj.push(item.dispatchBillDetailSn)
  329. })
  330. this.$confirm({
  331. title: '提示',
  332. content: '确认要批量删除吗?',
  333. centered: true,
  334. closable: true,
  335. onOk () {
  336. _this.deleteFun(obj, 1)
  337. }
  338. })
  339. },
  340. }
  341. }
  342. </script>
  343. <style lang="less">
  344. .empty-data{
  345. color: #999;
  346. text-align: center;
  347. padding: 20px;
  348. }
  349. .ve-table-body-td{
  350. .active-title{
  351. display: flex;
  352. align-items: center;
  353. justify-content: space-between;
  354. padding: 10px;
  355. background: #f3f8fa;
  356. }
  357. }
  358. .ve-table .ve-table-container .ve-table-content-wrapper table.ve-table-content tbody.ve-table-body tr.ve-table-body-tr td.table-body-cell-no,
  359. .ve-table .ve-table-container .ve-table-content-wrapper table.ve-table-content tbody.ve-table-body tr.ve-table-expand-tr td.table-body-cell-no{
  360. padding: 0;
  361. }
  362. .ve-table .ve-table-container .ve-table-content-wrapper{
  363. border-bottom: 1px solid #ddd;
  364. }
  365. </style>