pay.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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);" :disabled="payInfo.status==1 || payInfo.status==3">空置</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 class="tel flex">
  36. <label>订单状态:</label>
  37. <input type="text" class="card input" id="status" :style="{color:statusColor[payInfo.status]}" v-model="statusObj[payInfo.status]" disabled/>
  38. </view>
  39. <view class="tel flex" v-if="payInfo.invoice_status > 0">
  40. <label>发票抬头:</label>
  41. <input type="text" class="card input" id="real_fee" v-model="payInfo.invoice" disabled/>
  42. </view>
  43. <view class="tel flex" v-if="payInfo.invoice_status > 0">
  44. <label>发票备注:</label>
  45. <input type="text" class="card input" id="real_fee" v-model="payInfo.invoice_remark" disabled/>
  46. </view>
  47. <view class="tel flex" v-if="payInfo.invoice_status > 0">
  48. <label>发票状态:</label>
  49. <input type="text" class="card input" id="real_fee" v-model="invoiceStatusStr" disabled/>
  50. </view>
  51. </view>
  52. <button class="submit" style="margin-bottom:20rpx" @tap="paySubmit" v-if="needPay">{{payStatusStr}}</button>
  53. <button class="submit" style="margin-top:20rpx" @tap="openPopup" v-if="needInvoice">申请开票</button>
  54. <uni-popup ref="popup" :mask-click="false">
  55. <view class="popup-box">
  56. <view>
  57. <view class="popup-title">申请开票</view>
  58. <view class="popup-content-box">
  59. <view class="popup-content">
  60. <view class="popup-type">
  61. <view>开票抬头:</view><input type="text" v-model="invoiceName" />
  62. </view>
  63. <view class="popup-type">
  64. <view>备注:</view><input type="text" v-model="invoiceRemark" />
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. <view class="popup-footer">
  70. <button class="popup-submit" @click="submitInvocie">提交</button>
  71. </view>
  72. </view>
  73. </uni-popup>
  74. </view>
  75. </template>
  76. <script>
  77. import md5 from "@/common/md5.js";
  78. export default {
  79. data() {
  80. return {
  81. payInfo: {
  82. },
  83. payStatus:0,
  84. payStatusStr : '缴费',
  85. needPay : 1,
  86. needInvoice : 0,
  87. invoiceStatusStr : "待开票",
  88. pay_code : '',
  89. statusObj:getApp().globalData.statusObj,
  90. statusColor:getApp().globalData.statusColor,
  91. invoiceName : '',
  92. invoiceRemark : '',
  93. };
  94. },
  95. onLoad(option) {
  96. this.getPayDetail(option.id);
  97. this.pay_code = option.id;
  98. },
  99. methods: {
  100. reload(){
  101. this.getPayDetail(this.pay_code);
  102. },
  103. getPayDetail(payId) {
  104. let url = getApp().makeApiUrl("user",'user','get_order_info');
  105. let postData = {
  106. code:payId,
  107. openId: getApp().globalData.open_id,
  108. };
  109. uni.request({
  110. url: url,
  111. method: "POST",
  112. header: {
  113. "content-type": "application/x-www-form-urlencoded",
  114. },
  115. data: postData,
  116. success: (res) => {
  117. if (res.data.code === 200) {
  118. this.payInfo = res.data.data;
  119. this.payInfo.address = this.payInfo.estate_name + this.payInfo.building_name + this.payInfo.unit + this.payInfo.room;
  120. if (this.payInfo.status > 0 && this.payInfo.invoice_status == 0){
  121. this.needInvoice = 1;
  122. }
  123. else{
  124. this.needInvoice = 0;
  125. }
  126. if (this.payInfo.status == 2){
  127. this.payStatusStr = '补充缴费';
  128. }
  129. if (this.payInfo.status == 1 || this.payInfo.status == 3){
  130. this.needPay = 0;
  131. }
  132. if (this.payInfo.invoice_status == 2){
  133. this.invoiceStatusStr = "已开票";
  134. }
  135. } else {
  136. uni.showToast({
  137. title: res.data.msg,
  138. icon: "none",
  139. duration: 2500,
  140. });
  141. }
  142. },
  143. fail: () => {
  144. console.log("连接失败");
  145. },
  146. });
  147. },
  148. payChange(e){
  149. let v = e.detail.value;
  150. if (v == 2)
  151. {
  152. let value = this.payInfo.part_fee - this.payInfo.reduction;
  153. this.payInfo.real_fee = value;
  154. }
  155. else
  156. {
  157. let value = this.payInfo.total_fee - this.payInfo.reduction;
  158. this.payInfo.real_fee = value;
  159. }
  160. this.payInfo.type = e.detail.value;
  161. },
  162. paySubmit(){
  163. let that = this;
  164. let type = this.payInfo.type;
  165. if (this.payInfo.status == 2)
  166. {
  167. type = 3;
  168. }
  169. let url = getApp().makeApiUrl("user",'user','prepay');
  170. let postData = {
  171. code:this.pay_code,
  172. type : type,
  173. openId: getApp().globalData.open_id,
  174. };
  175. uni.request({
  176. url: url,
  177. method: "POST",
  178. header: {
  179. "content-type": "application/x-www-form-urlencoded",
  180. },
  181. data: postData,
  182. success: (res) => {
  183. if (res.data.code === 200) {
  184. let r = res.data.data;
  185. let timeStamp = Date.now().toString();
  186. let nonceStr = getApp().randomStr(32);
  187. let p = 'prepay_id=' + r.prepay_id;
  188. let appId = "wx3cf5d0fd376116e2";
  189. let key = 'd2452k56khlk987HJ456uy7856HKJsd3'; //支付的key
  190. let origin = "appId="+appId+"&nonceStr="+nonceStr+"&package="+p+"&signType=MD5&timeStamp="+timeStamp+"&key="+key;
  191. let md5Sign = getApp().MD5(origin);
  192. // console.log('md5Sign_origin:' + origin);
  193. // console.log('md5Sign:' + md5Sign);
  194. uni.requestPayment({
  195. appId: appId,
  196. timeStamp: timeStamp,
  197. nonceStr: nonceStr,
  198. package: p,
  199. signType: 'MD5',
  200. paySign: md5Sign,
  201. success: function (res) {
  202. console.log('success:' + JSON.stringify(res));
  203. setTimeout(function() {
  204. that.reload();
  205. }, 500);
  206. },
  207. fail: function (err) {
  208. console.log('fail:' + JSON.stringify(err));
  209. }
  210. });
  211. } else {
  212. uni.showToast({
  213. title: res.data.msg,
  214. icon: "none",
  215. duration: 2500,
  216. });
  217. }
  218. },
  219. fail: () => {
  220. console.log("连接失败");
  221. },
  222. });
  223. //支付这里缺少签名参数 还需要后台配合调用微信那边的接口
  224. //参考https://github.com/dcloudio/H5P.Server/tree/master/payment
  225. },
  226. submitInvocie(){
  227. this.closePopup();
  228. },
  229. openPopup() {
  230. this.$refs.popup.open('center');
  231. },
  232. closePopup() {
  233. this.$refs.popup.close();
  234. let that = this;
  235. let url = getApp().makeApiUrl("user",'user','invoice');
  236. let postData = {
  237. code:this.pay_code,
  238. invoice : this.invoiceName,
  239. remark : this.invoiceRemark,
  240. openId: getApp().globalData.open_id,
  241. };
  242. uni.request({
  243. url: url,
  244. method: "POST",
  245. header: {
  246. "content-type": "application/x-www-form-urlencoded",
  247. },
  248. data: postData,
  249. success: (res) => {
  250. if (res.data.code === 200) {
  251. uni.showToast({
  252. title: res.data.msg,
  253. icon: "none",
  254. duration: 2500,
  255. });
  256. setTimeout(function() {
  257. that.reload();
  258. }, 500);
  259. } else {
  260. uni.showToast({
  261. title: res.data.msg,
  262. icon: "none",
  263. duration: 2500,
  264. });
  265. }
  266. },
  267. fail: () => {
  268. console.log("连接失败");
  269. },
  270. });
  271. },
  272. },
  273. };
  274. </script>
  275. <style lang="scss" scoped>
  276. .content {
  277. font-size: 28rpx;
  278. font-weight: 200;
  279. padding: 1% 2%;
  280. .title {
  281. font-size: 30rpx;
  282. margin: 4% 0;
  283. }
  284. label {
  285. display: inline-block;
  286. width: 25%;
  287. vertical-align: middle;
  288. }
  289. .card {
  290. background-color: rgb(248, 247, 247);
  291. border-radius: 10rpx;
  292. }
  293. .flex {
  294. display: flex;
  295. align-items: center;
  296. margin-bottom: 2%;
  297. }
  298. .input {
  299. padding: 0 2%;
  300. margin: 2% 0;
  301. display: inline-block;
  302. width: 80%;
  303. height: 70rpx;
  304. }
  305. .supplyInfo {
  306. border-radius: 40rpx;
  307. padding: 4%;
  308. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  309. margin: 30rpx 0 30rpx 0;
  310. }
  311. .info {
  312. margin-top: 2%;
  313. border-radius: 40rpx;
  314. padding: 2% 4%;
  315. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  316. }
  317. .submit {
  318. color: white;
  319. font-weight: normal;
  320. width: 55%;
  321. border-radius: 20rpx;
  322. background-color: #02a7f0;
  323. margin: 120rpx auto;
  324. }
  325. }
  326. .popup-box {
  327. height: 100%;
  328. display: flex;
  329. flex-direction: column;
  330. justify-content: space-between;
  331. }
  332. .popup-title {
  333. text-align: center;
  334. font-weight: bold;
  335. height: 30px;
  336. border-bottom: 1px solid #d8d8d8;
  337. }
  338. .popup-content {
  339. font-size: 28rpx;
  340. padding: 10rpx 0 10rpx 0;
  341. }
  342. .popup-type {
  343. display: flex;
  344. height: 80rpx;
  345. align-items: center;
  346. margin-top: 60rpx;
  347. view {
  348. width: 30%;
  349. }
  350. input {
  351. border: 1px solid #d7d7d7;
  352. width: 60%;
  353. border-radius: 5rpx;
  354. padding-left: 10rpx;
  355. height: 56rpx;
  356. }
  357. }
  358. .popup-footer {
  359. display: flex;
  360. button{
  361. font-size: 26rpx;
  362. height: 60rpx;
  363. width: 150rpx;
  364. line-height: 60rpx;
  365. color: #FFFFFF;
  366. }
  367. }
  368. .popup-cancel {
  369. background-color: #AAAAAA;
  370. }
  371. .popup-submit {
  372. background-color: #249CD3;
  373. }
  374. </style>