electricityBillPro.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. define({
  2. template: `
  3. <div>
  4. <el-form ref="auth">
  5. <div class="vue-main-title">
  6. <div class="vue-main-title-left"></div>
  7. <div class="vue-main-title-content">电费充值</div>
  8. </div>
  9. <div style="margin:0 auto;width:80%;">
  10. <el-form-item label="电费充值">
  11. <el-radio v-model="form.electricity_bill_pro_goods.is_open" :label="1">开启</el-radio>
  12. <el-radio v-model="form.electricity_bill_pro_goods.is_open" :label="0">关闭</el-radio>
  13. <div class="form-item_tips">首次发布商品,先点击发布商品,再重新编辑商品,设置电费充值规格!</div>
  14. </el-form-item >
  15. <el-form-item label="电费充值">
  16. <el-table :data="list" :span-method="objectSpanMethod" border>
  17. <el-table-column prop="charge_type" label="类型">
  18. <template slot-scope="scope">[[scope.row.charge_type == "0" ? '国网' : '南网']]</template>
  19. </el-table-column>
  20. <el-table-column prop="spec_value" label="面值"></el-table-column>
  21. <el-table-column prop="status" label="状态">
  22. <template slot-scope="scope">
  23. <el-switch v-model="scope.row.status" :active-value="1" :inactive-value="0"></el-switch>
  24. </template>
  25. </el-table-column>
  26. <el-table-column prop="bingbird_goods_id" label="商品ID">
  27. <template slot-scope="scope">
  28. <el-input v-model="scope.row.bingbird_goods_id" @change="changeGoodsID(scope.$index,scope.row,$event)"></el-input>
  29. </template>
  30. </el-table-column>
  31. </el-table>
  32. </el-form-item >
  33. <el-form-item label="自定义文案" label-width="113px">
  34. <template slot-scope="scope">
  35. <el-input v-model="form.electricity_bill_pro_goods.desc" type="textarea" style="padding-right:10px"></el-input>
  36. </template>
  37. </el-form-item>
  38. <el-form-item label="顶部banner图片" label-width="113px">
  39. <el-input v-model="form.electricity_bill_pro_goods.banner" style="width: 60%;">
  40. <template slot="append"><span @click="displaySelectMaterialPopup('thumb')">选择图片</span></template>
  41. </el-input>
  42. </el-form-item>
  43. <el-form-item label=" " label-width="113px">
  44. <div style="position: relative;" v-if="form.electricity_bill_pro_goods.banner">
  45. <img :src="form.electricity_bill_pro_goods.banner" style="width: 150px; height: 150px; border-radius: 5px; cursor: pointer;object-fit:cover;" />
  46. <i class="el-icon-close" style="position: absolute;margin-left: 10px;" @click="btnDelete"></i>
  47. </div>
  48. <div style="position: relative;" v-else>
  49. <!-- <img src="" style="width: 150px; height: 150px; border-radius: 5px; cursor: pointer;object-fit:cover;" />-->
  50. <!-- <i class="el-icon-close" style="position: absolute;margin-left: 10px;" @click="btnDelete"></i>-->
  51. </div>
  52. <div class="form-item_tips">建议尺寸: 640 * 640 ,或正方型图片</div>
  53. </el-form-item>
  54. </div>
  55. </el-form>
  56. <upload-multimedia-img
  57. :upload-show="showSelectMaterialPopup"
  58. :type="materialType"
  59. :name="formFieldName"
  60. selNum="one"
  61. @replace="showSelectMaterialPopup = !showSelectMaterialPopup"
  62. @sure="selectedMaterial"
  63. ></upload-multimedia-img>
  64. </div>
  65. `,
  66. style: `
  67. .moreCol .el-table thead{
  68. display:none
  69. }
  70. .moreCol .el-table--border, .el-table--group{
  71. border: none;
  72. }
  73. .el-table .cell{
  74. padding-right:0 !important;
  75. }
  76. .el-table th > .cell {
  77. text-align: center;
  78. }
  79. .el-table .cell {
  80. text-align: center;
  81. }
  82. `,
  83. props: {
  84. form: {
  85. default() {
  86. return {};
  87. },
  88. },
  89. formKey: {
  90. type: String,
  91. },
  92. },
  93. delimiters: ['[[', ']]'],
  94. data() {
  95. return {
  96. showSelectMaterialPopup: false,
  97. materialType: "1",
  98. formFieldName: "",
  99. list: [],
  100. typeList:[],
  101. }
  102. },
  103. created() {
  104. if(this.form.options.length == 0){
  105. this.list = []
  106. return
  107. }
  108. this.list = this.form.options;
  109. this.objectSpanMethod = this.getRowspanMethod(this.list, ['charge_type']);
  110. for(let item of this.form.options){
  111. this.typeList.push(item.spec);
  112. }
  113. },
  114. methods: {
  115. validate() {
  116. return {
  117. desc:this.form.electricity_bill_pro_goods.desc,
  118. status:this.form.electricity_bill_pro_goods.is_open,
  119. banner:this.form.electricity_bill_pro_goods.banner,
  120. options:this.form.options
  121. }
  122. },
  123. displaySelectMaterialPopup(fieldName = "thumb", type = 1) {
  124. this.formFieldName = fieldName;
  125. this.showSelectMaterialPopup = !this.showSelectMaterialPopup;
  126. this.materialType = String(type);
  127. },
  128. selectedMaterial(name, image, imageUrl) {
  129. this.form.electricity_bill_pro_goods.banner = imageUrl[0].url
  130. },
  131. btnDelete(){
  132. this.form.electricity_bill_pro_goods.banner = ""
  133. },
  134. getRowspanMethod(data, rowspanArray) {
  135. // 要合并列的数据
  136. const rowspanNumObject = {};
  137. //初始化 rowspanNumObject
  138. rowspanArray.map(item => {
  139. rowspanNumObject[item] = new Array(data.length).fill(1, 0, 1).fill(0, 1);
  140. rowspanNumObject[`${item}-index`] = 0;
  141. });
  142. //计算相关的合并信息
  143. for (let i = 1; i < data.length; i++) {
  144. rowspanArray.map(key => {
  145. const index = rowspanNumObject[`${key}-index`];
  146. if (data[i][key] === data[i - 1][key]) {
  147. rowspanNumObject[key][index]++;
  148. } else {
  149. rowspanNumObject[`${key}-index`] = i;
  150. rowspanNumObject[key][i] = 1;
  151. }
  152. });
  153. }
  154. //提供合并的方法并导出
  155. const spanMethod = function({ row, column, rowIndex, columnIndex }) {
  156. if (rowspanArray.includes(column['property'])) {
  157. const rowspan = rowspanNumObject[column['property']][rowIndex];
  158. if (rowspan > 0) {
  159. return { rowspan: rowspan, colspan: 1 }
  160. }
  161. return { rowspan: 0, colspan: 0 }
  162. }
  163. return { rowspan: 1, colspan: 1 }
  164. };
  165. return spanMethod;
  166. },
  167. },
  168. });