increaseViewers.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. <template>
  2. <el-dialog
  3. title="添加观影人"
  4. :visible.sync="dialogVisible"
  5. width="90%"
  6. :before-close="handleClose">
  7. <div
  8. v-loading="loading"
  9. :element-loading-text="loadingText"
  10. element-loading-spinner="el-icon-loading"
  11. element-loading-background="rgba(0, 0, 0, 0.8)"
  12. class="increase-viewers-box">
  13. <div class="increase-viewers-info">
  14. <el-table
  15. :data="viewerList"
  16. border
  17. style="width: 100%">
  18. <el-table-column
  19. type="index"
  20. width="50">
  21. </el-table-column>
  22. <el-table-column
  23. label="姓名"
  24. width="180">
  25. <template slot-scope="scope">
  26. <div>
  27. <span v-if="actionIndex != scope.row.id">{{ scope.row.name }}</span>
  28. <el-input v-else v-model="tableForm.name" placeholder="请输入姓名"></el-input>
  29. </div>
  30. </template>
  31. </el-table-column>
  32. <el-table-column
  33. label="身份证号"
  34. width="240">
  35. <template slot-scope="scope">
  36. <div>
  37. <span v-if="actionIndex != scope.row.id">{{ scope.row.idcard }}</span>
  38. <el-input
  39. v-else
  40. v-model="tableForm.idcard"
  41. placeholder="请输入身份证号"
  42. clearable
  43. style="width: 240px;"
  44. @keyup.enter.native="handleQuery"
  45. >
  46. <el-button slot="append" :loading="idcardLoading" size="mini" type="primary" @click="readCert">{{ idcardLoading ? '识别中':'识别' }}</el-button>
  47. </el-input>
  48. </div>
  49. </template>
  50. </el-table-column>
  51. <el-table-column
  52. label="座位类型">
  53. <template slot-scope="scope">
  54. <span>{{ scope.row.seatTypeName }}</span>
  55. </template>
  56. </el-table-column>
  57. <el-table-column
  58. prop="date"
  59. label="座位号">
  60. <template slot-scope="scope">
  61. <span>{{ scope.row.seatName }}</span>
  62. </template>
  63. </el-table-column>
  64. <el-table-column
  65. prop="date"
  66. label="价格(元)">
  67. <template slot-scope="scope">
  68. <span>{{ scope.row.salePrice }}</span>
  69. </template>
  70. </el-table-column>
  71. <el-table-column
  72. label="人员类别"
  73. width="180">
  74. <template slot-scope="scope">
  75. <div>
  76. <span v-if="actionIndex != scope.row.id">{{ scope.row.identity }}</span>
  77. <el-select
  78. v-else
  79. v-model="tableForm.identity"
  80. placeholder="请选择人员类别"
  81. clearable
  82. style="width: 100%"
  83. >
  84. <el-option
  85. v-for="dict in personnelType"
  86. :key="dict.id"
  87. :label="dict.name"
  88. :value="dict.id"
  89. />
  90. </el-select>
  91. </div>
  92. </template>
  93. </el-table-column>
  94. <el-table-column
  95. label="应付金额(元)">
  96. <template slot-scope="scope">
  97. <span>{{ scope.row.realPrice }}</span>
  98. <!-- <div>
  99. <span v-if="actionIndex != scope.row.id">{{ scope.row.realPrice }}</span>
  100. <el-input v-else v-model="tableForm.realPrice" placeholder="请输入应付金额(元)"></el-input>
  101. </div> -->
  102. </template>
  103. </el-table-column>
  104. <el-table-column
  105. label="备注"
  106. width="180">
  107. <template slot-scope="scope">
  108. <div>
  109. <span v-if="actionIndex != scope.row.id">{{ scope.row.remark }}</span>
  110. <el-input v-else v-model="tableForm.remark" placeholder="请输入备注"></el-input>
  111. </div>
  112. </template>
  113. </el-table-column>
  114. <el-table-column
  115. label="操作"
  116. width="180">
  117. <template slot-scope="scope">
  118. <el-button
  119. size="mini"
  120. v-if="actionIndex == scope.row.id"
  121. @click="handleSeva(scope.$index, scope.row)">保存</el-button>
  122. <el-button
  123. :disabled="!!actionIndex"
  124. size="mini"
  125. v-if="actionIndex != scope.row.id"
  126. @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
  127. <el-button
  128. size="mini"
  129. type="danger"
  130. @click="handleDelete(scope.$index, scope.row)">删除</el-button>
  131. </template>
  132. </el-table-column>
  133. </el-table>
  134. </div>
  135. <div style="padding: 10px 0 20px;">合计:l累计观影人员{{ viewerList.length }}人,应付总额¥{{ moneyAll }}(元)</div>
  136. <div>
  137. <el-form
  138. :model="ruleForm"
  139. :rules="rules"
  140. ref="ruleForm11"
  141. label-width="100px"
  142. class="demo-ruleForm"
  143. size="mini"
  144. >
  145. <el-form-item label="用户来源:" prop="source">
  146. <el-radio-group v-model="ruleForm.source">
  147. <el-radio label="7">窗口</el-radio>
  148. <el-radio label="2">美团</el-radio>
  149. <el-radio label="3">携程</el-radio>
  150. </el-radio-group>
  151. </el-form-item>
  152. <el-form-item v-if="ruleForm.resource && ruleForm.resource != 1" label="核销码/订单码" prop="orderIdOrQrCode">
  153. <el-input style="width: 200px;" v-model="ruleForm.orderIdOrQrCode"></el-input>
  154. </el-form-item>
  155. <el-form-item label="支付方式:" prop="paymentType">
  156. <el-radio-group v-model="ruleForm.paymentType">
  157. <el-radio label="1">扫码</el-radio>
  158. <el-radio label="2">现金</el-radio>
  159. </el-radio-group>
  160. </el-form-item>
  161. <el-form-item label="应付金额:">
  162. ¥{{ moneyAll }}元
  163. </el-form-item>
  164. <el-form-item v-if="ruleForm.paymentType == 2" label="实付金额:" prop="realPrice">
  165. <el-input @input="setRealPrice" style="width: 200px;" v-model="ruleForm.realPrice"></el-input>
  166. </el-form-item>
  167. <el-form-item label="找零金额:" v-if="ruleForm.paymentType == 2">
  168. ¥{{ ruleForm.small }}元
  169. </el-form-item>
  170. </el-form>
  171. </div>
  172. <!-- 支付过程 控制 -->
  173. <div v-if="payStatus" class="increase-viewers-pay-status">
  174. <div class="increase-viewers-pay-status-info">
  175. <span>提示</span>
  176. <span>
  177. {{ payStatus==1 ? '生成订单失败!!!' :
  178. payStatus==2 ? '生成订单生成成功,请点击调取扫码盒子' :
  179. payStatus==4 ? '扫码支付失败!!!' :
  180. payStatus==5 ? '请出示付款码!!!' :
  181. payStatus==6 ? '连接扫码器失败!!!' :
  182. payStatus==7 ? '用户支付失败或未支付,请重新连接支付!!!' :
  183. payStatus==8 ? '用户支付成功,请点击打印票!!!' :
  184. payStatus==3 ? '' : '未知状态' }}
  185. </span>
  186. <!-- 重新生成订单 1 -->
  187. <el-button v-if="payStatus==1" @click="orderInfoSubmitFun()" type="primary">重新生成订单</el-button>
  188. <!-- 扫码支付 2 -->
  189. <el-button v-if="payStatus==2" @click="vbar_open(orderId)" type="success">扫码支付</el-button>
  190. <!-- 扫码支付 4 -->
  191. <el-button v-if="payStatus==4" @click="vbar_open(orderId)" type="success">重新扫码支付</el-button>
  192. <!-- 重新支付 3 -->
  193. <el-button v-if="payStatus==3" @click="gotoCashPayFun(orderId)" type="success">重新支付</el-button>
  194. <!-- 重新支付 6 7 -->
  195. <el-button v-if="payStatus==6 || payStatus==7" @click="vbar_open(orderId)" type="success">重新连接扫码支付</el-button>
  196. <!-- 打印 8 -->
  197. <div v-if="payStatus==8">
  198. <el-select v-model="printListId" placeholder="选择打印机">
  199. <el-option :label="item.deviceName" :key="item.id" :value="item.id" v-for="(item,index) in printList"></el-option>
  200. </el-select>
  201. <el-button style="margin-left: 15px" @click="print" type="success">打印门票</el-button>
  202. </div>
  203. </div>
  204. </div>
  205. </div>
  206. <span slot="footer" class="dialog-footer">
  207. <el-button @click="handleClose()">取 消</el-button>
  208. <el-button v-if="!orderId" :loading="loading" type="primary" @click="submitForm('ruleForm11')">确定支付</el-button>
  209. </span>
  210. </el-dialog>
  211. </template>
  212. <script>
  213. import {
  214. querySeatList,
  215. merchantPerformTimeList,
  216. orderInfoSubmit,
  217. gotoMicroPay,
  218. gotoCashPay,
  219. payQuery,
  220. selectRegion,
  221. orderInfoCancel,
  222. lockOrUnLock,
  223. merchantTheatreAuditoriumList
  224. } from '@/api/windowTicketSales/ticketingSales'
  225. import { pageList as getPrintListApi } from "@/api/device/pda";
  226. import { printApi } from '@/api/windowTicketSales/ticketingCollection'
  227. const https = require('https');
  228. const axios = require('axios');
  229. export default {
  230. data() {
  231. return {
  232. loading: false,
  233. loadingText: '',
  234. dialogVisible: false,
  235. actionIndex: false,
  236. tableForm: {
  237. name: '', // 姓名
  238. mobile: '', // 电话
  239. idcard: '', // 身份证
  240. identity: '', // 观影人身份
  241. remark: '', // 备注信息
  242. salePrice: '', // 原价
  243. realPrice: '', // 实付金额
  244. seatId: '', // 座位ID
  245. seatName: '', // 座位名称
  246. seatType: '', // 座位类型
  247. },
  248. ruleForm: {
  249. performId: "", // 剧目ID
  250. retailId: "", // 分销ID
  251. goodsList: [], // 商品列表
  252. auditoriumId: "", // 演出厅ID
  253. performTimeId: "1", // 场次时段ID
  254. seatTypeId: "", // 座位类型ID
  255. source: '', // 订单来源
  256. purchaser: {},// 购票人信息
  257. viewerList: [], // 观影人列表
  258. orderIdOrQrCode: '',
  259. paymentType: '', // 支付方式
  260. small: '',// 实付金额
  261. },
  262. viewerList: [], // 观影人列表
  263. rules: {
  264. source: [
  265. { required: true, message: '请选择用户来源', trigger: ['blur','change']},
  266. ],
  267. orderIdOrQrCode: [
  268. { required: true, message: '请输入核销码/订单码', trigger: ['blur','change']},
  269. ],
  270. paymentType: [
  271. { required: true, message: '请选择支付方式', trigger: ['blur','change']},
  272. ],
  273. realPrice: [
  274. { required: true, message: '请输入核销码/订单码', trigger: ['blur','change']},
  275. ],
  276. },
  277. moneyAll: '',
  278. payment: '',
  279. payStatus: null, // 支付状态
  280. orderId: null,
  281. websocket_connected: false, // 是否已连接
  282. websocketCtrl: null,
  283. websocketData: null,
  284. idcardLoading: false,
  285. personnelType: [
  286. { id: "0" , name:'无' },
  287. { id: "1", name:'现役军人' },
  288. { id: "2" , name:'警察' },
  289. { id: "3" , name:'消防员' },
  290. { id: "4" , name:'残疾军人' }
  291. ],
  292. payTime: null, // 支付等待时间
  293. printListId: null,
  294. printList: []
  295. };
  296. },
  297. methods: {
  298. async initData(list,params){
  299. this.websocketClear()
  300. this.idcardLoading = false
  301. this.ruleForm = {
  302. performId: "", // 剧目ID
  303. retailId: "", // 分销ID
  304. goodsList: [], // 商品列表
  305. auditoriumId: "", // 演出厅ID
  306. performTimeId: "1", // 场次时段ID
  307. seatTypeId: "", // 座位类型ID
  308. source: '', // 订单来源
  309. purchaser: {},// 购票人信息
  310. viewerList: [], // 观影人列表
  311. orderIdOrQrCode: '',
  312. paymentType: '', // 支付方式
  313. small: '',// 实付金额
  314. }
  315. this.payStatus = null
  316. this.orderId = null
  317. this.websocket_connected = false
  318. this.dialogVisible = true
  319. this.loading = true
  320. this.actionIndex = null
  321. this.viewerList = []
  322. let perform = await this.selectRegionFun(params)
  323. console.log("perform===",perform)
  324. // let perform = {
  325. // money: 1,
  326. // name: '普通票'
  327. // }
  328. let listCopy = []
  329. let listCopy1 = []
  330. list.forEach((item,index)=>{
  331. listCopy.push({
  332. id: index+1,
  333. name: '', // 姓名
  334. mobile: '', // 电话
  335. idcard: '', // 身份证
  336. identity: '', // 观影人身份
  337. remark: '', // 备注信息
  338. salePrice: perform.money, // 原价
  339. realPrice: perform.money, // 实付金额
  340. seatId: item.id, // 座位ID
  341. seatName: item.name?item.name:'暂无命名', // 座位名称
  342. seatType: perform.seatTypeId, // 座位类型
  343. seatTypeId: perform.seatTypeId,
  344. seatTypeName: perform.seatTypeName,
  345. })
  346. })
  347. //this.goodsList =
  348. this.viewerList = JSON.parse(JSON.stringify(listCopy))
  349. this.setMoneyAll()
  350. console.log(this.viewerList)
  351. this.loading = false
  352. this.$nextTick(()=>{
  353. this.$refs.ruleForm11.clearValidate()
  354. })
  355. },
  356. /** 获取票务信息 */
  357. async selectRegionFun(params){
  358. try {
  359. this.loadingText = "获取票务信息中..."
  360. let res = await selectRegion({
  361. "auditoriumId": params.auditoriumId, // 演艺厅ID
  362. "goodsId": params.goodsId, // 商品ID
  363. "performId": params.performId, // 上一界面节目ID
  364. "performTimeId": params.timeId, // 时段ID
  365. "retailId": "" // 分销ID
  366. })
  367. if(res.code == 200) {
  368. if(res.data.regionPriceList &&res.data.regionPriceList.length>0){
  369. let obj = res.data.regionPriceList[0]
  370. this.ruleForm.performId = obj.performId
  371. this.ruleForm.goodsList = [
  372. {
  373. goodsId: obj.goodsId,
  374. salePeice: obj.salePrice,
  375. saleNum: 1,
  376. }
  377. ]
  378. this.ruleForm.auditoriumId = obj.auditoriumId
  379. this.ruleForm.performId = obj.performId
  380. this.ruleForm.performTimeId = res.data.performTimeId
  381. this.ruleForm.seatTypeId = obj.seatTypeId
  382. return {
  383. money: obj.salePrice,
  384. //name: obj.goodsName,
  385. seatTypeId: obj.seatTypeId,
  386. seatTypeName: obj.seatTypeName,
  387. }
  388. }else {
  389. this.$message.error('存在座位未设置价格,请选择其他票!!!');
  390. this.loading = false
  391. this.dialogVisible = false
  392. }
  393. console.log("res====",res)
  394. }else {
  395. this.$message.error(res.msg);
  396. this.loading = false
  397. this.dialogVisible = false
  398. }
  399. } catch (error) {
  400. console.error("error=====",error)
  401. this.$message.error('价格查询出错');
  402. this.loading = false
  403. this.dialogVisible = false
  404. }
  405. },
  406. /** 退出窗口 */
  407. handleClose(done) {
  408. // if(this.payStatus==8) {
  409. // this.$message.error('请daying');
  410. // return
  411. // }
  412. this.$confirm('确认关闭?')
  413. .then(_ => {
  414. if(this.orderId){
  415. orderInfoCancel({
  416. orderId: this.orderId
  417. }).then((res)=>{
  418. if(res.code==200) {
  419. this.$emit('clearDialogVisible')
  420. this.dialogVisible = false
  421. }
  422. }).catch(()=>{
  423. this.$message.error('订单关闭失败!!!');
  424. })
  425. }else {
  426. this.dialogVisible = false
  427. }
  428. })
  429. .catch(_ => {});
  430. },
  431. handleSeva(index, row) {
  432. if(!this.tableForm.name){
  433. this.$message.error('请输入姓名!!!');
  434. return
  435. }
  436. if(!this.tableForm.idcard){
  437. this.$message.error('请输入身份证号!!!');
  438. return
  439. }
  440. if(this.tableForm.identity){
  441. if(!this.tableForm.remark){
  442. this.$message.error('请输入备注!!!');
  443. return
  444. }
  445. }
  446. this.$set(this.viewerList,index,JSON.parse(JSON.stringify(this.tableForm)))
  447. this.actionIndex = null
  448. this.setMoneyAll()
  449. },
  450. handleEdit(index, row) {
  451. this.actionIndex = row.id
  452. this.tableForm = JSON.parse(JSON.stringify(row))
  453. console.log(index, row);
  454. },
  455. handleDelete(index, row) {
  456. console.log(index, row);
  457. },
  458. setMoneyAll(){
  459. let moneyAll = 0
  460. this.viewerList.forEach((item,index) => {
  461. console.log("item.realPrice====",item.realPrice)
  462. if(item.realPrice && !isNaN(Number(item.realPrice))) {
  463. moneyAll = moneyAll + Number(item.realPrice)
  464. }
  465. })
  466. console.log("dsfsfdsf",moneyAll)
  467. this.moneyAll = moneyAll? moneyAll: ''
  468. },
  469. setRealPrice(value) {
  470. if(value && !isNaN(value)) {
  471. this.$set(this.ruleForm,'small',Number(value) - this.moneyAll )
  472. }
  473. },
  474. submitForm(formName) {
  475. this.$refs[formName].validate((valid) => {
  476. if (valid) {
  477. this.orderInfoSubmitFun()
  478. } else {
  479. console.log('error submit!!');
  480. return false;
  481. }
  482. });
  483. },
  484. resetForm(formName) {
  485. this.$refs[formName].resetFields();
  486. },
  487. /** 生成订单 */
  488. async orderInfoSubmitFun(){
  489. this.loading = true
  490. try {
  491. this.orderId = null
  492. this.loadingText = "生成订单中..."
  493. let res = await orderInfoSubmit({
  494. ...this.ruleForm,
  495. viewerList: this.viewerList
  496. })
  497. if(res.code == 200){
  498. this.orderId = res.data.orderId
  499. if(this.ruleForm.paymentType == 2) {
  500. this.gotoCashPayFun()
  501. }else {
  502. this.loading = false
  503. this.payStatus = 2
  504. }
  505. }else{
  506. this.$message.error('生成订单失败!!!');
  507. this.loading = false
  508. this.payStatus = 1
  509. }
  510. } catch (error) {
  511. this.$message.error('生成订单失败!!!');
  512. this.loading = false
  513. this.payStatus = 1
  514. }
  515. },
  516. /** 调取 订单支付码支付 */
  517. async gotoMicroPayFun(orderId,code){
  518. this.loading = true
  519. try {
  520. this.loadingText = "订单支付中..."
  521. this.payStatus = ''
  522. let res = await gotoMicroPay({
  523. "orderId": orderId, // 订单编号-提交订单返回
  524. "authCode": code // 微信扫码支付-支付码
  525. })
  526. if(res.code == 200){
  527. this.websocketClear()
  528. if(this.payTime){
  529. clearInterval(this.payTime)
  530. }
  531. this.payTime = setInterval(()=>{
  532. this.payQueryFun(this.orderId)
  533. },1500)
  534. }else{
  535. this.$message.error('支付失败!!!');
  536. this.payStatus = ''
  537. this.loading = false
  538. this.payStatus = 6
  539. }
  540. } catch (error) {
  541. this.$message.error('支付失败!!!');
  542. this.loading = false
  543. this.payStatus = 6
  544. }
  545. },
  546. /** 订单现金支付 */
  547. async gotoCashPayFun(orderId){
  548. this.loading = true
  549. try {
  550. this.loadingText = "订单支付中..."
  551. let res = await gotoCashPay({
  552. "orderId": orderId // 订单编号-提交订单返回
  553. })
  554. if(res.code == 200){
  555. if(this.payTime){
  556. clearInterval(this.payTime)
  557. }
  558. this.payTime = setInterval(()=>{
  559. this.payQueryFun(this.orderId)
  560. },1500)
  561. }else{
  562. this.$message.error('支付失败!!!');
  563. this.loading = false
  564. this.payStatus = 3
  565. }
  566. } catch (error) {
  567. this.$message.error('支付失败!!!');
  568. this.loading = false
  569. this.payStatus = 3
  570. }
  571. },
  572. /** 查看支付 状态 */
  573. async payQueryFun(orderId){
  574. this.loading = true
  575. try {
  576. this.loadingText = "订单支付中..."
  577. this.payStatus = ''
  578. let res = await payQuery({
  579. orderId: orderId
  580. })
  581. if(res.code == 200){
  582. if(res.data) {
  583. if(res.data.payStatus == 0) {
  584. if(this.payTime){
  585. clearInterval(this.payTime)
  586. }
  587. this.$message.error('用户未支付!!!');
  588. this.loading = false
  589. this.payStatus = 7
  590. }else if(res.data.payStatus == 1) {
  591. if(this.payTime){
  592. clearInterval(this.payTime)
  593. }
  594. this.$message('用户已支付!!!');
  595. // 开始 打印
  596. this.loading = false
  597. this.payStatus = 8
  598. this.getPrintListApi()
  599. }else if(res.data.payStatus == 2) {
  600. }else if(res.data.payStatus == 3) {
  601. if(this.payTime){
  602. clearInterval(this.payTime)
  603. }
  604. this.$message.error('用户支付失败!!!');
  605. this.loading = false
  606. this.payStatus = 7
  607. }else if(res.data.payStatus == 4) {
  608. if(this.payTime){
  609. clearInterval(this.payTime)
  610. }
  611. this.$message.error('支付退款!!!');
  612. this.loading = false
  613. this.payStatus = 7
  614. }
  615. }
  616. }else{
  617. this.$message.error('支付失败!!!');
  618. this.loading = false
  619. this.payStatus = 7
  620. }
  621. } catch (error) {
  622. this.$message.error('支付失败!!!');
  623. this.loading = false
  624. this.payStatus = 7
  625. }
  626. },
  627. /** 连接VBarServer */
  628. vbar_open() {
  629. this.loading = true
  630. this.loadingText = "连接扫码盒子中!!!"
  631. this.payStatus = null
  632. this.websocketClear()
  633. console.log('sdfdsfsd')
  634. if (!this.websocket_connected) {
  635. var host = "ws://localhost:2693";
  636. this.websocketCtrl = new WebSocket(host,'ctrl');
  637. this.websocketData = new WebSocket(host,'data');
  638. this.websocketData.onopen = (evt) => {
  639. console.log('sdasdasd====',evt)
  640. this.loading = false
  641. this.payStatus = 5
  642. this.websocket_connected = true;
  643. this.websocket_open_state(evt);
  644. }
  645. this.websocketData.onerror = (evt) => {
  646. console.log('sdasdasd11111====',evt)
  647. this.payStatus = 6
  648. //this.vbar_open()
  649. }
  650. this.websocketData.onmessage = (evt) => {
  651. console.log("接受消息====",evt)
  652. this.websocket_decode(evt.data);
  653. }
  654. }
  655. //setTimeout(this.vbar_open(), 3000);
  656. },
  657. /** 连接结果 */
  658. websocket_open_state(message){
  659. //document.getElementById('wsocket').value = "已连接";
  660. },
  661. //接收扫码结果处理
  662. websocket_decode(code){
  663. console.log()
  664. if(this.orderId && this.payStatus==5 &&code) {
  665. this.gotoMicroPayFun(this.orderId,code)
  666. }
  667. },
  668. /** 关闭通讯 */
  669. websocketClear(){
  670. if(this.websocketCtrl){
  671. this.websocketCtrl.close()
  672. }
  673. if(this.websocketData){
  674. this.websocketData.close()
  675. }
  676. this.websocket_connected = false
  677. },
  678. /** 读取身份证 */
  679. readCert(){
  680. this.idcardLoading = true
  681. var result = "";
  682. try {
  683. let xmlHttp = new XMLHttpRequest();
  684. let Protocol = window.location.protocol.split(':')[0];
  685. //获取当前协议,并且分割字符串,得到http或者https
  686. if (Protocol === 'https'){
  687. //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
  688. xmlHttp.open("POST", "http://127.0.0.1:18889/api/readCert?ReadSN=" + 0, false); //readCert读卡,生成正反面仿复印件
  689. }else {
  690. //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
  691. xmlHttp.open("POST", "http://127.0.0.1:18889/api/readCert?ReadSN=" + 0, false); //readCert读卡,生成正反面仿复印件
  692. }
  693. //发送请求
  694. xmlHttp.send();
  695. if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
  696. result = xmlHttp.responseText;
  697. xmlHttp.readyState = 1;
  698. }
  699. } catch (e) {
  700. console.error("e====",e)
  701. }
  702. let obj = JSON.parse(result)
  703. if(obj.resultContent && obj.resultContent.certNumber){
  704. this.$set(this.tableForm,"idcard",obj.resultContent.certNumber)
  705. this.$set(this.tableForm,"name",obj.resultContent.partyName)
  706. }else {
  707. this.$message.error('读取失败!!!');
  708. }
  709. this.idcardLoading = false
  710. //return result;
  711. console.log(result,obj)
  712. },
  713. /** 查询打印机列表 */
  714. getPrintListApi() {
  715. getPrintListApi({deviceType:5,pageNum: 1,
  716. pageSize: 999,})
  717. .then(response => {
  718. this.printList = response.data.rows;
  719. }).catch((error)=>{
  720. console.log("error===",error)
  721. }
  722. );
  723. },
  724. // 打印
  725. async print(list = []){
  726. if(!this.printListId) {
  727. this.$message.error('请选择打印机!!');
  728. return
  729. }
  730. this.loading = true
  731. this.loadingText = '打印中...'
  732. this.payStatus = ''
  733. try {
  734. let res = await printApi({
  735. orderId: this.orderId,
  736. source: 2,
  737. deviceId: this.printListId
  738. })
  739. if(res.code == 200) {
  740. let url = res.data.linkIp
  741. let printInfo = res.data.printInfo
  742. this.connectPrint(url,printInfo)
  743. }else {
  744. throw new Error(res)
  745. }
  746. } catch (error) {
  747. this.loading = false
  748. this.payStatus = 8
  749. console.error("error=====",error)
  750. }
  751. },
  752. /** 连接打印机 */
  753. connectPrint(url,data){
  754. // 创建忽略 SSL 的 axios 实例
  755. const ignoreSSL = axios.create({
  756. httpsAgent: new https.Agent({
  757. rejectUnauthorized: false
  758. }),
  759. withCredentials: true, // 跨域请求时发送Cookie
  760. timeout: 60000, // 请求超时
  761. headers: {
  762. "Content-Type": "application/json; charset=UTF-8;"
  763. }
  764. });
  765. ignoreSSL.post(url,
  766. { ...data }
  767. ).then(()=>{
  768. this.dialogVisible = false
  769. this.loading = false
  770. }).catch(()=>{
  771. this.loading = false
  772. this.payStatus = 8
  773. // this.dialogVisible = false
  774. // this.loading = false
  775. })
  776. // 在 axios 请求时,选择性忽略 SSL
  777. // const agent = new https.Agent({
  778. // rejectUnauthorized: false
  779. // });
  780. // axios.post(
  781. // url,
  782. // { httpsAgent: agent,...data }
  783. // ).then(()=>{
  784. // this.dialogVisible = false
  785. // this.loading = false
  786. // })
  787. // .catch(()=>{
  788. // this.dialogVisible = false
  789. // this.loading = false
  790. // })
  791. },
  792. }
  793. }
  794. </script>
  795. <style scoped lang="scss">
  796. .increase-viewers-box {
  797. width: 100%;
  798. height: calc( 100vh - 250px );
  799. box-sizing: border-box;
  800. overflow: hidden;
  801. overflow-y: auto;
  802. position: relative;
  803. }
  804. .increase-viewers-pay-status {
  805. width: 100%;
  806. height: 100%;
  807. position: absolute;
  808. z-index: 999999;
  809. background-color: rgba(0,0,0,0.3);
  810. top: 0;
  811. left: 0;
  812. .increase-viewers-pay-status-info {
  813. width: 100%;
  814. height: 100%;
  815. display: flex;
  816. flex-direction: column;
  817. justify-content: center;
  818. align-items: center;
  819. color: #fff;
  820. }
  821. }
  822. </style>