edit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <div class="bulkWarehousingOrderEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 内容 -->
  5. <a-page-header :ghost="false" :backIcon="false" class="bulkWarehousingOrderEdit-cont" >
  6. <!-- 自定义的二级文字标题 -->
  7. <template slot="subTitle">
  8. <a id="bulkWarehousingOrderEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  9. <span style="margin: 0 15px;color: #666;font-weight: bold;">单号:{{ productTotal&&productTotal.sparePartsNo }}</span>
  10. <span style="margin: 0 10px;color: #666;">供应商:{{ productTotal&&productTotal.supplierName }}</span>
  11. <a-button type="link" size="small" class="button-default" @click="showDetail=!showDetail">
  12. <a-icon :type="showDetail ? 'eye-invisible' : 'eye'"/> {{ showDetail?'隐藏':'查看' }}信息
  13. </a-button>
  14. </template>
  15. </a-page-header>
  16. <!-- 基础信息 -->
  17. <a-card size="small" :bordered="false" class="bulkWarehousingOrderEdit-cont" v-show="showDetail">
  18. <div v-if="productTotal" ref="detailBar">
  19. <a-descriptions :column="2">
  20. <a-descriptions-item label="入库单号">{{ (productTotal&&productTotal.sparePartsNo) || '--' }}</a-descriptions-item>
  21. <a-descriptions-item label="供应商">{{ (productTotal&&productTotal.supplierName) || '--' }}</a-descriptions-item>
  22. <a-descriptions-item label="入库类型">{{ (productTotal&&productTotal.sparePartsTypeDictValue) || '--' }}</a-descriptions-item>
  23. <a-descriptions-item label="入库仓库">{{ (productTotal&&productTotal.warehouseName) || '--' }}</a-descriptions-item>
  24. </a-descriptions>
  25. </div>
  26. </a-card>
  27. <a-card size="small" :bordered="false" class="bulkWarehousingOrderEdit-cont">
  28. <div ref="toolsBar">
  29. <!-- 筛选条件 -->
  30. <div class="table-page-search-wrapper">
  31. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  32. <a-row :gutter="15">
  33. <a-col :md="6" :sm="24">
  34. <a-form-item label="产品编码" prop="productCode">
  35. <a-input id="allocateBillEdit-productCode" v-model.trim="queryParam.productCode" placeholder="请输入产品编码" allowClear />
  36. </a-form-item>
  37. </a-col>
  38. <a-col :md="6" :sm="24">
  39. <a-form-item label="产品名称" prop="productName">
  40. <a-input id="allocateBillEdit-productName" v-model.trim="queryParam.productName" placeholder="请输入产品名称" allowClear />
  41. </a-form-item>
  42. </a-col>
  43. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  44. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="bulkWarehousingOrderEdit-refresh">查询</a-button>
  45. <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="bulkWarehousingOrderEdit-reset">重置</a-button>
  46. </a-col>
  47. </a-row>
  48. </a-form>
  49. </div>
  50. <!-- 操作按钮 -->
  51. <div class="table-operator" style="display: flex;align-items:center;">
  52. <div>
  53. <a-button id="bulkWarehousingOrderEdit-add" type="primary" class="button-primary" @click="handleEdit()">新增产品</a-button>
  54. <a-button id="bulkWarehousingOrderEdit-import" type="default" class="button-primary" @click="openGuideModal=true">导入产品</a-button>
  55. </div>
  56. <!-- 总计 -->
  57. <a-alert type="info" v-if="productTotal">
  58. <div slot="message">
  59. 入库数量 <strong>{{ (productTotal&&(productTotal.totalQty || productTotal.totalQty==0)) ? productTotal.totalQty : '--' }}</strong> ,
  60. <span v-if="$hasPermissions('B_sparePartsEdit_costPrice')">
  61. 入库金额 <strong>{{ (productTotal&&(productTotal.totalPrice || productTotal.totalPrice==0)) ? toThousands(productTotal.totalPrice) : '--' }}</strong>
  62. </span>
  63. </div>
  64. </a-alert>
  65. </div>
  66. </div>
  67. <!-- 列表 -->
  68. <s-table
  69. class="sTable fixPagination"
  70. :style="{ height: tableHeight+70+'px' }"
  71. ref="table"
  72. size="small"
  73. :rowKey="(record) => record.id"
  74. :columns="columns"
  75. :data="loadData"
  76. :scroll="{ y: tableHeight }"
  77. :defaultLoadData="false"
  78. bordered>
  79. <!-- 操作 -->
  80. <template slot="action" slot-scope="text, record">
  81. <a-button
  82. size="small"
  83. type="link"
  84. @click="handleEdit(record)"
  85. class="button-info"
  86. id="bulkWarehousingOrderList-edit-btn">编辑</a-button>
  87. <a-button
  88. size="small"
  89. type="link"
  90. @click="handleDel(record)"
  91. class="button-error"
  92. id="bulkWarehousingOrderList-del-btn">删除</a-button>
  93. </template>
  94. <template slot="productName" slot-scope="text, record">
  95. {{ record.productName }}
  96. <a-tag color="red" v-if="record.giftFlag==1">赠品</a-tag>
  97. </template>
  98. </s-table>
  99. </a-card>
  100. </a-spin>
  101. <div class="affix-cont">
  102. <a-button
  103. type="primary"
  104. id="bulkWarehousingOrderEdit-submit"
  105. :disabled="spinning"
  106. size="large"
  107. class="button-primary"
  108. @click="handleBack"
  109. style="padding: 0 60px;">保存</a-button>
  110. </div>
  111. <spare-parts-product-modal :openModal="openModal" :itemSn="itemSn" :nowData="productTotal" @ok="$refs.table.refresh(true)" @close="closeModal" />
  112. <!-- 导入产品 -->
  113. <importGuideModal :openModal="openGuideModal" :params="{sparePartsSn: $route.params.sn}" @close="openGuideModal=false" @ok="hanldeOk" />
  114. </div>
  115. </template>
  116. <script>
  117. import { commonMixin } from '@/utils/mixin'
  118. import { STable, VSelect } from '@/components'
  119. import { getOperationalPrecision } from '@/libs/tools.js'
  120. import sparePartsProductModal from './productModal.vue'
  121. import ImportGuideModal from './importGuideModal.vue'
  122. import { sparePartsDetailList, sparePartsPageCount, sparePartsDeleteDetail, sparePartsDetailBatchInsert } from '@/api/spareParts'
  123. export default {
  124. name: 'BulkWarehousingOrderEdit',
  125. mixins: [commonMixin],
  126. components: { STable, VSelect, sparePartsProductModal, ImportGuideModal },
  127. data () {
  128. return {
  129. spinning: false,
  130. disabled: false,
  131. showDetail: false,
  132. queryParam: {
  133. productCode: '',
  134. productName: ''
  135. },
  136. // 加载数据方法 必须为 Promise 对象
  137. loadData: parameter => {
  138. return sparePartsDetailList(Object.assign(parameter, this.queryParam, { sparePartsSn: this.$route.params.sn })).then(res => {
  139. let data
  140. if (res.status == 200) {
  141. data = res.data
  142. const no = (data.pageNo - 1) * data.pageSize
  143. for (var i = 0; i < data.list.length; i++) {
  144. data.list[i].no = no + i + 1
  145. // 小计 由于数据库内小数位数为4位,页面则需显示2位。因此会做小数运算精度处理
  146. data.list[i].subtotal = getOperationalPrecision(data.list[i].productCost || 0, data.list[i].productQty)
  147. }
  148. this.getDetailCount(Object.assign(parameter, { sparePartsSn: this.$route.params.sn }))
  149. }
  150. return data
  151. })
  152. },
  153. openModal: false, // 选择基本信息弹框是否显示
  154. basicInfoData: null, // 基本信息
  155. productTotal: null, // 合计
  156. itemSn: '',
  157. openGuideModal: false ,// 导入产品引导
  158. tableHeight: 0
  159. }
  160. },
  161. computed: {
  162. columns () {
  163. const arr = [
  164. { title: '序号', dataIndex: 'no', width: '5%', align: 'center' },
  165. { title: '产品编码', dataIndex: 'productCode', width: '20%', align: 'left', customRender: function (text) { return text || '--' } },
  166. { title: '产品名称', scopedSlots: { customRender: 'productName' }, width: '25%', align: 'left' },
  167. { title: '单位', dataIndex: 'unit', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  168. { title: '入库数量', dataIndex: 'productQty', width: '10%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  169. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  170. ]
  171. if (this.$hasPermissions('B_sparePartsEdit_costPrice')) { // 成本价权限
  172. arr.splice(5, 0, { title: '入库单价', dataIndex: 'productCost', width: '10%', align: 'right', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') })
  173. arr.splice(6,0,{ title: '小计', dataIndex: 'subtotal', width: '10%', align: 'right', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') })
  174. }
  175. return arr
  176. }
  177. },
  178. watch: {
  179. showDetail(newValue, oldValue){
  180. this.setTableH()
  181. },
  182. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  183. this.setTableH()
  184. }
  185. },
  186. methods: {
  187. // 添加/编辑
  188. handleEdit (row) {
  189. this.itemSn = (row && row.sparePartsDetailSn) ? row.sparePartsDetailSn : null
  190. this.openModal = true
  191. },
  192. setTableH () {
  193. this.$nextTick(() => { // 页面渲染完成后的回调
  194. const toolsBarH = this.$refs.toolsBar.offsetHeight
  195. this.tableHeight = window.innerHeight - toolsBarH - 282
  196. if(this.showDetail){
  197. this.tableHeight = this.tableHeight - this.$refs.detailBar.offsetHeight - 30
  198. }
  199. })
  200. },
  201. // 关闭
  202. closeModal () {
  203. this.itemSn = ''
  204. this.openModal = false
  205. },
  206. // 删除
  207. handleDel (row) {
  208. const _this = this
  209. this.$confirm({
  210. title: '提示',
  211. content: '删除后不可恢复,确定要进行删除吗?',
  212. centered: true,
  213. onOk () {
  214. _this.spinning = true
  215. sparePartsDeleteDetail({ sn: row.sparePartsDetailSn }).then(res => {
  216. if (res.status == 200) {
  217. _this.$message.success(res.message)
  218. _this.$refs.table.refresh()
  219. _this.spinning = false
  220. } else {
  221. _this.spinning = false
  222. }
  223. })
  224. }
  225. })
  226. },
  227. // 重置
  228. resetSearchForm () {
  229. this.queryParam.productCode = ''
  230. this.queryParam.productName = ''
  231. this.$refs.table.refresh(true)
  232. },
  233. // 导入产品
  234. hanldeOk (obj) {
  235. this.spinning = true
  236. sparePartsDetailBatchInsert(obj).then(res => {
  237. if (res.status == 200) {
  238. this.$refs.table.refresh(true)
  239. }
  240. this.spinning = false
  241. })
  242. },
  243. // 返回列表
  244. handleBack () {
  245. this.$router.push({ path: '/purchasingManagement/bulkWarehousingOrder/list', query: { closeLastOldTab: true } })
  246. },
  247. // 合计
  248. getDetailCount (params) {
  249. sparePartsPageCount(params).then(res => {
  250. if (res.status == 200) {
  251. this.productTotal = res.data
  252. } else {
  253. this.productTotal = null
  254. }
  255. })
  256. },
  257. pageInit () {
  258. this.productTotal = null
  259. this.openModal = false
  260. this.$refs.table.refresh(true)
  261. this.setTableH()
  262. }
  263. },
  264. mounted () {
  265. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  266. this.pageInit()
  267. }
  268. },
  269. activated () {
  270. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  271. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  272. this.pageInit()
  273. }
  274. },
  275. beforeRouteEnter (to, from, next) {
  276. next(vm => {})
  277. }
  278. }
  279. </script>
  280. <style lang="less" scoped>
  281. .bulkWarehousingOrderEdit-wrap{
  282. position: relative;
  283. height: 100%;
  284. padding-bottom: 51px;
  285. box-sizing: border-box;
  286. .bulkWarehousingOrderEdit-cont{
  287. margin-bottom: 6px;
  288. .table-operator{
  289. border: 0;
  290. padding-top: 0;
  291. }
  292. }
  293. }
  294. </style>