AddApplyReceipt.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <view class="detail-view">
  3. <u-form label-width="150" :model="add_form" ref="uForm">
  4. <view class="form-model-view">
  5. <u-form-item required label="收款单位" prop="customerName">
  6. <u-input @click="goPage('/pagesT/customer/selCustomer')" class="dis-input" disabled
  7. v-model="add_form.customerName" placeholder="请选择" />
  8. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  9. </u-form-item>
  10. <u-form-item label="收款人">
  11. <view class="form-value">{{ add_form.operatorName }}</view>
  12. </u-form-item>
  13. <u-form-item label="当前应收">
  14. <view class="form-value">{{ $utils.formattedNumber(add_form.receivable) }}</view>
  15. </u-form-item>
  16. <u-form-item label='所属店铺'>
  17. <view class="clearfix form-val" @click="goPage('/pagesT/shop/selShop')">
  18. <view class="float_right" @click.stop="add_form.shopId = ''">
  19. <u-icon :name="!add_form.shopId ? 'arrow-right' : 'close-circle-fill'" size="28"
  20. color="#999999">
  21. </u-icon>
  22. </view>
  23. <text class="float_right ellipsis">{{ add_form.shopId ? add_form.shopName : '请选择' }}</text>
  24. </view>
  25. </u-form-item>
  26. </view>
  27. <view class="form-model-view">
  28. <u-form-item label="收款单明细">
  29. <view class="form-value add-btn-go" @click="addAccount">
  30. <u-icon name="plus" size="24"></u-icon>
  31. <text>添加收款</text>
  32. </view>
  33. </u-form-item>
  34. <view class="detail-ul">
  35. <view class="detail-li" v-for="(item, index) in add_form.receiptRequisitionAccountDate"
  36. :key="index">
  37. <view class="del-icon" @click="delAccount(index)">
  38. <u-icon name="minus-circle-fill" size="40" color="#fa3534"></u-icon>
  39. </view>
  40. <view class="title clearfix">
  41. <view class="float_left">结算方式</view>
  42. <view class="float_right" @click="openMethods(index)">
  43. <text>{{ item.settlementMethod !== '' ? pay_type_list[item.settlementMethod - 1].label : '请选择' }}</text>
  44. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  45. </view>
  46. </view>
  47. <u-form-item label='结算账户'>
  48. <view class="clearfix form-val" @click="settlementAccount(index)">
  49. <view class="float_right" @click.stop="delsettlementAccount">
  50. <u-icon :name="!item.accountId ? 'arrow-right' : 'close-circle-fill'" size="28"
  51. color="#999999">
  52. </u-icon>
  53. </view>
  54. <text
  55. class="float_right ellipsis">{{ item.accountId ? item.accountName : '请选择' }}</text>
  56. </view>
  57. </u-form-item>
  58. <view class="money-ul">
  59. <view class="money-li"><input type="digit" @blur="moneyChange(index)"
  60. v-model="item.collectionAmount" placeholder="收款金额" /></view>
  61. <view class="money-li"><input type="digit" @blur="moneyChange(index)"
  62. v-model="item.preferentialAmount" placeholder="优惠金额" /></view>
  63. <view class="money-li"><input type="digit" v-model="item.actualAmount" placeholder="实收金额" />
  64. </view>
  65. </view>
  66. <view class="bottom clearfix"><input type="text" v-model="item.remark" placeholder="备注" />
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. <view class="form-model-view">
  72. <u-form-item label="收款总额">
  73. <view class="form-value">{{ totalCollectionAmount }}</view>
  74. </u-form-item>
  75. <u-form-item label="优惠总额">
  76. <view class="form-value">{{ totalPreferentialAmount }}</view>
  77. </u-form-item>
  78. <u-form-item label="实收总额">
  79. <view class="form-value">{{ totalActualAmount }}</view>
  80. </u-form-item>
  81. </view>
  82. </u-form>
  83. <u-select @confirm="methodsConfirm" v-model="methods_show" :list="pay_type_list"></u-select>
  84. <view class="detail-bottom">
  85. <view class="handel-btn" @click="submit">提交订单</view>
  86. </view>
  87. </view>
  88. </template>
  89. <script>
  90. export default {
  91. data() {
  92. return {
  93. rules: {
  94. customerName: [{
  95. required: true,
  96. message: '请选择收款单位',
  97. trigger: ['change', 'blur']
  98. }]
  99. },
  100. add_form: {
  101. customerId: '',
  102. customerName: '',
  103. operatorId: '',
  104. operatorName: '',
  105. receivable: '',
  106. shopId: "",
  107. shopName: "",
  108. receiptRequisitionAccountDate: [{
  109. collectionAmount: '',
  110. preferentialAmount: '',
  111. actualAmount: '',
  112. settlementMethod: '',
  113. remark: '',
  114. accountName: "",
  115. accountId: "",
  116. }]
  117. },
  118. methods_show: false,
  119. account_index: 0,
  120. pay_type_list: [{
  121. value: 1,
  122. label: '当面现金'
  123. },
  124. {
  125. value: 2,
  126. label: '私人微信'
  127. },
  128. {
  129. value: 3,
  130. label: '私人支付宝'
  131. },
  132. {
  133. value: 4,
  134. label: '私人银行卡'
  135. },
  136. {
  137. value: 5,
  138. label: '公司公户'
  139. },
  140. {
  141. value: 6,
  142. label: '公司微信'
  143. },
  144. {
  145. value: 7,
  146. label: '公司支付宝'
  147. },
  148. {
  149. value: 8,
  150. label: '公司银行卡'
  151. }
  152. ],
  153. customerData: '',
  154. account_id: '',
  155. shopData: {},
  156. AccountData: {},
  157. index: ''
  158. };
  159. },
  160. computed: {
  161. userInfo() {
  162. return this.$store.state.userInfo;
  163. },
  164. // 收款总额
  165. totalCollectionAmount() {
  166. if (!this.add_form.receiptRequisitionAccountDate.length) {
  167. return 0;
  168. } else if (this.add_form.receiptRequisitionAccountDate.length === 1) {
  169. return Number(this.add_form.receiptRequisitionAccountDate[0].collectionAmount);
  170. } else {
  171. let sum = 0;
  172. this.add_form.receiptRequisitionAccountDate.forEach(item => {
  173. sum = this.$NP.plus(sum, Number(item.collectionAmount) || 0);
  174. });
  175. return sum;
  176. }
  177. },
  178. // 优惠总额
  179. totalPreferentialAmount() {
  180. if (!this.add_form.receiptRequisitionAccountDate.length) {
  181. return 0;
  182. } else if (this.add_form.receiptRequisitionAccountDate.length === 1) {
  183. return Number(this.add_form.receiptRequisitionAccountDate[0].preferentialAmount);
  184. } else {
  185. let sum = 0;
  186. this.add_form.receiptRequisitionAccountDate.forEach(item => {
  187. sum = this.$NP.plus(sum, Number(item.preferentialAmount) || 0);
  188. });
  189. return sum;
  190. }
  191. },
  192. // 实收总额
  193. totalActualAmount() {
  194. if (!this.add_form.receiptRequisitionAccountDate.length) {
  195. return 0;
  196. } else if (this.add_form.receiptRequisitionAccountDate.length === 1) {
  197. return Number(this.add_form.receiptRequisitionAccountDate[0].actualAmount);
  198. } else {
  199. let sum = 0;
  200. this.add_form.receiptRequisitionAccountDate.forEach(item => {
  201. sum = this.$NP.plus(sum, Number(item.actualAmount) || 0);
  202. });
  203. return sum;
  204. }
  205. }
  206. },
  207. watch: {
  208. customerData(val) {
  209. if (val) {
  210. this.add_form.customerId = val.id;
  211. this.add_form.customerName = val.name;
  212. this.add_form.receivable = val.money;
  213. }
  214. },
  215. // 店铺
  216. shopData(val) {
  217. if (val) {
  218. this.add_form.shopName = val.name;
  219. this.add_form.shopId = val.id;
  220. }
  221. },
  222. AccountData(val) {
  223. if (val) {
  224. console.log(val);
  225. this.add_form.receiptRequisitionAccountDate[this.index].accountId = val.id
  226. this.add_form.receiptRequisitionAccountDate[this.index].accountName = val.name
  227. }
  228. }
  229. },
  230. onLoad(options) {
  231. if (options.id) {
  232. this.account_id = options.id;
  233. uni.setNavigationBarTitle({
  234. title: '编辑收款申请单'
  235. });
  236. this.getReceiptRequisitionInfo();
  237. } else {
  238. this.add_form.operatorId = this.userInfo.userCenterId;
  239. this.add_form.operatorName = this.userInfo.name;
  240. }
  241. },
  242. methods: {
  243. // 详情
  244. getReceiptRequisitionInfo() {
  245. this.$u.api.getReceiptRequisitionInfo(this.account_id).then(({
  246. data
  247. }) => {
  248. this.add_form = {
  249. customerId: data.customerId,
  250. customerName: data.customerName,
  251. operatorId: data.operatorId,
  252. operatorName: data.operatorName,
  253. receivable: data.receivable,
  254. receiptRequisitionAccountDate: data.accountList.map(item => {
  255. return {
  256. ...item,
  257. settlementMethod: item.settlementMethod
  258. };
  259. })
  260. };
  261. });
  262. },
  263. openMethods(index) {
  264. this.methods_show = true;
  265. this.account_index = index;
  266. },
  267. methodsConfirm(arr) {
  268. this.add_form.receiptRequisitionAccountDate[this.account_index].settlementMethod = arr[0].value;
  269. },
  270. addAccount() {
  271. this.add_form.receiptRequisitionAccountDate.push({
  272. collectionAmount: '',
  273. preferentialAmount: '',
  274. actualAmount: '',
  275. settlementMethod: '',
  276. remark: ''
  277. });
  278. },
  279. delAccount(index) {
  280. if (this.add_form.receiptRequisitionAccountDate.length === 1) {
  281. this.$u.toast('至少保留一条');
  282. return;
  283. }
  284. this.add_form.receiptRequisitionAccountDate.splice(index, 1);
  285. },
  286. moneyChange(index) {
  287. const target = this.$u.deepClone(this.add_form.receiptRequisitionAccountDate);
  288. //优惠金额不能大于收款金额
  289. if (Number(target[index].preferentialAmount) > Number(target[index].collectionAmount)) {
  290. target[index].preferentialAmount = Number(target[index].collectionAmount);
  291. }
  292. let collectionAmount = target[index].collectionAmount;
  293. let preferentialAmount = target[index].preferentialAmount;
  294. target[index].actualAmount = this.$NP.minus(collectionAmount, preferentialAmount);
  295. this.add_form.receiptRequisitionAccountDate = target;
  296. },
  297. // 添加
  298. submit() {
  299. this.$refs.uForm.validate(valid => {
  300. if (valid) {
  301. const params = {
  302. ...this.add_form,
  303. totalCollectionAmount: this.totalCollectionAmount,
  304. totalPreferentialAmount: this.totalPreferentialAmount,
  305. totalActualAmount: this.totalActualAmount
  306. };
  307. let isSub = true;
  308. for (let i in this.add_form.receiptRequisitionAccountDate) {
  309. let item = this.add_form.receiptRequisitionAccountDate[i];
  310. if (!item.collectionAmount) {
  311. isSub = false;
  312. this.$u.toast('请输入收款金额');
  313. break;
  314. }
  315. if (!item.settlementMethod) {
  316. isSub = false;
  317. this.$u.toast('请选择结算方式');
  318. break;
  319. }
  320. if(!item.accountId) {
  321. isSub = false;
  322. this.$u.toast('请选择结算账户');
  323. break;
  324. }
  325. }
  326. if (!isSub) {
  327. return;
  328. }
  329. if (this.account_id) {
  330. this.$u.api.editReceiptRequisition(this.account_id, params).then(res => {
  331. this.$u.toast('修改成功');
  332. setTimeout(() => {
  333. uni.navigateBack();
  334. }, 1500);
  335. });
  336. } else {
  337. this.$u.api.addReceiptRequisition(params).then(res => {
  338. this.$u.toast('新增成功');
  339. setTimeout(() => {
  340. uni.navigateBack();
  341. }, 1500);
  342. });
  343. }
  344. }
  345. });
  346. },
  347. settlementAccount(index) {
  348. if (!this.add_form.shopId) {
  349. this.$u.toast('必须先选择商铺');
  350. return
  351. }
  352. this.goPage('/pagesT/account/selAccount')
  353. this.index = index
  354. },
  355. delsettlementAccount() {
  356. this.add_form.receiptRequisitionAccountDate[this.index].accountId = "";
  357. this.add_form.receiptRequisitionAccountDate[this.index].accountName = "";
  358. }
  359. },
  360. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  361. onReady() {
  362. this.$refs.uForm.setRules(this.rules);
  363. }
  364. };
  365. </script>
  366. <style lang="scss" scoped>
  367. .detail-ul {
  368. .detail-li {
  369. padding-left: 60rpx;
  370. position: relative;
  371. border-bottom: 1px solid #eeeeee;
  372. &:last-child {
  373. border-bottom: 0 none;
  374. }
  375. .del-icon {
  376. position: absolute;
  377. top: 50%;
  378. left: 0;
  379. transform: translateY(-50%);
  380. }
  381. .title {
  382. line-height: 80rpx;
  383. }
  384. .money-ul {
  385. border-top: 1px solid #eeeeee;
  386. padding: 20rpx 0;
  387. display: flex;
  388. .money-li {
  389. flex: 3;
  390. border-right: 1px solid #eeeeee;
  391. input {
  392. height: 80rpx;
  393. line-height: 80rpx;
  394. text-align: center;
  395. }
  396. &:last-child {
  397. border-right: 0 none;
  398. }
  399. }
  400. }
  401. .bottom {
  402. border-top: 1px solid #eeeeee;
  403. input {
  404. height: 80rpx;
  405. line-height: 80rpx;
  406. }
  407. }
  408. }
  409. }
  410. </style>