index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <template>
  2. <div class="payStatusPopup">
  3. <el-dialog :visible.sync="show" width="30%" :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false">
  4. <!-- 支付成功打印小票 -->
  5. <div v-if="type === 1">
  6. <div class="icon">
  7. <i class="el-icon-success success"></i>
  8. </div>
  9. <div class="message">支付成功</div>
  10. <div class="btn_box" v-if="hidePointer">
  11. <div class="btn" @click="confirm">确认</div>
  12. </div>
  13. <div class="btn_box" v-else>
  14. <div class="btn" @click="setPointer(0)">打印小票</div>
  15. <div class="line"></div>
  16. <div class="btn" @click="setPointer(1)">打印条码</div>
  17. <div class="line"></div>
  18. <div class="btn" @click="close">关闭</div>
  19. </div>
  20. </div>
  21. <!-- 未支付 -->
  22. <div v-if="type === 2">
  23. <div class="icon">
  24. <i class="el-icon-warning warning"></i>
  25. </div>
  26. <div class="message">请支付后取衣</div>
  27. <div class="cell">
  28. <div class="label">需支付金额</div>
  29. <div class="amount_box">
  30. <span>¥</span>
  31. <span>{{ orderInfo.payAmount }}</span>
  32. </div>
  33. </div>
  34. <div class="cell">
  35. <div class="label">支付方式</div>
  36. <el-radio-group v-model="payType" @input="changePayType">
  37. <el-radio-button :label="3">余额</el-radio-button>
  38. <el-radio-button :label="2">现金</el-radio-button>
  39. <el-radio-button :label="0">微信/支付宝</el-radio-button>
  40. </el-radio-group>
  41. </div>
  42. <el-descriptions border direction="vertical" :column="3" :labelStyle="{ width: '140px' }" v-if="payType == '3'" style="margin: 0 30px">
  43. <el-descriptions-item label="用户" v-if="appUserInfo">{{ appUserInfo.realName }}</el-descriptions-item>
  44. <el-descriptions-item label="当前余额(元)" v-if="appUserInfo">{{ appUserInfo.rechargeBalance + appUserInfo.giveBalance }}</el-descriptions-item>
  45. <el-descriptions-item label="支付后余额(元)" v-if="appUserInfo">{{ appUserInfo.rechargeBalance + appUserInfo.giveBalance - orderInfo.payAmount }}</el-descriptions-item>
  46. </el-descriptions>
  47. <div class="cell" v-if="payType == 0">
  48. <div class="label">付款码</div>
  49. <!-- @change="handleQuery" -->
  50. <el-input ref="autoFocus" v-model="authCode" clearable placeholder="请选择付款码" />
  51. </div>
  52. <div class="btn_box">
  53. <div class="btn" style="color: #67c23a" @click="pay">确认支付</div>
  54. <div class="line"></div>
  55. <div class="btn" @click="close">关闭</div>
  56. </div>
  57. </div>
  58. <!-- 支付中,请等待 -->
  59. <div v-if="type == 3 || type == 5">
  60. <div class="icon">
  61. <i class="el-icon-loading loading"></i>
  62. </div>
  63. <div class="message">支付确认中,请等待...</div>
  64. <el-button type="primary" style="width: 70%; height: 40px; margin: 20px 15%" @click="close" v-if="showPaySuccessBtn">已确认支付</el-button>
  65. </div>
  66. <!-- 支付失败 -->
  67. <div v-if="type == 4">
  68. <div class="icon">
  69. <i class="el-icon-error error"></i>
  70. </div>
  71. <div class="message">{{ errorMessage }}</div>
  72. <div class="cell" v-if="!hideUser">
  73. <div class="label">支付方式</div>
  74. <el-radio-group v-model="payType" @input="changePayType">
  75. <el-radio-button :label="3">余额</el-radio-button>
  76. <el-radio-button :label="2">现金</el-radio-button>
  77. <el-radio-button :label="0">微信/支付宝</el-radio-button>
  78. </el-radio-group>
  79. </div>
  80. <el-descriptions border direction="vertical" :column="3" :labelStyle="{ width: '140px' }" v-if="payType == '3' && !hideUser" style="margin: 0 30px">
  81. <el-descriptions-item label="用户" v-if="appUserInfo">{{ appUserInfo.realName }}</el-descriptions-item>
  82. <el-descriptions-item label="当前余额(元)" v-if="appUserInfo">{{ appUserInfo.rechargeBalance + appUserInfo.giveBalance }}</el-descriptions-item>
  83. <el-descriptions-item label="支付后余额(元)" v-if="appUserInfo">{{ appUserInfo.rechargeBalance + appUserInfo.giveBalance - orderInfo.payAmount }}</el-descriptions-item>
  84. </el-descriptions>
  85. <div class="cell" v-if="payType == 0 && !hideUser">
  86. <div class="label">付款码</div>
  87. <!-- @change="handleQuery" -->
  88. <el-input ref="autoFocus" v-model="authCode" clearable placeholder="请选择付款码" />
  89. </div>
  90. <div class="btn_box">
  91. <div class="btn" style="color: #67c23a" @click="pay" v-if="!hideUser">确认支付</div>
  92. <div class="line" v-if="!hideUser"></div>
  93. <div class="btn" @click="close">关闭</div>
  94. </div>
  95. </div>
  96. <!-- 支付成功打印小票 -->
  97. <div v-if="type === 6">
  98. <div class="icon">
  99. <i class="el-icon-success success"></i>
  100. </div>
  101. <div class="message">定价成功</div>
  102. <div class="btn_box">
  103. <div class="btn" @click="confirm">确认</div>
  104. </div>
  105. </div>
  106. </el-dialog>
  107. </div>
  108. </template>
  109. <script>
  110. import { getLodop } from '@/utils/lodopUtils'
  111. import { getClothItem, listOrderClothItem } from '@/api/order/clothItem'
  112. import { getMemberInfoById } from '@/api/app/user'
  113. import { clothOrderPay, getOrderPayResult } from '@/api/order/cloth'
  114. export default {
  115. props: {
  116. hidePointer: {
  117. type: Boolean,
  118. default: false
  119. },
  120. hideUser: {
  121. type: Boolean,
  122. default: false
  123. }
  124. },
  125. data() {
  126. return {
  127. show: false,
  128. type: 1,
  129. orderInfo: {},
  130. number: 1,
  131. // 打印机设置
  132. LODOP: null,
  133. pointerList: [],
  134. // 打印收衣订单的数据
  135. pointerInfo: null,
  136. payType: 3,
  137. appUserInfo: {},
  138. authCode: '',
  139. time: '',
  140. showPaySuccessBtn: false,
  141. resultCount: 0,
  142. errorMessage: ''
  143. }
  144. },
  145. mounted() {
  146. this.number = 1
  147. const printerTime = setInterval(() => {
  148. this.LODOP = getLodop()
  149. this.number++
  150. if (this.number == 25) {
  151. clearInterval(printerTime)
  152. }
  153. if (this.LODOP) {
  154. clearInterval(printerTime)
  155. }
  156. }, 200)
  157. this.pointerList = JSON.parse(this.$cache.local.get('printerSeting'))
  158. },
  159. methods: {
  160. open(type, info, appUserInfo = null) {
  161. this.orderInfo = info
  162. this.type = type
  163. if (type == 1) {
  164. if (info.id && !this.hidePointer) {
  165. this.getClothItemInfo(info)
  166. }
  167. }
  168. if (type == 2) {
  169. this.appUserInfo = {}
  170. this.authCode = ''
  171. this.showPaySuccessBtn = false
  172. if (this.hideUser) {
  173. this.payType = 2
  174. } else {
  175. this.payType = 3
  176. this.getUserInfo(info.appUserId)
  177. }
  178. }
  179. if (type == 3) {
  180. this.payType = info.payType
  181. this.authCode = info.authCode
  182. this.showPaySuccessBtn = false
  183. console.log(appUserInfo)
  184. if (appUserInfo.id) {
  185. this.appUserInfo = appUserInfo
  186. }
  187. console.log('aasss', this.appUserInfo)
  188. this.pay()
  189. }
  190. if (type == 4) {
  191. this.errorMessage = info.payMsg
  192. }
  193. if (type == 5) {
  194. // this.getPayResult()
  195. }
  196. if (type == 6) {
  197. }
  198. this.show = true
  199. },
  200. close() {
  201. const _ = this
  202. if (this.type == 1) {
  203. this.$confirm('是否关闭打印操作?')
  204. .then(() => {
  205. _.show = false
  206. })
  207. .catch(() => {})
  208. }
  209. if (this.type == 2) {
  210. this.$confirm('是否取消支付操作?')
  211. .then(() => {
  212. _.show = false
  213. })
  214. .catch(() => {})
  215. }
  216. if (this.type == 3 || this.type == 5) {
  217. this.$confirm('请确认客户已完成付款再关闭?')
  218. .then(() => {
  219. _.show = false
  220. _.clearTimeOut(_.time)
  221. _.$emit('paySuccess')
  222. })
  223. .catch(() => {})
  224. }
  225. if (this.type == 4) {
  226. _.show = false
  227. }
  228. if (this.type == 6) {
  229. _.show = false
  230. }
  231. },
  232. confirm() {
  233. this.show = false
  234. this.$emit('confirm', this.orderInfo)
  235. },
  236. setPointer(type) {
  237. if (!this.LODOP) {
  238. this.$modal.msgError('请安装打印机软件')
  239. return
  240. }
  241. let p_name = ''
  242. this.pointerList.forEach((pointer) => {
  243. if (pointer.printType == type) {
  244. p_name = pointer.printName
  245. }
  246. })
  247. if (type == 0) {
  248. this.collectClothPrinter(this.LODOP, this.pointerInfo, p_name)
  249. } else {
  250. this.barCodePrinter(this.LODOP, this.pointerInfo, p_name)
  251. }
  252. this.show = false
  253. },
  254. // 获取打印数据
  255. getClothItemInfo(data) {
  256. getClothItem(data.id).then((res) => {
  257. if (res) {
  258. this.pointerInfo = res.data
  259. listOrderClothItem({ pageSize: 99999, pageNum: 1, orderNo: data.orderNo }).then((res) => {
  260. this.pointerInfo.orderClothDetails = res.data.records
  261. })
  262. }
  263. })
  264. },
  265. // 获取用户信息
  266. getUserInfo(id) {
  267. getMemberInfoById({
  268. appUserId: id
  269. }).then((response) => {
  270. this.appUserInfo = response.data
  271. })
  272. },
  273. changePayType() {
  274. if (this.payType == 0) {
  275. this.$nextTick((_) => {
  276. this.$refs.autoFocus.focus()
  277. })
  278. }
  279. },
  280. handleQuery(e, event) {
  281. console.log(event)
  282. console.log(this.authCode)
  283. },
  284. pay() {
  285. if (this.payType == 0 && !this.authCode) {
  286. this.type = 4
  287. this.errorMessage = '请先扫码'
  288. this.authCode = ''
  289. this.changePayType()
  290. return
  291. }
  292. if (this.payType == 3 && this.appUserInfo.rechargeBalance + this.appUserInfo.giveBalance < this.orderInfo.payAmount) {
  293. this.errorMessage = '余额不足'
  294. this.type = 4
  295. this.authCode = ''
  296. this.changePayType()
  297. return
  298. }
  299. this.type = 3
  300. clothOrderPay({
  301. appUserId: this.orderInfo.appUserId,
  302. payType: this.payType,
  303. authCode: this.authCode,
  304. orderNo: this.orderInfo.orderNo,
  305. payAmount: this.orderInfo.payAmount
  306. })
  307. .then((res) => {
  308. console.log('支付结果', res)
  309. if (res) {
  310. if (res.data.payResult == 100) {
  311. this.getPayResult()
  312. }
  313. if (res.data.payResult == 101 || res.data.payResult == 0) {
  314. this.errorMessage = res.data.payMsg
  315. this.type = 4
  316. this.authCode = ''
  317. this.changePayType()
  318. }
  319. if (res.data.payResult == 200) {
  320. this.type = 1
  321. this.$emit('paySuccess')
  322. }
  323. }
  324. })
  325. .catch((e) => {
  326. this.type = 4
  327. this.authCode = ''
  328. this.changePayType()
  329. this.errorMessage = e.data.msg
  330. // this.$message.error(e.data.msg)
  331. })
  332. },
  333. getPayResult() {
  334. getOrderPayResult({
  335. orderNo: this.orderInfo.orderNo
  336. })
  337. .then((res) => {
  338. console.log('支付结果1', res)
  339. if (res) {
  340. if (res.data.payResult == 100) {
  341. this.time = setTimeout(() => {
  342. if (this.resultCount == 6) {
  343. this.showPaySuccessBtn = true
  344. } else {
  345. this.resultCount++
  346. }
  347. this.getPayResult()
  348. }, 5000)
  349. }
  350. if (res.data.payResult == 101 || res.data.payResult == 0) {
  351. this.errorMessage = res.data.payMsg
  352. this.type = 4
  353. this.authCode = ''
  354. this.changePayType()
  355. }
  356. if (res.data.payResult == 200) {
  357. this.type = 1
  358. this.$emit('paySuccess')
  359. }
  360. }
  361. })
  362. .catch((e) => {
  363. this.type = 4
  364. this.authCode = ''
  365. this.errorMessage = e.data.msg
  366. })
  367. }
  368. }
  369. }
  370. </script>
  371. <style>
  372. .payStatusPopup .el-dialog__body {
  373. padding: 0;
  374. }
  375. </style>
  376. <style scoped lang="scss">
  377. .icon {
  378. font-size: 100px;
  379. text-align: center;
  380. .success {
  381. color: #67c23a;
  382. }
  383. .warning {
  384. color: #e6a23c;
  385. }
  386. .loading {
  387. color: #e4e7ed;
  388. }
  389. .error {
  390. color: #f56c6c;
  391. }
  392. }
  393. .btn_box {
  394. display: flex;
  395. align-items: center;
  396. margin-top: 20px;
  397. font-size: 16px;
  398. font-weight: 500;
  399. border-top: 1px solid #ebeef5;
  400. .btn {
  401. flex: 1;
  402. text-align: center;
  403. line-height: 60px;
  404. cursor: pointer;
  405. }
  406. .line {
  407. width: 1px;
  408. height: 60px;
  409. background: #ebeef5;
  410. }
  411. }
  412. .del_btn {
  413. position: absolute;
  414. top: 20px;
  415. right: 20px;
  416. font-size: 20px;
  417. cursor: pointer;
  418. }
  419. .cell {
  420. display: flex;
  421. align-items: center;
  422. padding: 0 40px 20px;
  423. .label {
  424. margin-right: 20px;
  425. min-width: 80px;
  426. }
  427. }
  428. .amount_box {
  429. span {
  430. color: #f56c6c;
  431. font-weight: bold;
  432. font-size: 20px;
  433. &:first-child {
  434. font-size: 16px;
  435. }
  436. }
  437. }
  438. .message {
  439. font-size: 20px;
  440. text-align: center;
  441. padding: 10px 0 20px;
  442. color: #606266;
  443. }
  444. </style>