edit.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template>
  2. <div class="chainTransferInEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="chainTransferInEdit-back" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="chainTransferInEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. </template>
  9. <!-- 操作区,位于 title 行的行尾 -->
  10. <template slot="extra">
  11. <a-radio-group key="3" v-model="printerType">
  12. <a-radio value="NEEDLE">针式</a-radio>
  13. <a-radio value="INK">喷墨</a-radio>
  14. </a-radio-group>
  15. <a-button key="2" id="chainTransferInEdit-preview-btn" :disabled="loadData.length==0" @click="handlePrint('preview')">打印预览</a-button>
  16. <a-button key="1" type="primary" id="chainTransferInEdit-print-btn" :disabled="loadData.length==0" @click="handlePrint('print')">快捷打印</a-button>
  17. </template>
  18. </a-page-header>
  19. <!-- 基础信息 -->
  20. <a-card size="small" :bordered="false" class="chainTransferInDetail-cont">
  21. <a-collapse :activeKey="['1']">
  22. <a-collapse-panel key="1" header="基础信息">
  23. <a-descriptions :column="3">
  24. <a-descriptions-item label="调入单号">{{ (basicInfoData&&basicInfoData.allocationLinkagePutNo) || '--' }}</a-descriptions-item>
  25. <a-descriptions-item label="调出对象">{{ (basicInfoData&&basicInfoData.outTenantName) || '--' }}</a-descriptions-item>
  26. <a-descriptions-item label="业务状态">{{ (basicInfoData&&basicInfoData.stateDictValue) || '--' }}</a-descriptions-item>
  27. <a-descriptions-item label="财务状态">{{ (basicInfoData&&basicInfoData.settleStateDictValue) || '--' }}</a-descriptions-item>
  28. </a-descriptions>
  29. </a-collapse-panel>
  30. </a-collapse>
  31. </a-card>
  32. <!-- 总计 -->
  33. <a-alert type="info" showIcon style="margin-bottom:15px">
  34. <div slot="message">总款数 <strong>{{ (basicInfoData&&basicInfoData.productTotalCategory) || 0 }}</strong> ,总数量 <strong>{{ (basicInfoData&&basicInfoData.productTotalQty) || 0 }}</strong> ,总成本¥<strong>{{ (basicInfoData&&basicInfoData.productTotalCost) || 0 }}</strong></div>
  35. </a-alert>
  36. <a-card size="small" :bordered="false" class="chainTransferInEdit-cont">
  37. <!-- 筛选条件 -->
  38. <div class="table-page-search-wrapper">
  39. <a-form layout="inline" @keyup.enter.native="getProductList(1)">
  40. <a-row :gutter="15">
  41. <a-col :md="6" :sm="24">
  42. <a-form-item label="产品编码" prop="productCode">
  43. <a-input id="chainTransferInEdit-productCode" v-model="queryParam.productCode" placeholder="请输入产品编码" allowClear />
  44. </a-form-item>
  45. </a-col>
  46. <a-col :md="6" :sm="24">
  47. <a-form-item label="产品名称" prop="productName">
  48. <a-input id="chainTransferInEdit-productName" v-model="queryParam.productName" placeholder="请输入产品名称" allowClear />
  49. </a-form-item>
  50. </a-col>
  51. <a-col :md="6" :sm="24">
  52. <a-form-item label="产品分类">
  53. <a-cascader
  54. @change="changeProductType"
  55. change-on-select
  56. v-model="productType"
  57. expand-trigger="hover"
  58. :options="productTypeList"
  59. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  60. id="chainTransferInEdit-productType"
  61. placeholder="请选择产品分类"
  62. allowClear />
  63. </a-form-item>
  64. </a-col>
  65. <a-col :md="6" :sm="24" style="margin-bottom: 24px;">
  66. <a-button type="primary" @click="getProductList(1)" :disabled="disabled" id="chainTransferInEdit-refresh">查询</a-button>
  67. <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="chainTransferInEdit-reset">重置</a-button>
  68. </a-col>
  69. </a-row>
  70. </a-form>
  71. </div>
  72. <!-- 列表 -->
  73. <a-table
  74. class="sTable"
  75. ref="table"
  76. size="small"
  77. :rowKey="(record) => record.id"
  78. :columns="columns"
  79. :dataSource="loadData"
  80. :scroll="{ x: 1415 }"
  81. bordered>
  82. <!-- 仓库仓位 -->
  83. <template slot="warehouse" slot-scope="text, record, index">
  84. <a-cascader
  85. @change="e => changeWarehouseCascade(e, record, index)"
  86. v-model="record.warehouseCascade"
  87. expand-trigger="hover"
  88. :allowClear="false"
  89. :options="warehouseCascadeData"
  90. :fieldNames="{ label: 'name', value: 'sn', children: 'warehouseLocationList' }"
  91. id="chainTransferInEdit-warehouseCascade"
  92. placeholder="请选择仓库仓位"
  93. style="width: 100%;" />
  94. </template>
  95. </a-table>
  96. </a-card>
  97. <a-affix :offset-bottom="0">
  98. <div style="text-align: center;width: 100%;background-color: #fff;padding: 12px 0;box-shadow: 0 0 20px #dcdee2;">
  99. <a-button
  100. type="primary"
  101. id="chainTransferInEdit-submit"
  102. size="large"
  103. class="button-primary"
  104. @click="handleSubmit"
  105. style="padding: 0 60px;">提交入库</a-button>
  106. </div>
  107. </a-affix>
  108. </a-spin>
  109. <!-- 打印 -->
  110. <div id="print"></div>
  111. </div>
  112. </template>
  113. <script>
  114. import { STable, VSelect } from '@/components'
  115. import { getOperationalPrecision } from '@/libs/tools.js'
  116. import { dealerProductTypeList } from '@/api/dealerProductType'
  117. import { warehouseCascadeList } from '@/api/warehouse'
  118. import { allocLinkagePutDetailSn, allocLinkagePutDetailList, allocLinkagePutDetailCount, allocLinkagePutDetailUpdate, allocLinkagePutSubmit, allocLinkagePutDetailPrint } from '@/api/allocLinkagePut'
  119. export default {
  120. components: { STable, VSelect },
  121. data () {
  122. return {
  123. spinning: false,
  124. queryParam: {
  125. productCode: '', // 产品编码
  126. productName: '', // 产品名称
  127. productTypeSn1: '', // 产品分类1
  128. productTypeSn2: '', // 产品分类2
  129. productTypeSn3: '' // 产品分类3
  130. },
  131. disabled: false, // 查询、重置按钮是否可操作
  132. productTypeList: [], // 产品分类 下拉数据
  133. productType: [],
  134. warehouseCascadeData: [], // 仓库仓位
  135. // 表头
  136. columns: [
  137. { title: '序号', dataIndex: 'no', width: 80, align: 'center', fixed: 'left' },
  138. { title: '产品编码', dataIndex: 'productCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  139. { title: '产品名称', dataIndex: 'dealerProductEntity.name', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  140. { title: '原厂编码', dataIndex: 'productOrigCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  141. { title: '成本价(¥)', dataIndex: 'putCost', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  142. { title: '调入数量', dataIndex: 'putQty', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  143. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  144. { title: '成本小计(¥)', dataIndex: 'costSubtotal', width: 115, align: 'center' },
  145. { title: '仓库仓位', scopedSlots: { customRender: 'warehouse' }, width: 280, align: 'center' }
  146. ],
  147. loadData: [],
  148. pageNo: 1, // 分页页码
  149. pageSize: 10, // 分页 每页多少条
  150. paginationProps: {
  151. showSizeChanger: true, // 是否可以改变 pageSize
  152. total: 0, // 分页总条数
  153. current: 1,
  154. onShowSizeChange: (current, pageSize) => this.changePageSize(current, pageSize),
  155. onChange: (current) => this.changePage(current)
  156. },
  157. basicInfoData: null, // 基本信息
  158. productTotal: null, // 合计
  159. printerType: 'NEEDLE' // 打印机类型
  160. }
  161. },
  162. methods: {
  163. // 重置
  164. resetSearchForm () {
  165. this.queryParam.productCode = ''
  166. this.queryParam.productName = ''
  167. this.queryParam.productTypeSn1 = ''
  168. this.queryParam.productTypeSn2 = ''
  169. this.queryParam.productTypeSn3 = ''
  170. this.productType = []
  171. this.getProductList(1)
  172. },
  173. // 基本信息
  174. getDetail () {
  175. allocLinkagePutDetailSn({ sn: this.$route.params.sn }).then(res => {
  176. if (res.status == 200) {
  177. this.basicInfoData = res.data
  178. this.getProductType()
  179. } else {
  180. this.basicInfoData = null
  181. }
  182. })
  183. },
  184. // 提交
  185. handleSubmit () {
  186. this.spinning = true
  187. allocLinkagePutSubmit({ sn: this.$route.params.sn }).then(res => {
  188. if (res.status == 200) {
  189. this.$message.success(res.message)
  190. this.handleBack()
  191. this.spinning = false
  192. } else {
  193. this.spinning = false
  194. }
  195. })
  196. },
  197. // 产品列表数据
  198. getProductList (pageNo) {
  199. this.disabled = true
  200. this.pageNo = pageNo || this.pageNo
  201. const params = Object.assign({ pageNo: this.pageNo, pageSize: this.pageSize }, this.queryParam, { allocationLinkagePutSn: this.$route.params.sn })
  202. allocLinkagePutDetailList(params).then(res => {
  203. if (res.status == 200) {
  204. this.getDetailCount(params)
  205. const data = res.data
  206. this.paginationProps.total = Number(res.data.count) || 0
  207. this.paginationProps.current = data.pageNo
  208. const no = (data.pageNo - 1) * data.pageSize
  209. for (var i = 0; i < data.list.length; i++) {
  210. data.list[i].no = no + i + 1
  211. const warehouseSn = data.list[i].warehouseSn || undefined
  212. const warehouseLocationSn = data.list[i].warehouseLocationSn || undefined
  213. data.list[i].warehouseSnBackups = warehouseSn
  214. data.list[i].warehouseLocationSnBackups = warehouseLocationSn
  215. if (warehouseSn || warehouseLocationSn) {
  216. data.list[i].warehouseCascade = [warehouseSn, warehouseLocationSn]
  217. } else {
  218. data.list[i].warehouseCascade = undefined
  219. }
  220. // 成本小计 由于数据库内小数位数为4位,页面则需显示2位。因此会做小数运算精度处理
  221. data.list[i].costSubtotal = getOperationalPrecision(data.list[i].putCost, data.list[i].putQty)
  222. }
  223. this.loadData = data.list
  224. this.disabled = false
  225. } else {
  226. this.paginationProps.total = 0
  227. this.paginationProps.current = 1
  228. this.loadData = []
  229. }
  230. })
  231. },
  232. // 合计
  233. getDetailCount (params) {
  234. allocLinkagePutDetailCount(params).then(res => {
  235. if (res.status == 200) {
  236. this.productTotal = res.data
  237. } else {
  238. this.productTotal = null
  239. }
  240. })
  241. },
  242. // 返回列表
  243. handleBack () {
  244. this.$router.push({ path: '/allocationManagement/chainTransferIn/list' })
  245. },
  246. // 产品分类 change
  247. changeProductType (val, opt) {
  248. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  249. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  250. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  251. },
  252. changeWarehouseCascade (val, opt, ind) {
  253. if (val.length < 2) {
  254. this.$message.warning('当前仓库无仓位,请选择其他仓库')
  255. const warehouseSnBackups = this.loadData[ind].warehouseSnBackups || undefined
  256. const warehouseLocationSnBackups = this.loadData[ind].warehouseLocationSnBackups || undefined
  257. this.loadData[ind].warehouseSn = warehouseSnBackups
  258. this.loadData[ind].warehouseLocationSn = warehouseLocationSnBackups
  259. if (warehouseSnBackups || warehouseLocationSnBackups) {
  260. this.loadData[ind].warehouseCascade = [warehouseSnBackups, warehouseLocationSnBackups]
  261. } else {
  262. this.loadData[ind].warehouseCascade = undefined
  263. }
  264. } else {
  265. this.loadData[ind].warehouseSn = val[0] ? val[0] : ''
  266. this.loadData[ind].warehouseLocationSn = val[1] ? val[1] : ''
  267. this.handleAdd(this.loadData[ind])
  268. }
  269. },
  270. // 添加/编辑
  271. handleAdd (row) {
  272. // 清空成本价或数量时,值应保持未清空前的值,因成本价和数量都不可为空
  273. if (!row.warehouseSn) {
  274. row.warehouseSn = row.warehouseSnBackups
  275. return
  276. }
  277. if (!row.warehouseLocationSn) {
  278. row.warehouseLocationSn = row.warehouseLocationSnBackups
  279. return
  280. }
  281. const params = {
  282. id: row.id,
  283. warehouseLocationSn: row.warehouseLocationSn,
  284. warehouseSn: row.warehouseSn
  285. }
  286. this.spinning = true
  287. allocLinkagePutDetailUpdate(params).then(res => {
  288. if (res.status == 200) {
  289. this.$message.success(res.message)
  290. this.getProductList()
  291. this.spinning = false
  292. } else {
  293. this.spinning = false
  294. }
  295. })
  296. },
  297. // 产品分类 列表
  298. getProductType () {
  299. dealerProductTypeList({ sysFlag: this.basicInfoData.allocationType == 'JIANGUAN' ? '1' : '0' }).then(res => {
  300. if (res.status == 200) {
  301. this.productTypeList = res.data
  302. } else {
  303. this.productTypeList = []
  304. }
  305. })
  306. },
  307. getWarehouseCascade () {
  308. warehouseCascadeList({}).then(res => {
  309. if (res.status == 200) {
  310. res.data.map(item => {
  311. item.sn = item.warehouseSn
  312. if (item.warehouseLocationList) {
  313. item.warehouseLocationList.map(subItem => {
  314. subItem.sn = subItem.warehouseLocationSn
  315. })
  316. }
  317. })
  318. this.warehouseCascadeData = res.data
  319. console.log(this.warehouseCascadeData)
  320. } else {
  321. this.warehouseCascadeData = []
  322. }
  323. })
  324. },
  325. // 打印预览/快捷打印
  326. handlePrint (type) {
  327. const _this = this
  328. _this.spinning = true
  329. allocLinkagePutDetailPrint({ sn: this.$route.params.sn, type: this.printerType }).then(res => {
  330. _this.spinning = false
  331. if (res.type == 'application/json') {
  332. var reader = new FileReader()
  333. reader.addEventListener('loadend', function () {
  334. const obj = JSON.parse(reader.result)
  335. _this.$notification.error({
  336. message: '提示',
  337. description: obj.message
  338. })
  339. })
  340. reader.readAsText(res)
  341. } else {
  342. this.print(res, type)
  343. }
  344. })
  345. },
  346. print (data, type) {
  347. if (!data) {
  348. return
  349. }
  350. const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
  351. document.getElementById('print').innerHTML = '<iframe id="printf" name="printf" src="' + url + '" hidden></iframe>'
  352. if (type == 'preview') { // 预览
  353. window.open(url)
  354. } else if (type == 'print') { // 打印
  355. window.frames['printf'].focus()
  356. window.frames['printf'].print()
  357. }
  358. }
  359. },
  360. beforeRouteEnter (to, from, next) {
  361. next(vm => {
  362. vm.getDetail()
  363. vm.getProductList(1)
  364. vm.getWarehouseCascade()
  365. })
  366. }
  367. }
  368. </script>
  369. <style lang="less">
  370. .chainTransferInEdit-wrap{
  371. .chainTransferInEdit-back{
  372. margin-bottom: 15px;
  373. }
  374. .chainTransferInEdit-cont{
  375. margin-bottom: 15px;
  376. }
  377. }
  378. </style>