edit.vue 22 KB

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