edit.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <div class="purchaseReceiptEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="purchaseReceiptEdit-back">
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="purchaseReceiptEdit-back-btn" href="javascript:;" @click="handleBack">
  8. <a-icon type="left" />
  9. 返回列表
  10. </a>
  11. <span style="margin: 0 15px;color: #666;font-weight: bold;">单号:{{ detailsData&&detailsData.sparePartsNo }}</span>
  12. <span style="margin: 0 10px;color: #666;">供应商:{{ detailsData&&detailsData.supplierName ||'--' }}</span>
  13. <a-button type="link" size="small" id="purchaseReceiptEdit-showDetail-btn" class="button-default" @click="showDetail=!showDetail">
  14. <a-icon :type="showDetail ? 'eye-invisible' : 'eye'"/> {{ showDetail?'隐藏':'查看' }}信息
  15. </a-button>
  16. </template>
  17. </a-page-header>
  18. <a-card size="small" :bordered="false" class="purchaseReceiptEdit-cont" v-show="showDetail">
  19. <div slot="title">
  20. <span>基础信息</span>
  21. <div style="cursor:pointer;color: #00aaff;float:right;" id="purchaseReceiptEdit-btn" @click.stop="handleEditBase" v-if="$hasPermissions('B_purchaseReceiptEdit_basicInfo')&&!(detailsData&&detailsData.supplierName)">
  22. <a-icon type="edit" /> 编辑基础信息
  23. </div>
  24. </div>
  25. <a-descriptions size="small" :column="4" style="margin-bottom: 10px;">
  26. <a-descriptions-item label="客户名称">{{ (detailsData && detailsData.lockBizDealerName) || '--' }}</a-descriptions-item>
  27. <a-descriptions-item label="收货地址">{{ (detailsData && detailsData.shippingAddr) || '--' }}</a-descriptions-item>
  28. <a-descriptions-item label="收货人">{{ (detailsData &&detailsData.consigneeName) || '--' }}</a-descriptions-item>
  29. <a-descriptions-item label="收货电话">{{ (detailsData && detailsData.consigneeTel) || '--' }}</a-descriptions-item>
  30. <a-descriptions-item label="业务状态">{{ detailsData&&detailsData.stateDictValue || '--' }}</a-descriptions-item>
  31. <a-descriptions-item label="备注">{{ detailsData&&detailsData.bizRemark || '--' }}</a-descriptions-item>
  32. <a-descriptions-item label="关联单号">{{ (detailsData && detailsData.lockBizNo) || '--' }}</a-descriptions-item>
  33. <a-descriptions-item label="销售类型">{{ (detailsData && detailsData.purchaseFlowType)?detailsData.purchaseFlowType==='DIRECT'?'直购':'平台购':'--' }}</a-descriptions-item>
  34. </a-descriptions>
  35. </a-card>
  36. <a-card size="small" :bordered="false" class="purchaseReceiptEdit-cont">
  37. <div class="table-page-search-wrapper" style="display:flex;align-items: center;justify-content: space-between;">
  38. <div style="flex-grow:1;">
  39. <a-form layout="inline" id="purchaseReceiptEdit-form-btn" @keyup.enter.native="$refs.table.refresh(true)">
  40. <a-row :gutter="15">
  41. <a-col :md="6" :sm="24">
  42. <a-form-item label="产品编码"><a-input id="purchaseReceiptEdit-productCode" v-model.trim="productForm.productCode" allowClear placeholder="请输入产品编码" /></a-form-item>
  43. </a-col>
  44. <a-col :md="6" :sm="24">
  45. <a-form-item label="产品名称"><a-input id="purchaseReceiptEdit-productName" v-model.trim="productForm.productName" allowClear placeholder="请输入产品名称" /></a-form-item>
  46. </a-col>
  47. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  48. <a-button type="primary" id="purchaseReceiptEdit-refresh" @click="$refs.table.refresh(true)">查询</a-button>
  49. <a-button style="margin-left: 5px" id="purchaseReceiptEdit-reset" @click="resetSearchForm">重置</a-button>
  50. </a-col>
  51. </a-row>
  52. </a-form>
  53. </div>
  54. </div>
  55. <div class="showBtn">
  56. <a-button id="purchaseReceiptEdit-add" v-if="$hasPermissions('B_purchaseReceiptEdit_add')" type="primary" class="button-warning" @click="handleAddEdit">新增产品</a-button>
  57. <a-button id="purchaseReceiptEdit-ex" v-if="$hasPermissions('B_purchaseReceiptEdit_import')" class="button-warning" @click="handleImport">导入产品</a-button>
  58. <a-button
  59. id="purchaseReceiptEdit-queryQty"
  60. type="primary"
  61. class="button-warning"
  62. :loading="loading"
  63. v-if="$hasPermissions('B_purchaseReceiptEdit_thirdQty')"
  64. @click="handleThirdQty">第三方库存</a-button>
  65. <a-alert type="info">
  66. <div slot="message" class="total-bar">
  67. <span>采购数量:{{ statisticsObj && (statisticsObj.productTotalQty || statisticsObj.productTotalQty == 0) ? statisticsObj.productTotalQty : '--' }};</span>
  68. <span v-if="$hasPermissions('M_purchaseReceiptEdit_costPrice')">采购金额:{{ (statisticsObj && (statisticsObj.productTotalCost || statisticsObj.productTotalCost == 0) )? statisticsObj.productTotalCost : '--' }};</span>
  69. </div>
  70. </a-alert>
  71. </div>
  72. <s-table
  73. class="sTable"
  74. ref="table"
  75. size="small"
  76. :rowKey="(record) => record.id"
  77. :columns="columns"
  78. :data="loadData"
  79. :defaultLoadData="false"
  80. bordered>
  81. <!-- 操作 -->
  82. <template slot="action" slot-scope="text, record">
  83. <a-button
  84. size="small"
  85. type="link"
  86. v-if="$hasPermissions('B_purchaseReceiptEdit_edit')"
  87. @click="handleAddEdit(record)"
  88. class="button-info"
  89. :id="'purchaseReceiptEdit-edit-btn'+record.id">编辑</a-button>
  90. <a-button
  91. size="small"
  92. type="link"
  93. :loading="delLoading"
  94. class="button-error"
  95. v-if="$hasPermissions('B_purchaseReceiptEdit_del')"
  96. @click="handleDel(record)"
  97. :id="'purchaseReceiptEdit-del-btn'+record.id">删除</a-button>
  98. </template>
  99. </s-table>
  100. </a-card>
  101. </a-spin>
  102. <div class="affix-cont">
  103. <a-button
  104. size="large"
  105. style="padding: 0 60px;"
  106. :disabled="spinning"
  107. type="primary"
  108. class="button-primary"
  109. v-if="$hasPermissions('B_purchaseReceiptEdit_submit')"
  110. @click="handleSubmit"
  111. id="purchaseReceiptEdit-submit">提交</a-button>
  112. </div>
  113. <!-- 新增弹窗-->
  114. <add-modal
  115. v-drag
  116. :itemSn="itemSn"
  117. :openModal="openAddModal"
  118. :nowData="detailsData"
  119. @ok="resetTable"
  120. @close="openAddModal=false" />
  121. <!-- 导入弹窗 -->
  122. <importGuideModal :openModal="openGuideModal" :params="{sparePartsSn: $route.query.sn}" @close="openGuideModal=false" @ok="hanldleImportOk" />
  123. <!-- 编辑基础信息弹窗 -->
  124. <basic-info-modal
  125. v-drag
  126. :openModal="openBasicInfoModal"
  127. :itemData="itemObj"
  128. :itemSn="sparePartsSn"
  129. @ok="resetSearchForm"
  130. @close="openBasicInfoModal = false" />
  131. </div>
  132. </template>
  133. <script>
  134. import { commonMixin } from '@/utils/mixin'
  135. // 组件
  136. import { STable, VSelect } from '@/components'
  137. import addModal from './addModal.vue'
  138. import basicInfoModal from './basicInfoModal.vue'
  139. import importGuideModal from './importGuideModal.vue'
  140. // 接口
  141. import { purchaseDetailPageList, queryDetailCount, purchaseDetailDel, purchaseSubmit, purchaseImportBatchInsert, purchaseDetailPageCount } from '@/api/purchase'
  142. import { getThirdStockQty } from '@/api/salesNew'
  143. export default {
  144. name: 'PurchaseReturnEdit',
  145. mixins: [commonMixin],
  146. components: { STable, VSelect, basicInfoModal, addModal, importGuideModal },
  147. data () {
  148. return {
  149. spinning: false,
  150. showDetail: true, // 是否显示基础信息
  151. delLoading: false, // 删除loading
  152. openAddModal: false, // 打开新增产品弹窗
  153. openBasicInfoModal: false, // 打开编辑基础信息弹窗
  154. openGuideModal: false, // 导入产品弹窗
  155. detailsData: null, // 基础信息数据
  156. addMoreLoading: false, // 防止多次添加 加载状态
  157. loading: false, // 第三方库存按钮加载状态
  158. // 查询参数
  159. productForm: {
  160. productCode: '', // 产品编码
  161. productName: '' // 产品名称
  162. },
  163. statisticsObj: undefined, // 统计明细
  164. sparePartsSn: undefined, // 采购入库sn
  165. itemSn: undefined, // 列表行 sn
  166. itemObj: null, // 基础信息弹窗回显数据
  167. // 加载数据方法 必须为 Promise 对象
  168. loadData: parameter => {
  169. this.productForm.sparePartsSn = this.sparePartsSn
  170. const parames = Object.assign(parameter, this.productForm)
  171. // 获取列表数据 有分页
  172. return purchaseDetailPageList(parames).then(res => {
  173. let data
  174. if (res.status == 200) {
  175. data = res.data
  176. // 计算表格序号
  177. const no = (data.pageNo - 1) * data.pageSize
  178. for (var i = 0; i < data.list.length; i++) {
  179. data.list[i].no = no + i + 1
  180. }
  181. // 获取统计数据
  182. this.getStatisticsData(parames)
  183. // 获取基础信息
  184. this.getBasicsData()
  185. }
  186. return data
  187. })
  188. }
  189. }
  190. },
  191. computed: {
  192. // 列表表头配置
  193. columns () {
  194. const _this = this
  195. const arr = [
  196. { title: '序号', dataIndex: 'no', align: 'center', width: '4%' },
  197. { title: '产品编码', dataIndex: 'productCode', width: '18%', align: 'center', customRender: function (text) { return text || '--' } },
  198. { title: '产品名称', dataIndex: 'productName', width: '25%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  199. { title: '单位', dataIndex: 'unit', align: 'center', width: '6%', customRender: function (text) { return text || '--' } },
  200. { title: '采购数量', dataIndex: 'productQty', align: 'center', width: '13%', customRender: function (text) { return text || text == 0 ? text : '--' } },
  201. { title: '第三方库存', dataIndex: 'thirdStockQty', align: 'center', width: '10%', customRender: function (text) { return text || text == 0 ? text : '--' } },
  202. // { title: '采购单价', dataIndex: 'productCost', width: '8%', align: 'right', customRender: function (text) { return text || text == 0 ? _this.toThousands(text, 2) : '--' }, },
  203. // { title: '采购金额', dataIndex: 'subtotal', width: '8%', align: 'right', customRender: function (text) { return text || text == 0 ? _this.toThousands(text, 2) : '--' } },
  204. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  205. ]
  206. if (this.$hasPermissions('M_purchaseReceiptEdit_costPrice')) {
  207. arr.splice(6, 0, { title: '采购单价', dataIndex: 'productCost', width: '8%', align: 'right', customRender: function (text) { return text || text == 0 ? _this.toThousands(text, 2) : '--' } })
  208. if (this.detailsData && this.detailsData.supplierName) {
  209. arr.splice(7, 0, { title: '采购金额', dataIndex: 'subtotal', width: '8%', align: 'right', customRender: function (text) { return text || text == 0 ? _this.toThousands(text, 2) : '--' } })
  210. } else {
  211. arr.splice(7, 0, { title: '采购金额', dataIndex: 'subtotal', width: '8%', align: 'right', customRender: function (text) { return text || '--' } })
  212. }
  213. }
  214. return arr
  215. }
  216. },
  217. methods: {
  218. // 新增产品成功 刷新基础信息时间,防止重复提交
  219. handleAddOk () {
  220. this.pageInit()
  221. },
  222. // 第三方库存
  223. handleThirdQty () {
  224. const params = {
  225. sparePartsSn: this.sparePartsSn
  226. }
  227. getThirdStockQty(params).then(res => {
  228. if (res.status == 200) {
  229. this.handleAddOk(true)
  230. }
  231. })
  232. },
  233. // 导入产品
  234. hanldleImportOk (listCon) {
  235. this.spinning = true
  236. purchaseImportBatchInsert(listCon).then(res => {
  237. if (res.status == 200) {
  238. this.$message.success('导入成功')
  239. this.handleAddOk()
  240. }
  241. this.spinning = false
  242. })
  243. },
  244. // 编辑基础信息
  245. handleEditBase () {
  246. this.itemObj = { dealerName: this.detailsData.lockBizDealerName, lockBizNo: this.detailsData.lockBizNo, bizRemark: this.detailsData.bizRemark }
  247. this.openBasicInfoModal = true
  248. },
  249. // 返回列表并刷新
  250. handleBack () {
  251. this.$router.push({ name: 'purchaseReceiptList', query: { closeLastOldTab: true } })
  252. },
  253. // 新增/编辑产品
  254. handleAddEdit (row) {
  255. if (this.detailsData && !this.detailsData.supplierName) {
  256. this.$message.warning('供应商不能为空,请先编辑基础信息!')
  257. return
  258. }
  259. this.itemSn = (row && row.sparePartsDetailSn) ? row.sparePartsDetailSn : null
  260. this.openAddModal = true
  261. },
  262. // 导入产品
  263. handleImport () {
  264. this.openGuideModal = true
  265. },
  266. // 删除所选产品
  267. handleDel (row) {
  268. const _this = this
  269. this.$confirm({
  270. title: '提示',
  271. content: '确认要删除吗?',
  272. centered: true,
  273. closable: true,
  274. onOk () {
  275. _this.delLoading = true
  276. _this.spinning = true
  277. purchaseDetailDel({ sn: row.sparePartsDetailSn })
  278. .then(res => {
  279. if (res.status == 200) {
  280. _this.resetTable()
  281. }
  282. _this.$message.info(res.message)
  283. _this.delLoading = false
  284. _this.spinning = false
  285. })
  286. .catch(err => {
  287. _this.$message.info(err.message)
  288. _this.delLoading = false
  289. })
  290. }
  291. })
  292. },
  293. // 刷新列表 更新操作时间
  294. resetTable () {
  295. this.itemSn = undefined
  296. this.$refs.table.refresh(true)
  297. },
  298. // 重置
  299. resetSearchForm () {
  300. this.productForm.productName = ''
  301. this.productForm.productCode = ''
  302. this.$refs.table.refresh(true)
  303. },
  304. // 提交采购入库
  305. handleSubmit (data) {
  306. this.spinning = true
  307. purchaseSubmit({ sn: this.sparePartsSn }).then(res => {
  308. if (res.status == 200) {
  309. this.handleBack()
  310. this.$message.success(res.message)
  311. }
  312. this.spinning = false
  313. })
  314. },
  315. // 初始化
  316. pageInit () {
  317. this.sparePartsSn = this.$route.query.sn
  318. this.$nextTick(() => {
  319. this.resetSearchForm()
  320. })
  321. },
  322. // 获取页面统计数据
  323. getStatisticsData (ajaxData) {
  324. purchaseDetailPageCount(ajaxData).then(res => {
  325. if (res.status == 200) {
  326. if (res.data) {
  327. this.statisticsObj = res.data
  328. } else {
  329. this.statisticsObj = null
  330. }
  331. }
  332. })
  333. },
  334. // 获取基础信息
  335. getBasicsData () {
  336. queryDetailCount({ sn: this.sparePartsSn }).then(res => {
  337. if (res.status == 200) {
  338. this.detailsData = res.data
  339. } else {
  340. this.detailsData = null
  341. }
  342. })
  343. }
  344. },
  345. mounted () {
  346. if (!this.$store.state.app.isNewTab) {
  347. // 页签刷新时调用
  348. this.pageInit()
  349. }
  350. },
  351. activated () {
  352. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  353. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  354. this.pageInit()
  355. }
  356. },
  357. beforeRouteEnter (to, from, next) {
  358. next(vm => {})
  359. }
  360. }
  361. </script>
  362. <style lang="less">
  363. .purchaseReceiptEdit-wrap {
  364. position: relative;
  365. height: 100%;
  366. padding-bottom: 51px;
  367. box-sizing: border-box;
  368. > .ant-spin-nested-loading {
  369. overflow-y: scroll;
  370. height: 100%;
  371. }
  372. .showBtn{
  373. display:flex;
  374. align-items:center;
  375. margin-bottom:10px;
  376. }
  377. .purchaseReceiptEdit-cont {
  378. margin-top: 6px;
  379. .ant-divider-horizontal {
  380. margin: 10px 0 24px;
  381. }
  382. .total-bar {
  383. display: flex;
  384. align-items: center;
  385. justify-content: space-between;
  386. > div {
  387. &:last-child {
  388. display: flex;
  389. align-items: center;
  390. justify-content: space-between;
  391. > div {
  392. padding: 0 10px;
  393. }
  394. }
  395. }
  396. }
  397. }
  398. }
  399. </style>