edit.vue 23 KB

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