detailProductList.vue 14 KB

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