index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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. </el-dialog>
  97. </div>
  98. </template>
  99. <script>
  100. import { getLodop } from '@/utils/lodopUtils'
  101. import { getClothItem, listOrderClothItem } from '@/api/order/clothItem'
  102. import { getMemberInfoById } from '@/api/app/user'
  103. import { clothOrderPay, getOrderPayResult } from '@/api/order/cloth'
  104. export default {
  105. props: {
  106. hidePointer: {
  107. type: Boolean,
  108. default: false
  109. },
  110. hideUser: {
  111. type: Boolean,
  112. default: false
  113. }
  114. },
  115. data() {
  116. return {
  117. show: false,
  118. type: 1,
  119. orderInfo: {},
  120. number: 1,
  121. // 打印机设置
  122. LODOP: null,
  123. pointerList: [],
  124. // 打印收衣订单的数据
  125. pointerInfo: null,
  126. payType: 3,
  127. appUserInfo: {},
  128. authCode: '',
  129. time: '',
  130. showPaySuccessBtn: false,
  131. resultCount: 0,
  132. errorMessage: ''
  133. }
  134. },
  135. mounted() {
  136. this.number = 1
  137. const printerTime = setInterval(() => {
  138. this.LODOP = getLodop()
  139. this.number++
  140. if (this.number == 25) {
  141. clearInterval(printerTime)
  142. }
  143. if (this.LODOP) {
  144. clearInterval(printerTime)
  145. }
  146. }, 200)
  147. this.pointerList = JSON.parse(this.$cache.local.get('printerSeting'))
  148. },
  149. methods: {
  150. open(type, info, appUserInfo = null) {
  151. this.orderInfo = info
  152. this.type = type
  153. if (type == 1) {
  154. if (info.id && !this.hidePointer) {
  155. this.getClothItemInfo(info)
  156. }
  157. }
  158. if (type == 2) {
  159. this.appUserInfo = {}
  160. this.authCode = ''
  161. this.showPaySuccessBtn = false
  162. if (this.hideUser) {
  163. this.payType = 2
  164. } else {
  165. this.payType = 3
  166. this.getUserInfo(info.appUserId)
  167. }
  168. }
  169. if (type == 3) {
  170. this.payType = info.payType
  171. this.authCode = info.authCode
  172. this.showPaySuccessBtn = false
  173. console.log(appUserInfo)
  174. if (appUserInfo.id) {
  175. this.appUserInfo = appUserInfo
  176. }
  177. console.log('aasss', this.appUserInfo)
  178. this.pay()
  179. }
  180. if (type == 4) {
  181. this.errorMessage = info.payMsg
  182. }
  183. if (type == 5) {
  184. // this.getPayResult()
  185. }
  186. this.show = true
  187. },
  188. close() {
  189. const _ = this
  190. if (this.type == 1) {
  191. this.$confirm('是否关闭打印操作?')
  192. .then(() => {
  193. _.show = false
  194. })
  195. .catch(() => {})
  196. }
  197. if (this.type == 2) {
  198. this.$confirm('是否取消支付操作?')
  199. .then(() => {
  200. _.show = false
  201. })
  202. .catch(() => {})
  203. }
  204. if (this.type == 3 || this.type == 5) {
  205. this.$confirm('请确认客户已完成付款再关闭?')
  206. .then(() => {
  207. _.show = false
  208. _.clearTimeOut(_.time)
  209. _.$emit('paySuccess')
  210. })
  211. .catch(() => {})
  212. }
  213. if (this.type == 4) {
  214. _.show = false
  215. }
  216. },
  217. confirm() {
  218. this.show = false
  219. this.$emit('confirm', this.orderInfo)
  220. },
  221. setPointer(type) {
  222. if (!this.LODOP) {
  223. this.$modal.msgError('请安装打印机软件')
  224. return
  225. }
  226. let p_name = ''
  227. this.pointerList.forEach((pointer) => {
  228. if (pointer.printType == type) {
  229. p_name = pointer.printName
  230. }
  231. })
  232. if (type == 0) {
  233. this.collectClothPrinter(this.LODOP, this.pointerInfo, p_name)
  234. } else {
  235. this.barCodePrinter(this.LODOP, this.pointerInfo, p_name)
  236. }
  237. this.show = false
  238. },
  239. // 获取打印数据
  240. getClothItemInfo(data) {
  241. getClothItem(data.id).then((res) => {
  242. if (res) {
  243. this.pointerInfo = res.data
  244. listOrderClothItem({ pageSize: 99999, pageNum: 1, orderNo: data.orderNo }).then((res) => {
  245. this.pointerInfo.orderClothDetails = res.data.records
  246. })
  247. }
  248. })
  249. },
  250. // 获取用户信息
  251. getUserInfo(id) {
  252. getMemberInfoById({
  253. appUserId: id
  254. }).then((response) => {
  255. this.appUserInfo = response.data
  256. })
  257. },
  258. changePayType() {
  259. if (this.payType == 0) {
  260. this.$nextTick((_) => {
  261. this.$refs.autoFocus.focus()
  262. })
  263. }
  264. },
  265. handleQuery(e, event) {
  266. console.log(event)
  267. console.log(this.authCode)
  268. },
  269. pay() {
  270. if (this.payType == 0 && !this.authCode) {
  271. this.type = 4
  272. this.errorMessage = '请先扫码'
  273. this.authCode = ''
  274. this.changePayType()
  275. return
  276. }
  277. if (this.payType == 3 && this.appUserInfo.rechargeBalance + this.appUserInfo.giveBalance < this.orderInfo.payAmount) {
  278. this.errorMessage = '余额不足'
  279. this.type = 4
  280. this.authCode = ''
  281. this.changePayType()
  282. return
  283. }
  284. this.type = 3
  285. clothOrderPay({
  286. appUserId: this.orderInfo.appUserId,
  287. payType: this.payType,
  288. authCode: this.authCode,
  289. orderNo: this.orderInfo.orderNo,
  290. payAmount: this.orderInfo.payAmount
  291. })
  292. .then((res) => {
  293. console.log('支付结果', res)
  294. if (res) {
  295. if (res.data.payResult == 100) {
  296. this.getPayResult()
  297. }
  298. if (res.data.payResult == 101 || res.data.payResult == 0) {
  299. this.errorMessage = res.data.payMsg
  300. this.type = 4
  301. this.authCode = ''
  302. this.changePayType()
  303. }
  304. if (res.data.payResult == 200) {
  305. this.type = 1
  306. this.$emit('paySuccess')
  307. }
  308. }
  309. })
  310. .catch((e) => {
  311. this.type = 4
  312. this.authCode = ''
  313. this.changePayType()
  314. this.errorMessage = e.data.msg
  315. // this.$message.error(e.data.msg)
  316. })
  317. },
  318. getPayResult() {
  319. getOrderPayResult({
  320. orderNo: this.orderInfo.orderNo
  321. })
  322. .then((res) => {
  323. console.log('支付结果1', res)
  324. if (res) {
  325. if (res.data.payResult == 100) {
  326. this.time = setTimeout(() => {
  327. if (this.resultCount == 6) {
  328. this.showPaySuccessBtn = true
  329. } else {
  330. this.resultCount++
  331. }
  332. this.getPayResult()
  333. }, 5000)
  334. }
  335. if (res.data.payResult == 101 || res.data.payResult == 0) {
  336. this.errorMessage = res.data.payMsg
  337. this.type = 4
  338. this.authCode = ''
  339. this.changePayType()
  340. }
  341. if (res.data.payResult == 200) {
  342. this.type = 1
  343. this.$emit('paySuccess')
  344. }
  345. }
  346. })
  347. .catch((e) => {
  348. this.type = 4
  349. this.authCode = ''
  350. this.errorMessage = e.data.msg
  351. })
  352. }
  353. }
  354. }
  355. </script>
  356. <style>
  357. .payStatusPopup .el-dialog__body {
  358. padding: 0;
  359. }
  360. </style>
  361. <style scoped lang="scss">
  362. .icon {
  363. font-size: 100px;
  364. text-align: center;
  365. .success {
  366. color: #67c23a;
  367. }
  368. .warning {
  369. color: #e6a23c;
  370. }
  371. .loading {
  372. color: #e4e7ed;
  373. }
  374. .error {
  375. color: #f56c6c;
  376. }
  377. }
  378. .btn_box {
  379. display: flex;
  380. align-items: center;
  381. margin-top: 20px;
  382. font-size: 16px;
  383. font-weight: 500;
  384. border-top: 1px solid #ebeef5;
  385. .btn {
  386. flex: 1;
  387. text-align: center;
  388. line-height: 60px;
  389. cursor: pointer;
  390. }
  391. .line {
  392. width: 1px;
  393. height: 60px;
  394. background: #ebeef5;
  395. }
  396. }
  397. .del_btn {
  398. position: absolute;
  399. top: 20px;
  400. right: 20px;
  401. font-size: 20px;
  402. cursor: pointer;
  403. }
  404. .cell {
  405. display: flex;
  406. align-items: center;
  407. padding: 0 40px 20px;
  408. .label {
  409. margin-right: 20px;
  410. min-width: 80px;
  411. }
  412. }
  413. .amount_box {
  414. span {
  415. color: #f56c6c;
  416. font-weight: bold;
  417. font-size: 20px;
  418. &:first-child {
  419. font-size: 16px;
  420. }
  421. }
  422. }
  423. .message {
  424. font-size: 20px;
  425. text-align: center;
  426. padding: 10px 0 20px;
  427. color: #606266;
  428. }
  429. </style>