pay.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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 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. getPayDetail(payId) {
  101. let url = getApp().makeApiUrl("user",'user','get_order_info');
  102. let postData = {
  103. code:payId,
  104. openId: getApp().globalData.open_id,
  105. };
  106. uni.request({
  107. url: url,
  108. method: "POST",
  109. header: {
  110. "content-type": "application/x-www-form-urlencoded",
  111. },
  112. data: postData,
  113. success: (res) => {
  114. if (res.data.code === 200) {
  115. this.payInfo = res.data.data;
  116. this.payInfo.address = this.payInfo.estate_name + this.payInfo.building_name + this.payInfo.unit + this.payInfo.room;
  117. if (this.payInfo.status > 0 && this.payInfo.invoice_status == 0){
  118. this.needInvoice = 1;
  119. }
  120. if (this.payInfo.status == 2){
  121. this.payStatusStr = '补充缴费';
  122. }
  123. if (this.payInfo.status == 1 || this.payInfo.status == 3){
  124. this.needPay = 0;
  125. }
  126. if (this.payInfo.invoice_status == 2){
  127. this.invoiceStatusStr = "已开票";
  128. }
  129. } else {
  130. uni.showToast({
  131. title: res.data.msg,
  132. icon: "none",
  133. duration: 2500,
  134. });
  135. }
  136. },
  137. fail: () => {
  138. console.log("连接失败");
  139. },
  140. });
  141. },
  142. payChange(e){
  143. let v = e.detail.value;
  144. if (v == 2)
  145. {
  146. let value = this.payInfo.part_fee - this.payInfo.reduction;
  147. this.payInfo.real_fee = value;
  148. }
  149. else
  150. {
  151. let value = this.payInfo.total_fee - this.payInfo.reduction;
  152. this.payInfo.real_fee = value;
  153. }
  154. this.payInfo.type = e.detail.value;
  155. },
  156. paySubmit(){
  157. let url = getApp().makeApiUrl("user",'user','prepay');
  158. let postData = {
  159. code:this.pay_code,
  160. type : this.payInfo.type,
  161. openId: getApp().globalData.open_id,
  162. };
  163. uni.request({
  164. url: url,
  165. method: "POST",
  166. header: {
  167. "content-type": "application/x-www-form-urlencoded",
  168. },
  169. data: postData,
  170. success: (res) => {
  171. if (res.data.code === 200) {
  172. let r = res.data.data;
  173. uni.requestPayment({
  174. provider: 'wxpay',
  175. timeStamp: String(Date.now()),
  176. nonceStr: r.nonce_str,
  177. package: 'prepay_id=' + r.prepay_id,
  178. signType: 'MD5',
  179. paySign: r.sign,
  180. success: function (res) {
  181. console.log('success:' + JSON.stringify(res));
  182. this.payStatus = 1;
  183. },
  184. fail: function (err) {
  185. console.log('fail:' + JSON.stringify(err));
  186. }
  187. });
  188. } else {
  189. uni.showToast({
  190. title: res.data.msg,
  191. icon: "none",
  192. duration: 2500,
  193. });
  194. }
  195. },
  196. fail: () => {
  197. console.log("连接失败");
  198. },
  199. });
  200. //支付这里缺少签名参数 还需要后台配合调用微信那边的接口
  201. //参考https://github.com/dcloudio/H5P.Server/tree/master/payment
  202. },
  203. submitInvocie(){
  204. this.closePopup();
  205. },
  206. openPopup() {
  207. this.$refs.popup.open('center');
  208. },
  209. closePopup() {
  210. this.$refs.popup.close();
  211. let url = getApp().makeApiUrl("user",'user','invoice');
  212. let postData = {
  213. code:this.pay_code,
  214. invoice : this.invoiceName,
  215. remark : this.invoiceRemark,
  216. openId: getApp().globalData.open_id,
  217. };
  218. uni.request({
  219. url: url,
  220. method: "POST",
  221. header: {
  222. "content-type": "application/x-www-form-urlencoded",
  223. },
  224. data: postData,
  225. success: (res) => {
  226. if (res.data.code === 200) {
  227. uni.showToast({
  228. title: res.data.msg,
  229. icon: "none",
  230. duration: 2500,
  231. });
  232. } else {
  233. uni.showToast({
  234. title: res.data.msg,
  235. icon: "none",
  236. duration: 2500,
  237. });
  238. }
  239. },
  240. fail: () => {
  241. console.log("连接失败");
  242. },
  243. });
  244. },
  245. },
  246. };
  247. </script>
  248. <style lang="scss" scoped>
  249. .content {
  250. font-size: 28rpx;
  251. font-weight: 200;
  252. padding: 1% 2%;
  253. .title {
  254. font-size: 30rpx;
  255. margin: 4% 0;
  256. }
  257. label {
  258. display: inline-block;
  259. width: 25%;
  260. vertical-align: middle;
  261. }
  262. .card {
  263. background-color: rgb(248, 247, 247);
  264. border-radius: 10rpx;
  265. }
  266. .flex {
  267. display: flex;
  268. align-items: center;
  269. margin-bottom: 2%;
  270. }
  271. .input {
  272. padding: 0 2%;
  273. margin: 2% 0;
  274. display: inline-block;
  275. width: 80%;
  276. height: 70rpx;
  277. }
  278. .supplyInfo {
  279. border-radius: 40rpx;
  280. padding: 4%;
  281. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  282. margin: 30rpx 0 30rpx 0;
  283. }
  284. .info {
  285. margin-top: 2%;
  286. border-radius: 40rpx;
  287. padding: 2% 4%;
  288. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  289. }
  290. .submit {
  291. color: white;
  292. font-weight: normal;
  293. width: 55%;
  294. border-radius: 20rpx;
  295. background-color: #02a7f0;
  296. margin: 120rpx auto;
  297. }
  298. }
  299. .popup-box {
  300. height: 100%;
  301. display: flex;
  302. flex-direction: column;
  303. justify-content: space-between;
  304. }
  305. .popup-title {
  306. text-align: center;
  307. font-weight: bold;
  308. height: 30px;
  309. border-bottom: 1px solid #d8d8d8;
  310. }
  311. .popup-content {
  312. font-size: 28rpx;
  313. padding: 10rpx 0 10rpx 0;
  314. }
  315. .popup-type {
  316. display: flex;
  317. height: 80rpx;
  318. align-items: center;
  319. margin-top: 60rpx;
  320. view {
  321. width: 30%;
  322. }
  323. input {
  324. border: 1px solid #d7d7d7;
  325. width: 60%;
  326. border-radius: 5rpx;
  327. padding-left: 10rpx;
  328. height: 56rpx;
  329. }
  330. }
  331. .popup-footer {
  332. display: flex;
  333. button{
  334. font-size: 26rpx;
  335. height: 60rpx;
  336. width: 150rpx;
  337. line-height: 60rpx;
  338. color: #FFFFFF;
  339. }
  340. }
  341. .popup-cancel {
  342. background-color: #AAAAAA;
  343. }
  344. .popup-submit {
  345. background-color: #249CD3;
  346. }
  347. </style>