queryPart.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. <template>
  2. <div class="productInfoList-wrap">
  3. <!-- 搜索条件 -->
  4. <div class="table-page-search-wrapper">
  5. <a-form layout="inline" @keyup.enter.native="searchTable">
  6. <a-row :gutter="15">
  7. <a-col :md="4" :sm="24">
  8. <a-form-item label="产品名称">
  9. <a-input id="productInfoList-name" v-model.trim="queryParam.productName" allowClear placeholder="请输入产品名称"/>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :md="4" :sm="24">
  13. <a-form-item label="产品编码">
  14. <a-input id="productInfoList-code" v-model.trim="queryParam.productCode" allowClear placeholder="请输入产品编码"/>
  15. </a-form-item>
  16. </a-col>
  17. <a-col :md="4" :sm="24" v-if="hasPrompActive">
  18. <a-form-item label="产品类型">
  19. <a-select allowClear v-model.trim="queryParam.promotionFlag" :dropdownMatchSelectWidth="false" placeholder="请选择产品类型">
  20. <a-select-option value="0">
  21. 正常产品
  22. </a-select-option>
  23. <a-select-option value="REGULAR">
  24. 正价产品(活动)
  25. </a-select-option>
  26. <a-select-option value="DISCOUNT">
  27. 特价产品
  28. </a-select-option>
  29. <a-select-option value="GIFT">
  30. 促销产品
  31. </a-select-option>
  32. <a-select-option value="GIFT1" v-if="showConvertPromoGifts">
  33. 促销产品(转采购额)
  34. </a-select-option>
  35. <a-select-option value="GATE">
  36. 门槛产品
  37. </a-select-option>
  38. </a-select>
  39. </a-form-item>
  40. </a-col>
  41. <a-col :md="4" :sm="24">
  42. <a-form-item label="下推类型">
  43. <a-select allowClear v-model.trim="queryParam.pushProductType" :dropdownMatchSelectWidth="false" placeholder="请选择下推类型">
  44. <a-select-option value="">
  45. 全部产品
  46. </a-select-option>
  47. <a-select-option value="ABLE">
  48. 剩余待下推数量>0的产品
  49. </a-select-option>
  50. <a-select-option value="ALL">
  51. 可全部下推的产品
  52. </a-select-option>
  53. <a-select-option value="NOTALL">
  54. 不可全部下推的产品
  55. </a-select-option>
  56. </a-select>
  57. </a-form-item>
  58. </a-col>
  59. <a-col :md="4" :sm="24">
  60. <a-form-item label="出库仓库">
  61. <chooseWarehouse ref="warehouse" v-model="queryParam.warehouseSn"></chooseWarehouse>
  62. </a-form-item>
  63. </a-col>
  64. <a-col :md="4" :sm="24" style="margin-bottom: 10px;">
  65. <a-button type="primary" @click="searchTable" :disabled="disabled" id="productInfoList-refresh">查询</a-button>
  66. <a-button style="margin-left: 5px" @click="resetSearchForm(null)" id="productInfoList-reset">重置</a-button>
  67. </a-col>
  68. </a-row>
  69. </a-form>
  70. </div>
  71. <!-- alert -->
  72. <div style="margin-bottom: 10px;display: flex;align-items: center;" v-if="detailData">
  73. <div style="display: flex;align-items: center;">
  74. <a-button type="primary" :disabled="newLoading" class="button-info" @click="handlePlAdd">批量添加</a-button>
  75. <a-button type="primary" :disabled="newLoading" class="button-info" v-if="showConvertPromoGifts" @click="handlePlPurchase">批量转采购额</a-button>
  76. <a-button type="primary" v-if="hasNormalProduct" ghost style="margin-left:6px;" :disabled="newLoading" @click="handlePlCancel">批量取消</a-button>
  77. <a-button type="primary" v-if="hasPrompActive&&hasNoPushedActive" ghost style="margin-left:6px;" :disabled="newLoading" @click="handleAllCancel">整单取消</a-button>
  78. <a-tooltip placement="top" v-if="hasPrompActive&&hasNoPushedActive" style="margin-left:6px;">
  79. <template slot="title">
  80. <span>参加促销活动的产品,不能单独取消,只能整单取消。</span>
  81. </template>
  82. <a-icon style="font-size: 14px;" type="question-circle" />
  83. </a-tooltip>
  84. <span style="margin-left: 10px;" v-if="selectedRowKeys.length">已选 {{ selectedRowKeys.length }} 项</span>
  85. </div>
  86. <div style="padding-left: 20px;">
  87. 总销售数量:<strong>{{ detailData&&(detailData.totalQty || detailData.totalQty==0) ? detailData.totalQty : '--' }}</strong>;
  88. 已取消数量:<strong>{{ detailData&&(detailData.totalCancelQty || detailData.totalCancelQty==0) ? detailData.totalCancelQty : '--' }}</strong>;
  89. 已下推数量:<strong>{{ detailData&&(detailData.totalPushedQty || detailData.totalPushedQty==0) ? detailData.totalPushedQty : '--' }}</strong>;
  90. 待下推数量:<strong>{{ detailData&&(detailData.totalUnpushedQty || detailData.totalUnpushedQty==0) ? detailData.totalUnpushedQty : '--' }}</strong>;
  91. <span v-if="$hasPermissions('B_salesDispatch_salesPrice')">总售价:<strong>{{ detailData&&(detailData.totalAmount || detailData.totalAmount==0) ? toThousands(detailData.totalAmount) : '--' }}</strong>;</span>
  92. <span v-if="$hasPermissions('B_salesDispatch_costPrice')">总成本:<strong>{{ detailData&&(detailData.totalCost || detailData.totalCost==0) ? toThousands(detailData.totalCost) : '--' }}</strong>;</span>
  93. <span v-if="$hasPermissions('B_salesDispatch_costPrice')&&$hasPermissions('B_salesDispatch_salesPrice')">总毛利:<strong>{{ detailData&&(detailData.grossProfit || detailData.grossProfit==0) ? toThousands(detailData.grossProfit) : '--' }}</strong>;</span>
  94. <span v-if="$hasPermissions('B_salesDispatch_salesPrice')">已取消金额:<strong>{{ detailData&&(detailData.totalCancelAmount || detailData.totalCancelAmount==0) ? toThousands(detailData.totalCancelAmount) : '--' }}</strong>;</span>
  95. <span v-if="$hasPermissions('B_salesDispatch_salesPrice')">已下推金额:<strong>{{ detailData&&(detailData.totalPushedAmount || detailData.totalPushedAmount==0) ? toThousands(detailData.totalPushedAmount) :'--' }}</strong>;</span>
  96. <span v-if="$hasPermissions('B_salesDispatch_salesPrice')">待下推金额:<strong>{{ detailData&&(detailData.totalUnpushedAmount || detailData.totalUnpushedAmount==0) ? toThousands(detailData.totalUnpushedAmount) : '--' }}</strong>;</span>
  97. <span v-if="$hasPermissions('B_salesDispatch_salesPrice')&&detailData&&detailData.totalConvertPromoGiftsAmount">促销产品转采购额金额:<strong>{{ toThousands(detailData.totalConvertPromoGiftsAmount) }}</strong>;</span>
  98. </div>
  99. </div>
  100. <a-spin :spinning="spinning" tip="Loading...">
  101. <ve-table
  102. border-y
  103. v-show="!showEmpty"
  104. :scroll-width="0"
  105. :max-height="tableHeight"
  106. :show-header="showTableHead"
  107. :row-style-option="{clickHighlight: true}"
  108. :cellSelectionOption="{enable: false}"
  109. :virtual-scroll-option="{enable: true}"
  110. :columns="columns"
  111. :table-data="tableData"
  112. row-key-field-name="id"
  113. :cell-style-option="cellStyleOption"
  114. :cell-span-option="cellSpanOption"
  115. :column-width-resize-option="columnWidthResizeOption"
  116. :checkbox-option="checkboxOption"
  117. />
  118. <div v-show="showEmpty" class="empty-data"><a-empty description="暂无产品" :image="simpleImage"/></div>
  119. <!-- 活动规则详情 -->
  120. <detailModal :openModal="openDetailModal" :itemSn="detailSn" @close="closeDetailModal"></detailModal>
  121. </a-spin>
  122. </div>
  123. </template>
  124. <script>
  125. import { commonMixin } from '@/utils/mixin'
  126. import { salesPromoQueryList } from '@/api/salesNew'
  127. import detailModal from '@/views/promotionRulesManagement/dealerPromotions/detailModal.vue'
  128. import { Empty } from 'ant-design-vue';
  129. import { salesDetailAllList, salesPromoDetailCount, salesDetaiCount } from '@/api/salesDetailNew'
  130. import { STable, VSelect } from '@/components'
  131. import chooseWarehouse from '@/views/common/chooseWarehouse'
  132. export default {
  133. name: 'QueryPart',
  134. mixins: [commonMixin],
  135. components: { STable, VSelect, chooseWarehouse, detailModal },
  136. props: {
  137. newLoading: {
  138. type: Boolean,
  139. default: false
  140. },
  141. maxHeight:{
  142. type: [String,Number],
  143. default: '300'
  144. },
  145. showHeader: {
  146. type: Boolean,
  147. default: true
  148. }
  149. },
  150. data () {
  151. return {
  152. advanced: true, // 高级搜索 展开/关闭
  153. openDetailModal: false,
  154. simpleImage: Empty.PRESENTED_IMAGE_SIMPLE,
  155. detailSn: null,
  156. productType: [],
  157. salesBillSn: '',
  158. detailData: null,
  159. queryParam: {
  160. pushProductType: '', // 类型
  161. productCode: '', // 产品编码
  162. productName: '', // 产品名称
  163. promotionFlag: undefined, // 是否促销品
  164. brandSn: undefined, // 产品品牌
  165. productTypeSn1: '', // 产品一级分类
  166. productTypeSn2: '', // 产品二级分类
  167. productTypeSn3: '', // 产品三级分类
  168. salesBillSn: '',
  169. warehouseSn: undefined,
  170. convertPromoGiftsFlag: undefined
  171. },
  172. disabled: false, // 查询、重置按钮是否可操作
  173. activeList: [], // 活动列表
  174. spinning: false,
  175. dataSource: [],
  176. tableData: [],
  177. cellStyleOption: {
  178. bodyCellClass: ({ row, column, rowIndex }) => {
  179. if (row.id.indexOf('promo-')>=0 && column.field === "no") {
  180. return "table-body-cell-no";
  181. }
  182. },
  183. },
  184. columnWidthResizeOption: {
  185. // default false
  186. enable: true,
  187. // column resize min width
  188. minWidth: 50
  189. },
  190. cellSpanOption: {
  191. bodyCellSpan: this.bodyCellSpan,
  192. },
  193. showEmpty: false,
  194. showTableHead: true,
  195. disableSelectedRowKeys: [],
  196. selectedRowKeys: [],
  197. colspanNums: 16,
  198. hasNormalProduct: false,
  199. }
  200. },
  201. computed: {
  202. tableHeight(){
  203. return (this.showEmpty ? 200 : this.maxHeight) + 'px'
  204. },
  205. hasPrompActive(){
  206. return this.detailData&&this.detailData.promoFlag==1
  207. },
  208. hasNoPushedActive(){
  209. return this.detailData&&this.detailData.totalPushedQty==0||!this.detailData.totalPushedQty
  210. },
  211. hasConvertPromoGifts(){
  212. return this.detailData&&this.detailData.totalConvertPromoGiftsAmount > 0
  213. },
  214. showConvertPromoGifts(){
  215. return this.activeList&&this.activeList.find(item => item.promotionRule&&item.promotionRule.convertExpenseFlag==1&&item.promotionRule.promotionRuleType=='BUY_PROD_GIVE_PROD')
  216. },
  217. checkboxOption () {
  218. return {
  219. disableSelectedRowKeys: this.disableSelectedRowKeys,
  220. selectedRowKeys: this.selectedRowKeys,
  221. // 行选择改变事件
  222. selectedRowChange: ({ row, isSelected, selectedRowKeys }) => {
  223. this.selectedRowChange({ row, isSelected, selectedRowKeys })
  224. },
  225. // 全选改变事件
  226. selectedAllChange: ({ isSelected, selectedRowKeys }) => {
  227. this.selectedAllChange({ isSelected, selectedRowKeys })
  228. },
  229. }
  230. },
  231. columns () {
  232. const _this = this
  233. const priceFormat = function(record,data,h){
  234. return (
  235. <div>
  236. {_this.toThousands(data)}
  237. {record.promotionFlag == 'GIFT' || record.promotionFlag == 'DISCOUNT' ? (
  238. <span title="原价">({ _this.toThousands(record.origPrice)})</span>
  239. ):''}
  240. </div>
  241. )
  242. }
  243. const numsFormat = function(data){
  244. return data || data == 0 ? data : '--'
  245. }
  246. const codeFormat = function(record,data,h){
  247. let ftext = ''
  248. let fcolor = ''
  249. if(record.promotionFlag == 'GIFT'){
  250. ftext = '促'
  251. fcolor = '#52c41a'
  252. }
  253. if(record.promotionFlag == 'GATE'){
  254. ftext = '槛'
  255. fcolor = '#108ee9'
  256. }
  257. return (
  258. <div>
  259. <span style="padding-right: 15px;">{data}</span>
  260. {ftext?(<a-badge count={ftext} number-style={{ backgroundColor: fcolor, zoom:'80%' }}></a-badge>):''}
  261. {record.convertPromoGiftsFlag == '1'?(<a-badge count="转" number-style={{ backgroundColor: '#ffaa00', zoom:'80%' }}></a-badge>):''}
  262. {Number(record.stockQty||0) < Number(record.unpushedQty||0)?(<a-badge count="缺" number-style={{ zoom:'80%' }}></a-badge>):''}
  263. </div>
  264. )
  265. }
  266. // 取消数量输入框
  267. const inputFormat = function(record,data,h) {
  268. if(record.unpushedQty>0){
  269. return (
  270. <div>
  271. <a-input-number
  272. size="small"
  273. value={record.cancelNums}
  274. onChange={e => _this.cancelNumsChange(e,record)}
  275. precision={0}
  276. min={0}
  277. max={record.unpushedQty}
  278. style="width: 100%;"
  279. placeholder="请输入" />
  280. </div>
  281. )
  282. }
  283. return '--'
  284. }
  285. // 转采购额数量输入框
  286. const inputFormat1 = function(record,data,h) {
  287. if(record.unpushedQty>=0){
  288. // 已选
  289. if(_this.selectedRowKeys.includes(record.id) && record.convertPromoGiftsFlag == 1){
  290. return (
  291. <div>
  292. <a-input-number
  293. size="small"
  294. value={record.convertPromoGiftsQty}
  295. onChange={e => _this.convertPromoGiftsChange(e,record)}
  296. precision={0}
  297. min={0}
  298. max={record.maxConvertNums}
  299. style="width: 100%;"
  300. placeholder="请输入" />
  301. </div>
  302. )
  303. }else{
  304. return record.convertPromoGiftsQty || 0
  305. }
  306. }
  307. return '--'
  308. }
  309. // 操作按钮
  310. const actionFormat = function(record,data,h) {
  311. if(record.unpushedQty>0){
  312. return (
  313. <div>
  314. <a-button
  315. size="small"
  316. type="link"
  317. class="button-info"
  318. onClick={()=>_this.handleAdd(record)}
  319. >添加</a-button>
  320. </div>
  321. )
  322. }
  323. return '--'
  324. }
  325. // 编号,并且格式化活动分类行
  326. const noFormat = function(record,data,h){
  327. return (
  328. <div>
  329. {record.id.indexOf('promo-')>=0 ? (
  330. <div class="active-title">
  331. {record.promo?(
  332. <div>
  333. <strong style="font-size:14px;">{record.promo.promotion.description} </strong>
  334. <span>({record.promo.promotionRule.description})</span>
  335. <span style="margin-left:20px;color:#00aaff;cursor: pointer;" onClick={()=>_this.showDesc(record.promo)}>
  336. <a-icon title="查看活动详情" type="eye"/> 活动详情
  337. </span>
  338. </div>
  339. ):(<div></div>)}
  340. <div>
  341. 款数:<strong>{record.total&&record.total.totalCategory||'--'}</strong>;
  342. 数量:<strong>{record.total&&record.total.totalQty||'--'}</strong>;
  343. {_this.$hasPermissions('B_salesEdit_salesPrice') ? (<span>总金额:<strong>{record.total&&record.total.totalAmount||'--'}</strong>;</span>):('')}
  344. {_this.$hasPermissions('B_salesEdit_salesPrice')&&record.promo&&record.total&&record.total.lossAmount ? (<span>优惠金额:<strong>{record.total.lossAmount}</strong>;</span>):('')}
  345. {_this.$hasPermissions('B_salesEdit_salesPrice')&&record.promo&&record.total&&record.total.cgejyAmount>0 ? (<span>采购额结余:<strong>{_this.toThousands(record.total.cgejyAmount)}</strong>;</span>):('')}
  346. {_this.$hasPermissions('B_salesEdit_salesPrice')&&record.promo&&record.total&&record.total.cgejyAmount<0 ? (<span>采购额超出:<strong>{_this.toThousands(record.total.cgeccAmount)}</strong>;</span>):('')}
  347. {_this.$hasPermissions('B_salesEdit_salesPrice')&&record.promo&&record.total&&record.total.convertPromoGiftsAmount ? (<span>促销产品转采购额金额:<strong>{record.total&&record.total.convertPromoGiftsAmount||'--'}</strong>;</span>):('')}
  348. {record.expenseAccountFlag!='WAIT' ? record.expenseAccountFlagDictValue : ''}
  349. </div>
  350. </div>
  351. ):(<span>{data}</span>)}
  352. </div>
  353. )
  354. }
  355. let arr= [
  356. { title: "", field: "", key: "acheck", width: 50, type: "checkbox", align: "center" },
  357. { title: '序号', field: 'no',key: "a", width: 50, align: 'center', operationColumn: false,renderBodyCell: ({ row, column, rowIndex }, h) => { return noFormat(row,row[column.field],h)} },
  358. { title: '产品编码', field: 'productCode',key: "b", width: 150, align: 'left',operationColumn: false,renderBodyCell: ({ row, column, rowIndex }, h) => { return codeFormat(row,row[column.field],h)} },
  359. { title: '产品名称', field: 'productName',key: "c", width: 250, align: 'left',operationColumn: false , ellipsis: { showTitle: true },renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--'}},
  360. { title: '原厂编码', field: 'productOrigCode',key: "d", width: 150, align: 'left',operationColumn: false,ellipsis: { showTitle: true },renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--'} },
  361. { title: '出库仓库', field: 'warehouseName',key: "e", width: 100, align: 'center',operationColumn: false,renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--'}}
  362. ]
  363. this.colspanNums = this.showConvertPromoGifts ? 7 : 6
  364. if (this.$hasPermissions('B_salesDispatch_salesPrice')) { // 售价权限
  365. this.colspanNums = this.colspanNums + 1
  366. arr.push({ title: '销售价', field: 'price', width: 80,key: "f", align: 'right',operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return priceFormat(row,row[column.field],h)} })
  367. }
  368. if (this.$hasPermissions('B_salesDispatch_costPrice')) {
  369. this.colspanNums = this.colspanNums + 1
  370. arr.push({ title: '成本价', field: 'showCost', width: 80,key: "g", align: 'right',operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return _this.toThousands(row[column.field])||'--'} })
  371. }
  372. this.colspanNums = this.colspanNums + 8
  373. arr = arr.concat([
  374. { title: '单位', field: 'productOrigUnit',key: "i", width: 80, align: 'center',operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return row[column.field] || '--'}},
  375. { title: '可用库存', field: 'stockQty', width: 80,key: "j", align: 'center',fixed: 'right',operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field])} },
  376. { title: '销售数量', field: 'qty', width: 80,key: "k", align: 'center',operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field])} },
  377. { title: '已取消', field: 'cancelQty', width: 80,key: "o", align: 'center',operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field])} },
  378. { title: '已下推', field: 'pushedQty', width: 80,key: "p", align: 'center',operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field])} },
  379. { title: '待下推', field: 'unpushedQty', width: 80,key: "q", align: 'center',operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return numsFormat(row[column.field])} },
  380. { title: '取消数量', field: 'cancelNums', width: 80,key: "r", align: 'center',fixed: 'right',operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => { return inputFormat(row,row[column.field],h)} },
  381. ])
  382. if(this.showConvertPromoGifts){
  383. arr.push({ title: '转采购额数量', field: 'convertPromoGiftsQty', width: 80,key: "z", align: 'center',fixed: 'right',operationColumn: false, renderBodyCell: ({ row, column, rowIndex }, h) => {
  384. return inputFormat1(row,row[column.field],h)
  385. } })
  386. }
  387. arr.push({ 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)} })
  388. return arr
  389. }
  390. },
  391. methods: {
  392. // 查看活动详情
  393. showDesc(row){
  394. this.detailSn = row.promoRuleSn
  395. this.openDetailModal = true
  396. },
  397. // 关闭详情弹窗
  398. closeDetailModal () {
  399. this.detailSn = null
  400. this.openDetailModal = false
  401. },
  402. // 合并活动分类单元格
  403. bodyCellSpan({ row, column, rowIndex }) {
  404. if (row.id.indexOf('promo-')>=0) {
  405. if(column.field=='no'){
  406. return {
  407. rowspan: 1,
  408. colspan: this.colspanNums,
  409. };
  410. }else{
  411. return {
  412. rowspan: 0,
  413. colspan: 0,
  414. }
  415. }
  416. }
  417. },
  418. cancelNumsChange(v,record){
  419. record.cancelNums = v
  420. this.dataSource.splice()
  421. },
  422. convertPromoGiftsChange(v,record){
  423. record.convertPromoGiftsQty = v
  424. this.dataSource.splice()
  425. },
  426. // 选择单元格
  427. selectedRowChange({ row, isSelected, selectedRowKeys }){
  428. // console.log(row, isSelected, selectedRowKeys);
  429. this.selectedRowKeys = selectedRowKeys;
  430. },
  431. // 全选行
  432. selectedAllChange({ isSelected, selectedRowKeys }){
  433. // console.log(isSelected, selectedRowKeys);
  434. this.selectedRowKeys = selectedRowKeys;
  435. },
  436. // 获取销售单参与的活动列表
  437. getActiveList(){
  438. salesPromoQueryList({ salesBillSn: this.salesBillSn }).then(res => {
  439. if(res.status == 200){
  440. this.activeList = res.data.filter(item => item.enabledFlag == 1) || []
  441. }
  442. this.$nextTick(()=>{
  443. this.searchTable()
  444. })
  445. })
  446. },
  447. async searchTable(){
  448. this.selectedRowKeys = []
  449. this.disableSelectedRowKeys = []
  450. this.dataSource = []
  451. this.disabled = true
  452. this.spinning = true
  453. this.queryParam.salesBillSn = this.salesBillSn
  454. this.queryParam.showStock = true
  455. const params = this.queryParam
  456. console.log(params)
  457. const active = this.activeList
  458. // 正常产品
  459. const hasSearchNormal = !params.promotionFlag || params.promotionFlag == 0
  460. const proList = hasSearchNormal ? await salesDetailAllList(params).then(res => res.data) : []
  461. const norTotal = hasSearchNormal ? await salesDetaiCount(params).then(res => res.data) : null
  462. // 是否有正常产品
  463. this.hasNormalProduct = proList.length > 0
  464. //没有活动时不显示统计
  465. let listData = active.length ? (proList.length ? [{
  466. id: 'promo-normal',
  467. total: norTotal
  468. },...proList] : []) : proList
  469. if(params.promotionFlag != 0){
  470. // 循环获取活动产品
  471. for(let i=0;i<active.length;i++){
  472. const promo = active[i]
  473. const activeParams = {
  474. promoRuleSn: promo.promoRuleSn,
  475. promoSn: promo.promoSn,
  476. salesPromoSn: promo.salesPromoSn,
  477. ...params
  478. }
  479. // 获取活动产品统计
  480. const acTotal = await salesPromoDetailCount(activeParams).then(res => res.data)
  481. if(acTotal){
  482. // 采购额结余
  483. acTotal.cgejyAmount = Number(acTotal.totalPromoGiftsAmount||0) - Number(acTotal.totalUsePromoGiftsAmount||0)
  484. // 采购额超出
  485. acTotal.cgeccAmount = Number(acTotal.totalUsePromoGiftsAmount||0) - Number(acTotal.totalPromoGiftsAmount||0)
  486. }
  487. // 有数据时才调用接口,避免做无用的调用
  488. if(acTotal&&acTotal.totalQty){
  489. // 获取活动产品列表
  490. const aclist = await salesDetailAllList(activeParams).then(res => res.data)
  491. const retList = aclist.length ? [{
  492. id: 'promo-'+i,
  493. promo: promo,
  494. total: acTotal
  495. },...aclist] : []
  496. // 将活动产品数据拼接
  497. listData = aclist&&aclist.length ? listData.concat(retList) : listData
  498. }
  499. }
  500. // 如果活动没有任何产品
  501. if(active.length){
  502. const hasAcp = listData.filter(item => item.id!='promo-normal').filter(item => item.id.indexOf("promo-")>=0)
  503. if(hasAcp && hasAcp.length==0){
  504. listData = listData.filter(item => item.id.indexOf("promo-")<0) || []
  505. }
  506. }
  507. }
  508. console.log(listData)
  509. this.dataSource = listData
  510. // 格式化数据
  511. let f = 0
  512. this.dataSource.map((item,i) => {
  513. if(item.id.indexOf('promo-')>=0){f = f - 1}
  514. item.no = i + 1 + f
  515. const productCode = (item.productEntity && item.productEntity.code) || (item.dealerProductEntity && item.dealerProductEntity.code)
  516. const productName = (item.productEntity && item.productEntity.name) || (item.dealerProductEntity && item.dealerProductEntity.name)
  517. const productOrigCode = (item.productEntity && item.productEntity.origCode) || (item.dealerProductEntity && item.dealerProductEntity.origCode)
  518. const productOrigUnit = (item.productEntity && item.productEntity.unit) || (item.dealerProductEntity && item.dealerProductEntity.unit)
  519. item.productCode = productCode || '--'
  520. item.productName = productName || '--'
  521. item.productOrigCode = productOrigCode == ' ' ? '--' : productOrigCode
  522. item.productOrigUnit = productOrigUnit || '--'
  523. item.cancelNums = item.unpushedQty
  524. if(item.convertPromoGiftsFlag == 1){
  525. item.maxConvertNums = item.unpushedQty + item.convertPromoGiftsQty
  526. }else{
  527. item.maxConvertNums = 0
  528. }
  529. // 库存为0或待下推数为0,不可添加
  530. // if(!item.unpushedQty || item.unpushedQty<0){
  531. // this.disableSelectedRowKeys.push(item.id)
  532. // }
  533. })
  534. this.showEmpty = this.dataSource.length <= 0
  535. this.tableData = this.dataSource
  536. this.spinning = false
  537. this.disabled = false
  538. },
  539. // 重置
  540. resetSearchForm (detailData) {
  541. this.queryParam.pushProductType = ''
  542. this.queryParam.productCode = ''
  543. this.queryParam.productName = ''
  544. this.queryParam.promotionFlag = undefined
  545. this.queryParam.brandSn = undefined
  546. this.queryParam.productTypeSn1 = ''
  547. this.queryParam.productTypeSn2 = ''
  548. this.queryParam.productTypeSn3 = ''
  549. this.queryParam.warehouseSn = undefined
  550. this.queryParam.convertPromoGiftsFlag = undefined
  551. this.productType = []
  552. this.dataSource = []
  553. this.clearSelectTable()
  554. this.searchTable()
  555. if(detailData){
  556. this.detailData = detailData
  557. }
  558. },
  559. pageInit (salesBillSn, detailData) {
  560. this.salesBillSn = salesBillSn
  561. this.detailData = detailData
  562. // 获取活动列表
  563. this.getActiveList()
  564. },
  565. // 清空选项
  566. clearSelectTable () {
  567. this.selectedRowKeys = []
  568. },
  569. // 添加
  570. handleAdd (row) {
  571. if (row.stockQty > 0) { // 可用库存大于0才可添加
  572. this.$emit('addProduct', [row.salesBillDetailSn])
  573. } else {
  574. this.$message.warning('库存为0,不可添加!')
  575. }
  576. },
  577. // 批量转采购额
  578. handlePlPurchase(){
  579. const _this = this
  580. const chooseList = this.selectedRowKeys
  581. if (chooseList.length == 0) {
  582. _this.$message.warning('请先选择产品!')
  583. return
  584. }
  585. const chooseRow = this.dataSource.filter(item => chooseList.includes(item.id) && item.convertPromoGiftsFlag==1)
  586. const noChooseRow = this.dataSource.filter(item => chooseList.includes(item.id) && !item.convertPromoGiftsFlag)
  587. const obj = []
  588. const noObj = []
  589. noChooseRow && noChooseRow.map(item => {
  590. noObj.push(item.productCode)
  591. })
  592. chooseRow && chooseRow.map(item => {
  593. obj.push({
  594. 'convertPromoGiftsQty': item.convertPromoGiftsQty,
  595. 'salesBillDetailSn': item.salesBillDetailSn
  596. })
  597. })
  598. if(obj.length){
  599. this.$confirm({
  600. title: '提示',
  601. content: <div><div style="text-align:center;padding:10px 0;font-weight:bold;">确定将选中的促销产品转成采购额吗?</div>{noObj.length?<div style="text-align:center;"><div>总共选择了 {chooseList.length} 个产品,其中 {obj.length} 个产品可转采购额。</div><div style="color:red;"> 产品 ({noObj.toString()}) 不可转采购额!</div></div>:''}<div style="font-size:12px;color:#999;padding:10px 0;text-align:center;">
  602. 当该销售单完结后,可将采购额转成费用报销单。</div></div>,
  603. centered: true,
  604. closable: true,
  605. class: 'confirm-center',
  606. onOk () {
  607. _this.$emit('convertPromoGifts', obj)
  608. }
  609. })
  610. }else{
  611. _this.$message.warning('所选产品都不可转采购额!')
  612. }
  613. },
  614. // 批量添加
  615. handlePlAdd () {
  616. const _this = this
  617. const chooseList = this.selectedRowKeys
  618. if (chooseList.length == 0) {
  619. _this.$message.warning('请先选择产品!')
  620. return
  621. }
  622. const chooseRow = this.dataSource.filter(item => chooseList.includes(item.id) && item.stockQty > 0)
  623. const noStockRow = this.dataSource.filter(item => chooseList.includes(item.id) && !item.stockQty)
  624. const obj = []
  625. const noObj = []
  626. chooseRow && chooseRow.map(item => {
  627. obj.push(item.salesBillDetailSn)
  628. })
  629. noStockRow && noStockRow.map(item => {
  630. noObj.push(item.productCode)
  631. })
  632. if(obj.length){
  633. this.$confirm({
  634. title: '提示',
  635. content: <div><div style="text-align:center;padding:10px 0;font-weight:bold;">确认要批量添加到待下推列表吗?</div>{noObj.length?<div><div>总共选择了 {chooseList.length} 个产品,其中 {obj.length} 个产品可添加。</div><div> 产品 ({noObj.toString()}) 因库存为0不可添加!</div></div>:''}</div>,
  636. centered: true,
  637. closable: true,
  638. class: 'confirm-center',
  639. onOk () {
  640. _this.$emit('addProduct', obj)
  641. }
  642. })
  643. }else{
  644. _this.$message.warning('所选产品库存都为0,不可添加!')
  645. }
  646. },
  647. // 整单取消
  648. handleAllCancel () {
  649. const _this = this
  650. this.$confirm({
  651. title: '提示',
  652. content: '确定整单取消订单?',
  653. centered: true,
  654. closable: true,
  655. onOk () {
  656. _this.$emit('cancelAll')
  657. }
  658. })
  659. },
  660. // 批量取消
  661. handlePlCancel () {
  662. const _this = this
  663. const chooseList = this.selectedRowKeys
  664. if (chooseList.length == 0) {
  665. _this.$message.warning('请先选择产品!')
  666. return
  667. }
  668. const chooseRow = this.dataSource.filter(item => chooseList.includes(item.id) && item.id.indexOf('promo-')<0)
  669. const hasActive = chooseRow && chooseRow.filter(item => item.promotionFlag != 0)
  670. if(hasActive.length>0){
  671. _this.$message.warning('参与促销的产品只可进行整单取消!')
  672. return
  673. }
  674. const obj = []
  675. chooseRow && chooseRow.map(item => {
  676. obj.push({
  677. 'cancelQty': item.cancelNums,
  678. 'salesBillDetailSn': item.salesBillDetailSn
  679. })
  680. })
  681. this.$emit('cancelProduct', obj)
  682. }
  683. }
  684. }
  685. </script>
  686. <style lang="less">
  687. .empty-data{
  688. color: #999;
  689. text-align: center;
  690. padding: 20px;
  691. }
  692. .ve-table-body-td{
  693. .active-title{
  694. display: flex;
  695. align-items: center;
  696. justify-content: space-between;
  697. padding: 10px;
  698. background: #f3f8fa;
  699. }
  700. }
  701. .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,
  702. .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{
  703. padding: 0;
  704. }
  705. .ve-table .ve-table-container .ve-table-content-wrapper{
  706. border-bottom: 1px solid #ddd;
  707. }
  708. </style>