openMember.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <template>
  2. <view class="content">
  3. <view class="card-list">
  4. <view class="card-label">{{memberInfo.typeValue}}</view>
  5. <view class="card-num">¥{{memberInfo.originalAmount}}</view>
  6. <view class="card-icon iconfont iconzu4931"></view>
  7. </view>
  8. <u-cell-group style="width: 100%; float: left;">
  9. <u-cell-item title="使用时间" :value="memberInfo.startDate + '~' + memberInfo.endDate" :arrow="false"></u-cell-item>
  10. <u-cell-item title="优惠金额" :value="couponId ? '-¥' + memberInfo.discountsAmount : ''" @click="couponShow = true"></u-cell-item>
  11. <u-cell-item title="学员姓名" :value="studentName" @click="studentShow = true" required></u-cell-item>
  12. <u-cell-item title="实际金额" :value="'¥' + memberInfo.realPayAmount" :arrow="false"></u-cell-item>
  13. <u-cell-item title="乙方签字" :arrow="false" :title-style="{width: '100%'}" required>
  14. <view class="canvas-container" slot="label">
  15. <canvas canvas-id="canvas" id="canvas" :disable-scroll="true" style="width: 100%; height: 200px;background-color: #FFFFFF;"
  16. @touchstart="handleTouchStart($event)" @touchmove="handleTouchMove($event)" @touchend="handleTouchEnd($event)"
  17. @touchcancel="handleEnd($event)"></canvas>
  18. </view>
  19. </u-cell-item>
  20. </u-cell-group>
  21. <u-popup v-model="couponShow" mode="bottom" border-radius="30" closeable>
  22. <scroll-view scroll-y style="height:300px;margin: 30px 0 15px 0;">
  23. <u-card :show-head="false" :show-foot="false" padding="0px" margin="0px 30px 20px 30px" borderRadius="40" v-for="(item, index) in couponList"
  24. :key="index" class="class-card" @click="selectCoupon(item)">
  25. <view class="class-content" slot="body">
  26. <view class="class-info-img">
  27. <u-image width="60px" height="60px" :src="item.url" shape="circle"></u-image>
  28. </view>
  29. <view class="class-info-content">
  30. <view class="class-info-label">{{item.name}}¥{{item.amount}}</view>
  31. <view class="class-info-text">{{item.typeValue}}&nbsp;&nbsp;{{item.content}}</view>
  32. <view class="class-info-text">{{item.endDate}}&nbsp;&nbsp;到期</view>
  33. </view>
  34. </view>
  35. </u-card>
  36. </scroll-view>
  37. </u-popup>
  38. <view class="handle-fix-box">
  39. <text class="contract-link" @click="checkContract()">点击查看合同协议</text>
  40. <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="submitContract()">确定支付¥{{memberInfo.realPayAmount}}</u-button>
  41. </view>
  42. <u-popup v-model="studentShow" mode="bottom" border-radius="30">
  43. <scroll-view scroll-y class="student-box">
  44. <u-card :title="item.studentName" title-size="32" :head-style="cardStyle" :head-border-bottom="false" :show-foot="false"
  45. margin="10px" borderRadius="20" v-for="(item, index) in studentList" :key="index" @click="selectStudent(item)">
  46. <view class="student-card" slot="body">
  47. <view class="class-info-text">性别:{{item.sex}}&nbsp;&nbsp;年龄:{{item.age}}</view>
  48. </view>
  49. </u-card>
  50. </scroll-view>
  51. <u-button type="warning" shape="circle" :ripple="true" :custom-style="{...customStyle,margin:'15px'}" @click="goToSubscribelForm()">新增学员</u-button>
  52. </u-popup>
  53. <u-top-tips ref="uTips"></u-top-tips>
  54. </view>
  55. </template>
  56. <script>
  57. var context = null
  58. import {
  59. mapGetters
  60. } from 'vuex'
  61. const NET = require('@/utils/request')
  62. const API = require('@/config/api')
  63. export default {
  64. computed: {
  65. ...mapGetters([
  66. 'mainColor',
  67. 'customStyle',
  68. ])
  69. },
  70. data() {
  71. return {
  72. memberCardId: '',
  73. memberInfo: {
  74. originalAmount: '',
  75. discountsAmount: '',
  76. realPayAmount: '',
  77. typeValue: '',
  78. endDate: '',
  79. startDate: '',
  80. },
  81. couponId: '',
  82. couponShow: false,
  83. couponList: [],
  84. cardStyle: {
  85. fontWeight: 'bold'
  86. },
  87. studentId: '',
  88. studentName: '',
  89. studentShow: false,
  90. studentList: [],
  91. contractInfo: {
  92. id: '',
  93. url: '',
  94. },
  95. canvasData: [],
  96. signUrl: ''
  97. }
  98. },
  99. watch: {
  100. canvasData() {
  101. context.moveTo(this.canvasData[0].x, this.canvasData[0].y)
  102. for (let i = 0; i < this.canvasData.length; i++) {
  103. context.lineTo(this.canvasData[i].x, this.canvasData[i].y)
  104. }
  105. context.stroke()
  106. context.draw(true)
  107. }
  108. },
  109. onLoad(options) {
  110. this.memberCardId = options.id
  111. this.getMemberInfo()
  112. context = uni.createCanvasContext('canvas')
  113. context.setLineWidth(3)
  114. context.setStrokeStyle("#000000")
  115. this.reset()
  116. },
  117. onShow() {
  118. NET.request(API.getAllStudentList, {}, 'POST').then(res => {
  119. this.studentList = res.data
  120. }).catch(error => {
  121. this.$refs.uTips.show({
  122. title: error.message,
  123. type: 'warning',
  124. })
  125. })
  126. },
  127. methods: {
  128. // 获取数据
  129. getMemberInfo() {
  130. NET.request(API.getMemberCardInfo, {
  131. id: this.memberCardId
  132. }, 'POST').then(res => {
  133. this.memberInfo = res.data
  134. }).catch(error => {
  135. this.$refs.uTips.show({
  136. title: error.message,
  137. type: 'warning',
  138. })
  139. })
  140. NET.request(API.getUsableCouponList, {
  141. id: this.memberCardId
  142. }, 'POST').then(res => {
  143. this.couponList = res.data.row
  144. }).catch(error => {
  145. this.$refs.uTips.show({
  146. title: error.message,
  147. type: 'warning',
  148. })
  149. })
  150. NET.request(API.getContractInfo, {
  151. cardId: this.memberCardId
  152. }, 'POST').then(res => {
  153. this.contractInfo = res.data
  154. }).catch(error => {
  155. this.$refs.uTips.show({
  156. title: error.message,
  157. type: 'warning',
  158. })
  159. })
  160. },
  161. // 更新数据
  162. refreshMemberInfo() {
  163. NET.request(API.getMemberCardInfoAfterCoupon, {
  164. memberId: this.memberCardId,
  165. couponId: this.couponId,
  166. studentId: this.studentId
  167. }, 'POST').then(res => {
  168. this.memberInfo = res.data
  169. this.couponShow = false
  170. this.studentShow = false
  171. }).catch(error => {
  172. this.$refs.uTips.show({
  173. title: error.message,
  174. type: 'warning',
  175. })
  176. })
  177. },
  178. // 选择优惠券
  179. selectCoupon(item) {
  180. this.couponId = item.id
  181. this.refreshMemberInfo()
  182. },
  183. // 选择学员
  184. selectStudent(item) {
  185. this.studentId = item.studentId
  186. this.studentName = item.studentName
  187. this.refreshMemberInfo()
  188. },
  189. // 显示合同
  190. checkContract() {
  191. uni.downloadFile({
  192. url: this.contractInfo.url,
  193. success: (res) => {
  194. uni.openDocument({
  195. filePath: res.tempFilePath,
  196. });
  197. }
  198. })
  199. },
  200. // 重置
  201. reset() {
  202. context.draw()
  203. },
  204. // 签字版触屏开始
  205. handleTouchStart(e) {
  206. this.canvasData = []
  207. const a = e.changedTouches[0]
  208. this.canvasData.push({
  209. x: a.x,
  210. y: a.y
  211. })
  212. },
  213. // 签字版触屏移动
  214. handleTouchMove(e) {
  215. const a = e.changedTouches[0]
  216. this.canvasData.push({
  217. x: a.x,
  218. y: a.y
  219. })
  220. },
  221. // 签字版触屏结束
  222. handleTouchEnd(e) {
  223. const a = e.changedTouches[0]
  224. this.canvasData.push({
  225. x: a.x,
  226. y: a.y
  227. })
  228. },
  229. handleEnd() {
  230. context.stroke()
  231. context.draw(true)
  232. },
  233. // 提交签字
  234. submitContract() {
  235. if (!this.studentId) {
  236. this.$refs.uTips.show({
  237. title: '请选择学员',
  238. type: 'warning',
  239. })
  240. return
  241. }
  242. let that = this
  243. uni.canvasToTempFilePath({
  244. canvasId: 'canvas',
  245. success: res => {
  246. uni.uploadFile({
  247. url: API.uploadFile,
  248. filePath: res.tempFilePath,
  249. name: 'file',
  250. header: {
  251. Authorization: uni.getStorageSync('token')
  252. },
  253. success: (uploadFileRes) => {
  254. that.signUrl = JSON.parse(uploadFileRes.data).data.id
  255. NET.request(API.submitContractForm, {
  256. contractId: that.contractInfo.id,
  257. fileId: that.signUrl,
  258. }, 'POST').then(res => {
  259. that.toPay(res.data.id)
  260. }).catch(error => {
  261. that.$refs.uTips.show({
  262. title: error.message,
  263. type: 'warning',
  264. })
  265. })
  266. }
  267. });
  268. }
  269. })
  270. },
  271. // 支付
  272. toPay(contractId) {
  273. NET.request(API.getPayParams, {
  274. id: this.memberCardId,
  275. couponId: this.couponId,
  276. studentId: this.studentId,
  277. contractId: contractId
  278. }, 'POST').then(res => {
  279. if (this.memberInfo.realPayAmount <= 0) {
  280. this.goToPayResult(res.data.oderNo)
  281. return false
  282. }
  283. uni.requestPayment({
  284. provider: 'wxpay',
  285. timeStamp: res.data.timeStamp,
  286. nonceStr: res.data.nonceStr,
  287. package: res.data.packageString,
  288. signType: res.data.signType,
  289. paySign: res.data.paySign,
  290. success: (payRes) => {
  291. this.goToPayResult(res.data.oderNo)
  292. },
  293. fail: (error) => {
  294. this.$refs.uTips.show({
  295. title: '支付未成功',
  296. type: 'warning',
  297. })
  298. }
  299. })
  300. }).catch(error => {
  301. this.$refs.uTips.show({
  302. title: error.message,
  303. type: 'warning',
  304. })
  305. })
  306. // uni.navigateTo({
  307. // url: '/pagesMain/contractInfo?memberCardId=' + this.memberCardId + '&couponId=' + this.couponId + '&studentId=' +
  308. // this.studentId
  309. // });
  310. },
  311. // 跳转支付结果
  312. goToPayResult(oderNo) {
  313. uni.redirectTo({
  314. url: '/pagesMain/payResult?id=' + oderNo
  315. });
  316. }
  317. },
  318. }
  319. </script>
  320. <style>
  321. page {
  322. width: 100%;
  323. height: 100%;
  324. }
  325. </style>
  326. <style lang="scss" scoped>
  327. @import "@/static/css/themes.scss";
  328. .content {
  329. width: 100%;
  330. float: left;
  331. padding: 15px 15px 85px 15px;
  332. box-sizing: border-box;
  333. .card-list {
  334. width: 100%;
  335. padding: 15px 20px;
  336. margin-bottom: 15px;
  337. float: left;
  338. background-color: #FFFFFF;
  339. border-radius: 15px;
  340. box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.2);
  341. position: relative;
  342. overflow: hidden;
  343. .card-label {
  344. width: 100%;
  345. margin-bottom: 10px;
  346. float: left;
  347. font-size: 18px;
  348. font-weight: bold;
  349. line-height: 20px;
  350. }
  351. .card-num {
  352. width: 100%;
  353. float: left;
  354. font-size: 28px;
  355. line-height: 28px;
  356. color: $mainColor;
  357. }
  358. .card-icon {
  359. font-size: 80px;
  360. color: $mainColor;
  361. position: absolute;
  362. right: -15px;
  363. bottom: -15x;
  364. opacity: 0.5;
  365. }
  366. }
  367. .class-card {
  368. .class-content {
  369. padding: 10px 15px;
  370. display: flex;
  371. align-items: center;
  372. position: relative;
  373. }
  374. .class-info-img {
  375. width: 60px;
  376. height: 60px;
  377. margin-right: 10px;
  378. }
  379. .class-info-content {
  380. flex: 1;
  381. }
  382. .class-info-label {
  383. font-size: 16px;
  384. color: #000000;
  385. word-break: break-all;
  386. }
  387. .class-info-text {
  388. color: #999999;
  389. margin-bottom: 5px;
  390. }
  391. }
  392. .student-box {
  393. max-height: 200px;
  394. padding: 0 15px;
  395. margin: 25px 0 0 0;
  396. box-sizing: border-box;
  397. overflow: auto;
  398. /deep/.u-card__head {
  399. padding-bottom: 0px !important;
  400. }
  401. }
  402. .canvas-container {
  403. width: 100%;
  404. height: 200px;
  405. }
  406. .handle-fix-box {
  407. height: 85px;
  408. text-align: center;
  409. .contract-link {
  410. color: $mainColor;
  411. line-height: 25px;
  412. }
  413. }
  414. }
  415. </style>