edit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <template>
  2. <div class="waitDispatch-wrap">
  3. <a-page-header :ghost="false" :backIcon="false" @back="handleBack" >
  4. <!-- 自定义的二级文字标题 -->
  5. <template slot="subTitle">
  6. <a id="waitDispatch-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  7. <span style="margin: 0 15px;color: #666;">客户名称:{{ detailData&&detailData.buyerName }}</span>
  8. <!-- <a-button id="waitDispatch-edit-btn" size="small" @click="handleEdit" style="margin-left:10px" key="0">编辑</a-button> -->
  9. </template>
  10. <!-- 操作区,位于 title 行的行尾 -->
  11. <template slot="extra">
  12. <a-button key="2" id="waitDispatch-preview-btn">打印预览</a-button>
  13. <a-button key="1" type="primary" id="waitDispatch-print-btn">快速打印</a-button>
  14. </template>
  15. </a-page-header>
  16. <a-card size="small" :bordered="false" class="waitDispatch-cont" v-if="salesBillSn">
  17. <!-- 查询配件列表 -->
  18. <queryPart
  19. ref="partQuery"
  20. :salesBillSn="salesBillSn"
  21. :detailData="detailData"
  22. :newLoading="isInster"
  23. @oneDispatch="oneDispatch"
  24. @cancelProduct="cancelProduct"
  25. @addProduct="insterProduct"></queryPart>
  26. </a-card>
  27. <a-card :bordered="false" class="waitDispatch-cont">
  28. <div slot="title">
  29. <div class="p-title">
  30. 待下推产品
  31. </div>
  32. </div>
  33. <div class="table-operator">
  34. <a-button
  35. type="primary"
  36. @click="delSalerDetailAll"
  37. :loading="delLoading"
  38. id="waitDispatch-del-all">批量移除</a-button>
  39. </div>
  40. <!-- 总计 -->
  41. <a-alert type="info" v-if="totalData">
  42. <div slot="message" class="total-bar">
  43. <div>
  44. 本次下推款数:<strong>¥{{ totalData&&totalData.totalAmount || 0 }}</strong>;
  45. 本次下推数量:<strong>{{ totalData&&totalData.totalCategory || 0 }}</strong>;
  46. </div>
  47. <div>
  48. </div>
  49. </div>
  50. </a-alert>
  51. <!-- 已选配件列表 -->
  52. <s-table
  53. class="sTable"
  54. ref="table"
  55. size="small"
  56. :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
  57. :rowKey="(record) => record.id"
  58. :columns="columns"
  59. :data="loadData"
  60. :showPagination="false"
  61. :scroll="{ x:1000, y: 300 }"
  62. bordered>
  63. <!-- 产品编码 -->
  64. <template slot="productCode" slot-scope="text, record">
  65. <a-badge count="促" v-if="record.promotionFlag == 1">
  66. <div style="padding-right: 15px;">{{ text }}</div>
  67. </a-badge>
  68. <span v-else>{{ text }}</span>
  69. </template>
  70. <!-- 本次下推数 -->
  71. <template slot="salesNums" slot-scope="text, record">
  72. <editable-cell
  73. size="small"
  74. :text="record.qty"
  75. :max="999999"
  76. :min="1"
  77. :precision="0"
  78. @change="onCellChange(record.id, 'qty', $event)" />
  79. </template>
  80. <!-- 操作 -->
  81. <template slot="action" slot-scope="text, record">
  82. <a-button
  83. size="small"
  84. type="primary"
  85. :loading="delLoading"
  86. class="button-error"
  87. @click="handleDel(record)"
  88. >移除</a-button>
  89. </template>
  90. </s-table>
  91. </a-card>
  92. <a-affix :offset-bottom="0">
  93. <div
  94. style="text-align: center;width: 100%;background-color: #fff;padding: 12px 0;box-shadow: 0 0 20px #dcdee2;">
  95. <a-button
  96. size="large"
  97. style="width: 150px;"
  98. type="primary"
  99. class="button-primary"
  100. @click="handleSubmit()"
  101. id="productInfoList-handleSubmit">下推</a-button>
  102. </div>
  103. </a-affix>
  104. </div>
  105. </template>
  106. <script>
  107. import { STable, VSelect } from '@/components'
  108. import queryPart from './queryPart.vue'
  109. import { salesDetailBySn } from '@/api/sales'
  110. import { salesDetailDispatchByOneKey, insertBatchOfWaitDispatch } from '@/api/salesDetail'
  111. import EditableCell from '@/views/common/editInput.js'
  112. import { deleteBatch, pushDown, queryCount, waitDispatchDetailAllList, updateQty } from '@/api/waitDispatchDetail'
  113. export default {
  114. name: 'SalesDetail',
  115. components: { STable, VSelect, queryPart, EditableCell },
  116. data () {
  117. return {
  118. salesBillSn: null, // 销售单sn
  119. disabled: false, // 查询、重置按钮是否可操作
  120. isInster: false, // 是否正在添加产品
  121. delLoading: false,
  122. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  123. dataSource: [],
  124. productForm: {
  125. salesBillSn: ''
  126. },
  127. selectedRowKeys: [], // Check here to configure the default column
  128. selectedRows: [],
  129. // 表头
  130. columns: [
  131. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  132. { title: '产品编码', dataIndex: 'productEntity.code', scopedSlots: { customRender: 'productCode' }, width: 300, align: 'center' },
  133. { title: '产品名称', dataIndex: 'productEntity.name', align: 'center', customRender: function (text) { return text || '--' } },
  134. { title: '剩余待下推', dataIndex: 'surplusQty', width: 150, align: 'center' },
  135. { title: '本次下推数', scopedSlots: { customRender: 'salesNums' }, width: 150, align: 'center' },
  136. { title: '单位', dataIndex: 'productEntity.unit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  137. { title: '操作', scopedSlots: { customRender: 'action' }, width: 150, align: 'center', fixed: 'right' }
  138. ],
  139. // 加载数据方法 必须为 Promise 对象
  140. loadData: parameter => {
  141. this.disabled = true
  142. this.productForm.salesBillSn = this.$route.params.sn
  143. // 查询统计
  144. this.getTotalData(Object.assign(parameter, this.productForm))
  145. return waitDispatchDetailAllList(Object.assign(parameter, this.productForm)).then(res => {
  146. const data = res.data
  147. const no = 0
  148. for (var i = 0; i < data.length; i++) {
  149. data[i].no = no + i + 1
  150. }
  151. this.disabled = false
  152. this.dataSource = data
  153. return data
  154. })
  155. },
  156. totalData: null
  157. }
  158. },
  159. methods: {
  160. onSelectChange (selectedRowKeys, selectedRows) {
  161. this.selectedRowKeys = selectedRowKeys
  162. this.selectedRows = selectedRows
  163. },
  164. // 统计查询
  165. getTotalData (params) {
  166. queryCount(params).then(res => {
  167. this.totalData = res.data || null
  168. })
  169. },
  170. // 修改数量
  171. onCellChange (id, key, value) {
  172. console.log(id, key, value)
  173. const dataSource = [...this.dataSource]
  174. const row = dataSource.find(item => item.id === id)
  175. if (row) {
  176. row[key] = Number(value)
  177. this.dataSource = dataSource
  178. }
  179. if (key == 'qty') {
  180. updateQty({
  181. salesBillDetailSn: row.salesBillDetailSn,
  182. qty: row.qty,
  183. salesBillSn: this.salesBillSn
  184. }).then(res => {
  185. this.resetSearchForm(true)
  186. if (res.status == 200) {
  187. this.$refs.partQuery.resetCurForm()
  188. this.$message.success(res.message)
  189. }
  190. })
  191. }
  192. },
  193. // 重置
  194. resetSearchForm (flag) {
  195. this.$refs.table.refresh(!!flag)
  196. this.getOrderDetail()
  197. },
  198. // 重置列表
  199. resetForm () {
  200. this.$refs.table.refresh()
  201. },
  202. // 返回
  203. handleBack () {
  204. this.$router.push({ name: 'salesQueryList' })
  205. },
  206. // 批量删除
  207. delSalerDetailAll () {
  208. const _this = this
  209. if (_this.selectedRowKeys.length < 1) {
  210. _this.$message.warning('请在选择待下推产品!')
  211. return
  212. }
  213. const obj = []
  214. _this.selectedRows.map(item => {
  215. obj.push(item.productSn)
  216. })
  217. this.$confirm({
  218. title: '提示',
  219. content: '确认要批量删除吗?',
  220. centered: true,
  221. closable: true,
  222. onOk () {
  223. _this.deleteFun(obj, 1)
  224. }
  225. })
  226. },
  227. // 删除产品
  228. handleDel (row) {
  229. const _this = this
  230. this.$confirm({
  231. title: '提示',
  232. content: '确认要删除吗?',
  233. centered: true,
  234. closable: true,
  235. onOk () {
  236. _this.deleteFun(row, 0)
  237. }
  238. })
  239. },
  240. // 移除操作
  241. deleteFun (row, type) {
  242. const _this = this
  243. _this.delLoading = true
  244. deleteBatch({ salesBillDetailSn: row.salesBillDetailSn, salesBillSn: _this.salesBillSn }).then(res => {
  245. if (res.status == 200) {
  246. _this.resetSearchForm(true)
  247. _this.$message.success(res.message)
  248. }
  249. _this.delLoading = false
  250. })
  251. },
  252. // 添加产品
  253. insterProduct (row, promotionFlag) {
  254. console.log(row)
  255. // 防止多次添加产品
  256. if (this.isInster) { return }
  257. const _this = this
  258. _this.saveNewProduct(row, promotionFlag)
  259. },
  260. // 保存添加的产品到销售列表
  261. saveNewProduct (row, promotionFlag) {
  262. this.$message.loading('正在添加产品...', 1)
  263. this.isInster = true
  264. insertBatchOfWaitDispatch({
  265. packQty: row.productPackQty,
  266. productSn: row.productSn,
  267. showCos: row.lastStockCost,
  268. price: row.productPrice,
  269. qty: row.salesNums,
  270. salesBillSn: this.detailData.salesBillSn,
  271. salesBillNo: this.detailData.salesBillNo,
  272. purchaseBillSn: this.detailData.purchaseBillSn,
  273. purchaseBillNo: this.detailData.purchaseBillNo,
  274. stockSn: row.stockSn,
  275. promotableFlag: 0, // 可促销标记 有活动的传1,没活动的传0
  276. promotionFlag: promotionFlag // 促销标记 正品传0,促销品传1
  277. }).then(res => {
  278. if (res.status == 200) {
  279. this.resetSearchForm()
  280. this.$refs.partQuery.resetCurForm()
  281. this.$message.success('产品添加成功', 2.5)
  282. }
  283. this.isInster = false
  284. })
  285. },
  286. // 批量取消产品
  287. cancelProduct (row) {
  288. },
  289. // 一键下推
  290. oneDispatch () {
  291. this.isInster = true
  292. salesDetailDispatchByOneKey({ salesBillSn: this.$route.params.sn }).then(res => {
  293. if (res.status == 200) {
  294. this.resetSearchForm()
  295. this.$refs.partQuery.resetCurForm()
  296. }
  297. this.isInster = false
  298. })
  299. },
  300. // 销售单详情
  301. getOrderDetail () {
  302. salesDetailBySn({ salesBillSn: this.$route.params.sn }).then(res => {
  303. console.log('getOrderDetail')
  304. if (res.status == 200) {
  305. this.detailData = res.data
  306. console.log(this.detailData)
  307. }
  308. })
  309. },
  310. // 提交下推
  311. handleSubmit () {
  312. pushDown({ salesBillSn: this.salesBillSn }).then(res => {
  313. if (res.status == 200) {
  314. this.handleBack()
  315. this.$message.success(res.message)
  316. }
  317. })
  318. }
  319. },
  320. mounted () {
  321. this.getOrderDetail()
  322. },
  323. beforeRouteEnter (to, from, next) {
  324. next(vm => {
  325. console.log('beforeRouteEnter')
  326. vm.salesBillSn = vm.$route.params.sn
  327. })
  328. }
  329. }
  330. </script>
  331. <style lang="less">
  332. .waitDispatch-wrap{
  333. .waitDispatch-cont{
  334. margin-top: 15px;
  335. }
  336. .sTable{
  337. margin-top: 15px;
  338. }
  339. .p-title{
  340. font-weight: bold;
  341. }
  342. .p-notes{
  343. span{
  344. color: #FF9900;
  345. }
  346. }
  347. .total-bar{
  348. display: flex;
  349. align-items: center;
  350. justify-content: space-between;
  351. > div{
  352. &:last-child{
  353. display: flex;
  354. align-items: center;
  355. justify-content: space-between;
  356. > div{
  357. padding: 0 10px;
  358. }
  359. }
  360. }
  361. }
  362. .redBg-row{
  363. background-color: #f5cdc8;
  364. }
  365. }
  366. </style>