edit.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <template>
  2. <div class="allocateBillEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="allocateBillEdit-back" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="allocateBillEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. <span style="margin: 0 15px;color: #666;">调往对象:{{ $route.params.name || '--' }}</span>
  9. </template>
  10. <!-- 操作区,位于 title 行的行尾 -->
  11. <template v-if="$hasPermissions('B_transferOut_print')" slot="extra">
  12. <a-button key="2" id="allocateBillEdit-preview-btn" :disabled="chooseLoadData.length==0" @click="handlePrint('preview')">打印预览</a-button>
  13. <a-button key="1" type="primary" id="allocateBillEdit-print-btn" :disabled="chooseLoadData.length==0" @click="handlePrint('print')">快捷打印</a-button>
  14. </template>
  15. </a-page-header>
  16. <!-- 选择产品 -->
  17. <a-card size="small" :bordered="false" class="allocateBillEdit-cont">
  18. <a-collapse :activeKey="['1']">
  19. <a-collapse-panel key="1" header="选择产品">
  20. <!-- 筛选条件 -->
  21. <div class="table-page-search-wrapper">
  22. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  23. <a-row :gutter="15">
  24. <a-col :md="6" :sm="24">
  25. <a-form-item label="产品编码" prop="productCode">
  26. <a-input id="allocateBillEdit-productCode" v-model="queryParam.productCode" placeholder="请输入产品编码" allowClear />
  27. </a-form-item>
  28. </a-col>
  29. <a-col :md="6" :sm="24">
  30. <a-form-item label="产品名称" prop="productName">
  31. <a-input id="allocateBillEdit-productName" v-model="queryParam.productName" placeholder="请输入产品名称" allowClear />
  32. </a-form-item>
  33. </a-col>
  34. <a-col :md="6" :sm="24">
  35. <a-form-item label="原厂编码" prop="productOrigCode">
  36. <a-input id="allocateBillEdit-productOrigCode" v-model="queryParam.productOrigCode" placeholder="请输入原厂编码" allowClear />
  37. </a-form-item>
  38. </a-col>
  39. <a-col :md="6" :sm="24" style="margin-bottom: 24px;">
  40. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="storeTransferOutList-refresh">查询</a-button>
  41. <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="storeTransferOutList-reset">重置</a-button>
  42. </a-col>
  43. </a-row>
  44. </a-form>
  45. </div>
  46. <!-- 列表 -->
  47. <s-table
  48. class="sTable"
  49. ref="table"
  50. size="small"
  51. :rowKey="(record) => record.stockSn"
  52. :columns="columns"
  53. :customRow="handleClickRow"
  54. :data="loadData"
  55. :scroll="{ x: 1240, y: 300 }"
  56. bordered>
  57. <!-- 操作 -->
  58. <template slot="action" slot-scope="text, record">
  59. <a-button size="small" type="primary" class="button-primary" @click="handleAdd(record)" id="allocateBillEdit-add-btn">添加</a-button>
  60. </template>
  61. </s-table>
  62. </a-collapse-panel>
  63. </a-collapse>
  64. </a-card>
  65. <!-- 已选产品 -->
  66. <a-card size="small" :bordered="false" class="allocateBillEdit-cont">
  67. <a-collapse :activeKey="['1']">
  68. <a-collapse-panel key="1" header="已选产品">
  69. <!-- 总计 -->
  70. <a-alert type="info" showIcon style="margin-bottom:15px">
  71. <div slot="message">
  72. 总数量:<strong>{{ (productTotal&&(productTotal.totalQty || productTotal.totalQty==0)) ? productTotal.totalQty : '--' }}</strong> ,
  73. 总成本(¥):<strong>{{ (productTotal&&(productTotal.totalCost || productTotal.totalCost==0)) ? productTotal.totalCost : '--' }}</strong> ,
  74. 总售价(¥):<strong>{{ (productTotal&&(productTotal.totalPrice || productTotal.totalPrice==0)) ? productTotal.totalPrice : '--' }}</strong>
  75. </div>
  76. </a-alert>
  77. <!-- 筛选条件 -->
  78. <a-row :gutter="15">
  79. <a-col :span="17">
  80. <div class="table-page-search-wrapper">
  81. <a-form layout="inline" @keyup.enter.native="getChooseProductList(1)">
  82. <a-row :gutter="15">
  83. <a-col :md="9" :sm="24">
  84. <a-form-item label="产品编码" prop="productCode">
  85. <a-input id="allocateBillEdit-productCode" v-model="chooseQueryParam.productCode" placeholder="请输入产品编码" allowClear />
  86. </a-form-item>
  87. </a-col>
  88. <a-col :md="9" :sm="24">
  89. <a-form-item label="产品名称" prop="productName">
  90. <a-input id="allocateBillEdit-productName" v-model="chooseQueryParam.productName" placeholder="请输入产品名称" allowClear />
  91. </a-form-item>
  92. </a-col>
  93. <a-col :md="6" :sm="24" style="margin-bottom: 24px;">
  94. <a-button type="primary" @click="getChooseProductList(1)" :disabled="chooseDisabled" id="storeTransferOutList-refresh">查询</a-button>
  95. <a-button style="margin-left: 8px" @click="chooseResetSearchForm" :disabled="chooseDisabled" id="storeTransferOutList-reset">重置</a-button>
  96. </a-col>
  97. </a-row>
  98. </a-form>
  99. </div>
  100. </a-col>
  101. <a-col :span="7" style="text-align: right;">
  102. <!-- <a-button size="small" id="allocateBillEdit-import-btn">导入明细</a-button> -->
  103. <a-button size="small" type="danger" style="margin-left: 8px" @click.stop="handleDel('', 'all')" id="chainTransferOutEdit-del-all-btn">整单删除</a-button>
  104. </a-col>
  105. </a-row>
  106. <!-- 列表 -->
  107. <a-table
  108. class="sTable"
  109. ref="chooseTable"
  110. size="small"
  111. :rowKey="(record) => record.id"
  112. :columns="chooseColumns"
  113. :dataSource="chooseLoadData"
  114. :scroll="{ x: 1335, y: 300 }"
  115. :loading="loading"
  116. :pagination="choosePaginationProps"
  117. bordered>
  118. <!-- 调出数量 -->
  119. <template slot="qty" slot-scope="text, record">
  120. <a-input-number
  121. id="allocateBillEdit-qty"
  122. v-model="record.qty"
  123. :precision="0"
  124. :min="1"
  125. :max="999999"
  126. placeholder="请输入"
  127. @blur="e => qtyBlur(e.target.value, record)"
  128. style="width: 100%;" />
  129. </template>
  130. <!-- 操作 -->
  131. <template slot="action" slot-scope="text, record">
  132. <a-button size="small" type="primary" class="button-error" @click="handleDel(record)" id="allocateBillEdit-del-btn">删除</a-button>
  133. </template>
  134. </a-table>
  135. </a-collapse-panel>
  136. </a-collapse>
  137. </a-card>
  138. <a-affix :offset-bottom="0">
  139. <div style="text-align: center;width: 100%;background-color: #fff;padding: 12px 0;box-shadow: 0 0 20px #dcdee2;">
  140. <a-button
  141. type="primary"
  142. id="allocateBillEdit-submit"
  143. size="large"
  144. class="button-primary"
  145. @click="handleSubmit"
  146. style="padding: 0 60px;">提交</a-button>
  147. </div>
  148. </a-affix>
  149. </a-spin>
  150. <!-- 打印 -->
  151. <div id="print"></div>
  152. </div>
  153. </template>
  154. <script>
  155. import { STable, VSelect } from '@/components'
  156. import { queryStockProductPage } from '@/api/stock'
  157. import { allocateBillDetailList, allocateBillDetailCount, allocateBillDetailSave, allocateBillSubmit, allocateBillDetailDel, allocateBillDetailDelAll, allocateBillDetailPrint } from '@/api/allocateBill'
  158. export default {
  159. components: { STable, VSelect },
  160. data () {
  161. return {
  162. spinning: false,
  163. queryParam: {
  164. productCode: '',
  165. productName: '',
  166. productOrigCode: ''
  167. },
  168. chooseQueryParam: {
  169. productCode: '',
  170. productName: ''
  171. },
  172. disabled: false, // 查询、重置按钮是否可操作
  173. loading: false,
  174. chooseDisabled: false, // 查询、重置按钮是否可操作
  175. advanced: false, // 高级搜索 展开/关闭
  176. productBrandList: [], // 产品品牌 下拉数据
  177. productTypeList: [], // 产品分类 下拉数据
  178. productType: [],
  179. warehouseList: [], // 仓库 下拉数据
  180. // 表头
  181. columns: [
  182. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  183. { title: '产品编码', dataIndex: 'productCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  184. { title: '产品名称', dataIndex: 'productName', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  185. { title: '原厂编码', dataIndex: 'productOrigCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  186. { title: '成本价', dataIndex: 'lastStockCost', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  187. { title: '售价', dataIndex: 'productPrice', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  188. { title: '库存数量', dataIndex: 'currentStockQty', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  189. { title: '单位', dataIndex: 'productUnit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  190. { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center', fixed: 'right' }
  191. ],
  192. // 加载数据方法 必须为 Promise 对象
  193. loadData: parameter => {
  194. this.disabled = true
  195. return queryStockProductPage(Object.assign(parameter, this.queryParam, { zeroQtyFlag: '0', dealerLevel: this.$route.params.dealerLevel })).then(res => {
  196. const data = res.data
  197. const no = (data.pageNo - 1) * data.pageSize
  198. for (var i = 0; i < data.list.length; i++) {
  199. data.list[i].no = no + i + 1
  200. }
  201. this.disabled = false
  202. return data
  203. })
  204. },
  205. // 表头
  206. chooseColumns: [
  207. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  208. { title: '产品编码', dataIndex: 'productEntity.code', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  209. { title: '产品名称', dataIndex: 'productEntity.name', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  210. { title: '原厂编码', dataIndex: 'productEntity.origCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  211. { title: '成本价', dataIndex: 'cost', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  212. { title: '售价', dataIndex: 'price', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  213. { title: '库存数量', dataIndex: 'currentStockQty', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  214. { title: '调出数量', scopedSlots: { customRender: 'qty' }, width: 140, align: 'center' },
  215. { title: '单位', dataIndex: 'productEntity.unit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  216. { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center', fixed: 'right' }
  217. ],
  218. chooseLoadData: [],
  219. choosePageNo: 1, // 分页页码
  220. choosePageSize: 10, // 分页 每页多少条
  221. choosePaginationProps: {
  222. showSizeChanger: true, // 是否可以改变 pageSize
  223. total: 0, // 分页总条数
  224. current: 1,
  225. onShowSizeChange: (current, pageSize) => this.changeChoosePageSize(current, pageSize),
  226. onChange: (current) => this.changeChoosePage(current)
  227. },
  228. productTotal: null // 合计
  229. }
  230. },
  231. methods: {
  232. // 重置
  233. resetSearchForm () {
  234. this.queryParam.productCode = ''
  235. this.queryParam.productName = ''
  236. this.queryParam.productOrigCode = ''
  237. this.$refs.table.refresh(true)
  238. },
  239. // 双击快速添加
  240. handleClickRow (record) {
  241. return {
  242. on: {
  243. dblclick: (event) => {
  244. this.handleAdd(record)
  245. }
  246. }
  247. }
  248. },
  249. // 已选产品 重置
  250. chooseResetSearchForm () {
  251. this.chooseQueryParam.productCode = ''
  252. this.chooseQueryParam.productName = ''
  253. this.choosePageNo = 1
  254. this.choosePageSize = 10
  255. this.choosePaginationProps.total = 0
  256. this.choosePaginationProps.current = 1
  257. this.getChooseProductList(1)
  258. },
  259. // 添加/编辑
  260. handleAdd (row, isEdit) {
  261. const params = {
  262. id: isEdit ? row.id : undefined,
  263. allocateSn: this.$route.params.sn,
  264. cost: isEdit ? row.cost : row.lastStockCost,
  265. price: isEdit ? row.price : row.productPrice,
  266. qty: isEdit ? row.qty : 1, // 添加时调出数量默认为1
  267. productSn: row.productSn
  268. }
  269. if (isEdit) { // 编辑
  270. // 清空数量时,值应保持未清空前的值,因数量不可为空
  271. if (!row.qty || row.qty == row.qtyBackups) {
  272. row.qty = row.qtyBackups
  273. return
  274. }
  275. }
  276. this.spinning = true
  277. allocateBillDetailSave(params).then(res => {
  278. if (res.status == 200) {
  279. this.$message.success(res.message)
  280. this.$refs.table.refresh()
  281. this.getChooseProductList()
  282. this.spinning = false
  283. } else {
  284. row.qty = row.qtyBackups
  285. this.spinning = false
  286. }
  287. })
  288. },
  289. // 删除
  290. handleDel (row, isAll) {
  291. const _this = this
  292. const content = isAll ? '删除后不可恢复,确定要进行整单删除吗?' : '删除后不可恢复,确定要进行删除吗?'
  293. this.$confirm({
  294. title: '提示',
  295. content: content,
  296. centered: true,
  297. onOk () {
  298. if (isAll) { // 整单删除
  299. _this.spinning = true
  300. allocateBillDetailDelAll({ sn: _this.$route.params.sn }).then(res => {
  301. if (res.status == 200) {
  302. _this.$message.success(res.message)
  303. _this.$refs.table.refresh()
  304. _this.getChooseProductList()
  305. _this.spinning = false
  306. } else {
  307. _this.spinning = false
  308. }
  309. })
  310. } else { // 单个删除
  311. _this.spinning = true
  312. allocateBillDetailDel({ id: row.id }).then(res => {
  313. if (res.status == 200) {
  314. _this.$message.success(res.message)
  315. _this.$refs.table.refresh()
  316. _this.getChooseProductList()
  317. _this.spinning = false
  318. } else {
  319. _this.spinning = false
  320. }
  321. })
  322. }
  323. }
  324. })
  325. },
  326. // 提交
  327. handleSubmit () {
  328. const _this = this
  329. _this.spinning = true
  330. allocateBillSubmit({ sn: this.$route.params.sn }).then(res => {
  331. if (res.status == 200) {
  332. this.$message.success(res.message)
  333. setTimeout(() => {
  334. _this.handleBack()
  335. _this.spinning = false
  336. }, 1000)
  337. } else {
  338. _this.spinning = false
  339. }
  340. })
  341. },
  342. // 合计
  343. getDetailCount (params) {
  344. allocateBillDetailCount(params).then(res => {
  345. if (res.status == 200) {
  346. this.productTotal = res.data
  347. } else {
  348. this.productTotal = null
  349. }
  350. })
  351. },
  352. // 返回列表
  353. handleBack () {
  354. this.$router.push({ path: '/allocationManagement/transferOut/list', query: { closeLastOldTab: true } })
  355. },
  356. // 已选产品 分页 一页多少条change
  357. changeChoosePageSize (current, pageSize) {
  358. this.choosePageNo = current
  359. this.choosePageSize = pageSize
  360. this.getChooseProductList()
  361. },
  362. // 已选产品 分页 页码change
  363. changeChoosePage (current) {
  364. this.choosePageNo = current
  365. this.getChooseProductList()
  366. },
  367. // 已选产品列表数据
  368. getChooseProductList (pageNo) {
  369. this.choosePageNo = this.choosePageNo || pageNo
  370. this.chooseDisabled = true
  371. this.loading = true
  372. const params = {
  373. pageNo: this.choosePageNo,
  374. pageSize: this.choosePageSize,
  375. allocateSn: this.$route.params.sn
  376. }
  377. allocateBillDetailList(Object.assign(params, this.chooseQueryParam)).then(res => {
  378. this.loading = false
  379. if (res.status == 200) {
  380. // 合计
  381. this.getDetailCount(Object.assign(params, this.chooseQueryParam))
  382. const data = res.data
  383. this.choosePaginationProps.total = Number(res.data.count) || 0
  384. this.choosePaginationProps.current = data.pageNo
  385. const no = (data.pageNo - 1) * data.pageSize
  386. for (var i = 0; i < data.list.length; i++) {
  387. data.list[i].no = no + i + 1
  388. data.list[i].qtyBackups = data.list[i].qty
  389. }
  390. this.chooseLoadData = data.list
  391. this.chooseDisabled = false
  392. } else {
  393. this.choosePaginationProps.total = 0
  394. this.choosePaginationProps.current = 1
  395. this.chooseLoadData = []
  396. }
  397. })
  398. },
  399. // 已选产品 调出数量 blur
  400. qtyBlur (val, record) {
  401. // 光标移出,值发生改变再调用编辑接口
  402. if (val != record.qtyBackups) {
  403. this.handleAdd(record, 'edit')
  404. }
  405. },
  406. // 打印预览/快捷打印
  407. handlePrint (type) {
  408. const _this = this
  409. _this.spinning = true
  410. allocateBillDetailPrint({ sn: this.$route.params.sn, isPreview: type == 'preview' ? 1 : 0 }).then(res => {
  411. _this.spinning = false
  412. if (res.type == 'application/json') {
  413. var reader = new FileReader()
  414. reader.addEventListener('loadend', function () {
  415. const obj = JSON.parse(reader.result)
  416. _this.$notification.error({
  417. message: '提示',
  418. description: obj.message
  419. })
  420. })
  421. reader.readAsText(res)
  422. } else {
  423. this.print(res, type)
  424. }
  425. })
  426. },
  427. print (data, type) {
  428. if (!data) {
  429. return
  430. }
  431. const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
  432. document.getElementById('print').innerHTML = '<iframe id="printf" name="printf" src="' + url + '" hidden></iframe>'
  433. if (type == 'preview') { // 预览
  434. window.open(url)
  435. } else if (type == 'print') { // 打印
  436. window.frames['printf'].focus()
  437. window.frames['printf'].print()
  438. }
  439. }
  440. },
  441. beforeRouteEnter (to, from, next) {
  442. next(vm => {
  443. vm.getChooseProductList(1)
  444. })
  445. }
  446. }
  447. </script>
  448. <style lang="less">
  449. .allocateBillEdit-wrap{
  450. .allocateBillEdit-back{
  451. margin-bottom: 10px;
  452. }
  453. .allocateBillEdit-cont{
  454. margin-bottom: 10px;
  455. .sub-title{
  456. font-size: 12px;
  457. color: #808695;
  458. margin-left: 10px;
  459. }
  460. .tag-txt{
  461. font-size: 12px;
  462. color: #ed1c24;
  463. }
  464. .edit-circle-btn{
  465. margin-left: 15px;
  466. i{
  467. vertical-align: text-bottom;
  468. }
  469. }
  470. .import-btn{
  471. margin-left: 15px;
  472. }
  473. }
  474. }
  475. </style>