pay.vue 10 KB

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