sendGoodModal.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. <template>
  2. <a-modal
  3. centered
  4. class="sendGood-detail-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. v-model="isShow"
  8. :title="modalTit"
  9. @cancel="handleCommonCancel"
  10. width="60%">
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <div class="common-main">
  13. <a-alert type="info" v-if="detail.length" style="margin-bottom:10px">
  14. <div slot="message">{{ customeName }},共 {{ detail && detail.length }} 个出库单,产品款数合计 <span>{{ productTotal&&productTotal.totalCategory }}</span> ,产品数量合计 <span>{{ productTotal&&productTotal.totalQty }}</span>。</div>
  15. </a-alert>
  16. <div class="toolsBar">
  17. <a-form-model
  18. ref="ruleForm"
  19. :model="form"
  20. :rules="rules"
  21. :label-col="formItemLayout.labelCol"
  22. :wrapper-col="formItemLayout.wrapperCol"
  23. >
  24. <a-row>
  25. <a-col span="12">
  26. <a-form-model-item label="托运日期" prop="sendDate">
  27. <a-date-picker :allowClear="false" inputReadOnly v-model="form.sendDate" :locale="locale"/>
  28. </a-form-model-item>
  29. </a-col>
  30. <a-col span="12">
  31. <a-form-model-item label="目的地">
  32. <a-input placeholder="请输入目的地(最多30字符)" :maxLength="30" v-model.trim="form.customerAddress"></a-input>
  33. </a-form-model-item>
  34. </a-col>
  35. <a-col span="12">
  36. <a-form-model-item label="收货人" prop="customerCacateName">
  37. <a-input placeholder="请输入收货人(最多30字符)" :maxLength="30" v-model.trim="form.customerCacateName"></a-input>
  38. </a-form-model-item>
  39. </a-col>
  40. <a-col span="12">
  41. <a-form-model-item label="电话" prop="customerCacatePhone">
  42. <a-input placeholder="请输入电话" :maxLength="30" v-model.trim="form.customerCacatePhone"></a-input>
  43. </a-form-model-item>
  44. </a-col>
  45. <a-col span="24">
  46. <a-form-model-item label="详细地址" prop="customerAddressDetail" :label-col="{span:3}" :wrapper-col="{span:19}">
  47. <a-textarea placeholder="请输入详细地址(最多300字符)" :maxLength="300" v-model.trim="form.customerAddressDetail"></a-textarea>
  48. </a-form-model-item>
  49. </a-col>
  50. <a-col span="12">
  51. <a-form-model-item label="物流电话" prop="transportTele">
  52. <a-input placeholder="请输入物流电话" :maxLength="30" v-model.trim="form.transportTele"></a-input>
  53. </a-form-model-item>
  54. </a-col>
  55. <a-col span="12">
  56. <a-form-model-item label="物流单号" prop="transportNo">
  57. <a-input placeholder="请输入物流单号" :maxLength="30" v-model.trim="form.transportNo"></a-input>
  58. </a-form-model-item>
  59. </a-col>
  60. <a-col span="12">
  61. <a-form-model-item label="付款方式">
  62. <v-select
  63. v-model="form.payType"
  64. ref="payType"
  65. code="SEND_BILL_PAY_TYPE"
  66. placeholder="请选择付款方式"
  67. allowClear></v-select>
  68. </a-form-model-item>
  69. </a-col>
  70. <a-col span="12">
  71. <a-form-model-item label="交货方式">
  72. <v-select
  73. v-model="form.handoverType"
  74. ref="handoverType"
  75. code="SEND_BILL_HANDOVER_TYPE"
  76. placeholder="请选择交货方式"
  77. allowClear></v-select>
  78. </a-form-model-item>
  79. </a-col>
  80. <a-col span="12">
  81. <a-form-model-item label="运费合计">
  82. <!-- <a-input disabled placeholder="请输入运费合计" v-model.trim="form.totalSendAmount"></a-input> -->
  83. {{ form.totalSendAmount||'--' }}
  84. </a-form-model-item>
  85. </a-col>
  86. </a-row>
  87. </a-form-model>
  88. </div>
  89. <div>
  90. <a-table :columns="columns" :pagination="false" :scroll="{ y: 200 }" :data-source="tableData" bordered>
  91. <!-- 物品名称 -->
  92. <template slot="goodName" slot-scope="text, record">
  93. <a-select v-model="record.goodsName" placeholder="请选择物品" style="width: 100%">
  94. <a-select-option value="易损件">
  95. 易损件
  96. </a-select-option>
  97. <a-select-option value="电池">
  98. 电池
  99. </a-select-option>
  100. <a-select-option value="机油">
  101. 机油
  102. </a-select-option>
  103. </a-select>
  104. </template>
  105. <!-- 数量 -->
  106. <template slot="qty" slot-scope="text, record">
  107. <a-input-number style="width: 100%;" :precision="0" v-model="record.goodsQty" :min="0" :max="999999"></a-input-number>
  108. </template>
  109. <!-- 体积 -->
  110. <template slot="volume" slot-scope="text, record">
  111. <a-input-number style="width: 100%;" :precision="2" v-model="record.goodsVolume" :min="0" :max="999999"></a-input-number>
  112. </template>
  113. <!-- 重量 -->
  114. <template slot="weight" slot-scope="text, record">
  115. <a-input-number style="width: 100%;" :precision="2" v-model="record.goodsWeight" :min="0" :max="999999"></a-input-number>
  116. </template>
  117. <!-- 计费单价 -->
  118. <template slot="price" slot-scope="text, record">
  119. <a-input-number style="width: 100%;" :precision="2" v-model="record.unitPrice" :min="0" :max="999999"></a-input-number>
  120. </template>
  121. <!-- 运费 -->
  122. <template slot="freight" slot-scope="text, record">
  123. <a-input-number
  124. style="width: 100%;"
  125. :precision="2"
  126. @change="amountChange('transportAmount',record)"
  127. v-model="record.transportAmount"
  128. :min="0"
  129. :max="999999"></a-input-number>
  130. </template>
  131. <!-- 保价 -->
  132. <template slot="supportValue" slot-scope="text, record">
  133. <a-input-number style="width: 100%;" :precision="2" v-model="record.supportValue" :min="0" :max="999999"></a-input-number>
  134. </template>
  135. <!-- 送货费 -->
  136. <template slot="deliveryExpense" slot-scope="text, record">
  137. <a-input-number
  138. style="width: 100%;"
  139. :precision="2"
  140. @change="amountChange('sendAmount',record)"
  141. v-model="record.sendAmount"
  142. :min="0"
  143. :max="999999"></a-input-number>
  144. </template>
  145. <!-- 其他 -->
  146. <template slot="other" slot-scope="text, record">
  147. <a-input-number
  148. style="width: 100%;"
  149. :precision="2"
  150. @change="amountChange('otherAmount',record)"
  151. v-model="record.otherAmount"
  152. :min="0"
  153. :max="999999"></a-input-number>
  154. </template>
  155. <!-- 操作 -->
  156. <template slot="action" slot-scope="text, record, index">
  157. <a-button
  158. size="small"
  159. type="link"
  160. class="button-error"
  161. @click="handleDel(record,index)"
  162. >
  163. 删除
  164. </a-button>
  165. </template>
  166. </a-table>
  167. <div style="padding: 5px; border:1px solid #eee;border-radius:0 0 10px;border-top: 0;text-align:center;">
  168. <a-button @click="addItem()" type="link">+新增发货明细</a-button>
  169. </div>
  170. </div>
  171. </div>
  172. <div class="btn-box">
  173. <a-button @click="handleCommonCancel" v-if="isCancel">{{ cancelText }}</a-button>
  174. <a-button type="primary" @click="handleCommonOk">{{ okText }}</a-button>
  175. </div>
  176. </a-spin>
  177. </a-modal>
  178. </template>
  179. <script>
  180. import moment from 'moment'
  181. import locale from 'ant-design-vue/es/date-picker/locale/zh_CN'
  182. import { STable, VSelect } from '@/components'
  183. import { sendBillInsert, sendBillFindBySn, sendBillUpdate } from '@/api/sendBill'
  184. export default {
  185. name: 'SendGoodModal',
  186. components: { STable, VSelect },
  187. props: {
  188. openModal: { // 弹框显示状态
  189. type: Boolean,
  190. default: false
  191. },
  192. modalTit: { // 弹框标题
  193. type: String,
  194. default: null
  195. },
  196. okText: { // 确定 按钮文字
  197. type: String,
  198. default: '确定'
  199. },
  200. cancelText: { // 取消 按钮文字
  201. type: String,
  202. default: '取消'
  203. },
  204. isCancel: { // 是否显示 取消 按钮
  205. type: Boolean,
  206. default: true
  207. }
  208. },
  209. data () {
  210. return {
  211. locale,
  212. isShow: this.openModal, // 是否打开弹框
  213. disabled: false,
  214. spinning: false,
  215. form: {
  216. 'stockOutSnList': [], // 出库单列表
  217. 'sendDate': moment(), // 托运时间
  218. 'customerAddress': '', // 目的地
  219. 'customerAddressDetail': '', // 详细地址
  220. 'transportTele': '', // 物流电话
  221. 'transportNo': '', // 物流单号
  222. 'customerCacateName': '', // 收货人
  223. 'customerCacatePhone': '', // 收货人电话
  224. 'payType': '', // 收款方式
  225. 'handoverType': '', // 发货方式
  226. 'totalSendAmount': '', // 发货总费用
  227. 'sendBillDetailList': [] // 发货列表
  228. },
  229. rules: {
  230. sendDate: [{ required: true, message: '请选择托运日期', trigger: 'change' }],
  231. customerCacateName: [{ required: true, message: '请输入收货人', trigger: 'change' }],
  232. customerCacatePhone: [{ required: true, message: '请输入电话', trigger: 'change' }],
  233. customerAddressDetail: [{ required: true, message: '请输入详细地址', trigger: 'change' }]
  234. },
  235. formItemLayout: {
  236. labelCol: { span: 6 },
  237. wrapperCol: { span: 15 }
  238. },
  239. detail: [],
  240. productTotal: null,
  241. tableData: [],
  242. columns: [
  243. { title: '序号', dataIndex: 'no', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  244. { title: '货物名称', dataIndex: 'goodsName', scopedSlots: { customRender: 'goodName' }, width: '10%', align: 'center' },
  245. { title: '件数', dataIndex: 'goodsQty', scopedSlots: { customRender: 'qty' }, width: '8%', align: 'center' },
  246. { title: '体积(m³)', dataIndex: 'goodsVolume', scopedSlots: { customRender: 'volume' }, width: '8%', align: 'center' },
  247. { title: '重量(kg)', dataIndex: 'goodsWeight', scopedSlots: { customRender: 'weight' }, width: '8%', align: 'center' },
  248. { title: '计费单价(元)', dataIndex: 'unitPrice', scopedSlots: { customRender: 'price' }, width: '9%', align: 'center' },
  249. { title: '运费(元)', dataIndex: 'transportAmount', scopedSlots: { customRender: 'freight' }, width: '9%', align: 'center' },
  250. { title: '保价(万)', dataIndex: 'supportValue', scopedSlots: { customRender: 'supportValue' }, width: '9%', align: 'center' },
  251. { title: '送货费', dataIndex: 'sendAmount', scopedSlots: { customRender: 'deliveryExpense' }, width: '9%', align: 'center' },
  252. { title: '其他', dataIndex: 'otherAmount', scopedSlots: { customRender: 'other' }, width: '8%', align: 'center' },
  253. { title: '合计', dataIndex: 'totalAmount', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  254. { title: '操作', scopedSlots: { customRender: 'action' }, width: '8%', align: 'center' }
  255. ],
  256. isEdit: false,
  257. customeName: ''
  258. }
  259. },
  260. methods: {
  261. // 新增,出库单和收货人信息
  262. setData (data, customeInfo) {
  263. this.detail = data
  264. this.customeName = data[0].demanderName
  265. this.isEdit = false
  266. this.getProductTotal()
  267. if (customeInfo) {
  268. this.form.customerCacateName = customeInfo.consigneeName
  269. this.form.customerCacatePhone = customeInfo.consigneeTel
  270. this.form.customerAddressDetail = customeInfo.addr
  271. }
  272. },
  273. // 编辑
  274. getDetail (data) {
  275. this.spinning = true
  276. this.isEdit = true
  277. this.customeName = data.customeName
  278. sendBillFindBySn({ sn: data.sendBillSn }).then(res => {
  279. console.log(res)
  280. this.spinning = false
  281. if (res.data) {
  282. this.detail = res.data.sendBillStockOutList // 出库单
  283. this.tableData = res.data.detailList // 发货明细
  284. this.tableData.map((item, i) => {
  285. item.no = i + 1
  286. })
  287. // 统计出库单
  288. this.getProductTotal()
  289. // 基本信息
  290. this.form.customerCacateName = res.data.customerCacateName
  291. this.form.customerCacatePhone = res.data.customerCacatePhone
  292. this.form.customerAddress = res.data.customerAddress
  293. this.form.customerAddressDetail = res.data.customerAddressDetail
  294. this.form.transportTele = res.data.transportTele
  295. this.form.transportNo = res.data.transportNo
  296. this.form.sendDate = res.data.sendDate
  297. this.form.payType = res.data.payType
  298. this.form.handoverType = res.data.handoverType
  299. this.form.totalSendAmount = res.data.totalSendAmount
  300. this.form.sendBillNo = data.sendBillNo
  301. this.form.sendBillSn = data.sendBillSn
  302. }
  303. })
  304. },
  305. // 出库单数据统计
  306. getProductTotal () {
  307. const ret = {
  308. totalCategory: 0,
  309. totalQty: 0
  310. }
  311. const stockOutSnList = []
  312. this.detail.map(item => {
  313. ret.totalCategory = ret.totalCategory + item.productTotalCategory
  314. ret.totalQty = ret.totalQty + item.productTotalQty
  315. stockOutSnList.push(item.stockOutSn)
  316. })
  317. // 编辑时不需要传
  318. this.form.stockOutSnList = this.isEdit ? [] : stockOutSnList
  319. this.productTotal = ret
  320. },
  321. // 计算运费合计
  322. getTotalSendAmount () {
  323. let ret = 0
  324. this.tableData.map(item => {
  325. ret = ret + Number(item.totalAmount || 0)
  326. })
  327. this.form.totalSendAmount = ret.toFixed(2)
  328. },
  329. // 计算每行发货费用合计
  330. amountChange (key, record) {
  331. record.totalAmount = (record.transportAmount || 0) + (record.sendAmount || 0) + (record.otherAmount || 0)
  332. record.totalAmount = Number(record.totalAmount).toFixed(2)
  333. this.getTotalSendAmount()
  334. },
  335. // 删除
  336. handleDel (row, index) {
  337. this.tableData.splice(index, 1)
  338. this.tableData.map((item, i) => {
  339. item.no = i + 1
  340. })
  341. this.getTotalSendAmount()
  342. },
  343. // 添加
  344. addItem () {
  345. const len = this.tableData.length
  346. this.tableData.push({
  347. 'no': len + 1,
  348. 'goodsName': undefined,
  349. 'goodsQty': '',
  350. 'goodsVolume': '',
  351. 'goodsWeight': '',
  352. 'unitPrice': '',
  353. 'transportAmount': '',
  354. 'supportValue': '',
  355. 'sendAmount': '',
  356. 'otherAmount': '',
  357. 'totalAmount': ''
  358. })
  359. },
  360. // 校验物品单
  361. vaildGood (key) {
  362. const ret = []
  363. this.tableData.map(item => {
  364. ret.push(!!item[key])
  365. })
  366. console.log(ret)
  367. return ret
  368. },
  369. // 确定
  370. handleCommonOk () {
  371. const _this = this
  372. if (_this.form.stockOutSnList.length == 0 && !this.isEdit) {
  373. _this.$message.info('请选择出库单!')
  374. return
  375. }
  376. this.$refs.ruleForm.validate(valid => {
  377. _this.form.sendBillDetailList = _this.tableData
  378. if (valid) {
  379. console.log(_this.form, this.isEdit)
  380. if (_this.form.sendBillDetailList.length == 0) {
  381. _this.$message.info('请新增发货明细!')
  382. return false
  383. }
  384. if (_this.vaildGood('goodsName').indexOf(false) >= 0) {
  385. _this.$message.info('请选择物品!')
  386. return false
  387. }
  388. if (_this.vaildGood('totalAmount').indexOf(false) >= 0) {
  389. _this.$message.info('请输入费用!')
  390. return false
  391. }
  392. const baseUrl = this.isEdit ? sendBillUpdate : sendBillInsert
  393. _this.spinning = true
  394. baseUrl(_this.form).then(res => {
  395. if (res.status == 200) {
  396. _this.$emit('ok')
  397. _this.isShow = false
  398. _this.$message.success(res.message)
  399. }
  400. _this.spinning = false
  401. })
  402. } else {
  403. return false
  404. }
  405. })
  406. },
  407. // 取消
  408. handleCommonCancel () {
  409. this.$emit('cancel')
  410. this.tableData = []
  411. this.detail = []
  412. this.spinning = false
  413. this.$refs.ruleForm.resetFields()
  414. this.form = {
  415. 'stockOutSnList': [], // 出库单列表
  416. 'sendDate': moment(), // 托运时间
  417. 'customerAddress': '', // 目的地
  418. 'customerAddressDetail': '', // 详细地址
  419. 'transportTele': '', // 物流电话
  420. 'transportNo': '', // 物流单号
  421. 'customerCacateName': '', // 收货人
  422. 'customerCacatePhone': '', // 收货人电话
  423. 'payType': '', // 收款方式
  424. 'handoverType': '', // 发货方式
  425. 'totalSendAmount': '', // 发货总费用
  426. 'sendBillDetailList': [] // 发货列表
  427. }
  428. }
  429. },
  430. watch: {
  431. // 父页面传过来的弹框状态
  432. openModal (newValue, oldValue) {
  433. this.isShow = newValue
  434. },
  435. // 重定义的弹框状态
  436. isShow (newValue, oldValue) {
  437. if (!newValue) {
  438. this.handleCommonCancel()
  439. }
  440. }
  441. }
  442. }
  443. </script>
  444. <style lang="less">
  445. .sendGood-detail-modal{
  446. .common-main{
  447. .toolsBar{
  448. border:1px solid #eee;
  449. border-radius: 3px;
  450. display: flex;
  451. align-items: center;
  452. margin-bottom: 10px;
  453. .ant-btn{
  454. margin-left: 30px;
  455. }
  456. }
  457. }
  458. .btn-box{
  459. text-align: center;
  460. margin-top: 30px;
  461. .ant-btn{
  462. margin:0 10px;
  463. }
  464. }
  465. }
  466. </style>