edit.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. <template>
  2. <div class="storeTransferOutEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="storeTransferOutEdit-back" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="storeTransferOutEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. <span style="margin: 0 15px;color: #666;">调往对象名称:{{ (basicInfoData&&basicInfoData.putPersonName) || '--' }}</span>
  9. </template>
  10. <!-- 操作区,位于 title 行的行尾 -->
  11. <template slot="extra" v-if="$hasPermissions('B_storeCallOutPrint')">
  12. <a-checkbox key="4" v-model="printCostChecked">打印成本</a-checkbox>
  13. <Print :disabled="chooseLoadDataSource.length==0" :showExport="false" @handlePrint="handlePrint"></Print>
  14. </template>
  15. </a-page-header>
  16. <!-- 选择产品 -->
  17. <a-card size="small" :bordered="false" class="storeTransferOutEdit-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="storeTransferOutEdit-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="storeTransferOutEdit-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="仓库">
  36. <a-select id="storeTransferOutEdit-warehouseSn" allowClear placeholder="请选择仓库" v-model="queryParam.warehouseSn" >
  37. <a-select-option v-for="item in warehouseList" :key="item.warehouseSn" :value="item.warehouseSn">{{ item.name }}</a-select-option>
  38. </a-select>
  39. </a-form-item>
  40. </a-col>
  41. <template v-if="advanced">
  42. <a-col :md="6" :sm="24">
  43. <a-form-item label="产品分类">
  44. <a-cascader
  45. @change="changeProductType"
  46. change-on-select
  47. v-model="productType"
  48. expand-trigger="hover"
  49. :options="productTypeList"
  50. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  51. id="storeTransferOutEdit-productType"
  52. placeholder="请选择产品分类"
  53. allowClear />
  54. </a-form-item>
  55. </a-col>
  56. <a-col :md="6" :sm="24">
  57. <a-form-item label="产品品牌">
  58. <a-select
  59. placeholder="请选择产品品牌"
  60. id="storeTransferOutEdit-brandSn"
  61. allowClear
  62. v-model="queryParam.brandSn"
  63. :showSearch="true"
  64. option-filter-prop="children"
  65. :filter-option="filterOption">
  66. <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn">{{ item.brandName }}</a-select-option>
  67. </a-select>
  68. </a-form-item>
  69. </a-col>
  70. </template>
  71. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  72. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="storeTransferOutList-refresh">查询</a-button>
  73. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="storeTransferOutList-reset">重置</a-button>
  74. <a @click="advanced=!advanced" style="margin-left: 5px">
  75. {{ advanced ? '收起' : '展开' }}
  76. <a-icon :type="advanced ? 'up' : 'down'"/>
  77. </a>
  78. </a-col>
  79. </a-row>
  80. </a-form>
  81. </div>
  82. <!-- 列表 -->
  83. <s-table
  84. class="sTable"
  85. ref="table"
  86. size="small"
  87. :rowKey="(record) => record.stockSn+record.productSn+record.warehouseSn+record.warehouseLocationSn"
  88. :columns="columns"
  89. :customRow="handleClickRow"
  90. :data="loadData"
  91. :scroll="{ y: 300 }"
  92. :defaultLoadData="false"
  93. bordered>
  94. <!-- 操作 -->
  95. <template slot="action" slot-scope="text, record">
  96. <a-button
  97. size="small"
  98. :disabled="record.currentQty==0"
  99. type="primary"
  100. class="button-primary"
  101. @click="handleAdd(record)"
  102. id="storeTransferOutEdit-add-btn">添加</a-button>
  103. </template>
  104. </s-table>
  105. </a-collapse-panel>
  106. </a-collapse>
  107. </a-card>
  108. <!-- 已选产品 -->
  109. <a-card size="small" :bordered="false" class="storeTransferOutEdit-cont">
  110. <a-collapse :activeKey="['1']">
  111. <a-collapse-panel key="1" header="已选产品">
  112. <!-- 总计 -->
  113. <a-alert type="info" style="margin-bottom:10px">
  114. <div slot="message">
  115. 总款数 <strong>{{ (productTotal&&(productTotal.productTotalCategory || productTotal.productTotalCategory==0)) ? productTotal.productTotalCategory : '--' }}</strong> ,
  116. 总数量 <strong>{{ (productTotal&&(productTotal.productTotalQty || productTotal.productTotalQty==0)) ? productTotal.productTotalQty : '--' }}</strong> ,
  117. 总成本 <strong>{{ (productTotal&&(productTotal.productTotalCost || productTotal.productTotalCost==0)) ? '¥'+productTotal.productTotalCost : '--' }}</strong>
  118. </div>
  119. </a-alert>
  120. <!-- 筛选条件 -->
  121. <a-row :gutter="15">
  122. <a-col :span="20">
  123. <div class="table-page-search-wrapper">
  124. <a-form layout="inline" @keyup.enter.native="$refs.chooseTable.refresh(true)">
  125. <a-row :gutter="15">
  126. <a-col :md="8" :sm="24">
  127. <a-form-item label="产品编码" prop="productCode">
  128. <a-input id="storeTransferOutEdit-productCode" v-model="chooseQueryParam.productCode" placeholder="请输入产品编码" allowClear />
  129. </a-form-item>
  130. </a-col>
  131. <a-col :md="8" :sm="24">
  132. <a-form-item label="产品名称" prop="productName">
  133. <a-input id="storeTransferOutEdit-productName" v-model="chooseQueryParam.productName" placeholder="请输入产品名称" allowClear />
  134. </a-form-item>
  135. </a-col>
  136. <a-col :md="8" :sm="24" style="margin-bottom: 10px;">
  137. <a-button type="primary" @click="$refs.chooseTable.refresh(true)" :disabled="chooseDisabled" id="storeTransferOutList-refresh">查询</a-button>
  138. <a-button style="margin-left: 8px" @click="chooseResetSearchForm" :disabled="chooseDisabled" id="storeTransferOutList-reset">重置</a-button>
  139. </a-col>
  140. </a-row>
  141. </a-form>
  142. </div>
  143. </a-col>
  144. <a-col :span="4" style="text-align: right;">
  145. <!-- <a-button size="small" id="storeTransferOutEdit-import-btn">导入明细</a-button> -->
  146. </a-col>
  147. </a-row>
  148. <!-- 列表 -->
  149. <s-table
  150. class="sTable"
  151. ref="chooseTable"
  152. size="small"
  153. :rowKey="(record) => record.id"
  154. :columns="chooseColumns"
  155. :data="chooseLoadData"
  156. :defaultLoadData="false"
  157. :scroll="{ y: 300 }"
  158. bordered>
  159. <!-- 调出数量 -->
  160. <template slot="outQty" slot-scope="text, record">
  161. <a-input-number
  162. size="small"
  163. id="storeTransferOutEdit-outQty"
  164. v-model="record.outQty"
  165. :precision="0"
  166. :min="1"
  167. :max="999999"
  168. placeholder="请输入"
  169. @blur="e => outQtyBlur(e.target.value, record)"
  170. style="width: 100%;" />
  171. </template>
  172. <!-- 操作 -->
  173. <template slot="action" slot-scope="text, record">
  174. <a-button size="small" type="primary" class="button-error" @click="handleDel(record)" id="storeTransferOutEdit-del-btn">删除</a-button>
  175. </template>
  176. </s-table>
  177. </a-collapse-panel>
  178. </a-collapse>
  179. </a-card>
  180. </a-spin>
  181. <div class="affix-cont">
  182. <a-button
  183. type="primary"
  184. id="storeTransferOutEdit-submit"
  185. size="large"
  186. :disabled="spinning"
  187. class="button-primary"
  188. @click="handleSubmit"
  189. style="padding: 0 60px;">提交</a-button>
  190. </div>
  191. </div>
  192. </template>
  193. <script>
  194. import { STable, VSelect } from '@/components'
  195. import { getOperationalPrecision } from '@/libs/tools.js'
  196. import { storeCallOutDetailList, storeCallOutDetail, storeCallOutDetailCount, storeCallOutDetailSave, storeCallOutDetailDel, storeCallOutSubmit, storeCallOutDetailPrint } from '@/api/storeCallOut'
  197. import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
  198. import { dealerProductTypeList } from '@/api/dealerProductType'
  199. import { warehouseAllList } from '@/api/warehouse'
  200. import { productQuery } from '@/api/allocWarehouse'
  201. import Print from '@/views/common/print.vue'
  202. import { hdPrint } from '@/libs/JGPrint'
  203. export default {
  204. components: { STable, VSelect, Print },
  205. data () {
  206. return {
  207. spinning: false,
  208. queryParam: {
  209. productCode: '',
  210. productName: '',
  211. warehouseSn: undefined,
  212. brandSn: undefined,
  213. productTypeSn1: undefined,
  214. productTypeSn2: undefined,
  215. productTypeSn3: undefined
  216. },
  217. chooseQueryParam: {
  218. productCode: '',
  219. productName: ''
  220. },
  221. disabled: false, // 查询、重置按钮是否可操作
  222. loading: false, // 表格加载中
  223. chooseDisabled: false, // 查询、重置按钮是否可操作
  224. advanced: false, // 高级搜索 展开/关闭
  225. productBrandList: [], // 产品品牌 下拉数据
  226. productTypeList: [], // 产品分类 下拉数据
  227. productType: [],
  228. warehouseList: [], // 仓库 下拉数据
  229. // 表头
  230. columns: [
  231. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  232. { title: '产品编码', dataIndex: 'productCode', width: '18%', align: 'center', customRender: function (text) { return text || '--' } },
  233. { title: '产品名称', dataIndex: 'productName', width: '18%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  234. { title: '单位', dataIndex: 'unit', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  235. { title: '仓库', dataIndex: 'warehouseName', width: '15%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  236. { title: '仓位', dataIndex: 'warehouseLocationName', width: '15%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  237. { title: '库存数量', dataIndex: 'currentQty', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  238. { title: '成本价(¥)', dataIndex: 'putCost', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  239. { title: '操作', scopedSlots: { customRender: 'action' }, width: '8%', align: 'center' }
  240. ],
  241. // 加载数据方法 必须为 Promise 对象
  242. loadData: parameter => {
  243. this.disabled = true
  244. return productQuery(Object.assign(parameter, this.queryParam, { 'currentQtyFlag': 0 })).then(res => {
  245. const data = res.data
  246. const no = (data.pageNo - 1) * data.pageSize
  247. for (var i = 0; i < data.list.length; i++) {
  248. data.list[i].no = no + i + 1
  249. }
  250. this.disabled = false
  251. return data
  252. })
  253. },
  254. // 表头
  255. chooseColumns: [
  256. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  257. { title: '产品编码', dataIndex: 'productCode', width: '16%', align: 'center', customRender: function (text) { return text || '--' } },
  258. { title: '产品名称', dataIndex: 'productName', width: '16%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  259. { title: '单位', dataIndex: 'productUnit', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  260. { title: '成本价(¥)', dataIndex: 'outCost', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  261. { title: '仓库', dataIndex: 'warehouseName', width: '12%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  262. { title: '仓位', dataIndex: 'warehouseLocationName', width: '12%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  263. { title: '调出数量', scopedSlots: { customRender: 'outQty' }, width: '8%', align: 'center' },
  264. { title: '成本小计(¥)', dataIndex: 'costSubtotal', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  265. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  266. ],
  267. // 加载数据方法 必须为 Promise 对象
  268. chooseLoadData: parameter => {
  269. this.chooseDisabled = true
  270. const params = Object.assign(this.chooseQueryParam, { storeCallOutSn: this.$route.params.sn })
  271. return storeCallOutDetailList(Object.assign(parameter, params)).then(res => {
  272. this.getDetailCount(params)
  273. const data = res.data
  274. const no = (data.pageNo - 1) * data.pageSize
  275. for (var i = 0; i < data.list.length; i++) {
  276. data.list[i].no = no + i + 1
  277. data.list[i].outQtyBackups = data.list[i].outQty
  278. // 成本小计 由于数据库内小数位数为4位,页面则需显示2位。因此会做小数运算精度处理
  279. data.list[i].costSubtotal = getOperationalPrecision(data.list[i].outCost, data.list[i].outQty)
  280. }
  281. this.chooseLoadDataSource = data.list || []
  282. this.chooseDisabled = false
  283. return data
  284. })
  285. },
  286. chooseLoadDataSource: [],
  287. basicInfoData: null, // 基本信息
  288. productTotal: null, // 合计
  289. printCostChecked: true // 打印成本
  290. }
  291. },
  292. methods: {
  293. // 重置
  294. resetSearchForm () {
  295. this.queryParam.productCode = ''
  296. this.queryParam.productName = ''
  297. this.queryParam.warehouseSn = undefined
  298. this.queryParam.brandSn = undefined
  299. this.queryParam.productTypeSn1 = undefined
  300. this.queryParam.productTypeSn2 = undefined
  301. this.queryParam.productTypeSn3 = undefined
  302. this.productType = []
  303. this.$refs.table.refresh(true)
  304. },
  305. // 打印预览/快捷打印
  306. handlePrint (type, printerType) {
  307. const _this = this
  308. _this.spinning = true
  309. const url = storeCallOutDetailPrint
  310. const params = { sn: this.$route.params.sn, type: printerType, costFlag: this.printCostChecked ? '1' : '0' }
  311. // 打印或导出
  312. hdPrint(printerType, type, url, params, '', function () {
  313. _this.spinning = false
  314. })
  315. },
  316. // 双击快速添加
  317. handleClickRow (record) {
  318. return {
  319. on: {
  320. dblclick: (event) => {
  321. this.handleAdd(record)
  322. }
  323. }
  324. }
  325. },
  326. // 已选产品 重置
  327. chooseResetSearchForm () {
  328. this.chooseQueryParam.productCode = ''
  329. this.chooseQueryParam.productName = ''
  330. this.$refs.chooseTable.refresh(true)
  331. },
  332. // 基本信息
  333. getDetail () {
  334. storeCallOutDetail({ id: this.$route.params.id }).then(res => {
  335. if (res.status == 200) {
  336. this.basicInfoData = res.data
  337. } else {
  338. this.basicInfoData = null
  339. }
  340. })
  341. },
  342. // 添加/编辑
  343. handleAdd (row, isEdit) {
  344. const params = {
  345. id: isEdit ? row.id : undefined,
  346. storeCallOutSn: this.$route.params.sn,
  347. outCost: isEdit ? row.outCost : row.putCost,
  348. outQty: isEdit ? row.outQty : 1, // 添加时调出数量默认为1
  349. productSn: row.productSn,
  350. productCode: row.productCode,
  351. productOrigCode: row.productOrigCode || undefined,
  352. productTypeSn1: row.productTypeSn1,
  353. productTypeSn2: row.productTypeSn2,
  354. productTypeSn3: row.productTypeSn3,
  355. brandSn: row.brandSn,
  356. warehouseSn: row.warehouseSn,
  357. warehouseLocationSn: row.warehouseLocationSn
  358. }
  359. if (isEdit) { // 编辑
  360. // 清空数量时,值应保持未清空前的值,因数量不可为空
  361. if (!row.outQty || row.outQty == row.outQtyBackups) {
  362. row.outQty = row.outQtyBackups
  363. return
  364. }
  365. }
  366. this.spinning = true
  367. storeCallOutDetailSave(params).then(res => {
  368. if (res.status == 200) {
  369. this.$message.success(res.message)
  370. this.$refs.table.refresh()
  371. this.$refs.chooseTable.refresh()
  372. this.spinning = false
  373. } else {
  374. this.spinning = false
  375. }
  376. })
  377. },
  378. // 删除
  379. handleDel (row) {
  380. const _this = this
  381. this.$confirm({
  382. title: '提示',
  383. content: '删除后不可恢复,确定要进行删除吗?',
  384. centered: true,
  385. onOk () {
  386. _this.spinning = true
  387. storeCallOutDetailDel({ id: row.id }).then(res => {
  388. if (res.status == 200) {
  389. _this.$message.success(res.message)
  390. _this.$refs.table.refresh()
  391. _this.$refs.chooseTable.refresh()
  392. _this.spinning = false
  393. } else {
  394. _this.spinning = false
  395. }
  396. })
  397. }
  398. })
  399. },
  400. // 提交
  401. handleSubmit () {
  402. const _this = this
  403. _this.spinning = true
  404. storeCallOutSubmit({ id: this.$route.params.id }).then(res => {
  405. if (res.status == 200) {
  406. this.$message.success(res.message)
  407. setTimeout(() => {
  408. _this.handleBack()
  409. _this.spinning = false
  410. }, 1000)
  411. } else {
  412. _this.spinning = false
  413. }
  414. })
  415. },
  416. // 合计
  417. getDetailCount (params) {
  418. storeCallOutDetailCount(params).then(res => {
  419. if (res.status == 200) {
  420. this.productTotal = res.data
  421. } else {
  422. this.productTotal = null
  423. }
  424. })
  425. },
  426. // 返回列表
  427. handleBack () {
  428. this.$router.push({ path: '/allocationManagement/storeTransferOut/list' })
  429. },
  430. // 已选产品 调出数量 blur
  431. outQtyBlur (val, record) {
  432. // 光标移出,值发生改变再调用编辑接口
  433. if (val != record.outQtyBackups) {
  434. this.handleAdd(record, 'edit')
  435. }
  436. },
  437. // 产品分类 change
  438. changeProductType (val, opt) {
  439. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  440. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  441. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  442. },
  443. // 产品品牌 列表
  444. getProductBrand () {
  445. // sysFlag不传,此处应查询所有产品
  446. dealerProductBrandQuery({}).then(res => {
  447. if (res.status == 200) {
  448. this.productBrandList = res.data
  449. } else {
  450. this.productBrandList = []
  451. }
  452. })
  453. },
  454. // 产品分类 列表
  455. getProductType () {
  456. dealerProductTypeList({}).then(res => {
  457. if (res.status == 200) {
  458. this.productTypeList = res.data
  459. } else {
  460. this.productTypeList = []
  461. }
  462. })
  463. },
  464. // 仓库下拉数据
  465. getWarehouseList (type) {
  466. warehouseAllList({}).then(res => {
  467. if (res.status == 200) {
  468. this.warehouseList = res.data
  469. } else {
  470. this.warehouseList = []
  471. }
  472. })
  473. },
  474. filterOption (input, option) {
  475. return (
  476. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  477. )
  478. },
  479. pageInit () {
  480. this.printCostChecked = true
  481. this.getDetail()
  482. this.getWarehouseList()
  483. this.getProductBrand()
  484. this.getProductType()
  485. this.resetSearchForm()
  486. this.chooseResetSearchForm()
  487. }
  488. },
  489. mounted () {
  490. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  491. this.pageInit()
  492. }
  493. },
  494. activated () {
  495. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  496. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  497. this.pageInit()
  498. }
  499. },
  500. beforeRouteEnter (to, from, next) {
  501. next(vm => {})
  502. }
  503. }
  504. </script>
  505. <style lang="less">
  506. .storeTransferOutEdit-wrap{
  507. position: relative;
  508. height: 100%;
  509. padding-bottom: 51px;
  510. box-sizing: border-box;
  511. .storeTransferOutEdit-back, .storeTransferOutEdit-cont{
  512. margin-bottom: 10px;
  513. }
  514. >.ant-spin-nested-loading{
  515. overflow-y: scroll;
  516. height: 100%;
  517. }
  518. }
  519. </style>