edit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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;">单号:{{ basicInfoData&&basicInfoData.sparePartsNo }}</span>
  10. <span style="margin: 0 10px;color: #666;">供应商:{{ basicInfoData&&basicInfoData.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="basicInfoData" ref="detailBar">
  19. <a-descriptions :column="2">
  20. <a-descriptions-item label="入库单号">{{ (basicInfoData&&basicInfoData.sparePartsNo) || '--' }}</a-descriptions-item>
  21. <a-descriptions-item label="供应商">{{ (basicInfoData&&basicInfoData.supplierName) || '--' }}</a-descriptions-item>
  22. <a-descriptions-item label="入库类型">{{ (basicInfoData&&basicInfoData.sparePartsTypeDictValue) || '--' }}</a-descriptions-item>
  23. <a-descriptions-item label="入库仓库">{{ (basicInfoData&&basicInfoData.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.productTotalQty || productTotal.productTotalQty==0)) ? productTotal.productTotalQty : '--' }}</strong> ,
  60. <span v-if="$hasPermissions('B_sparePartsEdit_costPrice')">
  61. 入库金额 <strong>{{ (productTotal&&(productTotal.productTotalCost || productTotal.productTotalCost==0)) ? toThousands(productTotal.productTotalCost) : '--' }}</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="basicInfoData" @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. import { queryDetailCount } from '@/api/purchase'
  124. export default {
  125. name: 'BulkWarehousingOrderEdit',
  126. mixins: [commonMixin],
  127. components: { STable, VSelect, sparePartsProductModal, ImportGuideModal },
  128. data () {
  129. return {
  130. spinning: false,
  131. disabled: false,
  132. showDetail: false,
  133. queryParam: {
  134. productCode: '',
  135. productName: ''
  136. },
  137. // 加载数据方法 必须为 Promise 对象
  138. loadData: parameter => {
  139. return sparePartsDetailList(Object.assign(parameter, this.queryParam, { sparePartsSn: this.$route.params.sn })).then(res => {
  140. let data
  141. if (res.status == 200) {
  142. data = res.data
  143. const no = (data.pageNo - 1) * data.pageSize
  144. for (var i = 0; i < data.list.length; i++) {
  145. data.list[i].no = no + i + 1
  146. // 小计 由于数据库内小数位数为4位,页面则需显示2位。因此会做小数运算精度处理
  147. data.list[i].subtotal = getOperationalPrecision(data.list[i].productCost || 0, data.list[i].productQty)
  148. }
  149. this.getDetailCount(Object.assign(parameter, { sparePartsSn: this.$route.params.sn }))
  150. this.getBasicInfoData()
  151. }
  152. return data
  153. })
  154. },
  155. openModal: false, // 选择基本信息弹框是否显示
  156. basicInfoData: null, // 基础信息
  157. productTotal: null, // 合计
  158. itemSn: '',
  159. openGuideModal: false, // 导入产品引导
  160. tableHeight: 0
  161. }
  162. },
  163. computed: {
  164. columns () {
  165. const arr = [
  166. { title: '序号', dataIndex: 'no', width: '5%', align: 'center' },
  167. { title: '产品编码', dataIndex: 'productCode', width: '20%', align: 'left', customRender: function (text) { return text || '--' } },
  168. { title: '产品名称', scopedSlots: { customRender: 'productName' }, width: '25%', align: 'left' },
  169. { title: '单位', dataIndex: 'unit', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  170. { title: '入库数量', dataIndex: 'productQty', width: '10%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  171. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  172. ]
  173. if (this.$hasPermissions('B_sparePartsEdit_costPrice')) { // 成本价权限
  174. arr.splice(5, 0, { title: '入库单价', dataIndex: 'productCost', width: '10%', align: 'right', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') })
  175. arr.splice(6, 0, { title: '小计', dataIndex: 'subtotal', width: '10%', align: 'right', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') })
  176. }
  177. return arr
  178. }
  179. },
  180. watch: {
  181. showDetail (newValue, oldValue) {
  182. this.setTableH()
  183. },
  184. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  185. this.setTableH()
  186. }
  187. },
  188. methods: {
  189. // 添加/编辑
  190. handleEdit (row) {
  191. this.itemSn = (row && row.sparePartsDetailSn) ? row.sparePartsDetailSn : null
  192. this.openModal = true
  193. },
  194. setTableH () {
  195. this.$nextTick(() => { // 页面渲染完成后的回调
  196. const toolsBarH = this.$refs.toolsBar.offsetHeight
  197. this.tableHeight = window.innerHeight - toolsBarH - 282
  198. if (this.showDetail) {
  199. this.tableHeight = this.tableHeight - this.$refs.detailBar.offsetHeight - 30
  200. }
  201. })
  202. },
  203. // 关闭
  204. closeModal () {
  205. this.itemSn = ''
  206. this.openModal = false
  207. },
  208. // 删除
  209. handleDel (row) {
  210. const _this = this
  211. this.$confirm({
  212. title: '提示',
  213. content: '删除后不可恢复,确定要进行删除吗?',
  214. centered: true,
  215. onOk () {
  216. _this.spinning = true
  217. sparePartsDeleteDetail({ sn: row.sparePartsDetailSn }).then(res => {
  218. if (res.status == 200) {
  219. _this.$message.success(res.message)
  220. _this.$refs.table.refresh()
  221. _this.spinning = false
  222. } else {
  223. _this.spinning = false
  224. }
  225. })
  226. }
  227. })
  228. },
  229. // 重置
  230. resetSearchForm () {
  231. this.queryParam.productCode = ''
  232. this.queryParam.productName = ''
  233. this.$refs.table.refresh(true)
  234. },
  235. // 导入产品
  236. hanldeOk (obj) {
  237. this.spinning = true
  238. sparePartsDetailBatchInsert(obj).then(res => {
  239. if (res.status == 200) {
  240. this.$refs.table.refresh(true)
  241. }
  242. this.spinning = false
  243. })
  244. },
  245. // 返回列表
  246. handleBack () {
  247. this.$router.push({ path: '/purchasingManagement/bulkWarehousingOrder/list', query: { closeLastOldTab: true } })
  248. },
  249. // 获取统计数据
  250. getDetailCount (params) {
  251. sparePartsPageCount(params).then(res => {
  252. if (res.status == 200) {
  253. this.productTotal = res.data
  254. } else {
  255. this.productTotal = null
  256. }
  257. })
  258. },
  259. // 获取基础信息数据
  260. getBasicInfoData () {
  261. queryDetailCount({ sn: this.$route.params.sn }).then(res => {
  262. if (res.status == 200) {
  263. this.basicInfoData = res.data
  264. } else {
  265. this.basicInfoData = null
  266. }
  267. })
  268. },
  269. pageInit () {
  270. this.productTotal = null
  271. this.openModal = false
  272. this.$refs.table.refresh(true)
  273. this.setTableH()
  274. }
  275. },
  276. mounted () {
  277. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  278. this.pageInit()
  279. }
  280. },
  281. activated () {
  282. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  283. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  284. this.pageInit()
  285. }
  286. },
  287. beforeRouteEnter (to, from, next) {
  288. next(vm => {})
  289. }
  290. }
  291. </script>
  292. <style lang="less" scoped>
  293. .bulkWarehousingOrderEdit-wrap{
  294. position: relative;
  295. height: 100%;
  296. padding-bottom: 51px;
  297. box-sizing: border-box;
  298. .bulkWarehousingOrderEdit-cont{
  299. margin-bottom: 6px;
  300. .table-operator{
  301. border: 0;
  302. padding-top: 0;
  303. }
  304. }
  305. }
  306. </style>