edit.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 @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">总售价:<strong>6</strong>;总款数:<strong>6</strong>;总数量:<strong>6</strong>;赠品总数量:<strong>6</strong>;</div>
  24. </a-alert>
  25. <!-- 查询条件 -->
  26. <a-row :gutter="15">
  27. <a-col :span="18">
  28. <a-form-model layout="inline" :model="productForm" @submit="handleSearch">
  29. <a-form-model-item label="产品编码">
  30. <a-input v-model="productForm.code" placeholder="输入产品编码" />
  31. </a-form-model-item>
  32. <a-form-model-item label="产品名称">
  33. <a-input v-model="productForm.name" placeholder="输入产品名称" />
  34. </a-form-model-item>
  35. <a-form-model-item>
  36. <a-button style="margin-bottom: 18px;" type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="salesEdit-refresh">查询</a-button>
  37. <a-button style="margin: 0 0 18px 8px" @click="resetSearchForm" :disabled="disabled" id="salesEdit-reset">重置</a-button>
  38. </a-form-model-item>
  39. </a-form-model>
  40. </a-col>
  41. <a-col :span="6">
  42. <div style="float:right;overflow: hidden;">
  43. <a-button size="small" id="salesEdit-dru">导入明细</a-button>
  44. <a-button size="small" type="primary" @click="delSalerDetailAll" style="margin-left: 10px" id="salesEdit-del-all">整单删除</a-button>
  45. </div>
  46. </a-col>
  47. </a-row>
  48. <!-- 已选配件列表 -->
  49. <s-table
  50. class="sTable"
  51. ref="table"
  52. size="default"
  53. :rowKey="(record) => record.id"
  54. :columns="columns"
  55. :data="loadData"
  56. :scroll="{ x: 1560, y: 150 }"
  57. bordered>
  58. <!-- 售价 -->
  59. <template slot="price" slot-scope="text, record">
  60. <editable-cell
  61. :text="record.price"
  62. id="salesEdit-price"
  63. :max="999999"
  64. :min="0"
  65. :precision="2"
  66. @change="onCellChange(record.id, 'price', $event)" />
  67. </template>
  68. <!-- 销售数量 -->
  69. <template slot="salesNums" slot-scope="text, record">
  70. <editable-cell
  71. :text="record.qty"
  72. id="salesEdit-salesNums"
  73. :max="999999"
  74. :min="1"
  75. :precision="0"
  76. @change="onCellChange(record.id, 'qty', $event)" />
  77. </template>
  78. <!-- 操作 -->
  79. <template slot="action" slot-scope="text, record">
  80. <a-button size="small" type="link" @click="handleDel(record)" id="productInfoList-Del">删除</a-button>
  81. </template>
  82. </s-table>
  83. </a-card>
  84. <!-- 选择客户弹框 -->
  85. <choose-custom-modal ref="custModal" :show="openModal" @ok="chooseCustomOk" @cancel="openModal=false" />
  86. </div>
  87. </template>
  88. <script>
  89. import { STable, VSelect } from '@/components'
  90. import queryPart from './queryPart.vue'
  91. import chooseCustomModal from './chooseCustomModal.vue'
  92. import { salesDetail } from '@/api/sales'
  93. import EditableCell from '@/views/common/editInput.js'
  94. import { salesDetailList, salesDetailInsert, salesDetailUpdatePrice, salesDetailUpdateQty, salesDetailDel, salesDetailDelAll } from '@/api/salesDetail'
  95. export default {
  96. name: 'SalesDetail',
  97. components: { STable, VSelect, queryPart, chooseCustomModal, EditableCell },
  98. data () {
  99. return {
  100. orderId: null, // 销售单id
  101. salesBillSn: null, // 销售单sn
  102. disabled: false, // 查询、重置按钮是否可操作
  103. openModal: false, // 客户弹框
  104. detailData: null, // 订单基础数据
  105. dataSource: [],
  106. productForm: {
  107. code: '',
  108. name: ''
  109. },
  110. // 表头
  111. columns: [
  112. { title: '序号', dataIndex: 'no', width: 80, align: 'center', fixed: 'left' },
  113. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: 140, align: 'center', sorter: true },
  114. { title: '产品名称', dataIndex: 'dealerProductEntity.name', align: 'center' },
  115. { title: '原厂编码', dataIndex: 'dealerProductEntity.origCode', width: 140, align: 'center' },
  116. { title: '品牌', dataIndex: 'dealerProductEntity.productBrandName', width: 100, align: 'center', sorter: true },
  117. { title: '仓库', dataIndex: 'warehouseEntity.name', width: 100, align: 'center', sorter: true },
  118. { title: '仓位', dataIndex: 'warehouseLocationEntity.name', width: 100, align: 'center' },
  119. { title: '售价', scopedSlots: { customRender: 'price' }, width: 150, align: 'center' },
  120. { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: 150, align: 'center' },
  121. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: 100, align: 'center' },
  122. { title: '售价小计', dataIndex: 'xj', width: 100, align: 'center' },
  123. { title: '折后小计', dataIndex: 'zhxj', width: 100, align: 'center' },
  124. { title: '操作', scopedSlots: { customRender: 'action' }, width: 170, align: 'center', fixed: 'right' }
  125. ],
  126. // 加载数据方法 必须为 Promise 对象
  127. loadData: parameter => {
  128. this.disabled = true
  129. return salesDetailList(Object.assign(parameter, this.productForm)).then(res => {
  130. const data = res.data
  131. const no = (data.pageNo - 1) * data.pageSize
  132. for (var i = 0; i < data.list.length; i++) {
  133. data.list[i].no = no + i + 1
  134. }
  135. this.disabled = false
  136. this.dataSource = data.list
  137. return data
  138. })
  139. }
  140. }
  141. },
  142. methods: {
  143. onCellChange (id, key, value) {
  144. console.log(id, key, value)
  145. const dataSource = [...this.dataSource]
  146. const row = dataSource.find(item => item.id === id)
  147. if (row) {
  148. row[key] = Number(value)
  149. this.dataSource = dataSource
  150. }
  151. // 修改价格
  152. if (key == 'price') {
  153. salesDetailUpdatePrice({
  154. salesBillSn: row.salesBillSn,
  155. productSn: row.productSn,
  156. price: row.price
  157. }).then(res => {
  158. if (res.status == 200) {
  159. this.$refs.table.refresh(true)
  160. }
  161. this.$message.info(res.message)
  162. })
  163. }
  164. if (key == 'qty') {
  165. salesDetailUpdateQty({
  166. id: row.id,
  167. qty: row.qty
  168. }).then(res => {
  169. if (res.status == 200) {
  170. this.$refs.table.refresh(true)
  171. }
  172. this.$message.info(res.message)
  173. })
  174. }
  175. },
  176. handleSearch () {
  177. },
  178. // 选择客户成功
  179. chooseCustomOk (data) {
  180. },
  181. // 编辑客户信息
  182. handleEdit () {
  183. this.openModal = true
  184. this.$refs.custModal.editCust(this.detailData)
  185. },
  186. // 重置
  187. resetSearchForm () {
  188. this.$refs.table.refresh()
  189. },
  190. // 返回
  191. handleBack () {
  192. this.$router.push({ path: '/salesManagement/salesQuery/list' })
  193. },
  194. // 整单删除
  195. delSalerDetailAll () {
  196. salesDetailDelAll({ salesBillSn: this.detailData.salesBillSn }).then(res => {
  197. if (res.status == 200) {
  198. this.resetSearchForm()
  199. }
  200. this.$message.info(res.message)
  201. })
  202. },
  203. // 删除产品
  204. handleDel (row) {
  205. salesDetailDel({ id: row.id }).then(res => {
  206. if (res.status == 200) {
  207. this.resetSearchForm()
  208. }
  209. this.$message.info(res.message)
  210. })
  211. },
  212. // 添加产品
  213. insterProduct (row) {
  214. console.log(row)
  215. salesDetailInsert({
  216. productSn: row.productSn,
  217. price: row.dealerProduct.cityPrice,
  218. qty: row.salesNums,
  219. salesBillSn: this.detailData.salesBillSn,
  220. salesBillNo: this.detailData.salesBillNo,
  221. warehouseSn: row.warehouseSn,
  222. warehouseLocationSn: row.warehouseLocationSn,
  223. stockSn: row.stockSn
  224. }).then(res => {
  225. console.log(res)
  226. if (res.status == 200) {
  227. this.resetSearchForm()
  228. }
  229. })
  230. },
  231. // 详情
  232. getOrderDetail () {
  233. salesDetail({ id: this.$route.params.id }).then(res => {
  234. if (res.status == 200) {
  235. this.detailData = res.data
  236. } else {
  237. this.detailData = null
  238. }
  239. })
  240. }
  241. },
  242. beforeRouteEnter (to, from, next) {
  243. next(vm => {
  244. // 获取销售单详情
  245. vm.getOrderDetail()
  246. vm.orderId = vm.$route.params.id
  247. })
  248. }
  249. }
  250. </script>
  251. <style lang="less">
  252. .salesEdit-wrap{
  253. .salesEdit-cont{
  254. margin-top: 15px;
  255. }
  256. }
  257. </style>