edit.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <template>
  2. <div class="salesEdit-wrap">
  3. <a-page-header :ghost="false" :backIcon="false" @back="handleBack" >
  4. <!-- 自定义的二级文字标题 -->
  5. <template slot="subTitle">
  6. <a id="salesEdit-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="salesEdit-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="salesEdit-preview-btn">打印预览</a-button>
  13. <a-button key="1" type="primary" id="salesEdit-print-btn">快速打印</a-button>
  14. </template>
  15. </a-page-header>
  16. <a-card size="small" :bordered="false" class="salesEdit-cont">
  17. <!-- 查询配件列表 -->
  18. <queryPart :buyerSn="detailData&&detailData.buyerSn" :priceType="$route.params.priceType" :newLoading="isInster" @add="insterProduct"></queryPart>
  19. </a-card>
  20. <a-card size="small" :bordered="false" class="salesEdit-cont">
  21. <!-- 总计 -->
  22. <a-alert style="margin-bottom: 15px;" type="info">
  23. <div slot="message" class="total-bar">
  24. <div>
  25. 总售价:<strong>¥{{ detailData&&detailData.totalAmount || 0 }}</strong>;
  26. 总款数:<strong>{{ detailData&&detailData.totalCategory || 0 }}</strong>;
  27. 总数量:<strong>{{ detailData&&detailData.totalQty || 0 }}</strong>;
  28. 赠品总数量:<strong>{{ detailData&&detailData.giftQty || 0 }}</strong>;
  29. </div>
  30. <div>
  31. <div>
  32. 折扣金额:
  33. <a-input-number id="discount" v-model="detailData.discountAmount" :min="0" :precision="2" :max="999999"/>
  34. <a-button type="primary" @click="salesDiscount" class="button-info">打折</a-button>
  35. </div>
  36. <div>
  37. 折扣:<strong>{{ detailData&&detailData.discountRate || 0 }}%</strong>;
  38. 折后总售价:<strong>¥{{ detailData&&detailData.discountedAmount || 0 }}</strong>;
  39. </div>
  40. </div>
  41. </div>
  42. </a-alert>
  43. <!-- 查询条件 -->
  44. <a-row :gutter="15">
  45. <a-col :span="18">
  46. <a-form-model layout="inline" :model="productForm">
  47. <a-form-model-item label="产品编码">
  48. <a-input v-model="productForm.productCode" allowClear placeholder="输入产品编码" />
  49. </a-form-model-item>
  50. <a-form-model-item label="产品名称">
  51. <a-input v-model="productForm.productName" allowClear placeholder="输入产品名称" />
  52. </a-form-model-item>
  53. <a-form-model-item>
  54. <a-button style="margin-bottom: 18px;" type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="salesEdit-refresh">查询</a-button>
  55. <a-button style="margin: 0 0 18px 8px" @click="resetForm" id="salesEdit-reset">重置</a-button>
  56. </a-form-model-item>
  57. </a-form-model>
  58. </a-col>
  59. <a-col :span="6">
  60. <div style="float:right;overflow: hidden;">
  61. <a-button size="small" id="salesEdit-dru">导入明细</a-button>
  62. <a-button
  63. size="small"
  64. type="primary"
  65. @click="delSalerDetailAll"
  66. :loading="delLoading"
  67. style="margin-left: 10px"
  68. id="salesEdit-del-all">整单删除</a-button>
  69. </div>
  70. </a-col>
  71. </a-row>
  72. <!-- 已选配件列表 -->
  73. <s-table
  74. class="sTable"
  75. ref="table"
  76. size="small"
  77. :rowKey="(record) => record.id"
  78. :columns="columns"
  79. :data="loadData"
  80. :scroll="{ x: 1560, y: 300 }"
  81. bordered>
  82. <!-- 产品编码 -->
  83. <template slot="productCode" slot-scope="text, record">
  84. <a-badge count="急" v-if="record.oosFlag == 1">
  85. <div style="padding-right: 15px;">{{ text }}</div>
  86. </a-badge>
  87. <span v-else>{{ text }}</span>
  88. </template>
  89. <!-- 售价 -->
  90. <template slot="price" slot-scope="text, record">
  91. <editable-cell
  92. :text="record.price"
  93. id="salesEdit-price"
  94. :max="999999"
  95. :min="0"
  96. :precision="2"
  97. punit="¥"
  98. @change="onCellChange(record.id, 'price', $event)" />
  99. </template>
  100. <!-- 销售数量 -->
  101. <template slot="salesNums" slot-scope="text, record">
  102. <editable-cell
  103. :text="record.qty"
  104. id="salesEdit-salesNums"
  105. :max="999999"
  106. :min="1"
  107. :precision="0"
  108. @change="onCellChange(record.id, 'qty', $event)" />
  109. </template>
  110. <!-- 操作 -->
  111. <template slot="action" slot-scope="text, record">
  112. <a-button
  113. size="small"
  114. type="primary"
  115. :loading="delLoading"
  116. class="button-error"
  117. @click="handleDel(record)"
  118. id="productInfoList-Del">删除</a-button>
  119. </template>
  120. </s-table>
  121. </a-card>
  122. <a-affix :offset-bottom="0">
  123. <div
  124. style="text-align: center;width: 100%;background-color: #fff;padding: 12px 0;box-shadow: 0 0 20px #dcdee2;">
  125. <a-button
  126. size="large"
  127. style="width: 150px;"
  128. type="primary"
  129. class="button-primary"
  130. @click="handleSubmit()"
  131. id="productInfoList-handleSubmit">提交</a-button>
  132. </div>
  133. </a-affix>
  134. <!-- 选择客户弹框 -->
  135. <choose-custom-modal ref="custModal" :show="openModal" @updateData="getOrderDetail" @cancel="openModal=false" />
  136. </div>
  137. </template>
  138. <script>
  139. import { STable, VSelect } from '@/components'
  140. import queryPart from './queryPart.vue'
  141. import chooseCustomModal from './chooseCustomModal.vue'
  142. import { salesDetail, salesWriteSubmit, salesWriteDiscount } from '@/api/sales'
  143. import EditableCell from '@/views/common/editInput.js'
  144. import { salesDetailList, salesDetailInsert, salesDetailUpdatePrice, salesDetailUpdateQty, salesDetailDel, salesDetailDelAll } from '@/api/salesDetail'
  145. export default {
  146. name: 'SalesDetail',
  147. components: { STable, VSelect, queryPart, chooseCustomModal, EditableCell },
  148. data () {
  149. return {
  150. orderId: null, // 销售单id
  151. salesBillSn: null, // 销售单sn
  152. disabled: false, // 查询、重置按钮是否可操作
  153. isInster: false, // 是否正在添加产品
  154. openModal: false, // 客户弹框
  155. delLoading: false,
  156. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  157. dataSource: [],
  158. productForm: {
  159. productName: '',
  160. productCode: ''
  161. },
  162. // 表头
  163. columns: [
  164. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  165. { title: '产品编码', dataIndex: 'dealerProductEntity.code', scopedSlots: { customRender: 'productCode' }, width: 140, align: 'center', sorter: true },
  166. { title: '产品名称', dataIndex: 'dealerProductEntity.name', align: 'center' },
  167. { title: '原厂编码', dataIndex: 'dealerProductEntity.origCode', width: 140, align: 'center' },
  168. { title: '品牌', dataIndex: 'dealerProductEntity.productBrandName', width: 100, align: 'center', sorter: true },
  169. { title: '仓库', dataIndex: 'warehouseEntity.name', width: 100, align: 'center', sorter: true },
  170. { title: '仓位', dataIndex: 'warehouseLocationEntity.name', width: 100, align: 'center' },
  171. { title: '售价', scopedSlots: { customRender: 'price' }, width: 150, align: 'center' },
  172. { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: 150, align: 'center' },
  173. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  174. { title: '售价小计', dataIndex: 'totalAmount', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) } },
  175. { title: '折后小计', dataIndex: 'discountedAmount', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) } },
  176. { title: '操作', scopedSlots: { customRender: 'action' }, width: 170, align: 'center', fixed: 'right' }
  177. ],
  178. // 加载数据方法 必须为 Promise 对象
  179. loadData: parameter => {
  180. this.disabled = true
  181. this.productForm.salesBillSn = this.$route.params.sn
  182. return salesDetailList(Object.assign(parameter, this.productForm)).then(res => {
  183. const data = res.data
  184. const no = (data.pageNo - 1) * data.pageSize
  185. for (var i = 0; i < data.list.length; i++) {
  186. data.list[i].no = no + i + 1
  187. }
  188. this.disabled = false
  189. this.dataSource = data.list
  190. return data
  191. })
  192. }
  193. }
  194. },
  195. methods: {
  196. onCellChange (id, key, value) {
  197. console.log(id, key, value)
  198. const dataSource = [...this.dataSource]
  199. const row = dataSource.find(item => item.id === id)
  200. if (row) {
  201. row[key] = Number(value)
  202. this.dataSource = dataSource
  203. }
  204. // 修改价格
  205. if (key == 'price') {
  206. salesDetailUpdatePrice({
  207. salesBillSn: row.salesBillSn,
  208. productSn: row.productSn,
  209. price: row.price
  210. }).then(res => {
  211. if (res.status == 200) {
  212. this.resetSearchForm(true)
  213. }
  214. this.$message.info(res.message)
  215. })
  216. }
  217. if (key == 'qty') {
  218. salesDetailUpdateQty({
  219. id: row.id,
  220. qty: row.qty
  221. }).then(res => {
  222. if (res.status == 200) {
  223. this.resetSearchForm(true)
  224. }
  225. this.$message.info(res.message)
  226. })
  227. }
  228. },
  229. // 编辑客户信息
  230. handleEdit () {
  231. this.openModal = true
  232. setTimeout(() => {
  233. this.$refs.custModal.editCust(this.detailData)
  234. }, 500)
  235. },
  236. // 重置
  237. resetSearchForm (flag) {
  238. this.$refs.table.refresh(!!flag)
  239. this.getOrderDetail()
  240. },
  241. // 重置列表
  242. resetForm () {
  243. this.productForm = {
  244. productName: '',
  245. productCode: ''
  246. }
  247. this.$refs.table.refresh()
  248. },
  249. // 返回
  250. handleBack () {
  251. this.$router.push({ name: 'salesQueryList' })
  252. },
  253. // 打折
  254. salesDiscount () {
  255. if (this.detailData.discountAmount <= 0) {
  256. return
  257. }
  258. console.log(this.detailData)
  259. salesWriteDiscount({
  260. discountAmount: this.detailData.discountAmount,
  261. salesBillSn: this.detailData.salesBillSn,
  262. id: this.detailData.id
  263. }).then(res => {
  264. if (res.status == 200) {
  265. this.resetSearchForm()
  266. }
  267. })
  268. },
  269. // 整单删除
  270. delSalerDetailAll () {
  271. const _this = this
  272. this.$confirm({
  273. title: '提示',
  274. content: '确认要整单删除吗?',
  275. centered: true,
  276. closable: true,
  277. onOk () {
  278. _this.delLoading = true
  279. salesDetailDelAll({ salesBillSn: _this.detailData.salesBillSn }).then(res => {
  280. if (res.status == 200) {
  281. _this.resetSearchForm()
  282. }
  283. _this.$message.info(res.message)
  284. _this.delLoading = false
  285. })
  286. }
  287. })
  288. },
  289. // 删除产品
  290. handleDel (row) {
  291. const _this = this
  292. this.$confirm({
  293. title: '提示',
  294. content: '确认要删除吗?',
  295. centered: true,
  296. closable: true,
  297. onOk () {
  298. _this.delLoading = true
  299. salesDetailDel({ id: row.id }).then(res => {
  300. if (res.status == 200) {
  301. _this.resetSearchForm(true)
  302. }
  303. _this.$message.info(res.message)
  304. _this.delLoading = false
  305. })
  306. }
  307. })
  308. },
  309. // 添加产品
  310. insterProduct (row) {
  311. console.log(row)
  312. // 防止多次添加产品
  313. if (this.isInster) {
  314. return
  315. }
  316. const _this = this
  317. // 库存不足时
  318. if (row.currentQty < row.salesNums) {
  319. this.$confirm({
  320. title: '提示',
  321. content: '库存不足,确认添加为急件吗?',
  322. centered: true,
  323. closable: true,
  324. onOk () {
  325. _this.saveNewProduct(row)
  326. }
  327. })
  328. } else {
  329. this.saveNewProduct(row)
  330. }
  331. },
  332. // 保存添加的产品到销售列表
  333. saveNewProduct (row) {
  334. this.$message.loading('正在添加产品...', 1)
  335. this.isInster = true
  336. salesDetailInsert({
  337. buyerSn: this.detailData.buyerSn,
  338. productSn: row.productSn,
  339. price: row.dealerProduct.cityPrice,
  340. qty: row.salesNums,
  341. salesBillSn: this.detailData.salesBillSn,
  342. salesBillNo: this.detailData.salesBillNo,
  343. warehouseSn: row.warehouseSn,
  344. warehouseLocationSn: row.warehouseLocationSn,
  345. stockSn: row.stockSn
  346. }).then(res => {
  347. if (res.status == 200) {
  348. this.resetSearchForm()
  349. this.$message.success('产品添加成功', 2.5)
  350. }
  351. this.isInster = false
  352. })
  353. },
  354. // 销售单详情
  355. getOrderDetail () {
  356. salesDetail({ id: this.$route.params.id }).then(res => {
  357. if (res.status == 200) {
  358. this.detailData = res.data
  359. }
  360. })
  361. },
  362. // 提交销售单
  363. handleSubmit () {
  364. salesWriteSubmit({ id: this.orderId }).then(res => {
  365. if (res.status == 200) {
  366. this.handleBack()
  367. this.$message.success(res.message)
  368. }
  369. })
  370. }
  371. },
  372. beforeRouteEnter (to, from, next) {
  373. next(vm => {
  374. // 获取销售单详情
  375. vm.getOrderDetail()
  376. vm.orderId = vm.$route.params.id
  377. vm.salesBillSn = vm.$route.params.sn
  378. })
  379. }
  380. }
  381. </script>
  382. <style lang="less">
  383. .salesEdit-wrap{
  384. .salesEdit-cont{
  385. margin-top: 15px;
  386. }
  387. .total-bar{
  388. display: flex;
  389. align-items: center;
  390. justify-content: space-between;
  391. > div{
  392. &:last-child{
  393. display: flex;
  394. align-items: center;
  395. justify-content: space-between;
  396. > div{
  397. padding: 0 10px;
  398. }
  399. }
  400. }
  401. }
  402. }
  403. </style>