pay.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <view class="content">
  3. <view class="supplyInfo">
  4. <view class="tel flex">
  5. <label>缴费名称:</label>
  6. <input type="text" class="card input" v-model="payInfo.name" disabled/>
  7. </view>
  8. <view class="tel flex">
  9. <label>订单编号:</label>
  10. <input type="text" class="card input" v-model="payInfo.code" disabled/>
  11. </view>
  12. <view class="tel flex">
  13. <label>住宅地址:</label>
  14. <input type="text" class="card input" v-model="payInfo.address" disabled/>
  15. </view>
  16. <view class="tel flex">
  17. <label>户主姓名:</label>
  18. <input type="text" class="card input" v-model="payInfo.owner_name" disabled/>
  19. </view>
  20. <view class="tel flex">
  21. <label>住宅面积:</label>
  22. <input type="text" class="card input" v-model="payInfo.area" disabled/>
  23. </view>
  24. <view class="tel flex">
  25. <label>缴费类型:</label>
  26. <radio-group @change="payChange">
  27. <radio value="1" :checked="payInfo.type!==2" style="margin-right: 30rpx;transform: scale(0.85);">金额</radio>
  28. <radio value="2" :checked="payInfo.type===2" style="transform: scale(0.85);">空置</radio>
  29. </radio-group>
  30. </view>
  31. <view class="tel flex">
  32. <label>缴费金额:</label>
  33. <input type="text" class="card input" id="real_fee" v-model="payInfo.real_fee" disabled/>
  34. </view>
  35. </view>
  36. <button class="submit" @tap="paySubmit">{{payStatus ? '申请开票' : '缴费'}}</button>
  37. <uni-popup ref="popup" :mask-click="false">
  38. <view class="popup-box">
  39. <view>
  40. <view class="popup-title">申请开票</view>
  41. <view class="popup-content-box">
  42. <view class="popup-content">
  43. <view class="popup-type">
  44. <view>开票抬头:</view><input type="text" value="" />
  45. </view>
  46. <view class="popup-type">
  47. <view>备注:</view><input type="text" value="" />
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="popup-footer">
  53. <button class="popup-submit" @click="submitInvocie">提交</button>
  54. </view>
  55. </view>
  56. </uni-popup>
  57. </view>
  58. </template>
  59. <script>
  60. import md5 from "@/common/md5.js";
  61. export default {
  62. data() {
  63. return {
  64. payInfo: {
  65. },
  66. payStatus:0,
  67. pay_code : '',
  68. };
  69. },
  70. onLoad(option) {
  71. this.getPayDetail(option.id);
  72. this.pay_code = option.id;
  73. },
  74. methods: {
  75. getPayDetail(payId) {
  76. let md5Sign = md5(
  77. "method=" +
  78. "user" +
  79. "&timestamp=" +
  80. getApp().globalData.globalTimestamp +
  81. "&secret=" +
  82. getApp().globalData.secret
  83. );
  84. let url =
  85. getApp().globalData.shareUrl +
  86. "api/api.php" +
  87. "?method=user&source=user&action=get_order_info&timestamp=" +
  88. getApp().globalData.globalTimestamp +
  89. "&sign=" +
  90. md5Sign;
  91. let postData = {
  92. code:payId,
  93. openId: getApp().globalData.open_id,
  94. };
  95. uni.request({
  96. url: url,
  97. method: "POST",
  98. header: {
  99. "content-type": "application/x-www-form-urlencoded",
  100. },
  101. data: postData,
  102. success: (res) => {
  103. if (res.data.code === 200) {
  104. this.payInfo = res.data.data;
  105. this.payInfo.address = this.payInfo.estate_name + this.payInfo.building_name + this.payInfo.unit + this.payInfo.room
  106. } else {
  107. uni.showToast({
  108. title: res.data.msg,
  109. icon: "none",
  110. duration: 2500,
  111. });
  112. }
  113. },
  114. fail: () => {
  115. console.log("连接失败");
  116. },
  117. });
  118. },
  119. payChange(e){
  120. let v = e.detail.value;
  121. if (v == 2)
  122. {
  123. let value = this.payInfo.part_fee - this.payInfo.reduction;
  124. this.payInfo.real_fee = value;
  125. }
  126. else
  127. {
  128. let value = this.payInfo.total_fee - this.payInfo.reduction;
  129. this.payInfo.real_fee = value;
  130. }
  131. this.payInfo.type = e.detail.value;
  132. },
  133. paySubmit(){
  134. if(this.payStatus){
  135. this.open()
  136. return
  137. }
  138. let md5Sign = md5(
  139. "method=" +
  140. "user" +
  141. "&timestamp=" +
  142. getApp().globalData.globalTimestamp +
  143. "&secret=" +
  144. getApp().globalData.secret
  145. );
  146. let url =
  147. getApp().globalData.shareUrl +
  148. "api/api.php" +
  149. "?method=user&source=user&action=prepay&timestamp=" +
  150. getApp().globalData.globalTimestamp +
  151. "&sign=" +
  152. md5Sign;
  153. let postData = {
  154. code:this.pay_code,
  155. type : this.payInfo.type,
  156. openId: getApp().globalData.open_id,
  157. };
  158. uni.request({
  159. url: url,
  160. method: "POST",
  161. header: {
  162. "content-type": "application/x-www-form-urlencoded",
  163. },
  164. data: postData,
  165. success: (res) => {
  166. if (res.data.code === 200) {
  167. let r = res.data.data;
  168. uni.requestPayment({
  169. provider: 'wxpay',
  170. timeStamp: String(Date.now()),
  171. nonceStr: r.nonce_str,
  172. package: 'prepay_id=' + r.prepay_id,
  173. signType: 'MD5',
  174. paySign: r.sign,
  175. success: function (res) {
  176. console.log('success:' + JSON.stringify(res));
  177. this.payStatus = 1;
  178. },
  179. fail: function (err) {
  180. console.log('fail:' + JSON.stringify(err));
  181. }
  182. });
  183. } else {
  184. uni.showToast({
  185. title: res.data.msg,
  186. icon: "none",
  187. duration: 2500,
  188. });
  189. }
  190. },
  191. fail: () => {
  192. console.log("连接失败");
  193. },
  194. });
  195. //支付这里缺少签名参数 还需要后台配合调用微信那边的接口
  196. //参考https://github.com/dcloudio/H5P.Server/tree/master/payment
  197. },
  198. submitInvocie(){
  199. this.closePopup()
  200. },
  201. open() {
  202. this.$refs.popup.open('center')
  203. },
  204. closePopup() {
  205. this.$refs.popup.close()
  206. },
  207. },
  208. };
  209. </script>
  210. <style lang="scss" scoped>
  211. .content {
  212. font-size: 28rpx;
  213. font-weight: 200;
  214. padding: 1% 2%;
  215. .title {
  216. font-size: 30rpx;
  217. margin: 4% 0;
  218. }
  219. label {
  220. display: inline-block;
  221. width: 25%;
  222. vertical-align: middle;
  223. }
  224. .card {
  225. background-color: rgb(248, 247, 247);
  226. border-radius: 10rpx;
  227. }
  228. .flex {
  229. display: flex;
  230. align-items: center;
  231. margin-bottom: 2%;
  232. }
  233. .input {
  234. padding: 0 2%;
  235. margin: 2% 0;
  236. display: inline-block;
  237. width: 80%;
  238. height: 70rpx;
  239. }
  240. .supplyInfo {
  241. border-radius: 40rpx;
  242. padding: 4%;
  243. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  244. margin: 30rpx 0 30rpx 0;
  245. }
  246. .info {
  247. margin-top: 2%;
  248. border-radius: 40rpx;
  249. padding: 2% 4%;
  250. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  251. }
  252. .submit {
  253. color: white;
  254. font-weight: normal;
  255. width: 55%;
  256. border-radius: 20rpx;
  257. background-color: #02a7f0;
  258. margin: 120rpx auto;
  259. }
  260. }
  261. .popup-box {
  262. height: 100%;
  263. display: flex;
  264. flex-direction: column;
  265. justify-content: space-between;
  266. }
  267. .popup-title {
  268. text-align: center;
  269. font-weight: bold;
  270. height: 30px;
  271. border-bottom: 1px solid #d8d8d8;
  272. }
  273. .popup-content {
  274. font-size: 28rpx;
  275. padding: 10rpx 0 10rpx 0;
  276. }
  277. .popup-type {
  278. display: flex;
  279. height: 80rpx;
  280. align-items: center;
  281. margin-top: 60rpx;
  282. view {
  283. width: 30%;
  284. }
  285. input {
  286. border: 1px solid #d7d7d7;
  287. width: 60%;
  288. border-radius: 5rpx;
  289. padding-left: 10rpx;
  290. height: 56rpx;
  291. }
  292. }
  293. .popup-footer {
  294. display: flex;
  295. button{
  296. font-size: 26rpx;
  297. height: 60rpx;
  298. width: 150rpx;
  299. line-height: 60rpx;
  300. color: #FFFFFF;
  301. }
  302. }
  303. .popup-cancel {
  304. background-color: #AAAAAA;
  305. }
  306. .popup-submit {
  307. background-color: #249CD3;
  308. }
  309. </style>