detailProductList.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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 == 'GATE'){
  124. ftext = '槛'
  125. fcolor = '#108ee9'
  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: 100, align: 'center',operationColumn: false,renderBodyCell: ({ row, column, rowIndex }, h) => { return codeFormat(row,row[column.field],h)} },
  175. { title: '产品名称', field: 'productName',key: "c", width: 200, 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. if(this.detailData && this.detailData.promoFlag==1){
  183. arr.splice(2,0,{ title: '活动规则', field: 'prompName',key: "m", width: 100, align: 'center',operationColumn: false },)
  184. }
  185. return arr
  186. }
  187. },
  188. methods: {
  189. // 合并活动分类单元格
  190. bodyCellSpan({ row, column, rowIndex }) {
  191. if (row.id.indexOf('promo-')>=0) {
  192. if(column.field=='no'){
  193. return {
  194. rowspan: 1,
  195. colspan: 17,
  196. };
  197. }else{
  198. return {
  199. rowspan: 0,
  200. colspan: 0,
  201. }
  202. }
  203. }
  204. },
  205. // 选择单元格
  206. selectedRowChange({ row, isSelected, selectedRowKeys }){
  207. // console.log(row, isSelected, selectedRowKeys);
  208. this.selectedRowKeys = selectedRowKeys;
  209. },
  210. // 全选行
  211. selectedAllChange({ isSelected, selectedRowKeys }){
  212. // console.log(isSelected, selectedRowKeys);
  213. this.selectedRowKeys = selectedRowKeys;
  214. },
  215. async searchTable(){
  216. this.selectedRowKeys = []
  217. this.disableSelectedRowKeys = []
  218. this.dataSource = []
  219. this.disabled = true
  220. this.spinning = true
  221. const params = this.productForm
  222. // 带下推产品
  223. const listData = await waitDispatchDetailAllList(params).then(res => res.data)
  224. console.log(listData)
  225. this.dataSource = listData
  226. // 格式化数据
  227. let f = 0
  228. this.dataSource.map((item,i) => {
  229. if(item.id.indexOf('promo-')>=0){f = f - 1}
  230. item.no = i + 1 + f
  231. const productCode = (item.productEntity && item.productEntity.code) || (item.dealerProductEntity && item.dealerProductEntity.code)
  232. const productName = (item.productEntity && item.productEntity.name) || (item.dealerProductEntity && item.dealerProductEntity.name)
  233. const productOrigCode = (item.productEntity && item.productEntity.origCode) || (item.dealerProductEntity && item.dealerProductEntity.origCode)
  234. const productOrigUnit = (item.productEntity && item.productEntity.unit) || (item.dealerProductEntity && item.dealerProductEntity.unit)
  235. const warehouseName = item.dispatchBill && item.dispatchBill.warehouseName || ''
  236. const prompName = item.promotionRule ? (item.promotionRule.promotion && item.promotionRule.promotion.description) + '('+item.promotionRule.description+')' : '--'
  237. item.productCode = productCode || '--'
  238. item.productName = productName || '--'
  239. item.productOrigCode = productOrigCode == ' ' ? '--' : productOrigCode
  240. item.productOrigUnit = productOrigUnit || '--'
  241. item.warehouseName = warehouseName || '--'
  242. item.qtyBackups = item.qty
  243. item.prompName = prompName || '--'
  244. })
  245. this.showEmpty = this.dataSource.length <= 0
  246. this.tableHeight = (this.showEmpty ? 300 : this.maxHeight) + 'px'
  247. this.spinning = false
  248. this.disabled = false
  249. },
  250. // 重置
  251. resetSearchForm () {
  252. this.dataSource = []
  253. this.clearSelectTable()
  254. this.searchTable()
  255. },
  256. pageInit (productForm, detailData, activeList) {
  257. this.productForm = Object.assign(this.productForm,productForm)
  258. this.detailData = detailData
  259. this.activeList = activeList
  260. // 获取活动列表
  261. this.resetSearchForm()
  262. },
  263. // 清空选项
  264. clearSelectTable () {
  265. this.selectedRowKeys = []
  266. },
  267. // 已选产品 blur
  268. cancelNumsChange (e, record) {
  269. const _this = this
  270. const val = e.target.value
  271. if (val && val != record.qtyBackups && val<=record.surplusQty) {
  272. _this.spinning = true
  273. updateQty({
  274. dispatchBillDetailSn: record.dispatchBillDetailSn,
  275. qty: record.qty,
  276. salesBillSn: _this.detailData.salesBillSn,
  277. dispatchBillSn: _this.productForm.dispatchBillSn
  278. }).then(res => {
  279. if (res.status == 200) {
  280. _this.$message.success(res.message)
  281. _this.spinning = false
  282. _this.$emit('refashTable', true)
  283. } else {
  284. record.qty = record.qtyBackups
  285. _this.spinning = false
  286. }
  287. })
  288. } else {
  289. record.qty = record.qtyBackups
  290. }
  291. },
  292. // 删除产品
  293. handleDel (row) {
  294. const _this = this
  295. this.$confirm({
  296. title: '提示',
  297. content: '确认要删除吗?',
  298. centered: true,
  299. closable: true,
  300. onOk () {
  301. _this.deleteFun(row, 0)
  302. }
  303. })
  304. },
  305. // 移除操作
  306. deleteFun (row, type) {
  307. const _this = this
  308. _this.spinning = true
  309. deleteBatch({
  310. dispatchBillSn: this.productForm.dispatchBillSn,
  311. dispatchBillDetailList : type == 0 ? [row.dispatchBillDetailSn] : row
  312. }).then(res => {
  313. if (res.status == 200) {
  314. _this.$emit('refashTable', true)
  315. _this.$message.success(res.message)
  316. _this.spinning = false
  317. } else {
  318. _this.spinning = false
  319. }
  320. })
  321. },
  322. // 批量删除
  323. delSalerDetailAll () {
  324. const _this = this
  325. const chooseList = this.selectedRowKeys
  326. if (chooseList.length == 0) {
  327. _this.$message.warning('请选择待下推产品!')
  328. return
  329. }
  330. const chooseRow = this.dataSource.filter(item => chooseList.includes(item.id) && item.id.indexOf('promo-')<0)
  331. const obj = []
  332. chooseRow && chooseRow.map(item => {
  333. obj.push(item.dispatchBillDetailSn)
  334. })
  335. this.$confirm({
  336. title: '提示',
  337. content: '确认要批量删除吗?',
  338. centered: true,
  339. closable: true,
  340. onOk () {
  341. _this.deleteFun(obj, 1)
  342. }
  343. })
  344. },
  345. }
  346. }
  347. </script>
  348. <style lang="less">
  349. .empty-data{
  350. color: #999;
  351. text-align: center;
  352. padding: 20px;
  353. }
  354. .ve-table-body-td{
  355. .active-title{
  356. display: flex;
  357. align-items: center;
  358. justify-content: space-between;
  359. padding: 10px;
  360. background: #f3f8fa;
  361. }
  362. }
  363. .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,
  364. .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{
  365. padding: 0;
  366. }
  367. .ve-table .ve-table-container .ve-table-content-wrapper{
  368. border-bottom: 1px solid #ddd;
  369. }
  370. </style>