billPush-detail.vue 21 KB

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