ShopPurchaseArea.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <el-form
  3. ref="dataForm"
  4. v-loading="loading"
  5. :model="dataForm"
  6. :rules="dataFormRules"
  7. label-position="left"
  8. label-width="90px"
  9. >
  10. <el-form-item v-if="formDisabled" label="单据编号" prop="purchaseId">
  11. <el-input disabled :value="dataForm.purchaseId" />
  12. </el-form-item>
  13. <el-row :gutter="20">
  14. <el-col :span="8">
  15. <el-form-item label="网点" prop="websitId">
  16. <el-select v-model="dataForm.websitId" :disabled="formDisabled" placeholder="请选择网点" style="width: 100%">
  17. <el-option v-for="(item, index) in authShop" :key="index" :label="item.name" :value="item.websitId" />
  18. </el-select>
  19. </el-form-item>
  20. </el-col>
  21. <el-col :span="8">
  22. <el-form-item label="供应商" prop="venderId">
  23. <el-select
  24. v-model="dataForm.venderId"
  25. filterable
  26. :disabled="formDisabled"
  27. placeholder="请选择供应商"
  28. style="width: 100%"
  29. >
  30. <el-option
  31. v-for="(item, index) in venderList"
  32. :key="index"
  33. :label="item.venderName"
  34. :value="item.venderId"
  35. :disabled="item.status !== 'ON'"
  36. />
  37. </el-select>
  38. </el-form-item>
  39. </el-col>
  40. <el-col :span="8">
  41. <el-form-item label="状态" prop="flag">
  42. <el-input disabled :value="sheetFlagStr('label', dataForm.flag)" />
  43. </el-form-item>
  44. </el-col>
  45. </el-row>
  46. <el-form-item v-if="dataForm.notes3" label="申请单备注">
  47. <el-input v-model="dataForm.notes3" disabled />
  48. </el-form-item>
  49. <el-form-item label="备注">
  50. <el-input
  51. v-model="dataForm.notes2"
  52. autocomplete="off"
  53. placeholder="备注"
  54. :disabled="inputParam.openType === 'view'"
  55. />
  56. </el-form-item>
  57. <el-row>
  58. <el-col>
  59. <el-divider>采购明细</el-divider>
  60. </el-col>
  61. <el-col>
  62. <el-table
  63. ref="goodsTable"
  64. :data="dataForm.items"
  65. max-height="500"
  66. size="mini"
  67. border
  68. header-cell-class-name="headerRowColor"
  69. class="detail-table"
  70. show-summary
  71. :summary-method="getSummaries"
  72. >
  73. <el-table-column prop="goodsId" label="辅材编号" width="160" />
  74. <el-table-column prop="goodsName" label="辅材名称" />
  75. <el-table-column prop="applyCost" label="预估进价" header-align="left" align="center" />
  76. <el-table-column prop="applyQty" label="订货数量" header-align="left" align="center" />
  77. <el-table-column prop="checkQty" label="供应数量" header-align="left" align="center">
  78. <template slot-scope="{ $index, row }">
  79. <label v-if="inputParam.openType === 'view'">{{ row.checkQty + ' /' + row.goodsStockUnit }}</label>
  80. <el-form-item
  81. v-else
  82. style="margin: 18px 0"
  83. label-width="0"
  84. size="mini"
  85. :prop="'items.' + $index + '.checkQty'"
  86. :rules="dataFormRules.checkQty"
  87. >
  88. <el-input v-model="row.checkQty" size="mini">
  89. <template slot="suffix">{{ ' /' + row.goodsStockUnit }}</template>
  90. </el-input>
  91. </el-form-item>
  92. </template>
  93. </el-table-column>
  94. <template v-if="dataForm.flag === 100">
  95. <el-table-column prop="recQty" label="验收数量" />
  96. <el-table-column prop="recGiftQty" label="验收赠品数量" />
  97. </template>
  98. <el-table-column prop="goodsStockUnit" label="采购单位" />
  99. <el-table-column prop="goodsSpecification" label="规格" />
  100. </el-table>
  101. <el-row>
  102. <el-col :span="24"
  103. ><div>共 {{ goodsTotalCount }} 条记录</div></el-col
  104. >
  105. </el-row>
  106. </el-col>
  107. </el-row>
  108. <div style="text-align: right">
  109. <el-button @click="cancelForm">取 消</el-button>
  110. <el-button
  111. v-if="$restrict('edit') && dataForm.flag === 'SUBMIT' && dataForm.isRecheck === 'NO'"
  112. type="primary"
  113. :disabled="saveBtn"
  114. @click="submitForm('edit')"
  115. >保 存</el-button
  116. >
  117. <el-button
  118. v-if="$restrict('verify') && dataForm.flag === 'SUBMIT' && dataForm.isRecheck === 'NO'"
  119. type="success"
  120. @click="verifySheet(dataForm.purchaseId)"
  121. >核 实</el-button
  122. >
  123. <el-button
  124. v-if="$restrict('revoke') && dataForm.flag === 'SUBMIT' && dataForm.isRecheck === 'NO'"
  125. type="danger"
  126. @click="revokeSheet(dataForm.purchaseId)"
  127. >撤 消</el-button
  128. >
  129. </div>
  130. </el-form>
  131. </template>
  132. <script>
  133. import {
  134. editPurchaseApplySheet,
  135. revokePurchaseApplySheet,
  136. getPurchaseApplySheet,
  137. verifyPurchaseApplySheet
  138. } from '@/api/material-system/vender/shop-purchase-apply'
  139. import { listPageV2 } from '@/api/auxiliaryFittings/supplier'
  140. import { getWebsit } from '@/api/customerManagement.js'
  141. export default {
  142. name: 'ShopPurchaseArea',
  143. props: {
  144. inputParam: {
  145. type: Object,
  146. default: function () {
  147. return {
  148. openType: 'add',
  149. purchaseId: ''
  150. }
  151. }
  152. }
  153. },
  154. data() {
  155. const validatecheckQty = (rule, value, callback) => {
  156. this.saveBtn = true
  157. if (Number.isNaN(parseFloat(value))) {
  158. return callback(new Error('请输入数字值'))
  159. }
  160. if (parseFloat(value) < 0) {
  161. return callback(new Error('不能少于0'))
  162. }
  163. this.saveBtn = false
  164. callback()
  165. }
  166. return {
  167. loading: false,
  168. dataForm: {
  169. purchaseId: '', // 单据ID
  170. websitId: '', // 网点ID
  171. websitName: '', // 网点名称
  172. venderId: '', // 供应商ID
  173. venderName: '', // 供应商名称
  174. notes2: '', // 备注
  175. notes3: '', // 网点备注
  176. flag: '',
  177. items: [] // 关系辅材列表
  178. },
  179. authShop: [],
  180. dataFormRules: {
  181. checkQty: [{ validator: validatecheckQty, trigger: 'blur' }]
  182. },
  183. venderList: [],
  184. saveBtn: false // 保存按钮状态
  185. }
  186. },
  187. computed: {
  188. formDisabled() {
  189. return this.inputParam.openType === 'view' || this.dataForm.purchaseId !== ''
  190. },
  191. goodsTotalCount: function () {
  192. return this.dataForm && this.dataForm.items ? this.dataForm.items.length : 0
  193. }
  194. },
  195. mounted() {
  196. this.getVenderList()
  197. this.getDetail()
  198. getWebsit({ type: 'C', status: true }).then(res => {
  199. this.authShop = res.data
  200. })
  201. },
  202. methods: {
  203. sheetFlagStr(type, val, filterArrays) {
  204. const flag = [
  205. { label: '保存', value: 'SAVE' },
  206. { label: '提交', value: 'SUBMIT' },
  207. { label: '作废', value: 'FAIL' },
  208. { label: '已审核', value: 'OK' }
  209. ].filter(obj => {
  210. if (filterArrays) {
  211. return filterArrays.indexOf(obj.value) >= 0
  212. }
  213. return true
  214. })
  215. if (type === 'select') {
  216. // 下拉选择返回数组
  217. return flag
  218. } else if (type === 'label') {
  219. // 显示代号返回字符
  220. if (val === null || val === '') return ''
  221. const obj = flag.find(o => o.value === val)
  222. return obj ? obj.label : ''
  223. }
  224. return ''
  225. },
  226. // 获取供应商列表
  227. getVenderList() {
  228. listPageV2({
  229. pageNum: 1,
  230. pageSize: -1,
  231. params: [
  232. { param: 'a.status', compare: '=', value: 'ON' },
  233. { param: 'a.vender_type', compare: 'like', value: '辅材' }
  234. ]
  235. }).then(res => {
  236. this.venderList = res.data.records
  237. })
  238. },
  239. getDetail(id) {
  240. if (id || this.inputParam.purchaseId) {
  241. this.loading = true
  242. getPurchaseApplySheet({ purchaseId: id || this.inputParam.purchaseId }).then(res => {
  243. this.loading = false
  244. this.setDataForm(res.data)
  245. })
  246. }
  247. },
  248. cancelForm() {
  249. this.$parent.backUpdPage()
  250. },
  251. submitForm(type) {
  252. this.$refs.dataForm.validate(valid => {
  253. if (valid) {
  254. editPurchaseApplySheet(this.dataForm).then(() => {
  255. this.cancelForm()
  256. this.$successMsg('保存成功')
  257. })
  258. }
  259. })
  260. },
  261. setDataForm(data) {
  262. this.dataForm = {
  263. purchaseId: data.purchaseId, // 单据编号
  264. websitId: data.websitId, // 网点ID
  265. venderId: data.venderId, // 供应商Id
  266. flag: data.flag,
  267. notes: data.notes, // 备注
  268. items: data.items // 关系商品列表
  269. }
  270. },
  271. // 核实 采购申请单
  272. verifySheet(purchaseId) {
  273. this.$confirm(
  274. `此操作将核实 ${purchaseId} 单据,<span style="color: #ff0000;">当前内容如果已修改将忽略保存</span>,是否继续?`,
  275. '提示',
  276. {
  277. confirmButtonText: '确定',
  278. cancelButtonText: '取消',
  279. type: 'warning',
  280. dangerouslyUseHTMLString: true
  281. }
  282. )
  283. .then(() => {
  284. this.loading = true
  285. verifyPurchaseApplySheet({ purchaseId: purchaseId }).then(
  286. () => {
  287. setTimeout(() => {
  288. this.inputParam.openType = 'view'
  289. this.getDetail(purchaseId)
  290. this.cancelForm()
  291. this.$successMsg('核实成功')
  292. this.loading = false
  293. }, 2000)
  294. },
  295. () => {
  296. this.loading = false
  297. }
  298. )
  299. })
  300. .catch(() => console.log('取消'))
  301. },
  302. // 撤消单据
  303. revokeSheet(purchaseId) {
  304. this.$confirm(`此操作将撤消 ${purchaseId} 单据, 是否继续?`, '提示', {
  305. confirmButtonText: '确定',
  306. cancelButtonText: '取消',
  307. type: 'warning'
  308. })
  309. .then(() => {
  310. revokePurchaseApplySheet({ purchaseId: purchaseId }).then(() => {
  311. this.cancelForm()
  312. this.$successMsg('撤消成功')
  313. })
  314. })
  315. .catch(() => console.log('取消'))
  316. },
  317. getSummaries(param) {
  318. const { columns, data } = param
  319. const sums = []
  320. columns.forEach((column, index) => {
  321. if (index === 0) {
  322. sums[index] = '合计'
  323. return
  324. }
  325. const values = data.map(item => Number(item[column.property]))
  326. if (!values.every(value => isNaN(value))) {
  327. sums[index] = values.reduce((prev, curr) => {
  328. const value = Number(curr)
  329. if (!isNaN(value)) {
  330. return prev + curr
  331. } else {
  332. return prev
  333. }
  334. }, 0)
  335. } else {
  336. sums[index] = ''
  337. }
  338. })
  339. return sums
  340. }
  341. }
  342. }
  343. </script>
  344. <style lang="scss" scoped>
  345. .detail-table {
  346. width: 100%;
  347. margin: 15px 0;
  348. ::v-deep .el-input__suffix-inner {
  349. color: red;
  350. }
  351. }
  352. </style>