edit.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. <template>
  2. <div class="salesEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" @back="handleBack" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="salesEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. <span style="margin: 0 15px;color: #666;">客户名称:{{ detailData&&detailData.buyerName }}</span>
  9. <!-- <div style="margin: 0 15px;display:inline-block;color: #666;">
  10. <span>出库仓库:</span>
  11. <chooseWarehouse style="width:200px" :allowClear="false" ref="warehouse" v-model="warehouseSn" @change="handleWarehouse"></chooseWarehouse>
  12. </div> -->
  13. </template>
  14. </a-page-header>
  15. <a-card size="small" :bordered="false" class="salesEdit-cont">
  16. <div slot="title">
  17. <div class="p-title">
  18. 选择产品
  19. </div>
  20. </div>
  21. <!-- 查询配件列表 -->
  22. <queryPart ref="partQuery" :newLoading="isInster" @add="insterProduct"></queryPart>
  23. </a-card>
  24. <a-card size="small" :bordered="false" class="salesEdit-cont">
  25. <div slot="title">
  26. <a-row :gutter="15" type="flex">
  27. <a-col :span="2">
  28. <div class="p-title">
  29. 已选产品
  30. </div>
  31. </a-col>
  32. <a-col :span="16" v-if="activeName">
  33. <div class="p-notes">
  34. <a-icon style="color: #FF9900;" type="bell" /> 已选产品可参加<span>{{ activeName }}</span>的促销活动,促销产品为指定产品
  35. </div>
  36. </a-col>
  37. </a-row>
  38. </div>
  39. <!-- 总计 -->
  40. <a-alert type="info" style="margin-bottom: 10px;">
  41. <div slot="message" class="total-bar">
  42. <div>
  43. <span v-if="$hasPermissions('B_salesEdit_salesPrice')">总售价:<strong>{{ detailData&&(detailData.totalCommonAmount || detailData.totalCommonAmount==0) ? toThousands(detailData.totalCommonAmount) : '--' }}</strong>;</span>
  44. 总款数:<strong>{{ detailData&&(detailData.totalCommonCategory || detailData.totalCommonCategory==0) ? detailData.totalCommonCategory : '--' }}</strong>;
  45. 总数量:<strong>{{ detailData&&(detailData.totalCommonQty || detailData.totalCommonQty==0) ? detailData.totalCommonQty : '--' }}</strong>;
  46. </div>
  47. </div>
  48. </a-alert>
  49. <!-- 筛选条件 -->
  50. <div class="table-page-search-wrapper">
  51. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  52. <a-row :gutter="15">
  53. <a-col :md="4" :sm="24">
  54. <a-form-item label="出库仓库" prop="warehouseSn">
  55. <chooseWarehouse ref="warehouse" v-model="queryParam.warehouseSn"></chooseWarehouse>
  56. </a-form-item>
  57. </a-col>
  58. <a-col :md="4" :sm="24">
  59. <a-form-item label="产品编码" prop="productCode">
  60. <a-input id="salesEdit-productCode" v-model.trim="queryParam.productCode" placeholder="请输入产品编码" allowClear />
  61. </a-form-item>
  62. </a-col>
  63. <a-col :md="4" :sm="24">
  64. <a-form-item label="产品名称" prop="productName">
  65. <a-input id="salesEdit-productName" v-model.trim="queryParam.productName" placeholder="请输入产品名称" allowClear />
  66. </a-form-item>
  67. </a-col>
  68. <a-col :md="4" :sm="24">
  69. <a-form-item label="品牌">
  70. <ProductBrand id="salesEdit-productBrandSn" v-model="queryParam.productBrandSn"></ProductBrand>
  71. </a-form-item>
  72. </a-col>
  73. <a-col :md="4" :sm="24">
  74. <a-form-item label="产品分类">
  75. <productTypeAll placeholder="请选择产品分类" @change="changeProductType" v-model="productType" id="salesEdit-productType"></productTypeAll>
  76. </a-form-item>
  77. </a-col>
  78. <a-col :md="4" :sm="24" style="margin-bottom: 10px;">
  79. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="salesEdit-refresh">查询</a-button>
  80. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="salesEdit-reset">重置</a-button>
  81. </a-col>
  82. <a-col :md="24" :sm="24" style="text-align:right;">
  83. <span>已选{{ selectTotal }}项</span>
  84. <a-dropdown>
  85. <a-menu slot="overlay" @click="handleMenuClick">
  86. <a-menu-item key="0">
  87. 仓库设置
  88. </a-menu-item>
  89. <a-menu-item key="1">
  90. 删除已选项
  91. </a-menu-item>
  92. <a-menu-item key="2">
  93. 全部删除
  94. </a-menu-item>
  95. </a-menu>
  96. <a-button
  97. style="margin:0 15px;"
  98. type="primary"
  99. ghost> 批量操作 <a-icon type="down" /> </a-button>
  100. </a-dropdown>
  101. <a-button
  102. type="default"
  103. @click="openGuideModal=true">导入产品</a-button>
  104. </a-col>
  105. </a-row>
  106. </a-form>
  107. </div>
  108. <!-- 已选配件列表 -->
  109. <s-table
  110. class="sTable"
  111. ref="table"
  112. size="small"
  113. :rowKey="(record) => record.id"
  114. :columns="columns"
  115. :data="loadData"
  116. :row-selection="{ columnWidth: 40 }"
  117. @rowSelection="rowSelectionFun"
  118. :defaultLoadData="false"
  119. :scroll="{ y: 300 }"
  120. bordered>
  121. <!-- 产品编码 -->
  122. <template slot="productCode" slot-scope="text, record">
  123. <a-badge count="缺" v-if="Number(record.stockQty||0) < Number(record.unpushedQty||0)">
  124. <div style="padding-right: 15px;">{{ text }}</div>
  125. </a-badge>
  126. <span v-if="!(Number(record.stockQty||0) < Number(record.unpushedQty||0))">{{ text }}</span>
  127. </template>
  128. <!-- 产品名称 -->
  129. <template slot="productName" slot-scope="text, record">
  130. <div class="ellipsisCon">
  131. <a-tooltip placement="rightBottom">
  132. <template slot="title">
  133. <span>{{ text }}</span>
  134. </template>
  135. <span class="ellipsisText">{{ text }}</span>
  136. </a-tooltip>
  137. <a-badge :number-style="{ backgroundColor: '#52c41a' }" count="活动" v-if="record.promotableFlag == 1"></a-badge>
  138. </div>
  139. </template>
  140. <!-- 销售数量 -->
  141. <template slot="salesNums" slot-scope="text, record">
  142. <a-input-number
  143. id="salesEdit-qty"
  144. size="small"
  145. v-model="record.qty"
  146. :precision="0"
  147. :min="1"
  148. :max="99999999"
  149. placeholder="请输入"
  150. @blur="e => onCellBlur(e.target.value, record)"
  151. style="width: 100%;" />
  152. </template>
  153. <!-- 当前库存 -->
  154. <template slot="stockQty" slot-scope="text, record">
  155. <div v-if="record.stockQty || record.stockQty==0">
  156. <p style="margin: 0;" v-if="Number(record.stockQty) < Number(record.unpushedQty)">{{ record.stockQty }}(<span class="redStyle">缺{{ Number(record.unpushedQty||0) - Number(record.stockQty||0) }}</span>)</p>
  157. <p style="margin: 0;" v-else>{{ record.stockQty }}</p>
  158. </div>
  159. <span v-else>--</span>
  160. </template>
  161. <!-- 出库仓库 -->
  162. <template slot="warehouseBox" slot-scope="text, record">
  163. <chooseWarehouse style="width:100%;" :allowClear="false" ref="warehouseBox" v-model="record.warehouseSn" @change="handleWarehouseBox(record)"></chooseWarehouse>
  164. </template>
  165. <!-- 操作 -->
  166. <template slot="action" slot-scope="text, record">
  167. <a-button
  168. size="small"
  169. type="link"
  170. :loading="delLoading"
  171. class="button-error"
  172. @click="handleDel(record)"
  173. >删除</a-button>
  174. <a-button
  175. size="small"
  176. type="link"
  177. :loading="delLoading"
  178. class="button-warning"
  179. @click="handleSelCx(record)"
  180. v-if="record.promotableFlag == 1"
  181. >选择促销品</a-button>
  182. </template>
  183. </s-table>
  184. </a-card>
  185. <a-card size="small" :bordered="false" class="salesEdit-cont">
  186. <div slot="title">
  187. <div class="p-title">
  188. 已选促销品
  189. </div>
  190. </div>
  191. <!-- 总计 -->
  192. <a-alert type="info" style="margin-bottom: 10px;">
  193. <div slot="message" class="total-bar">
  194. <div>
  195. <span>总成本:<strong>{{ detailData&&(detailData.totalPromoCost || detailData.totalPromoCost==0) ? toThousands(detailData.totalPromoCost) : '--' }}</strong>;</span>
  196. 总款数:<strong>{{ detailData&&(detailData.totalPromoCategory || detailData.totalPromoCategory==0) ? detailData.totalPromoCategory : '--' }}</strong>;
  197. 总数量:<strong>{{ detailData&&(detailData.totalPromoQty || detailData.totalPromoQty==0) ? detailData.totalPromoQty : '--' }}</strong>;
  198. </div>
  199. <div>
  200. </div>
  201. </div>
  202. </a-alert>
  203. <!-- 已选促销品列表 -->
  204. <queryPromotable ref="promotable" :delLoading="delLoading" @onCellBlur="onCellBlur" @del="handleDel"></queryPromotable>
  205. </a-card>
  206. </a-spin>
  207. <div class="affix-cont">
  208. <a-button
  209. size="large"
  210. style="padding: 0 60px;"
  211. :disabled="spinning"
  212. type="primary"
  213. class="button-primary"
  214. @click="handleSubmit()"
  215. id="productInfoList-handleSubmit">提交</a-button>
  216. </div>
  217. <!-- 添加产品 -->
  218. <ChooseActive
  219. ref="activeProduct"
  220. :openModal="newActive"
  221. @ok="addNewActive"
  222. :newLoading="isInster"
  223. @close="closeActive"></ChooseActive>
  224. <!-- 导入产品 -->
  225. <importGuideModal :openModal="openGuideModal" :params="{salesBillSn: $route.params.sn}" @close="closeGuideModel" @ok="hanldeOk" />
  226. <!-- 仓库设置 -->
  227. <setWarehouse :show="openWarehouseModal" @ok="chooseWarehouseOk" @cancel="openWarehouseModal=false"></setWarehouse>
  228. <!-- 价格更新弹窗 -->
  229. <setPriceModal :show="priceUpdateModal" :totalRealAmount="updataData.totalRealAmount" :totalAmount="updataData.totalAmount" @ok="updatePrice" @cancel="priceUpdateModal=false"></setPriceModal>
  230. </div>
  231. </template>
  232. <script>
  233. import { commonMixin } from '@/utils/mixin'
  234. import { STable, VSelect } from '@/components'
  235. import queryPart from './queryPart.vue'
  236. import queryPromotable from './queryPromotable.vue'
  237. import ChooseActive from './chooseActive.vue'
  238. import ImportGuideModal from './importGuideModal.vue'
  239. import setWarehouse from './setWarehouse.vue'
  240. import setPriceModal from './setPriceModal.vue'
  241. import chooseWarehouse from '@/views/common/chooseWarehouse'
  242. import ProductBrand from '@/views/common/productBrand.js'
  243. import productTypeAll from '@/views/common/productTypeAll.js'
  244. import { salesModify, salesDetailBySn, salesWriteSubmit, getPromoacActiveList, deleteAll, submitCheck, updateBatch, updateWarehouse } from '@/api/sales'
  245. import { salesDetailStockList, salesDetailInsert, salesDetailUpdateQty, salesDetailDel, salesDetailBatchDel, addPromoGoods, salesBatchInsert } from '@/api/salesDetail'
  246. export default {
  247. name: 'SalesEdit',
  248. mixins: [commonMixin],
  249. components: { STable,
  250. VSelect,
  251. queryPart,
  252. queryPromotable,
  253. ChooseActive,
  254. ImportGuideModal,
  255. chooseWarehouse,
  256. setWarehouse,
  257. setPriceModal,
  258. ProductBrand,
  259. productTypeAll },
  260. data () {
  261. return {
  262. spinning: false,
  263. salesBillSn: null, // 销售单sn
  264. disabled: false, // 查询、重置按钮是否可操作
  265. chooseDisabled: false,
  266. isInster: false, // 是否正在添加产品
  267. delLoading: false,
  268. newActive: false, // 选择促销品
  269. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  270. dataSource: [],
  271. productForm: {
  272. salesBillSn: '',
  273. promotionFlag: 0
  274. },
  275. openWarehouseModal: false, // 打开仓库设置
  276. warehouseSn: undefined,
  277. activeName: '', // 促销活动
  278. nowData: null,
  279. // 加载数据方法 必须为 Promise 对象
  280. loadData: parameter => {
  281. this.disabled = true
  282. this.productForm.salesBillSn = this.$route.params.sn
  283. return salesDetailStockList(Object.assign(parameter, this.productForm, this.queryParam)).then(res => {
  284. let data
  285. if (res.status == 200) {
  286. data = res.data
  287. const no = (data.pageNo - 1) * data.pageSize
  288. for (var i = 0; i < data.list.length; i++) {
  289. data.list[i].no = no + i + 1
  290. data.list[i].qtyBackups = data.list[i].qty
  291. }
  292. this.disabled = false
  293. this.dataSource = data.list
  294. this.$refs.promotable.getData(this.salesBillSn)
  295. }
  296. return data
  297. })
  298. },
  299. openGuideModal: false, // 导入产品引导
  300. queryParam: {
  301. warehouseSn: undefined,
  302. productCode: '',
  303. productName: '',
  304. productBrandSn: undefined,
  305. productTypeSn1: '', // 产品一级分类
  306. productTypeSn2: '', // 产品二级分类
  307. productTypeSn3: '' // 产品三级分类
  308. },
  309. productType: [],
  310. rowSelectionInfo: null,
  311. priceUpdateModal: false, // 价格更新弹窗
  312. updataData: {
  313. totalRealAmount: '',
  314. totalAmount: ''
  315. }
  316. }
  317. },
  318. computed: {
  319. selectTotal () {
  320. return this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length || 0
  321. },
  322. columns () {
  323. const arr = [
  324. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  325. { title: '产品编码', dataIndex: 'productEntity.code', scopedSlots: { customRender: 'productCode' }, width: '13%', align: 'center', sorter: true },
  326. { title: '产品名称', dataIndex: 'productEntity.name', scopedSlots: { customRender: 'productName' }, width: '20%', align: 'left' },
  327. // { title: '售价', dataIndex: 'price', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  328. { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: '8%', align: 'center' },
  329. { title: '库存', dataIndex: 'stockQty', scopedSlots: { customRender: 'stockQty' }, width: '8%', align: 'center' },
  330. { title: '出库仓库', scopedSlots: { customRender: 'warehouseBox' }, width: '15%', align: 'center' },
  331. { title: '单位', dataIndex: 'productEntity.unit', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  332. // { title: '售价小计', dataIndex: 'totalAmount', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  333. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  334. ]
  335. if (this.$hasPermissions('B_salesEdit_salesPrice')) { // 售价权限
  336. arr.splice(3, 0, { title: '售价', dataIndex: 'price', width: '8%', align: 'right', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') })
  337. arr.splice(7, 0, { title: '售价小计', dataIndex: 'totalAmount', width: '8%', align: 'right', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') })
  338. }
  339. return arr
  340. }
  341. },
  342. methods: {
  343. // 设置单个出库仓库
  344. handleWarehouseBox (row) {
  345. const snArr = [row.salesBillDetailSn]
  346. const ajax_data = {
  347. warehouseSn: row.warehouseSn,
  348. salesBillDetailSnList: snArr,
  349. salesBillSn: this.$route.params.sn
  350. }
  351. this.setWarehouseInfo(ajax_data)
  352. },
  353. chooseWarehouseOk (sn) {
  354. const _this = this
  355. const snArr = []
  356. _this.rowSelectionInfo.selectedRows.forEach(item => {
  357. snArr.push(item.salesBillDetailSn)
  358. })
  359. const ajax_data = {
  360. warehouseSn: sn,
  361. salesBillDetailSnList: snArr,
  362. salesBillSn: _this.$route.params.sn
  363. }
  364. _this.setWarehouseInfo(ajax_data)
  365. },
  366. setWarehouseInfo (data) {
  367. const _this = this
  368. _this.spinning = true
  369. updateWarehouse(data).then(res => {
  370. if (res.status == 200) {
  371. _this.openWarehouseModal = false
  372. _this.resetSearchForm(true)
  373. _this.$refs.promotable.resetCurForm()
  374. _this.$message.success(res.message)
  375. }
  376. _this.$refs.table.refresh(true)
  377. _this.spinning = false
  378. })
  379. },
  380. // 产品分类 change
  381. changeProductType (val, opt) {
  382. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  383. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  384. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  385. },
  386. // 选择仓库
  387. handleWarehouse (val) {
  388. this.warehouseSn = val
  389. const _this = this
  390. _this.spinning = true
  391. salesModify({
  392. id: _this.detailData.id,
  393. warehouseSn: val
  394. }).then(res => {
  395. if (res.status == 200) {
  396. _this.$refs.partQuery.resetCurForm()
  397. _this.$refs.table.refresh(true)
  398. _this.spinning = false
  399. } else {
  400. _this.spinning = false
  401. _this.warehouseSn = _this.$route.params.wSn
  402. }
  403. })
  404. },
  405. handleMenuClick (e) {
  406. const _this = this
  407. if (e.key == 0) { // 仓库设置
  408. if (!_this.rowSelectionInfo || (_this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  409. _this.$message.warning('请先选择要设置的产品!')
  410. } else {
  411. _this.openWarehouseModal = true
  412. }
  413. } else if (e.key == 1) { // 删除已选项
  414. this.handleBatchDel()
  415. } else {
  416. this.handleBatchDelAll()
  417. }
  418. },
  419. // 表格选中项
  420. rowSelectionFun (obj) {
  421. this.rowSelectionInfo = obj || null
  422. },
  423. handleBatchDelAll () {
  424. const _this = this
  425. if (_this.dataSource.length == 0) {
  426. _this.$message.warning('暂无可删除的已选产品!')
  427. return
  428. }
  429. this.$confirm({
  430. title: '提示',
  431. content: '确认要删除全部已选产品吗?',
  432. centered: true,
  433. onOk () {
  434. _this.spinning = true
  435. deleteAll({ salesBillSn: _this.productForm.salesBillSn }).then(res => {
  436. if (res.status == 200) {
  437. _this.resetSearchForm(true)
  438. _this.$refs.promotable.resetCurForm()
  439. _this.$message.success(res.message)
  440. }
  441. _this.spinning = false
  442. })
  443. }
  444. })
  445. },
  446. // 批量删除已选产品
  447. handleBatchDel () {
  448. const _this = this
  449. if (!_this.rowSelectionInfo || (_this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  450. _this.$message.warning('请先选择要删除的产品后再进行批量操作!')
  451. return
  452. }
  453. const obj = []
  454. _this.rowSelectionInfo && _this.rowSelectionInfo.selectedRows.map(item => {
  455. obj.push(item.salesBillDetailSn)
  456. })
  457. this.$confirm({
  458. title: '提示',
  459. content: '已选产品' + obj.length + '项,确认要批量删除吗?',
  460. centered: true,
  461. onOk () {
  462. _this.spinning = true
  463. salesDetailBatchDel({
  464. salesBillSn: _this.salesBillSn,
  465. salesBillDetailSnList: obj
  466. }).then(res => {
  467. if (res.status == 200) {
  468. _this.resetSearchForm(true)
  469. _this.$refs.promotable.resetCurForm()
  470. _this.$message.success(res.message)
  471. }
  472. _this.spinning = false
  473. })
  474. }
  475. })
  476. },
  477. // 已选产品 blur
  478. onCellBlur (val, record) {
  479. const _this = this
  480. // 光标移出,值发生改变再调用编辑接口
  481. if (val && val != record.qtyBackups) {
  482. _this.spinning = true
  483. salesDetailUpdateQty({
  484. salesBillDetailSn: record.salesBillDetailSn,
  485. qty: record.qty,
  486. salesBillSn: _this.salesBillSn
  487. }).then(res => {
  488. _this.resetSearchForm(true)
  489. _this.$refs.promotable.resetCurForm()
  490. if (res.status == 200) {
  491. _this.$message.success(res.message)
  492. }
  493. _this.spinning = false
  494. })
  495. } else {
  496. record.qty = record.qtyBackups
  497. }
  498. },
  499. chooseResetSearchForm () {
  500. this.queryParam.productCode = ''
  501. this.queryParam.productName = ''
  502. this.queryParam.warehouseSn = undefined
  503. this.$refs.table.refresh(true)
  504. },
  505. // 重置
  506. resetSearchForm (flag) {
  507. this.queryParam.productCode = ''
  508. this.queryParam.productName = ''
  509. this.queryParam.warehouseSn = undefined
  510. this.queryParam.productBrandSn = undefined
  511. this.queryParam.productTypeSn1 = ''
  512. this.queryParam.productTypeSn2 = ''
  513. this.queryParam.productTypeSn3 = ''
  514. this.productType = []
  515. this.$refs.table.refresh(!!flag)
  516. this.getPromoacActiveList()
  517. this.getOrderDetail(false)
  518. this.$refs.table.clearSelected() // 清空表格选中项
  519. },
  520. // 返回
  521. handleBack () {
  522. this.$router.push({ path: '/salesManagement/salesQuery/list', query: { closeLastOldTab: true } })
  523. },
  524. // 删除产品
  525. handleDel (row) {
  526. const _this = this
  527. this.$confirm({
  528. title: '提示',
  529. content: '确认要删除吗?',
  530. centered: true,
  531. closable: true,
  532. onOk () {
  533. _this.delLoading = true
  534. _this.spinning = true
  535. salesDetailDel({ salesBillDetailSn: row.salesBillDetailSn, salesBillSn: _this.salesBillSn }).then(res => {
  536. if (res.status == 200) {
  537. _this.resetSearchForm(true)
  538. _this.$refs.promotable.resetCurForm()
  539. _this.$message.success(res.message)
  540. }
  541. _this.delLoading = false
  542. _this.spinning = false
  543. })
  544. }
  545. })
  546. },
  547. // 添加产品
  548. insterProduct (row, promotionFlag) {
  549. console.log(row)
  550. // 防止多次添加产品
  551. if (this.isInster) { return }
  552. const _this = this
  553. _this.saveNewProduct(row, promotionFlag)
  554. },
  555. // 保存添加的产品到销售列表
  556. saveNewProduct (row, promotionFlag) {
  557. this.$message.loading('正在添加产品...', 1)
  558. this.isInster = true
  559. this.spinning = true
  560. salesDetailInsert({
  561. packQty: row.productPackQty,
  562. productSn: row.productSn,
  563. showCost: row.lastStockCost,
  564. price: row.productPrice,
  565. origPrice: row.productPrice,
  566. promotionGiftsAmount: 0,
  567. usePromotionGiftsAmount: 0,
  568. qty: row.salesNums,
  569. salesBillSn: this.detailData.salesBillSn,
  570. salesBillNo: this.detailData.salesBillNo,
  571. purchaseBillSn: this.detailData.purchaseBillSn,
  572. purchaseBillNo: this.detailData.purchaseBillNo,
  573. stockSn: row.stockSn,
  574. promotableFlag: row.isJoinActivityProduct || 0, // 可促销标记 有活动的传1,没活动的传0
  575. promotionFlag: promotionFlag, // 促销标记 正品传0,促销品传1
  576. warehouseSn: row.warehouseSn
  577. }).then(res => {
  578. if (res.status == 200) {
  579. this.resetSearchForm()
  580. this.$message.success('产品添加成功', 2.5)
  581. this.spinning = false
  582. } else {
  583. this.spinning = false
  584. }
  585. this.isInster = false
  586. }).catch(err => {
  587. this.isInster = false
  588. })
  589. },
  590. // 销售单详情
  591. getOrderDetail (flag) {
  592. salesDetailBySn({ salesBillSn: this.$route.params.sn }).then(res => {
  593. if (res.status == 200) {
  594. this.detailData = res.data
  595. if (flag) {
  596. this.$refs.partQuery.pageInit(this.detailData && this.detailData.buyerSn || '')
  597. }
  598. }
  599. })
  600. },
  601. // 提交销售单
  602. handleSubmit () {
  603. // 先不提交,先判断是否有价格更新 (下级创建时判断)
  604. if (this.detailData && this.detailData.salesBillSource && this.detailData.salesBillSource == 'PURCHASE') {
  605. submitCheck({ salesBillSn: this.salesBillSn }).then(res => {
  606. if (res.status == 200) {
  607. if (res.data.detailList.length > 0) {
  608. this.updataData = res.data
  609. const _this = this
  610. this.$nextTick(() => {
  611. _this.priceUpdateModal = true
  612. })
  613. } else {
  614. const ajax_data = { salesBillSn: this.salesBillSn }
  615. this.submitResult(ajax_data)
  616. }
  617. }
  618. })
  619. } else {
  620. const ajax_data = { salesBillSn: this.salesBillSn }
  621. this.submitResult(ajax_data)
  622. }
  623. },
  624. // 提交
  625. submitResult (data) {
  626. this.spinning = true
  627. salesWriteSubmit(data).then(res => {
  628. if (res.status == 200) {
  629. this.handleBack()
  630. this.$message.success(res.message)
  631. this.spinning = false
  632. } else {
  633. this.spinning = false
  634. }
  635. })
  636. },
  637. // 选择价格类型 并更新
  638. updatePrice (type) {
  639. const _this = this
  640. if (type == 0) {
  641. const ajax_data = {
  642. salesBillSn: _this.salesBillSn,
  643. productPriceChangeFlag: type
  644. }
  645. _this.submitResult(ajax_data)
  646. } else {
  647. updateBatch(_this.updataData.detailList).then(res => {
  648. if (res.status == 200) {
  649. const ajax_data = {
  650. salesBillSn: _this.salesBillSn,
  651. productPriceChangeFlag: type
  652. }
  653. _this.submitResult(ajax_data)
  654. }
  655. })
  656. }
  657. },
  658. // 获取促销活动
  659. getPromoacActiveList () {
  660. const _this = this
  661. getPromoacActiveList({ salesBillSn: this.salesBillSn }).then(res => {
  662. if (res.status == 200) {
  663. _this.activeName = ''
  664. res.data.map(item => {
  665. _this.activeName += item.name + '、'
  666. })
  667. _this.activeName = _this.activeName.slice(0, _this.activeName.length - 1)
  668. }
  669. })
  670. },
  671. // 选择促销品
  672. handleSelCx (row) {
  673. // this.nowData = row
  674. this.newActive = true
  675. this.$refs.activeProduct.getData(row, this.detailData && this.detailData.buyerSn || '', this.salesBillSn)
  676. },
  677. // 批量添加促销品
  678. addNewActive (list) {
  679. const temp = []
  680. list.map(item => {
  681. temp.push(Object.assign(item, {
  682. salesBillSn: this.detailData.salesBillSn,
  683. salesBillNo: this.detailData.salesBillNo,
  684. purchaseBillSn: this.detailData.purchaseBillSn,
  685. purchaseBillNo: this.detailData.purchaseBillNo
  686. }))
  687. })
  688. this.isInster == true
  689. this.spinning = true
  690. addPromoGoods(temp).then(res => {
  691. if (res.status == 200) {
  692. this.$refs.promotable.getData(this.salesBillSn)
  693. this.getOrderDetail(false)
  694. this.newActive = false
  695. this.isInster == false
  696. this.spinning = false
  697. } else {
  698. this.spinning = false
  699. }
  700. })
  701. },
  702. closeActive () {
  703. this.nowData = null
  704. this.newActive = false
  705. },
  706. closeGuideModel () {
  707. this.openGuideModal = false
  708. },
  709. // 导入产品
  710. hanldeOk (obj) {
  711. salesBatchInsert(obj).then(res => {
  712. if (res.status == 200) {
  713. this.$refs.table.refresh(true)
  714. this.getOrderDetail(false)
  715. }
  716. })
  717. },
  718. pageInit () {
  719. this.getOrderDetail(true)
  720. this.$refs.table.refresh(true)
  721. this.salesBillSn = this.$route.params.sn
  722. this.warehouseSn = this.$route.params.sn ? this.$route.params.wSn : ''
  723. // 获取促销活动
  724. this.getPromoacActiveList()
  725. }
  726. },
  727. mounted () {
  728. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  729. this.pageInit()
  730. }
  731. },
  732. activated () {
  733. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  734. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  735. this.pageInit()
  736. }
  737. },
  738. beforeRouteEnter (to, from, next) {
  739. next(vm => {})
  740. }
  741. }
  742. </script>
  743. <style lang="less">
  744. .salesEdit-wrap{
  745. position: relative;
  746. height: 100%;
  747. padding-bottom: 51px;
  748. box-sizing: border-box;
  749. >.ant-spin-nested-loading{
  750. overflow-y: scroll;
  751. height: 100%;
  752. }
  753. .salesEdit-cont{
  754. margin-top: 10px;
  755. }
  756. .p-title{
  757. font-weight: bold;
  758. font-size: 14px;
  759. }
  760. .p-notes{
  761. font-size: 14px;
  762. span{
  763. color: #FF9900;
  764. }
  765. }
  766. .redStyle{
  767. font-weight: bold;
  768. color: red;
  769. }
  770. .ellipsisCon{
  771. display: flex;
  772. justify-content: space-between;
  773. align-items: center;
  774. .ellipsisText{
  775. width: 100%;
  776. overflow: hidden;
  777. text-overflow: ellipsis;
  778. display: box;
  779. display: -webkit-box;
  780. -webkit-line-clamp: 1;
  781. -webkit-box-orient: vertical;
  782. }
  783. }
  784. .total-bar{
  785. display: flex;
  786. align-items: center;
  787. justify-content: space-between;
  788. > div{
  789. &:last-child{
  790. display: flex;
  791. align-items: center;
  792. justify-content: space-between;
  793. > div{
  794. padding: 0 10px;
  795. }
  796. }
  797. }
  798. }
  799. }
  800. </style>