goodsExt.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <div class="goodsExt">
  3. <div class="inline-left">
  4. <p style="width:70px;margin-left:40px">商品类型</p>
  5. <el-select
  6. size="mini"
  7. v-model="extType"
  8. :disabled="enterType == 'detail'"
  9. placeholder="请选择"
  10. @change="changeType"
  11. >
  12. <el-option
  13. v-for="item in extList"
  14. :key="item.id"
  15. :label="item.name"
  16. :value="item.id"
  17. >
  18. </el-option>
  19. </el-select>
  20. </div>
  21. <el-form size="mini" label-width="100px" v-if="extType == 2">
  22. <el-form-item label="规格明细" v-if="tableData.length > 0">
  23. <table border="1">
  24. <tr>
  25. <th v-for="(item, index) in Attr" :key="index">
  26. {{ item.name }}
  27. </th>
  28. <th><span>*</span> 选择音频</th>
  29. </tr>
  30. <tr v-for="(item, index) in tableData" :key="index">
  31. <td v-for="(item1, index1) in item.attr" :key="index1">
  32. {{ item1 }}
  33. </td>
  34. <td class="upImg">
  35. <el-select
  36. size="mini"
  37. :disabled="enterType == 'detail'"
  38. v-model="typeList[index]"
  39. placeholder="请选择"
  40. >
  41. <el-option
  42. v-for="item2 in mediaList"
  43. :key="item2.pack_id"
  44. :label="item2.name"
  45. :value="item2.pack_id"
  46. >
  47. </el-option>
  48. </el-select>
  49. <!-- <img :src="item.pic" class="mainImg" />
  50. <input
  51. type="file"
  52. class="file"
  53. :name="index"
  54. @change="changeImg"
  55. /> -->
  56. </td>
  57. </tr>
  58. </table>
  59. </el-form-item>
  60. </el-form>
  61. </div>
  62. </template>
  63. <script type="text/ecmascript-6">
  64. import { mapGetters } from 'vuex';
  65. export default {
  66. name: 'goodsExt',
  67. props: {
  68. enterType: {
  69. type: String,
  70. default: 'edit'
  71. },
  72. goodsId: {
  73. type: String
  74. },
  75. Info: {
  76. type: Object
  77. }
  78. },
  79. data() {
  80. return {
  81. extList: [
  82. {
  83. name: '其它商品',
  84. id: '0'
  85. },
  86. {
  87. name: '视频课程',
  88. id: '1'
  89. },
  90. {
  91. name: '音频课程',
  92. id: '2'
  93. },
  94. {
  95. name: '课程周边',
  96. id: '3'
  97. }
  98. ],
  99. tableData: [],
  100. typeList: [],
  101. mediaInfo: {},
  102. inputSize: 'mini',
  103. extType: '0',
  104. baseRules: {},
  105. mediaList: [],
  106. Attr: [],
  107. roleList: [], // 身份列表
  108. isInit: true
  109. };
  110. },
  111. computed: {
  112. ...mapGetters(['attrTable', 'tableHead']),
  113. attrTable1() {
  114. return this.attrTable;
  115. },
  116. tableHead1() {
  117. return this.tableHead;
  118. }
  119. },
  120. async created() {
  121. this.tableData = this.attrTable;
  122. this.Attr = this.tableHead;
  123. this.getMediaList();
  124. },
  125. mounted() {},
  126. methods: {
  127. changeType(val) {
  128. this.extType = val;
  129. this.$emit('changeType', val);
  130. },
  131. getMediaList() {
  132. this.httpPost(this.$root.mediaList).then(
  133. res => {
  134. this.mediaList = res.list;
  135. this.loading = false;
  136. },
  137. () => {
  138. this.loading = false;
  139. }
  140. );
  141. }
  142. },
  143. watch: {
  144. Info: {
  145. handler(val) {
  146. // 编辑
  147. if (!this.isInit) {
  148. return false;
  149. }
  150. console.log(22222, val);
  151. this.mediaInfo = JSON.parse(JSON.stringify(val));
  152. this.extType = this.mediaInfo.goods_type;
  153. this.tableData = this.mediaInfo.media_info;
  154. this.typeList = this.mediaInfo.media_info.map(
  155. item => item.pack_id
  156. );
  157. },
  158. deep: true
  159. },
  160. attrTable1: {
  161. handler(val) {
  162. this.tableData = val;
  163. },
  164. deep: true
  165. },
  166. tableHead1: {
  167. handler(val) {
  168. console.log(444444, val);
  169. this.Attr = val;
  170. },
  171. deep: true
  172. },
  173. typeList: {
  174. handler(val) {
  175. // 选择音频时向父组件传递
  176. let media = [];
  177. let list = this.typeList.slice(0);
  178. this.tableData.forEach((item, i) => {
  179. media.push({
  180. attr: item.attr,
  181. pack_id: list[i]
  182. });
  183. });
  184. this.$emit('editMedia', media);
  185. },
  186. deep: true
  187. }
  188. }
  189. };
  190. </script>
  191. <style lang="stylus" rel="stylesheet/stylus" scoped>
  192. @import '~assets/main.styl';
  193. .el-input {
  194. width: 100px !important;
  195. }
  196. .basic {
  197. width: 100%;
  198. height: 30px;
  199. background: bk;
  200. border-radius(3px);
  201. padding: 0 15px;
  202. overflow: hidden;
  203. h1 {
  204. word(14px);
  205. font-weight: bold;
  206. line-height: 30px;
  207. }
  208. }
  209. .upImg {
  210. position: relative;
  211. .mainImg {
  212. width: 60px;
  213. height: 60px;
  214. margin-top: 10px;
  215. }
  216. input {
  217. width: 60px;
  218. height: 60px;
  219. opacity: 0;
  220. position: absolute;
  221. left: 20px;
  222. top: 10px;
  223. }
  224. }
  225. table {
  226. border: 1px solid border-color;
  227. width: 100%;
  228. tr {
  229. height: 40px;
  230. line-height: 40px;
  231. text-align: left;
  232. }
  233. th {
  234. span {
  235. color: red;
  236. }
  237. font-weight: normal;
  238. color: gray3;
  239. padding-left: 20px;
  240. }
  241. td {
  242. padding-left: 20px;
  243. bor-top();
  244. bor-bottom();
  245. color: gray9;
  246. width: 80px;
  247. }
  248. }
  249. .el-form {
  250. margin-top: 10px;
  251. padding-left: 20px;
  252. }
  253. .el-input {
  254. width: 300px;
  255. }
  256. .el-button {
  257. margin-left: 10px;
  258. margin-bottom: 10px;
  259. }
  260. </style>