detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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">
  5. <template slot="subTitle">
  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'"
  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">
  16. <!-- <span>打印字段:</span>
  17. <a-select key="1" style="width:150px" id="salesDetail-pritKey" placeholder="请选择打印字段" allowClear>
  18. <a-select-option v-for="item in pritKey" :key="item.id" :value="item.id">{{ item.name }}</a-select-option>
  19. </a-select>
  20. <span><i style="color: red;">*</i>打印模板:</span>
  21. <a-select key="2" style="width:150px" id="salesDetail-pritKey" placeholder="请选择打印模板" allowClear>
  22. <a-select-option v-for="item in pritModal" :key="item.id" :value="item.id">{{ item.name }}</a-select-option>
  23. </a-select> -->
  24. <!-- <a-button key="5" id="salesDetail-export-btn">导出</a-button> -->
  25. <a-radio-group key="3" v-model="printerType">
  26. <a-radio value="NEEDLE">针式</a-radio>
  27. <a-radio value="INK">喷墨</a-radio>
  28. </a-radio-group>
  29. <a-button key="2" id="salesDetail-preview-btn" :disabled="localDataSource.length==0" @click="handlePrint('preview')">打印预览</a-button>
  30. <a-button key="1" type="primary" id="salesDetail-print-btn" :disabled="localDataSource.length==0" @click="handlePrint('print')">快捷打印</a-button>
  31. </template>
  32. </a-page-header>
  33. <!-- 基础信息 -->
  34. <a-card size="small" :bordered="false" class="salesDetail-cont">
  35. <a-collapse :activeKey="['1']">
  36. <a-collapse-panel key="1" header="基础信息">
  37. <a-descriptions size="small" :column="3" v-if="detailData">
  38. <a-descriptions-item label="客户名称">{{ detailData.buyerName || '--' }}</a-descriptions-item>
  39. <a-descriptions-item label="客户地址">{{ detailData.shippingAddressProvinceName || '--' }}{{ detailData.shippingAddressCityName || '--' }}{{ detailData.shippingAddressCountyName || '--' }}{{ detailData.shippingAddress || '--' }}</a-descriptions-item>
  40. <a-descriptions-item label="收款方式">{{ detailData.settleStyleEntity.name || '--' }}</a-descriptions-item>
  41. <a-descriptions-item label="联系电话">{{ detailData.consigneeTel || '--' }}</a-descriptions-item>
  42. <a-descriptions-item label="备注">{{ detailData.remarks || '--' }}</a-descriptions-item>
  43. <a-descriptions-item label="销售单号">{{ detailData.salesBillNo || '--' }}</a-descriptions-item>
  44. <a-descriptions-item label="制单人">{{ detailData.operatorName || '--' }}</a-descriptions-item>
  45. <a-descriptions-item label="业务员">{{ detailData.salesManName || '--' }}</a-descriptions-item>
  46. <a-descriptions-item label="业务状态">{{ detailData.billStatusDictValue || '--' }}</a-descriptions-item>
  47. <a-descriptions-item label="财务状态">{{ detailData.financialStatusDictValue || '--' }}</a-descriptions-item>
  48. </a-descriptions>
  49. </a-collapse-panel>
  50. </a-collapse>
  51. </a-card>
  52. <a-card size="small" :bordered="false" class="pages-wrap">
  53. <!-- alert -->
  54. <a-alert type="info" style="margin-bottom: 15px;" v-if="detailData">
  55. <div slot="message">
  56. 总款数:<strong>{{ detailData.totalCategory || 0 }}</strong>;总数量:<strong>{{ detailData.totalQty || 0 }}</strong>;总赠品数量:<strong>{{ detailData.giftQty || 0 }}</strong>;急件总款数:<strong>{{ detailData.oosCategory || 0 }}</strong>;急件总数量:<strong>{{ detailData.oosQty || 0 }}</strong>;<br/>
  57. 总售价:<strong>{{ detailData.totalAmount || 0 }}</strong>;总成本:<strong>{{ detailData.totalCost || 0 }}</strong>;总毛利:<strong>{{ detailData.grossProfit || 0 }}</strong>;折后总售价:<strong>{{ detailData.discountedAmount || 0 }}</strong>;折扣:<strong>{{ detailData.discountRate || 0 }}%</strong>;折扣金额:<strong>{{ detailData.discountAmount || 0 }}</strong>;
  58. </div>
  59. </a-alert>
  60. <!-- 列表 -->
  61. <s-table
  62. class="sTable"
  63. ref="table"
  64. size="small"
  65. :rowKey="(record) => record.id"
  66. :columns="columns"
  67. :data="loadData"
  68. :scroll="{ x: 1660 }"
  69. bordered>
  70. </s-table>
  71. </a-card>
  72. </a-spin>
  73. <!-- 打印 -->
  74. <div id="print"></div>
  75. </div>
  76. </template>
  77. <script>
  78. import { getOperationalPrecision } from '@/libs/tools.js'
  79. import { STable, VSelect } from '@/components'
  80. import { salesDetailBySn, salesDetailPrint } from '@/api/sales'
  81. import { salesDetailList } from '@/api/salesDetail'
  82. export default {
  83. name: 'SalesDetail',
  84. components: { STable, VSelect },
  85. data () {
  86. return {
  87. spinning: false,
  88. disabled: false,
  89. pritKey: [
  90. { id: 0, name: '打印促销' },
  91. { id: 1, name: '打印支付方式' },
  92. { id: 2, name: '打印收款方式' }
  93. ],
  94. pritModal: [
  95. { id: 0, name: '普通模板一' },
  96. { id: 1, name: '普通模板二' },
  97. { id: 2, name: '仓库模板一' }
  98. ],
  99. // 表头
  100. columns: [
  101. { title: '序号', dataIndex: 'no', width: 80, align: 'center', fixed: 'left' },
  102. { title: '产品编码', dataIndex: 'productCode', width: 140, align: 'center' },
  103. { title: '产品名称', dataIndex: 'productName', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  104. { title: '原厂编码', dataIndex: 'productOrigCode', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
  105. { title: '成本价', dataIndex: 'cost', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) } },
  106. { title: '售价', dataIndex: 'price', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) } },
  107. { title: '折后售价', dataIndex: 'discountedPrice', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) } },
  108. { title: '销售数量', dataIndex: 'qty', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  109. { title: '单位', dataIndex: 'productOrigUnit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  110. { title: '售价小计', dataIndex: 'totalAmount', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) } },
  111. { title: '折后小计', dataIndex: 'discountedAmount', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) } },
  112. { title: '折扣金额', dataIndex: 'discountAmount', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) } },
  113. { title: '仓库', dataIndex: 'warehouseName', width: 100, align: 'center' },
  114. { title: '仓位', dataIndex: 'warehouseLocationName', width: 100, align: 'center' },
  115. { title: '是否急件', dataIndex: 'oosFlagDictValue', width: 100, align: 'center', customRender: function (text) { return text || '--' } }
  116. ],
  117. // 加载数据方法 必须为 Promise 对象
  118. loadData: parameter => {
  119. this.disabled = true
  120. return salesDetailList(Object.assign(parameter, { salesBillSn: this.$route.params.sn })).then(res => {
  121. const data = res.data
  122. const no = (data.pageNo - 1) * data.pageSize
  123. for (var i = 0; i < data.list.length; i++) {
  124. data.list[i].no = no + i + 1
  125. const productCode = (data.list[i].productEntity && data.list[i].productEntity.code) || (data.list[i].dealerProductEntity && data.list[i].dealerProductEntity.code)
  126. const productName = (data.list[i].productEntity && data.list[i].productEntity.name) || (data.list[i].dealerProductEntity && data.list[i].dealerProductEntity.name)
  127. const productOrigCode = (data.list[i].productEntity && data.list[i].productEntity.origCode) || (data.list[i].dealerProductEntity && data.list[i].dealerProductEntity.origCode)
  128. const productOrigUnit = (data.list[i].productEntity && data.list[i].productEntity.unit) || (data.list[i].dealerProductEntity && data.list[i].dealerProductEntity.unit)
  129. data.list[i].productCode = productCode || '--'
  130. data.list[i].productName = productName || '--'
  131. data.list[i].productOrigCode = productOrigCode || '--'
  132. data.list[i].productOrigUnit = productOrigUnit || '--'
  133. data.list[i].warehouseName = data.list[i].warehouseEntity && data.list[i].warehouseEntity.name || '--'
  134. data.list[i].warehouseLocationName = data.list[i].warehouseLocationEntity && data.list[i].warehouseLocationEntity.name || '--'
  135. // 售价小计 由于数据库内小数位数为4位,页面则需显示2位。因此会做小数运算精度处理
  136. data.list[i].salePriceSubtotal = getOperationalPrecision(data.list[i].price, data.list[i].qty)
  137. }
  138. this.localDataSource = data.list
  139. this.disabled = false
  140. return data
  141. })
  142. },
  143. localDataSource: [],
  144. detailData: null, // 详情数据
  145. printerType: 'NEEDLE' // 打印机类型
  146. }
  147. },
  148. methods: {
  149. // 返回
  150. handleBack () {
  151. this.$router.push({ name: 'salesQueryList' })
  152. // this.$router.back()
  153. },
  154. // 编辑
  155. handleEdit () {
  156. const row = this.detailData
  157. this.$router.push({ name: 'salesEdit', params: { id: row.id, sn: row.salesBillSn, priceType: row.priceType } })
  158. },
  159. // 详情
  160. getDetail () {
  161. salesDetailBySn({ salesBillSn: this.$route.params.sn }).then(res => {
  162. if (res.status == 200) {
  163. this.detailData = res.data
  164. } else {
  165. this.detailData = null
  166. }
  167. })
  168. },
  169. // 打印预览/快捷打印
  170. handlePrint (type) {
  171. const _this = this
  172. _this.spinning = true
  173. salesDetailPrint({ sn: this.$route.params.sn, type: this.printerType }).then(res => {
  174. _this.spinning = false
  175. if (res.type == 'application/json') {
  176. var reader = new FileReader()
  177. reader.addEventListener('loadend', function () {
  178. const obj = JSON.parse(reader.result)
  179. _this.$notification.error({
  180. message: '提示',
  181. description: obj.message
  182. })
  183. })
  184. reader.readAsText(res)
  185. } else {
  186. this.print(res, type)
  187. }
  188. })
  189. },
  190. print (data, type) {
  191. if (!data) {
  192. return
  193. }
  194. const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
  195. document.getElementById('print').innerHTML = '<iframe id="printf" name="printf" src="' + url + '" hidden></iframe>'
  196. if (type == 'preview') { // 预览
  197. window.open(url)
  198. } else if (type == 'print') { // 打印
  199. window.frames['printf'].focus()
  200. window.frames['printf'].print()
  201. }
  202. }
  203. },
  204. mounted () {
  205. this.getDetail()
  206. }
  207. }
  208. </script>
  209. <style lang="less">
  210. .salesDetail-wrap{
  211. .salesDetail-cont{
  212. margin-bottom: 15px;
  213. }
  214. }
  215. </style>