index.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <template-page
  3. ref="pageRef"
  4. :get-list="getList"
  5. :table-attributes="tableAttributes"
  6. :table-events="tableEvents"
  7. :options-evens-group="optionsEvensGroup"
  8. :moreParameters="moreParameters"
  9. :column-parsing="columnParsing"
  10. :exportList="exportList"
  11. :operation="operation()"
  12. >
  13. <div class="cartographer_big">
  14. <el-dialog
  15. :title="formDialogTitles[formDialogType]"
  16. width="100%"
  17. :modal="false"
  18. :visible.sync="formDialog"
  19. :before-close="handleClose"
  20. >
  21. <zj-page-container>
  22. <zj-page-fill>
  23. <div style="box-sizing: border-box; padding: 20px 20px 0 20px">
  24. <zj-form-container ref="formRef" :form-data="formData" :form-attributes="{ size: 'mini' }">
  25. <zj-form-module title="单据信息" label-width="100px" :form-data="formData" :form-items="formItems">
  26. </zj-form-module>
  27. <zj-form-module title="商品信息" label-width="100px" :form-data="formData" :form-items="formItems2">
  28. </zj-form-module>
  29. </zj-form-container>
  30. </div>
  31. </zj-page-fill>
  32. <div style="text-align: right; box-sizing: border-box; padding: 16px 20px">
  33. <el-button v-if="formDialogType == 0" size="mini" type="primary" @click="save">保存</el-button>
  34. <el-button v-if="formDialogType == 1" size="mini" type="primary" @click="save2">保存</el-button>
  35. <el-button v-if="formDialogType == 1" size="mini" type="primary" @click="submit">提交</el-button>
  36. <el-button v-if="formDialogType == 3" size="mini" type="primary" @click="examine('OK')">审核通过</el-button>
  37. <el-button v-if="formDialogType == 3" size="mini" type="primary" @click="examine('FAIL')"
  38. >审核驳回</el-button
  39. >
  40. </div>
  41. </zj-page-container>
  42. </el-dialog>
  43. </div>
  44. </template-page>
  45. </template>
  46. <script>
  47. import TemplatePage from '@/components/template/template-page-1.vue'
  48. import import_mixin from '@/components/template/import_mixin.js'
  49. import operation_mixin from '@/components/template/operation_mixin.js'
  50. import {
  51. goodsPlanItemList,
  52. goodsPlanListExport,
  53. goodsPlanAdd,
  54. goodsPlanUpdate,
  55. goodsPlanSubmit,
  56. goodsPlanDetail,
  57. goodsPlanConfirm,
  58. goodsPlanDel
  59. } from '@/api/purchaseSchedule.js'
  60. import form_ty from './mixins/common_form'
  61. import storage_table from './mixins/storage_table'
  62. import storage_goods from './mixins/storage_goods'
  63. import { delayPerform, firstPerform, intervalPerform, passivePerform, queuePerform } from 'js-perform-lock'
  64. export default {
  65. components: { TemplatePage },
  66. mixins: [import_mixin, operation_mixin, form_ty, storage_table, storage_goods],
  67. data() {
  68. return {
  69. // 表格属性
  70. tableAttributes: {
  71. // 启用勾选列
  72. selectColumn: false
  73. },
  74. // 表格事件
  75. tableEvents: {
  76. 'selection-change': this.selectionChange
  77. },
  78. // 勾选选中行
  79. recordSelected: [],
  80. /** 表单变量 */
  81. formDialogType: 0,
  82. formDialogTitles: ['新增', '编辑', '详情', '审核'],
  83. formDialog: false,
  84. formData: {
  85. companyWechatId: '',
  86. companyWechatName: '',
  87. examineBy: '',
  88. examineTime: '',
  89. fileUrl: '',
  90. remark: '',
  91. status: '',
  92. submitBy: '',
  93. submitTime: '',
  94. totalAmount: '',
  95. totalQty: '',
  96. updateBy: '',
  97. updateTime: '',
  98. venderId: '',
  99. venderName: '',
  100. storageId: '',
  101. storageName: '',
  102. enginCode: '',
  103. enginName: '',
  104. freightAmount: '',
  105. orderGoodsType: '',
  106. fileUrl: [],
  107. items: []
  108. },
  109. logs: []
  110. }
  111. },
  112. computed: {
  113. // 事件组合
  114. optionsEvensGroup() {
  115. return [
  116. [
  117. [
  118. this.optionsEvensAuth('add', {
  119. click: () => {
  120. this.openForm()
  121. this.formDialog = true
  122. }
  123. })
  124. ]
  125. ]
  126. ]
  127. },
  128. // 更多参数
  129. moreParameters() {
  130. return []
  131. }
  132. },
  133. watch: {
  134. 'formData.items': {
  135. handler(newVal, oldVal) {
  136. this.formData.totalAmount = newVal
  137. .filter(item => item.qty && item.price)
  138. .map(item => item.qty * item.price)
  139. .reduce((prev, cur, index, arr) => {
  140. return prev + cur
  141. }, 0)
  142. .toFixed(2)
  143. },
  144. deep: true
  145. }
  146. },
  147. methods: {
  148. tishicuowu: new delayPerform(500).refactor(function (/**可接收参数**/) {
  149. if (this.logs) {
  150. var logs = Array.from(
  151. new Set(
  152. JSON.parse(JSON.stringify(this.logs)).map(item => {
  153. return `${item.index !== undefined ? '第' + (item.index + 1) + '行:' : ''}${item.errMsg}`
  154. })
  155. )
  156. )
  157. this.logs = []
  158. this.$message({
  159. dangerouslyUseHTMLString: true,
  160. type: 'warning',
  161. message: logs.join('<div/>'),
  162. duration: 5000
  163. })
  164. }
  165. }),
  166. // 列表请求函数
  167. getList(p, cb) {
  168. return goodsPlanItemList(p)
  169. },
  170. // 列表导出函数
  171. exportList: goodsPlanListExport,
  172. // 表格列解析渲染数据更改
  173. columnParsing(item, defaultData) {
  174. return defaultData
  175. },
  176. // 监听勾选变化
  177. selectionChange(data) {
  178. this.recordSelected = data
  179. },
  180. // 打开创建弹窗
  181. openForm() {
  182. this.isEditIndex = -1
  183. this.getGysList()
  184. this.getBaseList()
  185. },
  186. // 打开详情弹窗
  187. openDetailForm(row, type) {
  188. goodsPlanDetail({ id: row.id }).then(res => {
  189. Object.assign(this.formData, res.data, {
  190. fileUrl: res.data.fileUrl ? [{ url: res.data.fileUrl }] : [],
  191. items: res.data.items.map(item => ({ ...item, details: {} }))
  192. })
  193. this.formDialogType = type
  194. this.openForm()
  195. this.formDialog = true
  196. })
  197. },
  198. // 关闭弹窗
  199. handleClose() {
  200. this.$refs?.formRef?.resetFields()
  201. this.$data.formData = this.$options.data().formData
  202. this.formDialog = false
  203. this.formDialogType = 0
  204. },
  205. // 操作按钮
  206. operation() {
  207. return this.operationBtn({
  208. edit: {
  209. conditions: ({ row, index, column }) => {
  210. return row.status == 'SAVE'
  211. },
  212. click: ({ row, index, column }) => {
  213. this.openDetailForm(row, 1)
  214. }
  215. },
  216. del: {
  217. prompt: '是否确定删除',
  218. conditions: ({ row, index, column }) => {
  219. return row.status == 'SAVE'
  220. },
  221. click: ({ row, index, column }) => {
  222. goodsPlanDel({
  223. id: row.id
  224. }).then(res => {
  225. this.$message({
  226. type: 'success',
  227. message: '删除成功'
  228. })
  229. this.$refs.pageRef.refreshList()
  230. })
  231. }
  232. },
  233. details: {
  234. click: ({ row, index, column }) => {
  235. this.openDetailForm(row, 2)
  236. }
  237. },
  238. examine: {
  239. conditions: ({ row, index, column }) => {
  240. return row.status == 'WAIT'
  241. },
  242. click: ({ row, index, column }) => {
  243. this.openDetailForm(row, 3)
  244. }
  245. }
  246. })
  247. },
  248. // 保存
  249. save() {
  250. this.$refs.formRef.validateField(this.getVfyKey(this.isEditIndex), (valid, invalidFields, errLabels) => {
  251. if (valid && this.eidtItems()) {
  252. goodsPlanAdd({
  253. ...this.formData,
  254. items: this.formData.items.map((item, index) => ({ ...item, index: index + 1 })),
  255. fileUrl: this.formData.fileUrl.map(item => item.url).join(',')
  256. }).then(res => {
  257. this.$message({
  258. type: 'success',
  259. message: '保存成功'
  260. })
  261. this.handleClose()
  262. this.$refs.pageRef.refreshList()
  263. })
  264. }
  265. })
  266. },
  267. save2() {
  268. this.$refs.formRef.validateField(this.getVfyKey(this.isEditIndex), (valid, invalidFields, errLabels) => {
  269. if (valid && this.eidtItems()) {
  270. goodsPlanUpdate({
  271. ...this.formData,
  272. items: this.formData.items.map((item, index) => ({ ...item, index: index + 1 })),
  273. fileUrl: this.formData.fileUrl.map(item => item.url).join(',')
  274. }).then(res => {
  275. this.$message({
  276. type: 'success',
  277. message: '保存成功'
  278. })
  279. this.handleClose()
  280. this.$refs.pageRef.refreshList()
  281. })
  282. }
  283. })
  284. },
  285. // 提交
  286. submit() {
  287. this.$refs.formRef.validateField(this.getVfyKey(this.isEditIndex), (valid, invalidFields, errLabels) => {
  288. if (valid && this.eidtItems()) {
  289. goodsPlanUpdate({
  290. ...this.formData,
  291. items: this.formData.items.map((item, index) => ({ ...item, index: index + 1 })),
  292. fileUrl: this.formData.fileUrl.map(item => item.url).join(',')
  293. }).then(res => {
  294. goodsPlanSubmit({
  295. id: this.formData.id
  296. }).then(res => {
  297. this.$message({
  298. type: 'success',
  299. message: '提交成功'
  300. })
  301. this.handleClose()
  302. this.$refs.pageRef.refreshList()
  303. })
  304. })
  305. }
  306. })
  307. },
  308. // 审核
  309. examine(type) {
  310. goodsPlanConfirm({
  311. id: this.formData.id,
  312. statusEnum: type
  313. }).then(res => {
  314. this.$message({
  315. type: 'success',
  316. message: '操作成功'
  317. })
  318. this.handleClose()
  319. this.$refs.pageRef.refreshList()
  320. })
  321. }
  322. }
  323. }
  324. </script>
  325. <style lang="scss" scoped>
  326. .tab {
  327. padding: 20px 20px 0 20px;
  328. }
  329. ::v-deep .teshudeshangchuananniu {
  330. color: #409eff !important;
  331. }
  332. </style>