SyCottonYarnModal.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <template>
  2. <div class="reply" ref = "replyModal">
  3. <a-modal
  4. :title="(defultMethods == 'add')?'新增':'编辑'"
  5. width="85%"
  6. :visible="visible"
  7. :maskClosable="false"
  8. :confirmLoading="confirmLoading"
  9. :getContainer ='()=>$refs.replyModal'
  10. @cancel="handleCancel"
  11. destroyOnClose>
  12. <template #footer>
  13. <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" @change="handleImportExcel" :customRequest="implementImport" >
  14. <a-button type="primary">导入</a-button>
  15. </a-upload>
  16. <a-button @click="handleCancel" style="margin-left: 8px;">取消</a-button>
  17. <a-button type="primary" @click="handleOk">保存</a-button>
  18. </template>
  19. <div class="table-page-search-wrapper">
  20. <!-- 主表单区域 -->
  21. <a-form-model layout="inline" ref="form" :model="formState" :rules="validatorRules">
  22. <a-row :gutter="24">
  23. <a-col :md="8" :sm="8">
  24. <a-form-model-item label="编号" prop="code">
  25. <a-input placeholder="请输入" v-model="formState.code" />
  26. </a-form-model-item>
  27. </a-col>
  28. <a-col :md="8" :sm="8">
  29. <a-form-model-item label="名称" prop="name">
  30. <a-input placeholder="请输入名称" v-model="formState.name"/>
  31. </a-form-model-item>
  32. </a-col>
  33. <a-col :md="8" :sm="8">
  34. <a-form-model-item label="合计" prop="totalNum">
  35. <a-input placeholder="请输入" v-model="formState.totalNum" readOnly/>
  36. </a-form-model-item>
  37. </a-col>
  38. </a-row>
  39. <a-row :gutter="24">
  40. <a-col :md="24" :sm="8">
  41. <a-form-model-item label="备注信息" class="nresume" style="height:100px !important">
  42. <a-input type="textarea" placeholder="请输入" v-model="formState.demo"/>
  43. </a-form-model-item>
  44. </a-col>
  45. </a-row>
  46. </a-form-model>
  47. <!-- 子表单区域 -->
  48. <a-tabs v-model="activeKey" @change="handleChangeTabs">
  49. <a-tab-pane tab="棉纱" :key="refKeys[0]" :forceRender="true">
  50. <a-button type="primary" @click="addList" style="margin-bottom: 1%;">增行</a-button>
  51. <a-table
  52. bordered
  53. :columns="syCottonYarnBTable.columns"
  54. :data-source="syCottonYarnBTable.dataSource"
  55. :loading="syCottonYarnBTable.loading"
  56. :scroll="{x: 1800,y:300 }"
  57. :pagination="false"
  58. >
  59. <!-- 表头--日期 -->
  60. <span slot="orderDateTitle" class="form-table-heard">
  61. 日期
  62. </span>
  63. <!-- 表头--入库单号 -->
  64. <span slot="receiptNoTitle" class="form-table-heard">
  65. 入库单号
  66. </span>
  67. <!-- 表头--每吨纱价格 -->
  68. <span slot="priceTitle" class="form-table-heard">
  69. 每吨纱价格
  70. </span>
  71. <!-- 表头--集装箱号 -->
  72. <span slot="containerNoTitle" class="form-table-heard">
  73. 集装箱号
  74. </span>
  75. <span slot="reasonTitle" class="form-table-heard">
  76. 原因
  77. </span>
  78. <!-- 表头--总价 -->
  79. <span slot="totalPriceTitle" class="form-table-heard">
  80. 总价
  81. </span>
  82. <!-- 日期 -->
  83. <span slot="orderDate" slot-scope="text, record,index">
  84. <a-date-picker
  85. placeholder="请选择"
  86. v-model="record.orderDate"
  87. />
  88. </span>
  89. <!-- 入库单号 -->
  90. <span slot="receiptNo" slot-scope="text, record, index">
  91. <a-input placeholder="请输入" v-model="record.receiptNo" />
  92. </span>
  93. <!-- 吨数 -->
  94. <span slot="tonnage" slot-scope="text, record, index">
  95. <a-input placeholder="请输入" v-model="record.tonnage" />
  96. </span>
  97. <!-- 柜子数量 -->
  98. <span slot="cabinets" slot-scope="text, record, index">
  99. <a-input placeholder="请输入" v-model="record.cabinets" />
  100. </span>
  101. <!-- 每吨纱价格 -->
  102. <span slot="price" slot-scope="text, record, index">
  103. <a-input placeholder="请输入" v-model="record.price" />
  104. </span>
  105. <!-- 集装箱号 -->
  106. <span slot="containerNo" slot-scope="text, record, index">
  107. <a-input placeholder="请输入" v-model="record.containerNo" />
  108. </span>
  109. <!-- 原因 -->
  110. <span slot="reason" slot-scope="text, record, index">
  111. <a-input placeholder="请输入" v-model="record.reason" />
  112. </span>
  113. <!-- 总价 -->
  114. <span slot="totalPrice" slot-scope="text, record, index">
  115. <a-input placeholder="请输入" v-model="record.totalPrice" @change="changeTotalPrice"/>
  116. </span>
  117. <!-- 备注 -->
  118. <span slot="demo" slot-scope="text, record, index">
  119. <a-input placeholder="请输入" v-model="record.demo" />
  120. </span>
  121. </a-table>
  122. <!-- <j-editable-table
  123. :ref="refKeys[0]"
  124. :loading="syCottonYarnBTable.loading"
  125. :columns="syCottonYarnBTable.columns"
  126. :dataSource="syCottonYarnBTable.dataSource"
  127. :maxHeight="300"
  128. :rowNumber="true"
  129. :rowSelection="true"
  130. :actionButton="true"/> -->
  131. </a-tab-pane>
  132. </a-tabs>
  133. </div>
  134. </a-modal>
  135. </div>
  136. </template>
  137. <script>
  138. import moment from 'moment'
  139. import pick from 'lodash.pick'
  140. import { FormTypes } from '@/utils/JEditableTableUtil'
  141. import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
  142. import { putAction,postAction,getAction } from '@/api/manage'
  143. import {fileDetail} from '@api/oa/cd-sy-cotton'
  144. export default {
  145. name: 'SyCottonYarnModal',
  146. mixins: [JEditableTableMixin],
  147. data() {
  148. return {
  149. // 新增时子表默认添加几行空数据
  150. addDefaultRowNum: 1,
  151. validatorRules: {
  152. name:[{required: true, message: '名称不能为空!'}],
  153. code:[{required: true, message: '编号不能为空!'}],
  154. },
  155. refKeys: ['syCottonYarnB', ],
  156. activeKey: 'syCottonYarnB',
  157. formState:{},
  158. defultMethods:'add',
  159. zhuId:'',
  160. passVerification:'yes',
  161. // 搬运装卸费用-棉纱-子表
  162. syCottonYarnBTable: {
  163. loading: false,
  164. dataSource: [],
  165. columns: [
  166. {
  167. // title: '日期',
  168. align: "center",
  169. dataIndex: 'orderDate',
  170. width: '9%',
  171. scopedSlots: { customRender: 'orderDate' },
  172. slots:{title:'orderDateTitle'}
  173. },
  174. {
  175. // title: '入库单号',
  176. align: "center",
  177. dataIndex: 'receiptNo',
  178. width: '9%',
  179. scopedSlots: { customRender: 'receiptNo' },
  180. slots:{title:'receiptNoTitle'}
  181. },
  182. {
  183. title: '吨数',
  184. align: "center",
  185. dataIndex: 'tonnage',
  186. width: '9%',
  187. scopedSlots: { customRender: 'tonnage' },
  188. },
  189. {
  190. title: '柜子数量',
  191. align: "center",
  192. dataIndex: 'cabinets',
  193. width: '9%',
  194. scopedSlots: { customRender: 'cabinets' },
  195. },
  196. {
  197. // title: '每吨纱价格',
  198. align: "center",
  199. dataIndex: 'price',
  200. width: '9%',
  201. scopedSlots: { customRender: 'price' },
  202. slots:{title:'priceTitle'}
  203. },
  204. {
  205. // title: '集装箱号',
  206. align: "center",
  207. dataIndex: 'containerNo',
  208. width: '9%',
  209. scopedSlots: { customRender: 'containerNo' },
  210. slots:{title:'containerNoTitle'}
  211. },
  212. {
  213. // title: '原因',
  214. align: "center",
  215. dataIndex: 'reason',
  216. width: '9%',
  217. scopedSlots: { customRender: 'reason' },
  218. slots:{title:'reasonTitle'}
  219. },
  220. {
  221. // title: '总价',
  222. align: "center",
  223. dataIndex: 'totalPrice',
  224. width: '9%',
  225. scopedSlots: { customRender: 'totalPrice' },
  226. slots:{title:'totalPriceTitle'}
  227. },
  228. {
  229. title: '签字',
  230. align: "center",
  231. dataIndex: 'jhyName',
  232. width: '9%',
  233. scopedSlots: { customRender: 'jhyName' },
  234. },
  235. {
  236. title: '备注',
  237. align: "center",
  238. dataIndex: 'demo',
  239. width: '9%',
  240. scopedSlots: { customRender: 'demo' },
  241. },
  242. ]
  243. },
  244. url: {
  245. add: "/oa/syCottonYarn/add",
  246. edit: "/oa/syCottonYarn/edit",
  247. syCottonYarnB: {
  248. list: '/oa/syCottonYarn/querySyCottonYarnBByMainId'
  249. },
  250. }
  251. }
  252. },
  253. methods: {
  254. // 获取表头信息
  255. getHeaderList(id){
  256. getAction('/oa/syCottonYarn/queryById', {id:id}).then((res) => {
  257. if(res.success){
  258. var zhuId = '' //主表id
  259. this.formState=res.result //详情
  260. zhuId = res.result.id
  261. this.getTable(zhuId)
  262. }else{
  263. this.$message.warning(res.message)
  264. }
  265. })
  266. },
  267. getTable(id){
  268. getAction('/oa/syCottonYarn/querySyCottonYarnBByMainId', {id:id}).then((res) => {
  269. if(res.success){
  270. res.result.map(item =>{
  271. if(item.orderDate !==''&& item.orderDate){
  272. item.orderDate = moment(item.orderDate)
  273. }
  274. })
  275. this.syCottonYarnBTable.dataSource = res.result
  276. }else{
  277. this.$message.warning(res.message)
  278. }
  279. })
  280. },
  281. addList(){
  282. this.syCottonYarnBTable.dataSource.push({})
  283. },
  284. //总价改变
  285. changeTotalPrice(){
  286. var Hj = 0
  287. this.syCottonYarnBTable.dataSource.map(item=>{
  288. Hj+= Number(item.totalPrice)
  289. })
  290. this.formState.totalNum = Hj
  291. this.$forceUpdate()
  292. },
  293. /** 调用完edit()方法之后会自动调用此方法 */
  294. // editAfter() {
  295. // this.$nextTick(() => {
  296. // this.form.setFieldsValue(pick(this.model, 'name', 'code', 'demo', ))
  297. // 时间格式化
  298. // this.form.setFieldsValue({ ckTime: this.model.ckTime ? moment(this.model.ckTime) : null })
  299. // this.form.setFieldsValue({ rsxzTime: this.model.rsxzTime ? moment(this.model.rsxzTime) : null })
  300. // this.form.setFieldsValue({ cwjlTime: this.model.cwjlTime ? moment(this.model.cwjlTime) : null })
  301. // })
  302. // 加载子表数据
  303. // if (this.model.id) {
  304. // let params = { id: this.model.id }
  305. // this.requestSubTableData(this.url.syCottonYarnB.list, params, this.syCottonYarnBTable)
  306. // }
  307. // },
  308. /** 整理成formData */
  309. classifyIntoFormData(allValues) {
  310. let main = Object.assign(this.model, allValues.formValue)
  311. //时间格式化
  312. // main.ckTime = main.ckTime ? main.ckTime.format('YYYY-MM-DD HH:mm:ss') : null;
  313. // main.rsxzTime = main.rsxzTime ? main.rsxzTime.format('YYYY-MM-DD HH:mm:ss') : null;
  314. // main.cwjlTime = main.cwjlTime ? main.cwjlTime.format('YYYY-MM-DD HH:mm:ss') : null;
  315. return {
  316. ...main, // 展开
  317. syCottonYarnBList: allValues.tablesValue[0].values,
  318. }
  319. },
  320. //保存
  321. handleOk(){
  322. this.$refs.form.validate(async valid => {
  323. if(valid){
  324. var obj = this.formState
  325. this.syCottonYarnBTable.dataSource.map(item=>{
  326. if(item.orderDate!==''&&item.orderDate){
  327. item.orderDate = moment(item.orderDate).format('YYYY-MM-DD HH:mm:ss');
  328. }
  329. })
  330. obj.syCottonYarnBList = this.syCottonYarnBTable.dataSource
  331. await this.judageTablez(obj.syCottonYarnBList)
  332. if(this.defultMethods == 'add' && this.passVerification == 'yes'){
  333. postAction(this.url.add, obj).then(res => {
  334. if (res.success) {
  335. this.$message.success('新增成功')
  336. this.handleCancel()
  337. this.$emit('close')
  338. }else{
  339. this.$message.error(res.message);
  340. }
  341. })
  342. }else if(this.passVerification == 'yes'){
  343. putAction(this.url.edit, obj).then((res) => {
  344. if(res.success){
  345. this.$message.success('编辑成功')
  346. this.handleCancel()
  347. this.$emit('close')
  348. }else{
  349. this.$message.warning(res.message)
  350. }
  351. })
  352. }
  353. }
  354. })
  355. },
  356. judageTablez(data){
  357. this.passVerification = 'yes'
  358. if(data.length == 0){
  359. this.$message.error('请添加子表数据!');
  360. this.passVerification = 'no'
  361. }else{
  362. for (var i=0; i<data.length;i++){
  363. var tableRow = data[i];
  364. var required = [
  365. {key:'orderDate',value:'日期'},
  366. {key:'receiptNo',value:'入库单号'},
  367. {key:'price',value:'每吨纱价格'},
  368. {key:'containerNo',value:'集装箱号'},
  369. {key:'reason',value:'原因'},
  370. {key:'totalPrice',value:'总价'},
  371. ]
  372. for(var j=0 ; j<required.length;j++){
  373. if(tableRow[required[j].key] == null || tableRow[required[j].key] == "" || tableRow[required[j].key] == undefined){
  374. this.$message.error('第'+(i+1)+'行'+required[j].value+'无值,无法保存');
  375. this.passVerification = 'no'
  376. return
  377. }
  378. }
  379. }
  380. }
  381. },
  382. // 导入
  383. implementImport(file) {
  384. const formData = new FormData()
  385. formData.append('file', file.file)
  386. fileDetail(formData).then(res => {
  387. // this.loading = false
  388. if (res.success) {
  389. // this.visible = true
  390. this.message = res.message.split(';').filter((element) => {
  391. return element !== "";
  392. });
  393. this.file = file
  394. this.$message.success('导入成功')
  395. }else{
  396. this.$message.error(res.message);
  397. }
  398. })
  399. },
  400. //关闭
  401. handleCancel(){
  402. this.syCottonYarnBTable.dataSource=[]
  403. this.formState = {}
  404. this.visible = false
  405. this.defultMethods='add'
  406. this.zhuId = ''
  407. this.$emit('close')
  408. },
  409. }
  410. }
  411. </script>
  412. <style scoped lang="less">
  413. /deep/ .nresume .ant-input{
  414. height: 100px !important;
  415. }
  416. /deep/ .td{
  417. text-align:center;
  418. }
  419. .form-table-heard:before {
  420. content: '*';
  421. color: red;
  422. }
  423. </style>