openMember.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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. reset() {
  201. context.draw()
  202. },
  203. handleTouchStart(e) {
  204. this.canvasData = []
  205. const a = e.changedTouches[0]
  206. this.canvasData.push({
  207. x: a.x,
  208. y: a.y
  209. })
  210. },
  211. handleTouchMove(e) {
  212. const a = e.changedTouches[0]
  213. this.canvasData.push({
  214. x: a.x,
  215. y: a.y
  216. })
  217. },
  218. handleTouchEnd(e) {
  219. const a = e.changedTouches[0]
  220. this.canvasData.push({
  221. x: a.x,
  222. y: a.y
  223. })
  224. },
  225. handleEnd() {
  226. context.stroke()
  227. context.draw(true)
  228. },
  229. submitContract() {
  230. if (!this.studentId) {
  231. this.$refs.uTips.show({
  232. title: '请选择学员',
  233. type: 'warning',
  234. })
  235. return
  236. }
  237. let that = this
  238. uni.canvasToTempFilePath({
  239. canvasId: 'canvas',
  240. success: res => {
  241. uni.uploadFile({
  242. url: API.uploadFile,
  243. filePath: res.tempFilePath,
  244. name: 'file',
  245. header: {
  246. Authorization: uni.getStorageSync('token')
  247. },
  248. success: (uploadFileRes) => {
  249. that.signUrl = JSON.parse(uploadFileRes.data).data.id
  250. NET.request(API.submitContractForm, {
  251. contractId: that.contractInfo.id,
  252. fileId: that.signUrl,
  253. }, 'POST').then(res => {
  254. that.toPay(res.data.id)
  255. }).catch(error => {
  256. that.$refs.uTips.show({
  257. title: error.message,
  258. type: 'warning',
  259. })
  260. })
  261. }
  262. });
  263. }
  264. })
  265. },
  266. // 支付
  267. toPay(contractId) {
  268. NET.request(API.getPayParams, {
  269. id: this.memberCardId,
  270. couponId: this.couponId,
  271. studentId: this.studentId,
  272. contractId: contractId
  273. }, 'POST').then(res => {
  274. if (this.memberInfo.realPayAmount <= 0) {
  275. this.goToPayResult(res.data.oderNo)
  276. return false
  277. }
  278. uni.requestPayment({
  279. provider: 'wxpay',
  280. timeStamp: res.data.timeStamp,
  281. nonceStr: res.data.nonceStr,
  282. package: res.data.packageString,
  283. signType: res.data.signType,
  284. paySign: res.data.paySign,
  285. success: (payRes) => {
  286. this.goToPayResult(res.data.oderNo)
  287. },
  288. fail: (error) => {
  289. this.$refs.uTips.show({
  290. title: '支付未成功',
  291. type: 'warning',
  292. })
  293. }
  294. })
  295. }).catch(error => {
  296. this.$refs.uTips.show({
  297. title: error.message,
  298. type: 'warning',
  299. })
  300. })
  301. // uni.navigateTo({
  302. // url: '/pagesMain/contractInfo?memberCardId=' + this.memberCardId + '&couponId=' + this.couponId + '&studentId=' +
  303. // this.studentId
  304. // });
  305. },
  306. // 跳转支付结果
  307. goToPayResult(oderNo) {
  308. uni.redirectTo({
  309. url: '/pagesMain/payResult?id=' + oderNo
  310. });
  311. }
  312. },
  313. }
  314. </script>
  315. <style>
  316. page {
  317. width: 100%;
  318. height: 100%;
  319. }
  320. </style>
  321. <style lang="scss" scoped>
  322. @import "@/static/css/themes.scss";
  323. .content {
  324. width: 100%;
  325. float: left;
  326. padding: 15px 15px 85px 15px;
  327. box-sizing: border-box;
  328. .card-list {
  329. width: 100%;
  330. padding: 15px 20px;
  331. margin-bottom: 15px;
  332. float: left;
  333. background-color: #FFFFFF;
  334. border-radius: 15px;
  335. box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.2);
  336. position: relative;
  337. overflow: hidden;
  338. .card-label {
  339. width: 100%;
  340. margin-bottom: 10px;
  341. float: left;
  342. font-size: 18px;
  343. font-weight: bold;
  344. line-height: 20px;
  345. }
  346. .card-num {
  347. width: 100%;
  348. float: left;
  349. font-size: 28px;
  350. line-height: 28px;
  351. color: $mainColor;
  352. }
  353. .card-icon {
  354. font-size: 80px;
  355. color: $mainColor;
  356. position: absolute;
  357. right: -15px;
  358. bottom: -15x;
  359. opacity: 0.5;
  360. }
  361. }
  362. .class-card {
  363. .class-content {
  364. padding: 10px 15px;
  365. display: flex;
  366. align-items: center;
  367. position: relative;
  368. }
  369. .class-info-img {
  370. width: 60px;
  371. height: 60px;
  372. margin-right: 10px;
  373. }
  374. .class-info-content {
  375. flex: 1;
  376. }
  377. .class-info-label {
  378. font-size: 16px;
  379. color: #000000;
  380. word-break: break-all;
  381. }
  382. .class-info-text {
  383. color: #999999;
  384. margin-bottom: 5px;
  385. }
  386. }
  387. .student-box {
  388. max-height: 200px;
  389. padding: 0 15px;
  390. margin: 25px 0 0 0;
  391. box-sizing: border-box;
  392. overflow: auto;
  393. /deep/.u-card__head {
  394. padding-bottom: 0px !important;
  395. }
  396. }
  397. .canvas-container {
  398. width: 100%;
  399. height: 200px;
  400. }
  401. .handle-fix-box {
  402. height: 85px;
  403. text-align: center;
  404. .contract-link {
  405. color: $mainColor;
  406. line-height: 25px;
  407. }
  408. }
  409. }
  410. </style>