edit.vue 22 KB

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