edit.vue 15 KB

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