edit.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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: 30px 0;box-shadow: 0 0 20px #dcdee2;">
  125. <a-button
  126. size="large"
  127. style="width: 150px;"
  128. type="primary"
  129. @click="handleSubmit()"
  130. id="productInfoList-handleSubmit">提交</a-button>
  131. </div>
  132. </a-affix>
  133. <!-- 选择客户弹框 -->
  134. <choose-custom-modal ref="custModal" :show="openModal" @updateData="getOrderDetail" @cancel="openModal=false" />
  135. </div>
  136. </template>
  137. <script>
  138. import { STable, VSelect } from '@/components'
  139. import queryPart from './queryPart.vue'
  140. import chooseCustomModal from './chooseCustomModal.vue'
  141. import { salesDetail, salesWriteSubmit, salesWriteDiscount } from '@/api/sales'
  142. import EditableCell from '@/views/common/editInput.js'
  143. import { salesDetailList, salesDetailInsert, salesDetailUpdatePrice, salesDetailUpdateQty, salesDetailDel, salesDetailDelAll } from '@/api/salesDetail'
  144. export default {
  145. name: 'SalesDetail',
  146. components: { STable, VSelect, queryPart, chooseCustomModal, EditableCell },
  147. data () {
  148. return {
  149. orderId: null, // 销售单id
  150. salesBillSn: null, // 销售单sn
  151. disabled: false, // 查询、重置按钮是否可操作
  152. isInster: false, // 是否正在添加产品
  153. openModal: false, // 客户弹框
  154. delLoading: false,
  155. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  156. dataSource: [],
  157. productForm: {
  158. productName: '',
  159. productCode: ''
  160. },
  161. // 表头
  162. columns: [
  163. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  164. { title: '产品编码', dataIndex: 'dealerProductEntity.code', scopedSlots: { customRender: 'productCode' }, width: 140, align: 'center', sorter: true },
  165. { title: '产品名称', dataIndex: 'dealerProductEntity.name', align: 'center' },
  166. { title: '原厂编码', dataIndex: 'dealerProductEntity.origCode', width: 140, align: 'center' },
  167. { title: '品牌', dataIndex: 'dealerProductEntity.productBrandName', width: 100, align: 'center', sorter: true },
  168. { title: '仓库', dataIndex: 'warehouseEntity.name', width: 100, align: 'center', sorter: true },
  169. { title: '仓位', dataIndex: 'warehouseLocationEntity.name', width: 100, align: 'center' },
  170. { title: '售价', scopedSlots: { customRender: 'price' }, width: 150, align: 'center' },
  171. { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: 150, align: 'center' },
  172. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  173. { title: '售价小计', dataIndex: 'totalAmount', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) } },
  174. { title: '折后小计', dataIndex: 'discountedAmount', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) } },
  175. { title: '操作', scopedSlots: { customRender: 'action' }, width: 170, align: 'center', fixed: 'right' }
  176. ],
  177. // 加载数据方法 必须为 Promise 对象
  178. loadData: parameter => {
  179. this.disabled = true
  180. this.productForm.salesBillSn = this.$route.params.sn
  181. return salesDetailList(Object.assign(parameter, this.productForm)).then(res => {
  182. const data = res.data
  183. const no = (data.pageNo - 1) * data.pageSize
  184. for (var i = 0; i < data.list.length; i++) {
  185. data.list[i].no = no + i + 1
  186. }
  187. this.disabled = false
  188. this.dataSource = data.list
  189. return data
  190. })
  191. }
  192. }
  193. },
  194. methods: {
  195. onCellChange (id, key, value) {
  196. console.log(id, key, value)
  197. const dataSource = [...this.dataSource]
  198. const row = dataSource.find(item => item.id === id)
  199. if (row) {
  200. row[key] = Number(value)
  201. this.dataSource = dataSource
  202. }
  203. // 修改价格
  204. if (key == 'price') {
  205. salesDetailUpdatePrice({
  206. salesBillSn: row.salesBillSn,
  207. productSn: row.productSn,
  208. price: row.price
  209. }).then(res => {
  210. if (res.status == 200) {
  211. this.resetSearchForm(true)
  212. }
  213. this.$message.info(res.message)
  214. })
  215. }
  216. if (key == 'qty') {
  217. salesDetailUpdateQty({
  218. id: row.id,
  219. qty: row.qty
  220. }).then(res => {
  221. if (res.status == 200) {
  222. this.resetSearchForm(true)
  223. }
  224. this.$message.info(res.message)
  225. })
  226. }
  227. },
  228. // 编辑客户信息
  229. handleEdit () {
  230. this.openModal = true
  231. setTimeout(() => {
  232. this.$refs.custModal.editCust(this.detailData)
  233. }, 500)
  234. },
  235. // 重置
  236. resetSearchForm (flag) {
  237. this.$refs.table.refresh(!!flag)
  238. this.getOrderDetail()
  239. },
  240. // 重置列表
  241. resetForm () {
  242. this.productForm = {
  243. productName: '',
  244. productCode: ''
  245. }
  246. this.$refs.table.refresh()
  247. },
  248. // 返回
  249. handleBack () {
  250. this.$router.push({ name: 'salesQueryList' })
  251. },
  252. // 打折
  253. salesDiscount () {
  254. if (this.detailData.discountAmount <= 0) {
  255. return
  256. }
  257. console.log(this.detailData)
  258. salesWriteDiscount({
  259. discountAmount: this.detailData.discountAmount,
  260. salesBillSn: this.detailData.salesBillSn,
  261. id: this.detailData.id
  262. }).then(res => {
  263. if (res.status == 200) {
  264. this.resetSearchForm()
  265. }
  266. })
  267. },
  268. // 整单删除
  269. delSalerDetailAll () {
  270. const _this = this
  271. this.$confirm({
  272. title: '提示',
  273. content: '确认要整单删除吗?',
  274. centered: true,
  275. closable: true,
  276. onOk () {
  277. _this.delLoading = true
  278. salesDetailDelAll({ salesBillSn: _this.detailData.salesBillSn }).then(res => {
  279. if (res.status == 200) {
  280. _this.resetSearchForm()
  281. }
  282. _this.$message.info(res.message)
  283. _this.delLoading = false
  284. })
  285. }
  286. })
  287. },
  288. // 删除产品
  289. handleDel (row) {
  290. const _this = this
  291. this.$confirm({
  292. title: '提示',
  293. content: '确认要删除吗?',
  294. centered: true,
  295. closable: true,
  296. onOk () {
  297. _this.delLoading = true
  298. salesDetailDel({ id: row.id }).then(res => {
  299. if (res.status == 200) {
  300. _this.resetSearchForm(true)
  301. }
  302. _this.$message.info(res.message)
  303. _this.delLoading = false
  304. })
  305. }
  306. })
  307. },
  308. // 添加产品
  309. insterProduct (row) {
  310. console.log(row)
  311. // 防止多次添加产品
  312. if (this.isInster) {
  313. return
  314. }
  315. const _this = this
  316. // 库存不足时
  317. if (row.currentQty < row.salesNums) {
  318. this.$confirm({
  319. title: '提示',
  320. content: '库存不足,确认添加为急件吗?',
  321. centered: true,
  322. closable: true,
  323. onOk () {
  324. _this.saveNewProduct(row)
  325. }
  326. })
  327. } else {
  328. this.saveNewProduct(row)
  329. }
  330. },
  331. // 保存添加的产品到销售列表
  332. saveNewProduct (row) {
  333. this.$message.loading('正在添加产品...', 1)
  334. this.isInster = true
  335. salesDetailInsert({
  336. buyerSn: this.detailData.buyerSn,
  337. productSn: row.productSn,
  338. price: row.dealerProduct.cityPrice,
  339. qty: row.salesNums,
  340. salesBillSn: this.detailData.salesBillSn,
  341. salesBillNo: this.detailData.salesBillNo,
  342. warehouseSn: row.warehouseSn,
  343. warehouseLocationSn: row.warehouseLocationSn,
  344. stockSn: row.stockSn
  345. }).then(res => {
  346. if (res.status == 200) {
  347. this.resetSearchForm()
  348. this.$message.success('产品添加成功', 2.5)
  349. }
  350. this.isInster = false
  351. })
  352. },
  353. // 销售单详情
  354. getOrderDetail () {
  355. salesDetail({ id: this.$route.params.id }).then(res => {
  356. if (res.status == 200) {
  357. this.detailData = res.data
  358. }
  359. })
  360. },
  361. // 提交销售单
  362. handleSubmit () {
  363. salesWriteSubmit({ id: this.orderId }).then(res => {
  364. if (res.status == 200) {
  365. this.handleBack()
  366. this.$message.success(res.message)
  367. }
  368. })
  369. }
  370. },
  371. beforeRouteEnter (to, from, next) {
  372. next(vm => {
  373. // 获取销售单详情
  374. vm.getOrderDetail()
  375. vm.orderId = vm.$route.params.id
  376. vm.salesBillSn = vm.$route.params.sn
  377. })
  378. }
  379. }
  380. </script>
  381. <style lang="less">
  382. .salesEdit-wrap{
  383. .salesEdit-cont{
  384. margin-top: 15px;
  385. }
  386. .total-bar{
  387. display: flex;
  388. align-items: center;
  389. justify-content: space-between;
  390. > div{
  391. &:last-child{
  392. display: flex;
  393. align-items: center;
  394. justify-content: space-between;
  395. > div{
  396. padding: 0 10px;
  397. }
  398. }
  399. }
  400. }
  401. }
  402. </style>