billPush-detail.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. <template>
  2. <el-dialog
  3. :visible.sync="showDialog"
  4. :title="title"
  5. width="95%"
  6. :modal-append-to-body="true"
  7. style="text-align:left;"
  8. @close="closeDialog"
  9. append-to-body
  10. :close-on-click-modal="false"
  11. >
  12. <div class="user-panel" v-loading="loading">
  13. <el-form ref="form" :model="formModel" :rules="ruleValidate" :inline="true" class="demo-form-inline" label-width="120px">
  14. <el-form-item label="账单名称:" prop="name">
  15. <el-input v-model="formModel.name" placeholder="请输入账单名称" class="input-form-main"></el-input>
  16. </el-form-item>
  17. <el-form-item label="收款方:" prop="payee">
  18. <el-input v-model="formModel.payee" placeholder="请输入收款方" class="input-form-main"></el-input>
  19. </el-form-item>
  20. <el-form-item label="收款账户:" prop="collectionAccountId">
  21. <!-- <el-input v-model="formModel.collectionAccountId" style="display:none"></el-input>
  22. <el-input v-model="formModel.collectionAccountName" placeholder="请输入收款方" class="input-form-main" readonly="readonly"></el-input> -->
  23. <el-select v-model="formModel.collectionAccountId" class="input-form-main" >
  24. <el-option
  25. v-for="collectionAccount in collectionAccountList"
  26. :key="collectionAccount.id"
  27. :label="collectionAccount.name"
  28. :value="collectionAccount.id"
  29. ></el-option>
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item label="缴费单位:" prop="checkinInfoId">
  33. <el-select v-model="formModel.checkinInfoId" filterable class="input-form-main" @change="handleCompanyChange">
  34. <el-option
  35. v-for="checkinInfo in companyList"
  36. :key="checkinInfo.id"
  37. :label="checkinInfo.companyName"
  38. :value="checkinInfo.id"
  39. ></el-option>
  40. </el-select>
  41. </el-form-item>
  42. <el-form-item label="推送用户:" prop="personName" >
  43. <!--
  44. <el-input v-model="formModel.personId" style="display:none"></el-input>
  45. -->
  46. <el-input v-model="formModel.personName" class="input-form-main"></el-input>
  47. <!-- <el-select v-model="formModel.personId" class="input-form-main" filterable>
  48. <el-option
  49. v-for="person in personList"
  50. :key="person.id"
  51. :label="person.name"
  52. :value="person.id"
  53. ></el-option>
  54. </el-select> -->
  55. </el-form-item>
  56. <el-form-item label="备注:" prop="bak">
  57. <el-input type="textarea" v-model="formModel.bak" placeholder="请输入备注" class="input-form-main"></el-input>
  58. </el-form-item>
  59. <el-form-item label="开票类型:" prop="invoiceType">
  60. <el-select v-model="formModel.invoiceType" filterable class="input-form-main">
  61. <el-option
  62. v-for="company in invoiceTypeList"
  63. :key="company.value"
  64. :label="company.name"
  65. :value="company.value"
  66. ></el-option>
  67. </el-select>
  68. </el-form-item>
  69. <el-form-item label="微信支付:" prop="isOpenWechat" v-if="formModel.isMobilePayment">
  70. <el-switch
  71. v-model="formModel.isOpenWechat"
  72. active-color="#13ce66"
  73. inactive-color="#ff4949"
  74. @change="handlChange(row)">
  75. </el-switch>
  76. </el-form-item>
  77. <el-form-item label="支付宝支付:" prop="isOpenAlipay" v-if="formModel.isMobilePayment">
  78. <el-switch
  79. v-model="formModel.isOpenAlipay"
  80. active-color="#13ce66"
  81. inactive-color="#ff4949"
  82. @change="handlChange(row)">
  83. </el-switch>
  84. </el-form-item>
  85. <h3>账单信息</h3>
  86. <el-table
  87. class="compact-table"
  88. :data="formModel.billPushGoodsList"
  89. show-summary :summary-method="getSummaries">
  90. <el-table-column prop="sort" type="index" label="序号" width="50"></el-table-column>
  91. <el-table-column prop="goodsId" label="收费项目" width="150">
  92. <template slot-scope="scope">
  93. <el-form-item
  94. :prop="'billPushGoodsList.' + scope.$index + '.goodsId'"
  95. :rules="ruleValidate['goodsId']"
  96. >
  97. <el-select
  98. v-model="scope.row.goodsId"
  99. placeholder="请选择"
  100. @change="handGoodsChange(scope)" size="mini">
  101. <el-option
  102. v-for="result in goodsList"
  103. :key="result.id"
  104. :label="result.goodsName"
  105. :value="result.id"
  106. ></el-option>
  107. </el-select>
  108. </el-form-item>
  109. </template>
  110. </el-table-column>
  111. <el-table-column prop="beginEndTime" label="起止时间" width="380">
  112. <template slot-scope="scope">
  113. <el-form-item
  114. :prop="'billPushGoodsList.' + scope.$index + '.beginEndTime'"
  115. :rules="ruleValidate['beginEndTime']"
  116. >
  117. <el-date-picker
  118. v-model="scope.row.beginEndTime"
  119. type="daterange"
  120. range-separator="至"
  121. start-placeholder="开始时间"
  122. end-placeholder="结束时间"
  123. placeholder="选择时间范围"
  124. value-format="yyyy-MM-dd"
  125. size="mini"
  126. >
  127. </el-date-picker>
  128. </el-form-item>
  129. </template>
  130. </el-table-column>
  131. <el-table-column prop="numStr" label="数量" width="310">
  132. <template slot-scope="scope">
  133. <el-form-item
  134. :prop="'billPushGoodsList.' + scope.$index + '.numStr3'"
  135. :rules="ruleValidate['numStr3']"
  136. >
  137. <template v-if="scope.row.goodTypeId=='7'">
  138. <el-input style="width:85px" placeholder="止码" v-model.number="scope.row.numStr2" @change="handStartChange(scope)" size="mini"></el-input>
  139. -<el-input style="width:85px" placeholder="起码" v-model.number="scope.row.numStr" @change="handStartChange(scope)" size="mini"></el-input>
  140. =<el-input style="width:85px" v-model.number="scope.row.numStr3" @change="handNumChange(scope)" size="mini"></el-input>
  141. </template>
  142. <template v-else>
  143. <el-input placeholder="数量" v-model.number="scope.row.numStr3" @change="handNumChange(scope)" size="mini"></el-input>
  144. </template>
  145. </el-form-item>
  146. </template>
  147. </el-table-column>
  148. <el-table-column prop="standard" label="收费标准" width="200">
  149. <template slot-scope="scope">
  150. <el-form-item
  151. :prop="'billPushGoodsList.' + scope.$index + '.unitPrice'"
  152. :rules="ruleValidate['unitPrice']"
  153. size="mini"
  154. >
  155. <el-input placeholder="收费标准" v-model="scope.row.unitPrice" @change="handNumChange(scope)" size="mini">
  156. <template slot="append">{{scope.row.unit}}</template>
  157. </el-input>
  158. </el-form-item>
  159. </template>
  160. </el-table-column>
  161. <el-table-column prop="totalFee" label="合计金额(元)">
  162. <template slot-scope="scope">
  163. <el-form-item
  164. :prop="'billPushGoodsList.' + scope.$index + '.totalFee'"
  165. :rules="ruleValidate['totalFee']" size="mini"
  166. >
  167. <el-input placeholder="合计金额" :value="scope.row.totalFee" readonly="readonly" size="mini">
  168. </el-input>
  169. </el-form-item>
  170. </template>
  171. </el-table-column>
  172. <el-table-column label="操作" width="100" fixed="right">
  173. <template slot-scope="{row}">
  174. <el-form-item>
  175. <i class="el-icon-delete my-font" @click="handleDelete(row)"></i>
  176. <i class="el-icon-document-add my-font" @click="handleInsert(row)"></i>
  177. </el-form-item>
  178. </template>
  179. </el-table-column>
  180. <div slot="empty">
  181. <el-button icon="el-icon-circle-plus-outline" :plain="true" @click="handleAdd()">新增</el-button>
  182. </div>
  183. </el-table>
  184. </el-form>
  185. <div class="el-table__empty-block" v-if="formModel.billPushGoodsList.length!=0">
  186. <el-button icon="el-icon-circle-plus-outline" @click="handleAdd()">新增</el-button>
  187. </div>
  188. </div>
  189. <span slot="footer" class="dialog-footer">
  190. <el-button @click="closeDialog">取 消</el-button>
  191. <el-button type="primary" @click="handleSubmit" :loading="submitting">保存</el-button>
  192. </span>
  193. </el-dialog>
  194. </template>
  195. <script>
  196. import Constant from "@/constant";
  197. import billPushApi from "@/api/business/billPush";
  198. import companyInfoApi from "@/api/base/companyInfo";
  199. import companyPaymentApi from "@/api/base/companyPayment";
  200. import companyGoodsInfoApi from "@/api/base/companyGoodsInfo";
  201. import personInfoApi from "@/api/base/personInfo";
  202. export default {
  203. props: ["businessKey", "title"],
  204. data() {
  205. return {
  206. ruleValidate: {
  207. name: [{ required: true, message: "账单名称不能为空", trigger: "blur" }],
  208. checkinInfoId: [{ required: true, message: "缴费单位不能为空", trigger: "blur" }],
  209. // payService: [{ required: true, message: "收费项目不能为空", trigger: "blur" }],
  210. invoiceType: [{ required: true, message: "开票类型不能为空", trigger: "blur" }],
  211. personName: [{ required: true, message: "推送用户不能为空", trigger: "blur" }],
  212. beginEndTime:[{ required: true, message: "起止时间不能为空", trigger: "blur" }],
  213. numStr3:[{ required: true, message: "数量不能为空", trigger: "blur" }],
  214. goodsId:[{ required: true, message: "收费项目未选择", trigger: "blur" }]
  215. },
  216. formModel: {
  217. name:"",
  218. payee:"",
  219. companyId:"",
  220. // payService:"",
  221. collectionAccountId:"",
  222. collectionAccountName:"",
  223. bak:"",
  224. billPushGoodsList:[],
  225. removeBillPushGoodsList:[],
  226. personId:0,
  227. personName:"",
  228. checkinInfoId:"",
  229. isOpenWechat:false,
  230. isOpenAlipay:false,
  231. },
  232. beginEndTime: null,
  233. personList:[],
  234. goodsList:[],
  235. collectionAccountList:[],
  236. payServiceList:[],
  237. tableData:[],
  238. companyList:[],
  239. invoiceTypeList:[],
  240. showDialog: true,
  241. loading: false,
  242. submitting: false,
  243. props: {
  244. // 配置项(必选)
  245. value: "id",
  246. label: "name",
  247. children: "children"
  248. },
  249. }
  250. },
  251. created() {
  252. companyPaymentApi.getCompanyList().then((response)=>{
  253. var jsonData = response.data;
  254. this.companyList = jsonData.data;
  255. });
  256. companyPaymentApi.list().then((response)=>{
  257. var jsonData = response.data;
  258. this.collectionAccountList = jsonData.data;
  259. });
  260. billPushApi.invoiceTypeList().then((response)=>{
  261. var jsonData = response.data;
  262. this.invoiceTypeList = jsonData.data;
  263. });
  264. },
  265. methods: {
  266. closeDialog() {
  267. this.$emit("close", false);
  268. },
  269. handleCompanyChange(newVal){
  270. // this.formModel.personName = newVal;
  271. var self = this;
  272. var formData = new FormData();
  273. formData.append("checkinInfoId", newVal);
  274. companyGoodsInfoApi.findByCheckinInfoId(formData).then((response)=>{
  275. var jsonData = response.data;
  276. this.goodsList = jsonData.data;
  277. });
  278. companyPaymentApi.findByCheckInId(formData).then((response)=>{
  279. var jsonData = response.data;
  280. this.formModel.personId = jsonData.data.id;
  281. this.formModel.checkinInfoId = jsonData.data.checkinInfoId;
  282. self.$set(self.formModel, 'personName', jsonData.data.name);
  283. });
  284. },
  285. handleSubmit() {
  286. var self = this;
  287. this.$refs["form"].validate(valid => {
  288. if (valid) {
  289. //增加转型,避免直接修改formModel
  290. var requestData = JSON.parse(JSON.stringify(self.formModel));
  291. var billPushGoodsList = requestData.billPushGoodsList;
  292. if(billPushGoodsList.length==0) {
  293. this.$message.warning("收费项目不能为空!");
  294. return;
  295. }
  296. for(var i=0;i<billPushGoodsList.length;i++){
  297. billPushGoodsList[i].sortNo = i+1;
  298. if(billPushGoodsList[i].beginEndTime!=null){
  299. billPushGoodsList[i].beginDate = billPushGoodsList[i].beginEndTime[0];
  300. billPushGoodsList[i].endDate = billPushGoodsList[i].beginEndTime[1]
  301. billPushGoodsList[i].beginEndTime=null;
  302. }
  303. billPushGoodsList[i].standard = billPushGoodsList[i].unitPrice + billPushGoodsList[i].unit;
  304. }
  305. var removeBillPushGoodsList = requestData.removeBillPushGoodsList;
  306. for(var j=0;j<removeBillPushGoodsList.length;j++){
  307. removeBillPushGoodsList[j].sortNo = j+1;
  308. if(removeBillPushGoodsList[j].beginEndTime!=null){
  309. removeBillPushGoodsList[j].beginDate = removeBillPushGoodsList[j].beginEndTime[0];
  310. removeBillPushGoodsList[j].endDate = removeBillPushGoodsList[j].beginEndTime[1];
  311. removeBillPushGoodsList[j].beginEndTime=null;
  312. }
  313. }
  314. (function() {
  315. var id = requestData.id;
  316. if (id == null || id.length == 0) {
  317. return billPushApi.add(requestData);
  318. } else {
  319. return billPushApi.update(requestData);
  320. }
  321. })().then(function(response) {
  322. var jsonData = response.data;
  323. if (jsonData.result) {
  324. self.$message({
  325. message: "保存成功!",
  326. type: "success"
  327. });
  328. self.$emit("close", true);
  329. } else {
  330. self.$message({
  331. message: jsonData.message + "",
  332. type: "warning"
  333. });
  334. self.$emit("close", false);
  335. }
  336. });
  337. }
  338. });
  339. },
  340. handleAdd() {
  341. this.formModel.billPushGoodsList.push({
  342. sortNo: this.formModel.billPushGoodsList.length + 1,
  343. goodsId: "",
  344. beginEndTime: null,
  345. numStr: "",
  346. numStr2: "",
  347. numStr3: "",
  348. totalFee: "",
  349. standard: "",
  350. unit: ""
  351. });
  352. },
  353. handleInsert(row) {
  354. var billPushGoodsList = this.formModel.billPushGoodsList;
  355. var index = billPushGoodsList.indexOf(row);
  356. if(index>=0){
  357. billPushGoodsList.splice(index+1,0,{
  358. sortNo: index + 2,
  359. goodsId: "",
  360. beginEndTime: null,
  361. numStr: "",
  362. numStr2: "",
  363. numStr3: "",
  364. totalFee: "",
  365. standard: "",
  366. unit: ""
  367. });
  368. }
  369. },
  370. handleDelete(row) {
  371. var billPushGoodsList = this.formModel.billPushGoodsList;
  372. billPushGoodsList.splice(billPushGoodsList.indexOf(row), 1);
  373. this.formModel.removeBillPushGoodsList.push(row);
  374. },
  375. getSummaries(param) {
  376. const { columns, data } = param;
  377. const sums = [];
  378. columns.forEach((column, index) => {
  379. if (index === 0) {
  380. sums[index] = '合计';
  381. return;
  382. }
  383. const values = data.map(item => Number(item[column.property]));
  384. if (!values.every(value => isNaN(value))) {
  385. sums[5] = values.reduce((prev, curr) => {
  386. const value = Number(curr);
  387. if (!isNaN(value)) {
  388. return prev + curr;
  389. } else {
  390. return prev;
  391. }
  392. }, 0);
  393. sums[5] = this.fmtMoney(sums[5]);
  394. } else {
  395. sums[index] = '';
  396. }
  397. });
  398. return sums;
  399. },
  400. fmtMoney(value){
  401. const num = Number(value);
  402. if (!isNaN(num)) {
  403. return num.toFixed(2);
  404. }
  405. else{
  406. return num;
  407. }
  408. },
  409. handGoodsChange(scope){
  410. var row = scope.row;
  411. // setTimeout(()=>{
  412. var formData = new FormData();
  413. formData.append("id", row.goodsId);
  414. formData.append("companyId", this.formModel.companyId);
  415. companyPaymentApi.loadDetails(formData).then((response)=>{
  416. var jsonData = response.data;
  417. if(jsonData.result){
  418. var data = jsonData.data;
  419. // row.standard = data.unitPriceStr;
  420. // row.unit = data.unitPrice;
  421. // row.goodTypeId = data.goodType;
  422. this.$set(row,"standard",data.unitPriceStr);
  423. this.$set(row,"unit",data.unit);
  424. this.$set(row,"unitPrice",data.unitPrice);
  425. this.$set(row,"goodTypeId",data.goodType);
  426. //如果是电费会返回起码
  427. this.$set(row,"numStr", data.numStr);
  428. }
  429. });
  430. // },100);
  431. },
  432. handNumChange(scope){
  433. var row = scope.row;
  434. var num = row.numStr3;
  435. var unitPrice = row.unitPrice;
  436. var totalFee = num*1*unitPrice*1;
  437. if(totalFee!=null){
  438. this.formModel.billPushGoodsList[scope.$index].totalFee = totalFee.toFixed(2);
  439. }
  440. },
  441. handStartChange(scope){
  442. var row = scope.row;
  443. var num1=row.numStr;
  444. var num2=row.numStr2;
  445. var unitPrice = row.unitPrice;
  446. setTimeout(()=>{
  447. if(num1!=null&&num2!=null){
  448. var num3 = num2-num1;
  449. this.formModel.billPushGoodsList[scope.$index].numStr3 = num3;
  450. var totalFee = num3*1*unitPrice*1;
  451. if(totalFee!=null){
  452. this.formModel.billPushGoodsList[scope.$index].totalFee = totalFee.toFixed(2);
  453. }
  454. }
  455. },100);
  456. }
  457. },
  458. mounted: function() {
  459. var self = this;
  460. (function() {
  461. if (self.businessKey.length == 0) {
  462. return billPushApi.create();
  463. } else {
  464. return billPushApi.edit(self.businessKey);
  465. }
  466. })()
  467. .then(response => {
  468. var jsonData = response.data;
  469. self.loading = false;
  470. if (jsonData.result) {
  471. self.formModel = jsonData.data;
  472. var billPushGoodsList = self.formModel.billPushGoodsList;
  473. for(var i=0;i<billPushGoodsList.length;i++){
  474. var beginEndTime = [];
  475. beginEndTime.push(billPushGoodsList[i].beginDate);
  476. beginEndTime.push(billPushGoodsList[i].endDate);
  477. billPushGoodsList[i].beginEndTime = beginEndTime;
  478. }
  479. if(jsonData.data.checkinInfoId!=null&&jsonData.data!=""){
  480. this.handleCompanyChange(jsonData.data.checkinInfoId);
  481. }
  482. } else {
  483. self.$message.error(jsonData.message + "");
  484. }
  485. })
  486. .catch(error => {
  487. self.$message.error(error + "");
  488. });
  489. }
  490. }
  491. </script>
  492. <style rel="stylesheet/scss" lang="scss" scoped>
  493. .input-form-main{
  494. width: 300px;
  495. }
  496. .link-span{
  497. margin-right: 20px;
  498. }
  499. .el-form-item{
  500. margin-bottom: 25px;
  501. }
  502. .my-font {
  503. font-size: 20px;
  504. cursor: pointer;
  505. margin-right: 10px;
  506. }
  507. .user-panel {
  508. margin: 10px auto;
  509. }
  510. .compact-table{
  511. .el-form-item {
  512. margin-bottom: 5px;
  513. }
  514. }
  515. </style>