sendGoodModal.vue 16 KB

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