detail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <div class="salesDetail-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="salesDetail-cont" :style="{ padding: !outBizSn ? '16px 24px' : '0px 24px' }">
  5. <template slot="subTitle" v-if="!outBizSn">
  6. <a href="javascript:;" @click="handleBack"><a-icon type="left"></a-icon> 返回列表</a>
  7. <a-button
  8. v-if="(detailData&&detailData.billStatus !== 'CANCEL' && detailData.billStatus !== 'FINISH' && detailData.billStatus != 'WAIT_OUT_WAREHOUSE')&&$hasPermissions('B_salesEdit')"
  9. type="primary"
  10. size="small"
  11. style="background-color: #1890ff;margin-left: 20px;border: #1890ff;"
  12. id="salesDetail-edit-btn"
  13. @click.stop="handleEdit">编辑</a-button>
  14. </template>
  15. <template slot="extra" v-if="outBizSn ? $hasPermissions('B_outboundOrderDetail') : $hasPermissions('B_salesPrint')">
  16. <a-radio-group key="4" v-model="printerType">
  17. <a-radio value="NEEDLE">针式</a-radio>
  18. <a-radio value="INK">喷墨</a-radio>
  19. </a-radio-group>
  20. <a-button key="3" id="salesDetail-preview-btn" :disabled="localDataSource.length==0" @click="handlePrint('preview')">打印预览</a-button>
  21. <a-button key="2" type="primary" id="salesDetail-print-btn" :disabled="localDataSource.length==0" @click="handlePrint('print')">快捷打印</a-button>
  22. <a-button
  23. key="1"
  24. type="primary"
  25. class="button-warning"
  26. id="salesDetail-export-btn"
  27. :disabled="localDataSource.length==0"
  28. @click="handlePrint('export')">导出Excel</a-button>
  29. </template>
  30. </a-page-header>
  31. <!-- 基础信息 -->
  32. <a-card size="small" :bordered="false" class="salesDetail-cont">
  33. <a-collapse :activeKey="['1']">
  34. <a-collapse-panel key="1" header="基础信息">
  35. <a-descriptions size="small" :column="3">
  36. <a-descriptions-item label="客户名称">{{ detailData&&detailData.buyerName || '--' }}</a-descriptions-item>
  37. <a-descriptions-item label="客户地址" :span="2">
  38. <div v-if="detailData&&(detailData.shippingAddressProvinceName || detailData.shippingAddressCityName || detailData.shippingAddressCountyName || detailData.shippingAddress)">
  39. {{ detailData&&detailData.shippingAddressProvinceName || '' }}
  40. {{ detailData&&detailData.shippingAddressCityName || '' }}
  41. {{ detailData&&detailData.shippingAddressCountyName || '' }}
  42. {{ detailData&&detailData.shippingAddress || '' }}
  43. </div>
  44. <span v-else>--</span>
  45. </a-descriptions-item>
  46. <a-descriptions-item label="收款方式">{{ detailData&&detailData.settleStyleEntity&&detailData.settleStyleEntity.name || '--' }}</a-descriptions-item>
  47. <a-descriptions-item label="联系电话">{{ detailData&&detailData.consigneeTel || '--' }}</a-descriptions-item>
  48. <a-descriptions-item label="备注">{{ detailData&&detailData.remarks || '--' }}</a-descriptions-item>
  49. <a-descriptions-item label="销售单号">{{ detailData&&detailData.salesBillNo || '--' }}</a-descriptions-item>
  50. <a-descriptions-item label="制单人">{{ detailData&&detailData.operatorName || '--' }}</a-descriptions-item>
  51. <a-descriptions-item label="业务员">{{ detailData&&detailData.salesManName || '--' }}</a-descriptions-item>
  52. <a-descriptions-item label="来源">{{ detailData&&detailData.salesBillSourceDictValue || '--' }}</a-descriptions-item>
  53. <a-descriptions-item label="下级采购单号" v-if="detailData&&detailData.salesBillSource=='PURCHASE'">{{ detailData&&detailData.purchaseBillNo || '--' }}</a-descriptions-item>
  54. <a-descriptions-item label="业务状态">{{ detailData&&detailData.billStatusDictValue || '--' }}</a-descriptions-item>
  55. <a-descriptions-item label="财务状态">{{ detailData&&detailData.financialStatusDictValue || '--' }}</a-descriptions-item>
  56. </a-descriptions>
  57. </a-collapse-panel>
  58. </a-collapse>
  59. </a-card>
  60. <a-card size="small" :bordered="false" class="pages-wrap">
  61. <!-- alert -->
  62. <a-alert type="info" style="margin-bottom: 10px;">
  63. <div slot="message">
  64. 总款数:<strong>{{ detailData&&(detailData.totalCategory || detailData.totalCategory==0) ? detailData.totalCategory : '--' }}</strong>;
  65. 总数量:<strong>{{ detailData&&(detailData.totalQty || detailData.totalQty==0) ? detailData.totalQty : '--' }}</strong>;
  66. 总赠品数量:<strong>{{ detailData&&(detailData.giftQty || detailData.giftQty==0) ? detailData.giftQty : '--' }}</strong>;
  67. 急件总款数:<strong>{{ detailData&&(detailData.oosCategory || detailData.oosCategory==0) ? detailData.oosCategory : '--' }}</strong>;
  68. 急件总数量:<strong>{{ detailData&&(detailData.oosQty || detailData.oosQty==0) ? detailData.oosQty : '--' }}</strong>;<br/>
  69. 总售价:<strong>{{ detailData&&(detailData.totalAmount || detailData.totalAmount==0) ? detailData.totalAmount : '--' }}</strong>;
  70. 总成本:<strong>{{ detailData&&(detailData.totalCost || detailData.totalCost==0) ? detailData.totalCost : '--' }}</strong>;
  71. 总毛利:<strong>{{ detailData&&(detailData.grossProfit || detailData.grossProfit==0) ? detailData.grossProfit : '--' }}</strong>;
  72. 折后总售价:<strong>{{ detailData&&(detailData.discountedAmount || detailData.discountedAmount==0) ? detailData.discountedAmount : '--' }}</strong>;
  73. 折扣:<strong>{{ detailData&&(detailData.discountRate || detailData.discountRate==0) ? detailData.discountRate+'%' : '--' }}</strong>;
  74. 折扣金额:<strong>{{ detailData&&(detailData.discountAmount || detailData.discountAmount==0) ? detailData.discountAmount : '--' }}</strong>;
  75. </div>
  76. </a-alert>
  77. <!-- 列表 -->
  78. <s-table
  79. class="sTable"
  80. ref="table"
  81. size="small"
  82. :rowKey="(record) => record.id"
  83. :columns="columns"
  84. :data="loadData"
  85. :defaultLoadData="false"
  86. bordered>
  87. </s-table>
  88. </a-card>
  89. </a-spin>
  90. <!-- 打印 -->
  91. <div id="print"></div>
  92. </div>
  93. </template>
  94. <script>
  95. import moment from 'moment'
  96. import { getOperationalPrecision } from '@/libs/tools.js'
  97. import { STable, VSelect } from '@/components'
  98. import { salesDetailBySn, salesDetailPrint, salesDetailExport } from '@/api/sales'
  99. import { salesDetailList } from '@/api/salesDetail'
  100. import { getLodop } from '@/libs/LodopFuncs'
  101. export default {
  102. name: 'SalesDetail',
  103. components: { STable, VSelect },
  104. props: {
  105. outBizSn: { // 有值则为弹框,无值则为页面
  106. type: [Number, String],
  107. default: ''
  108. }
  109. },
  110. data () {
  111. return {
  112. spinning: false,
  113. disabled: false,
  114. // 表头
  115. columns: [
  116. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  117. { title: '产品编码', dataIndex: 'productCode', width: '11%', align: 'center', customRender: function (text) { return text || '--' } },
  118. { title: '产品名称', dataIndex: 'productName', width: '11%', align: 'center', customRender: function (text) { return text || '--' } },
  119. { title: '原厂编码', dataIndex: 'productOrigCode', width: '9%', align: 'center', customRender: function (text) { return text || '--' } },
  120. { title: '成本价', dataIndex: 'cost', width: '5%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  121. { title: '售价', dataIndex: 'price', width: '5%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  122. { title: '折后售价', dataIndex: 'discountedPrice', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  123. { title: '销售数量', dataIndex: 'qty', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  124. { title: '单位', dataIndex: 'productOrigUnit', width: '4%', align: 'center', customRender: function (text) { return text || '--' } },
  125. { title: '售价小计', dataIndex: 'totalAmount', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  126. { title: '折后小计', dataIndex: 'discountedAmount', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  127. { title: '折扣金额', dataIndex: 'discountAmount', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  128. { title: '仓库', dataIndex: 'warehouseName', width: '7%', align: 'center', customRender: function (text) { return text || '--' } },
  129. { title: '仓位', dataIndex: 'warehouseLocationName', width: '7%', align: 'center', customRender: function (text) { return text || '--' } },
  130. { title: '是否急件', dataIndex: 'oosFlagDictValue', width: '6%', align: 'center', customRender: function (text) { return text || '--' } }
  131. ],
  132. // 加载数据方法 必须为 Promise 对象
  133. loadData: parameter => {
  134. this.disabled = true
  135. return salesDetailList(Object.assign(parameter, { salesBillSn: this.outBizSn || this.$route.params.sn })).then(res => {
  136. const data = res.data
  137. const no = (data.pageNo - 1) * data.pageSize
  138. for (var i = 0; i < data.list.length; i++) {
  139. data.list[i].no = no + i + 1
  140. const productCode = (data.list[i].productEntity && data.list[i].productEntity.code) || (data.list[i].dealerProductEntity && data.list[i].dealerProductEntity.code)
  141. const productName = (data.list[i].productEntity && data.list[i].productEntity.name) || (data.list[i].dealerProductEntity && data.list[i].dealerProductEntity.name)
  142. const productOrigCode = (data.list[i].productEntity && data.list[i].productEntity.origCode) || (data.list[i].dealerProductEntity && data.list[i].dealerProductEntity.origCode)
  143. const productOrigUnit = (data.list[i].productEntity && data.list[i].productEntity.unit) || (data.list[i].dealerProductEntity && data.list[i].dealerProductEntity.unit)
  144. data.list[i].productCode = productCode || '--'
  145. data.list[i].productName = productName || '--'
  146. data.list[i].productOrigCode = productOrigCode || '--'
  147. data.list[i].productOrigUnit = productOrigUnit || '--'
  148. data.list[i].warehouseName = data.list[i].warehouseEntity && data.list[i].warehouseEntity.name || '--'
  149. data.list[i].warehouseLocationName = data.list[i].warehouseLocationEntity && data.list[i].warehouseLocationEntity.name || '--'
  150. // 售价小计 由于数据库内小数位数为4位,页面则需显示2位。因此会做小数运算精度处理
  151. data.list[i].salePriceSubtotal = getOperationalPrecision(data.list[i].price, data.list[i].qty)
  152. }
  153. this.localDataSource = data.list
  154. this.disabled = false
  155. return data
  156. })
  157. },
  158. localDataSource: [],
  159. detailData: null, // 详情数据
  160. printerType: 'NEEDLE' // 打印机类型
  161. }
  162. },
  163. methods: {
  164. // 返回
  165. handleBack () {
  166. this.$router.push({ path: '/salesManagement/salesQuery/list', query: { closeLastOldTab: true } })
  167. },
  168. // 编辑
  169. handleEdit () {
  170. const row = this.detailData
  171. this.$router.push({ name: 'salesEdit', params: { id: row.id, sn: row.salesBillSn, priceType: row.priceType } })
  172. },
  173. // 详情
  174. getDetail () {
  175. salesDetailBySn({ salesBillSn: this.outBizSn || this.$route.params.sn }).then(res => {
  176. if (res.status == 200) {
  177. this.detailData = res.data
  178. } else {
  179. this.detailData = null
  180. }
  181. })
  182. },
  183. // 打印预览/快捷打印
  184. handlePrint (type) {
  185. const _this = this
  186. _this.spinning = true
  187. let url = salesDetailPrint
  188. let params = { sn: this.outBizSn || this.$route.params.sn, type: this.printerType }
  189. if (type == 'export') { // 导出
  190. url = salesDetailExport
  191. params = { sn: this.outBizSn || this.$route.params.sn }
  192. }
  193. url(params).then(res => {
  194. _this.spinning = false
  195. if (res.type == 'application/json') {
  196. var reader = new FileReader()
  197. reader.addEventListener('loadend', function () {
  198. const obj = JSON.parse(reader.result)
  199. _this.$notification.error({
  200. message: '提示',
  201. description: obj.message
  202. })
  203. })
  204. reader.readAsText(res)
  205. } else {
  206. if (type == 'export') { // 导出
  207. this.download(res)
  208. } else {
  209. this.print(res, type)
  210. }
  211. }
  212. })
  213. },
  214. print (data, type) {
  215. if (!data) {
  216. return
  217. }
  218. const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
  219. document.getElementById('print').innerHTML = '<iframe id="printfsqd" name="printfsqd" src="' + url + '" hidden></iframe>'
  220. if ((type == 'preview' || type == 'print') && this.printerType == 'NEEDLE') {
  221. const LODOP = getLodop()
  222. const rx = /<body[^>]*>([\s\S]+?)<\/body>/i///
  223. let m = rx.exec(data)
  224. if (m) m = m[1]
  225. LODOP.SET_SHOW_MODE('HIDE_PAPER_BOARD', 1) // 隐藏底图上有模拟走纸板的条纹线
  226. LODOP.SET_PRINT_PAGESIZE(3, '2140', '45', '') // 这里3表示纵向打印且纸高“按内容的高度”;2140表示纸宽214.0mm;45表示页底空白4.5mm
  227. LODOP.ADD_PRINT_HTM(0, 0, '100%', '100%', m)
  228. // LODOP.ADD_PRINT_TABLE(0, 0, '100%', '100%', m)
  229. LODOP.PREVIEW()
  230. } else {
  231. if (type == 'preview') { // 预览
  232. window.open(url)
  233. } else if (type == 'print') { // 打印
  234. window.frames['printfsqd'].focus()
  235. window.frames['printfsqd'].print()
  236. }
  237. }
  238. },
  239. download (data) {
  240. if (!data) { return }
  241. const url = window.URL.createObjectURL(new Blob([data]))
  242. const link = document.createElement('a')
  243. link.style.display = 'none'
  244. link.href = url
  245. const a = moment().format('YYYYMMDDHHmmss')
  246. const fname = '销售' + a
  247. link.setAttribute('download', fname + '.xlsx')
  248. document.body.appendChild(link)
  249. link.click()
  250. }
  251. },
  252. mounted () {
  253. if (!this.$store.state.app.isNewTab || this.outBizSn) { // 页签刷新 或 为弹框时调用
  254. this.$refs.table.refresh(true)
  255. this.getDetail()
  256. }
  257. },
  258. activated () {
  259. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  260. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  261. this.$refs.table.refresh(true)
  262. this.getDetail()
  263. }
  264. },
  265. beforeRouteEnter (to, from, next) {
  266. next(vm => {})
  267. }
  268. }
  269. </script>
  270. <style lang="less">
  271. .salesDetail-wrap{
  272. .salesDetail-cont{
  273. margin-bottom: 10px;
  274. }
  275. }
  276. </style>