device-param-101280.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. function PackageComponent(option) {
  2. var _el = option.el;
  3. var _rule = option.policy.rule;
  4. var _money = option.policy.money;
  5. var _auto_stop = option.policy.auto_stop;
  6. var _type = option.policy.type;
  7. var app = this.app = new Vue({
  8. el: _el,
  9. template: `
  10. <div>
  11. <h5 class="mui-content-padded">离线卡配置</h5>
  12. <div class="edit-box" action="">
  13. <div class="mui-input-row">
  14. <label class="">离线卡刷卡金额 </label>
  15. <div class="mui-pull-right edit-row">
  16. <input type="number" min=0 max=50 step="0.01" v-model.number="info.money" class="save-data padding-r-35">
  17. <span class="mini-unit">元</span>
  18. </div>
  19. </div>
  20. <div class="mui-input-row mui-checkbox" v-if="info.type==='time'">
  21. <label>充满自动停止
  22. <input type="checkbox" v-model="info.auto_stop">
  23. </label>
  24. </div>
  25. </div>
  26. <h5 class="mui-content-padded">离线卡计费规则</h5>
  27. <div class="mui-input-group">
  28. <div class="mui-input-row mui-radio">
  29. <label for="type1">1. 按时间计费</label>
  30. <input id="type1" v-model="info.type" name="type" value="time" type="radio">
  31. </div>
  32. <template v-if="info.type==='time'">
  33. <ul class="mui-table-view" style="background: #F6F6F6">
  34. <li class="mui-table-view-cell table" v-for="(item, index) in info.rule.prices">
  35. <div class="inline-block">
  36. {{ powerRadio(item, index, info.rule.prices) }},{{ item.price }} 元/小时
  37. </div>
  38. <span class="mui-pull-right">
  39. <em v-on:click.stop="editPackageRule(item,index)" class="padding-t-b-10"><i
  40. class="iconfont icon-edit c-primary"></i>编辑</em>
  41. <em v-on:click.stop="deletePackageRule(item,index)" class="padding-t-b-10"><i
  42. class="iconfont icon-delete c-red"></i>删除</em></span>
  43. </li>
  44. <div class="mui-table-view-cell" v-on:click.stop="addPolicyRule()"><span><i
  45. class="iconfont icon-add c-success font-18"></i>添加</span></div>
  46. </ul>
  47. </template>
  48. </div>
  49. <div class="mui-input-group">
  50. <div class="mui-input-row mui-radio">
  51. <label for="type2">2. 按电量计费</label>
  52. <input id="type2" v-model="info.type" name="type" value="elec" type="radio">
  53. </div>
  54. <template v-if="info.type==='elec'">
  55. <ul class="mui-table-view edit-box" style="background: #F6F6F6">
  56. <li>
  57. <div class="mui-input-row">
  58. <label class="">电量单价 </label>
  59. <div class="mui-pull-right edit-row">
  60. <input type="number" max="5000" step="0.01" min="0" v-model.number="info.rule.price"
  61. class="save-data padding-r-35">
  62. <span class="mini-unit">元/度</span>
  63. </div>
  64. </div>
  65. </li>
  66. </ul>
  67. </template>
  68. </div>
  69. <div class="mui-input-group" v-if="false">
  70. <div class="mui-input-row mui-radio">
  71. <label for="type3">3. 按次计费</label>
  72. <input id="type3" v-model="info.type" name="type" value="count" type="radio">
  73. </div>
  74. <template v-if="info.type==='count'">
  75. <ul class="mui-table-view edit-box" style="background: #F6F6F6">
  76. <li>
  77. <div class="mui-input-row">
  78. <label class="">单次最大电量 </label>
  79. <div class="mui-pull-right edit-row">
  80. <input type="number" max="5000" step="0.01" min="0" v-model.number="info.rule.elec"
  81. class="save-data padding-r-35">
  82. <span class="mini-unit">度</span>
  83. </div>
  84. </div>
  85. </li>
  86. <li>
  87. <div class="mui-input-row">
  88. <label class="">单次最大时长 </label>
  89. <div class="mui-pull-right edit-row">
  90. <input type="number" max="5000" step="0.01" min="0" v-model.number="info.rule.time"
  91. class="save-data padding-r-35">
  92. <span class="mini-unit">分钟</span>
  93. </div>
  94. </div>
  95. </li>
  96. </ul>
  97. </template>
  98. </div>
  99. <div class="edit-back packageDialog" v-if="info.dialogOpen">
  100. <div class="edit-content">
  101. <div class="edit-box ">
  102. <template v-if="info.type=='time'">
  103. <div class="mui-input-row">
  104. <label>功率</label>
  105. <div class="mui-pull-right edit-row">
  106. <input type="number" min="0.00" step="0.01" maxlength="9" v-model.number="info.dialogData.power"
  107. />
  108. <span>瓦</span>
  109. </div>
  110. </div>
  111. <div class="mui-input-row ">
  112. <label>费用</label>
  113. <div class="mui-pull-right edit-row">
  114. <input type="number" min="0.00" step="0.01" maxlength="9" v-model.number="info.dialogData.price"
  115. />
  116. <span>元/小时</span>
  117. </div>
  118. </div>
  119. </template>
  120. <template v-if="info.type=='elec'">
  121. <div class="mui-input-row">
  122. <label>价格</label>
  123. <div class="mui-pull-right edit-row">
  124. <input type="number" min="0.00" step="0.01" maxlength="9" disabled value="1"
  125. />
  126. <span>元</span>
  127. </div>
  128. </div>
  129. <div class="mui-input-row ">
  130. <label>电量</label>
  131. <div class="mui-pull-right edit-row">
  132. <input type="number" min="0.00" step="0.01" maxlength="9" v-model.number="info.dialogData.elec"
  133. />
  134. <span>度</span>
  135. </div>
  136. </div>
  137. </template>
  138. </div>
  139. <div class="mui-popup-buttons ">
  140. <span class="mui-popup-button" v-on:click.stop="closeRulePanel()">取消</span>
  141. <span class="mui-popup-button mui-popup-button-bold" v-on:click.stop="savePackageRule()">确认</span>
  142. </div>
  143. </div>
  144. </div>
  145. </div>
  146. `
  147. ,
  148. data: {
  149. info: {
  150. type: 'time',
  151. dialogIndex: 0,
  152. dialogOpen: false,
  153. dialogData: {},
  154. rule: {
  155. prices:[],
  156. },
  157. money: 0,
  158. auto_stop: false,
  159. },
  160. },
  161. mounted: function () {
  162. var that = this
  163. that.initPackages();
  164. },
  165. computed: {},
  166. filters: {},
  167. methods: {
  168. save_obj() {
  169. if (this.info.type === 'time') {
  170. delete this.info.rule.price
  171. } else if (this.info.type === 'elec') {
  172. delete this.info.rule.prices
  173. delete this.info.rule.time
  174. } else if (this.info.type === 'count') {
  175. this.info.type = 'elec'
  176. delete this.info.rule.prices
  177. }
  178. console.log('this.info.type111', this.info.type)
  179. console.log('this.info', this.info)
  180. },
  181. initPackages: function () {
  182. this.info.type = _type;
  183. this.info.auto_stop = _auto_stop;
  184. this.info.money = _money;
  185. this.info.rule = _rule;
  186. },
  187. getDefaultPolicyDialog() {
  188. return {
  189. "power": '',
  190. "price": ''
  191. }
  192. },
  193. addPolicyRule() {
  194. this.info.dialogIndex = (this.info.rule.prices || []).length;
  195. this.info.dialogOpen = true;
  196. $("body").addClass("over-hide");
  197. this.info.dialogData = this.getDefaultPolicyDialog();
  198. },
  199. editPackageRule: function (obj, index) {
  200. this.info.dialogIndex = index;
  201. this.info.dialogOpen = true;
  202. this.info.dialogData = $.extend(true, {}, obj);
  203. $("body").addClass("over-hide");//避免滚动穿透,直接禁止body滚动
  204. },
  205. deletePackageRule: function (obj, index) {
  206. var that = this;
  207. var info = that.info
  208. var packages = info.rule.prices
  209. if (info.type === 'elec') {
  210. if (packages.length <= 1) {
  211. mui.toast("必须有一条配置");
  212. return
  213. }
  214. }
  215. info.rule.prices.splice(index, 1);
  216. },
  217. closeRulePanel: function () {
  218. this.info.dialogOpen = false;
  219. $("body").removeClass("over-hide");//恢复body滚动
  220. },
  221. savePackageRule: function () {
  222. var that = this;
  223. var info = that.info
  224. var dialogData = info.dialogData;
  225. var packages
  226. if (info.type == 'time') {
  227. packages = this.info.rule.prices || []
  228. }
  229. if (info.type === 'time') {
  230. if ($.trim(dialogData.power) === '') {
  231. mui.toast("功率不能为空");
  232. return;
  233. }
  234. if (!dialogData.price) {
  235. mui.toast("价格不能为空");
  236. return;
  237. }
  238. }
  239. if (info.type === 'elec') {
  240. if ($.trim(dialogData.power) === '') {
  241. mui.toast("功率不能为空");
  242. return;
  243. }
  244. if (!dialogData.price) {
  245. mui.toast("价格不能为空");
  246. return;
  247. }
  248. }
  249. if (info.chrmt === 'ELEC') {
  250. if (!dialogData.elec) {
  251. mui.toast("电量不能为空");
  252. return;
  253. }
  254. }
  255. console.log('info.dialogIndex', info.dialogIndex)
  256. console.log('packages', packages)
  257. packages[info.dialogIndex] = $.extend(true, {}, info.dialogData);
  258. this.info.rule.prices = packages
  259. info.dialogOpen = false;
  260. $("body").removeClass("over-hide");//恢复body滚动
  261. },
  262. addPackageRule: function () {
  263. var that = this;
  264. var info = that.info
  265. var key = 'package_' + info.chrmt.toLowerCase()
  266. var packages = info[key]
  267. if (key === 'package_elec') {
  268. if (packages.length >= 1) {
  269. mui.toast("只能有一条配置");
  270. return
  271. }
  272. }
  273. info.dialogIndex = packages.length;
  274. info.dialogOpen = true;
  275. $("body").addClass("over-hide");//避免滚动穿透,直接禁止body滚动
  276. if (info.chrmt === 'TIME') {
  277. info.dialogData = {
  278. power: "",
  279. time: "",
  280. };
  281. }
  282. if (info.chrmt === 'ELEC') {
  283. info.dialogData = {
  284. price: "1",
  285. elec: "",
  286. };
  287. }
  288. if (info.chrmt === 'POWER') {
  289. info.dialogData = {
  290. power: "",
  291. time: "",
  292. };
  293. }
  294. },
  295. powerRadio(item, index, obj) {
  296. return ((obj[index - 1] && obj[index - 1].power) || 0) + "W-" + item.power + "W"
  297. },
  298. }
  299. });
  300. }
  301. PackageComponent.prototype.getPolicyTemp = function () {
  302. return {
  303. "money": this.app.info.money,
  304. "type": this.app.info.type,
  305. "rule": this.app.info.rule,
  306. "auto_stop": this.app.info.auto_stop
  307. }
  308. };
  309. function VolumeComponent(option) {
  310. var _el = option.el;
  311. var _packages = option.packages;
  312. var _volume = option.volume;
  313. var app = this.app = new Vue({
  314. el: _el,
  315. template: `
  316. <div >
  317. <div class="mui-input-group">
  318. <div class="mui-input-row">
  319. <label class="">默认语音音量</label>
  320. <div class="mui-pull-right ">
  321. <input type="number" class="mui-text-right padding-r-35" maxlength="1" min=0 max=7 required placeholder="音量" v-model.number="info.volume"/>
  322. </div>
  323. </div>
  324. <div class="mui-table-view-cell" v-for="(obj,index) in info.packages">
  325. <span>时间{{obj.start}}-{{obj.end}},</span>
  326. <span>音量{{obj.volume}}</span>
  327. <span class="mui-pull-right">
  328. <em v-on:click.stop="editPackageRule(obj,index)" class="padding-t-b-10"><i class="iconfont icon-edit c-primary"></i>编辑</em>
  329. <em v-on:click.stop="deletePackageRule(obj,index)" class="padding-t-b-10"><i class="iconfont icon-delete c-red"></i>删除</em></span>
  330. </div>
  331. <div class="mui-table-view-cell"
  332. v-on:click.stop="addPackageRule()"><span><i class="iconfont icon-add c-success font-18"></i>添加</span></div>
  333. </div>
  334. <div class="edit-back packageDialog" v-if="info.dialogOpen">
  335. <div class="edit-content">
  336. <div class="edit-box ">
  337. <div class="mui-input-row">
  338. <label>开始时间</label>
  339. <div class="mui-pull-right edit-row">
  340. <input type="time" v-model="info.dialogData.start"
  341. />
  342. </div>
  343. </div>
  344. <div class="mui-input-row">
  345. <label>结束时间</label>
  346. <div class="mui-pull-right edit-row">
  347. <input type="time" v-model="info.dialogData.end"
  348. />
  349. </div>
  350. </div>
  351. <div class="mui-input-row ">
  352. <label>音量</label>
  353. <div class="mui-pull-right edit-row">
  354. <input type="number" maxlength="4" min=0 max=7 v-model.number="info.dialogData.volume"/>
  355. </div>
  356. </div>
  357. </div>
  358. <div class="mui-popup-buttons ">
  359. <span class="mui-popup-button" v-on:click.stop="closeRulePanel()">取消</span>
  360. <span class="mui-popup-button mui-popup-button-bold" v-on:click.stop="savePackageRule()">确认</span>
  361. </div>
  362. </div>
  363. </div>
  364. </div>
  365. `
  366. ,
  367. data: {
  368. info: {
  369. dialogIndex: 0,
  370. dialogOpen: false,
  371. dialogData: {},
  372. volume: 1,
  373. packages: []
  374. },
  375. },
  376. mounted: function () {
  377. var that = this
  378. that.initPackages();
  379. },
  380. computed: {},
  381. filters: {},
  382. methods: {
  383. initPackages: function () {
  384. this.info.packages = _packages;
  385. this.info.volume = _volume;
  386. },
  387. editPackageRule: function (obj, index) {
  388. this.info.dialogIndex = index;
  389. this.info.dialogOpen = true;
  390. this.info.dialogData = $.extend(true, {}, obj);
  391. $("body").addClass("over-hide");//避免滚动穿透,直接禁止body滚动
  392. },
  393. deletePackageRule: function (obj, index) {
  394. var that = this;
  395. that.info.packages.splice(index, 1);
  396. },
  397. closeRulePanel: function () {
  398. this.info.dialogOpen = false;
  399. $("body").removeClass("over-hide");//恢复body滚动
  400. },
  401. savePackageRule: function () {
  402. var dialogData = this.info.dialogData;
  403. if ($.trim(dialogData.start) === '') {
  404. mui.toast("开始时间不能为空");
  405. return;
  406. }
  407. if ($.trim(dialogData.end) === '') {
  408. mui.toast("结束时间不能为空");
  409. return;
  410. }
  411. if (dialogData.volume === '') {
  412. mui.toast("音量不能为空");
  413. return;
  414. }
  415. this.info.packages[this.info.dialogIndex] = $.extend(true, {}, this.info.dialogData);
  416. this.info.dialogOpen = false;
  417. $("body").removeClass("over-hide");//恢复body滚动
  418. },
  419. addPackageRule: function () {
  420. this.info.dialogIndex = this.info.packages.length;
  421. this.info.dialogOpen = true;
  422. $("body").addClass("over-hide");//避免滚动穿透,直接禁止body滚动
  423. this.info.dialogData = {
  424. start: "",
  425. end: "",
  426. volume: "",
  427. };
  428. },
  429. }
  430. });
  431. }
  432. VolumeComponent.prototype.getVolumeList = function () {
  433. return this.app.info.packages;
  434. };
  435. VolumeComponent.prototype.getDefaultVolume = function () {
  436. return this.app.info.volume;
  437. };