index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <div class="page">
  3. <template-page v-if="isShowTab && !formDialog" ref="pageRef" :get-list="getList" :table-attributes="tableAttributes"
  4. :table-events="tableEvents" :operationColumnWidth="140" :options-evens-group="optionsEvensGroup"
  5. :moreParameters="moreParameters" :column-parsing="columnParsing" :operation="operation()" :exportList="exportList">
  6. <div slot="moreSearch">
  7. <el-radio-group v-model="flag" size="mini" @change="changeType">
  8. <el-radio-button label="">全部</el-radio-button>
  9. <el-radio-button label="SAVE">保存</el-radio-button>
  10. <el-radio-button label="SUBMIT">提交</el-radio-button>
  11. <el-radio-button label="PAY_NOT_TAKE">已支付未提货</el-radio-button>
  12. <el-radio-button label="PAY_TAKE">已支付已提货</el-radio-button>
  13. <el-radio-button label="CANCEL">取消订单</el-radio-button>
  14. </el-radio-group>
  15. <br><br>
  16. </div>
  17. </template-page>
  18. <div class="detail" v-if="formDialog">
  19. <auxiliarySalesOrderDetail :id="id" @back="backList" :formType="formDialogType"
  20. :title="'辅材销售订单' + formDialogTitles[formDialogType]"></auxiliarySalesOrderDetail>
  21. </div>
  22. <print-preview ref="preView" @initPrint="handleInitPrint" @refreshList="handleRefreshList" />
  23. </div>
  24. </template>
  25. <script>
  26. import TemplatePage from '@/components/template/template-page-1.vue'
  27. import auxiliarySalesOrderDetail from '../components/auxiliarySalesOrderDetail.vue'
  28. import import_mixin from '@/components/template/import_mixin.js'
  29. import ImageUpload from '@/components/file-upload'
  30. import { downloadFiles } from '@/utils/util'
  31. import { required, mobileRequired, mobile, httpUrl, email } from '@/components/template/rules_verify.js'
  32. import { listPageV2, pageExport, getDetail, add, edit, submit } from "@/api/auxiliaryFittings/auxiliarySalesOrder";
  33. import { getWebsit } from "@/api/customerManagement";
  34. import printPreview from '../components/preview.vue'
  35. import { disAutoConnect, hiprint } from 'vue-plugin-hiprint'
  36. import operation_mixin from '@/components/template/operation_mixin.js'
  37. disAutoConnect()
  38. export default {
  39. components: { TemplatePage, ImageUpload, auxiliarySalesOrderDetail, printPreview },
  40. mixins: [import_mixin, operation_mixin],
  41. data() {
  42. return {
  43. // 表格属性
  44. tableAttributes: {
  45. // 启用勾选列
  46. selectColumn: true
  47. },
  48. // 表格事件
  49. tableEvents: {
  50. 'selection-change': this.selectionChange
  51. },
  52. // 勾选选中行
  53. recordSelected: [],
  54. /** 表单变量 */
  55. formDialogType: 0,
  56. formDialogTitles: ["新增", "编辑", "详情"],
  57. formDialog: false,
  58. id: '',
  59. flag: '',
  60. websitList: [],
  61. isShowTab: true,
  62. orderEnginBaseId: '',
  63. payQrcode: JSON.parse(localStorage.getItem('greemall_user')).payQrcode,
  64. }
  65. },
  66. computed: {
  67. // 事件组合
  68. optionsEvensGroup() {
  69. return [
  70. [
  71. [
  72. this.optionsEvensAuth("add", {
  73. click: this.addData
  74. }),
  75. ]
  76. ]
  77. ]
  78. },
  79. // 更多参数
  80. moreParameters() {
  81. return []
  82. },
  83. formItems() { },
  84. filterArr() {
  85. return function (arr, size) {
  86. //判断如果不是数组(就没有length),或者size没有传值,size小于1,就返回空数组
  87. if (!arr.length || !size || size < 1) return []
  88. let [start, end, result] = [null, null, []]
  89. for (let i = 0; i < Math.ceil(arr.length / size); i++) {
  90. start = i * size
  91. end = start + size
  92. result.push(arr.slice(start, end))
  93. }
  94. return result
  95. }
  96. }
  97. },
  98. created(){
  99. if(this.$route.query.id){
  100. this.id = this.$route.query.id
  101. this.formDialogType = 2
  102. this.openForm()
  103. }
  104. if(this.$route.query.orderEnginBaseId){
  105. this.orderEnginBaseId = this.$route.query.orderEnginBaseId
  106. }
  107. },
  108. watch: {
  109. flag(){
  110. this.isShowTab = false
  111. this.$nextTick(()=>{
  112. this.isShowTab = true
  113. })
  114. }
  115. },
  116. methods: {
  117. // 切换状态
  118. changeType(val) {
  119. this.$refs.pageRef.refreshList()
  120. },
  121. backList() {
  122. this.id = ''
  123. this.formDialog = false;
  124. this.$refs.pageRef.refreshList()
  125. },
  126. // 列表请求函数
  127. getList(p, cb) {
  128. try {
  129. var pam = JSON.parse(JSON.stringify(p))
  130. pam.params.push({ "param": "a.goods_type", "compare": "=", "value": 'M' }, { 'param': 'a.flag', "compare": "=", "value": this.flag }, { 'param': 'a.order_engin_base_id', "compare": "=", "value": this.orderEnginBaseId })
  131. cb && cb(pam)
  132. return listPageV2(pam)
  133. } catch (error) {
  134. console.log(error)
  135. }
  136. },
  137. // 列表导出函数
  138. exportList: pageExport,
  139. // 表格列解析渲染数据更改
  140. columnParsing(item, defaultData) {
  141. if (item.jname === 'idCardImg') {
  142. defaultData.render = (h, { row, index, column }) => {
  143. return (
  144. <div style="padding:0 6px;cursor: pointer;">
  145. {row.idCardImg ? row.idCardImg.split(",").map(url => <el-image src={url} preview-src-list={[url]} fit="fit" style="width:80px;height:80px;" />) : null}
  146. </div>
  147. )
  148. }
  149. }
  150. return defaultData
  151. },
  152. // 监听勾选变化
  153. selectionChange(data) {
  154. this.recordSelected = data
  155. },
  156. operation() {
  157. return this.operationBtn({
  158. edit: {
  159. conditions: ({ row, index, column }) => {
  160. return row.flag == 'SAVE'
  161. },
  162. click: ({ row, index, column }) => {
  163. this.id = row.salesId
  164. this.formDialogType = 1
  165. this.openForm()
  166. }
  167. },
  168. detail: {
  169. conditions: ({ row, index, column }) => {
  170. return row.flag != 'SAVE'
  171. },
  172. click: ({ row, index, column }) => {
  173. this.id = row.salesId
  174. this.formDialogType = 2
  175. this.openForm()
  176. }
  177. },
  178. confirmDelivery: {
  179. conditions: ({ row, index, column }) => {
  180. return row.flag == 'PAY_NOT_TAKE'
  181. },
  182. click: ({ row, index, column }) => {
  183. this.id = row.salesId
  184. this.formDialogType = row.flag == 'SAVE' ? 1 : 2
  185. this.openForm()
  186. }
  187. },
  188. print: {
  189. click: ({ row, index, column }) => {
  190. this.toPrint(row, 2)
  191. }
  192. },
  193. })
  194. },
  195. addData() {
  196. this.formDialogType = 0
  197. this.openForm()
  198. },
  199. openForm() {
  200. this.formDialog = true;
  201. },
  202. getWebsit() {
  203. getWebsit({ type: 'C' }).then(res => {
  204. this.websitList = res.data
  205. })
  206. },
  207. // 点击打印
  208. async toPrint(row, type) {
  209. this.getWebsit()
  210. let pagingData = []
  211. const { data } = await getDetail({
  212. salesId: row.salesId
  213. })
  214. pagingData = this.filterArr(data.items, 4)
  215. // 初始化模板,否则生成的模板叠加
  216. hiprint.init()
  217. this.hiprintTemplate = new hiprint.PrintTemplate()
  218. // 兼容批量打印
  219. // let params = !type ? this.filterArr() : [row.salesId]
  220. let len = pagingData.length
  221. let loadingLen = len
  222. // 使用 i-- 提升for效率
  223. this.$startLoading()
  224. for (let i = 0; i < len; i++) {
  225. try {
  226. let websitHtml = ''
  227. let html = ''
  228. let num = 0
  229. let totalAmount = 0
  230. pagingData[i].forEach(item => {
  231. totalAmount = (Number(item.saleAmount) * 100 + totalAmount * 100) / 100
  232. num += Number(item.salesQty)
  233. html += `
  234. <tr align="center">
  235. <td>${item.goodsName}</td>
  236. <td>${item.goodsSpecification}</td>
  237. <td>${item.goodsSalesUnit}</td>
  238. <td>${item.salesQty}</td>
  239. <td>${item.price}</td>
  240. <td>${item.saleAmount}</td>
  241. <td></td>
  242. <td></td>
  243. </tr>
  244. `
  245. })
  246. this.websitList.slice(0, 5).forEach(item => {
  247. websitHtml += `
  248. <div style="display: flex;font-size: 14px;margin-bottom: 6px;">
  249. <div style="margin-right: 10px;">${item.name}</div>
  250. <div style="margin-right: 10px;">${item.websitPhone}</div>
  251. <div>地址: ${item.address}</div>
  252. </div>
  253. `
  254. })
  255. // 模板基础配置
  256. this.panel = this.hiprintTemplate.addPrintPanel({
  257. height: 140,
  258. width: 241,
  259. fontFamily: '黑体',
  260. fontSize: 13,
  261. paperFooter: 340,
  262. paperHeader: 10,
  263. paperNumberDisabled: true
  264. })
  265. // 获取收款单模板和基础配置
  266. this.panel.addPrintHtml({
  267. options: {
  268. width: 633,
  269. top: 30,
  270. left: 20,
  271. fontFamily: '黑体',
  272. fontSize: 13,
  273. content: this.setTableDom(data, html, websitHtml, totalAmount, num, len, i)
  274. }
  275. })
  276. loadingLen--
  277. } catch (error) {
  278. console.log(999, error)
  279. this.$endLoading()
  280. return
  281. }
  282. }
  283. if (loadingLen === 0) {
  284. this.$endLoading()
  285. }
  286. console.log(333)
  287. // 预览打印内容
  288. this.$refs.preView.show(this.hiprintTemplate, this.panel)
  289. },
  290. // 打印模板
  291. setTableDom(data, html, websitHtml, totalAmount, num, length, page) {
  292. return `
  293. <div style="font-family:'黑体';font-size: 16px;">
  294. <div style="display: flex;justify-content: center;align-items: center;position: relative;">
  295. <h1 style="text-align:center;margin: 10px 0;">${data.websitName}销售单</h1>
  296. <div style="position: absolute;right:0;">共 ${length}页 第 ${page+1} 页</div>
  297. </div>
  298. <div style="display: flex;justify-content: space-between;">
  299. <div style="width: 28%;"></div>
  300. <div>单据日期: ${data.createTime}</div>
  301. <div>单据编号: ${data.salesId}</div>
  302. </div>
  303. <div style="display: flex;justify-content: space-between;font-size: 16px;margin: 10px 0;">
  304. <div>客户: ${data.workerName}</div>
  305. <div>摘要: ${data.payType == 'CASH' ? '现金' : data.payType == 'WECHAT' ? '微信': '工程支付'}</div>
  306. </div>
  307. <div style="display: flex;font-size: 16px;margin-bottom: 10px;">
  308. <div>联系电话: ${data.workerMobile}</div>
  309. <div style="margin-left: 50px;">收货地址: ${data.province?(data.province + data.city + data.area + data.street + data.address):''}</div>
  310. </div>
  311. <div >
  312. <table border=".5" cellspacing="0" width="856"
  313. style="border-color: rgb(0,0,0);
  314. border-collapse: collapse;
  315. border-style: none;
  316. border: 1px solid rgb(0,0,0);
  317. font-weight: normal;
  318. text-decoration: none;
  319. vertical-align: middle;
  320. box-sizing: border-box;
  321. word-wrap: break-word;
  322. word-break: break-all;">
  323. <tr align="center">
  324. <td>商品名称</td>
  325. <td>规格</td>
  326. <td>单位</td>
  327. <td>数量</td>
  328. <td>单价</td>
  329. <td>金额</td>
  330. <td>仓库</td>
  331. <td>备注</td>
  332. </tr>
  333. ${html}
  334. <tr align="center" align="center">
  335. <td>小计: </td>
  336. <td colspan="2"></td>
  337. <td>${num}</td>
  338. <td></td>
  339. <td>${totalAmount}</td>
  340. <td colspan="2">金额总计: ${totalAmount}</td>
  341. </tr>
  342. </table>
  343. </div>
  344. <div style="display: flex;justify-content: space-between;font-size: 16px;margin: 10px 0;">
  345. <div>制单人: ${data.createBy || ''}</div>
  346. <div>审核人: ${data.confirmBy || ''}</div>
  347. <div>业务员: </div>
  348. <div>签收人: </div>
  349. </div>
  350. <div style="display: flex;justify-content: space-between;">
  351. <div>
  352. ${websitHtml}
  353. </div>
  354. ${data.payType == 'CASH'?`<div style="">
  355. <img style="width: 80px;height: 80px;" src="${this.payQrcode}"/>
  356. </div>`:''}
  357. </div>
  358. <div style="margin:100px 0 0 0">
  359. <div></div>
  360. </div>
  361. </div>
  362. `
  363. },
  364. handleRefreshList() {
  365. this.recordSelected = []
  366. this.$refs.pageRef.refreshList()
  367. },
  368. handleInitPrint() {
  369. this.$nextTick(() => {
  370. this.initPrint()
  371. })
  372. },
  373. // 下载导入模版
  374. handleDownload() {
  375. // downloadFiles('charging/standard/download');
  376. },
  377. }
  378. }
  379. </script>
  380. <style lang="scss" scoped>
  381. .page {
  382. height: 100%;
  383. }
  384. .tab {
  385. padding: 20px 20px 0 20px;
  386. }
  387. </style>